blob: d0b65b29abf37d75c23d329fef246ac60749c83e [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===------------------------ functional ----------------------------------===//
3//
Howard Hinnantc566dc32010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantc51e1022010-05-11 19:42:16 +00005//
Howard Hinnantee11c312010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantc51e1022010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_FUNCTIONAL
12#define _LIBCPP_FUNCTIONAL
13
14/*
15 functional synopsis
16
17namespace std
18{
19
20template <class Arg, class Result>
21struct unary_function
22{
23 typedef Arg argument_type;
24 typedef Result result_type;
25};
26
27template <class Arg1, class Arg2, class Result>
28struct binary_function
29{
30 typedef Arg1 first_argument_type;
31 typedef Arg2 second_argument_type;
32 typedef Result result_type;
33};
34
Howard Hinnantf06d9262010-08-20 19:36:46 +000035template <class T>
Howard Hinnantc51e1022010-05-11 19:42:16 +000036class reference_wrapper
37 : public unary_function<T1, R> // if wrapping a unary functor
38 : public binary_function<T1, T2, R> // if wraping a binary functor
39{
40public:
41 // types
42 typedef T type;
43 typedef see below result_type; // Not always defined
44
45 // construct/copy/destroy
Howard Hinnantf7724cd2011-05-28 17:59:48 +000046 reference_wrapper(T&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000047 reference_wrapper(T&&) = delete; // do not bind to temps
Howard Hinnantf7724cd2011-05-28 17:59:48 +000048 reference_wrapper(const reference_wrapper<T>& x) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000049
50 // assignment
Howard Hinnantf7724cd2011-05-28 17:59:48 +000051 reference_wrapper& operator=(const reference_wrapper<T>& x) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000052
53 // access
Howard Hinnantf7724cd2011-05-28 17:59:48 +000054 operator T& () const noexcept;
55 T& get() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000056
57 // invoke
58 template <class... ArgTypes>
Howard Hinnantc9c775b2013-09-21 17:58:58 +000059 typename result_of<T&(ArgTypes&&...)>::type
Howard Hinnantc51e1022010-05-11 19:42:16 +000060 operator() (ArgTypes&&...) const;
61};
62
Howard Hinnantf7724cd2011-05-28 17:59:48 +000063template <class T> reference_wrapper<T> ref(T& t) noexcept;
Howard Hinnantf06d9262010-08-20 19:36:46 +000064template <class T> void ref(const T&& t) = delete;
Howard Hinnantf7724cd2011-05-28 17:59:48 +000065template <class T> reference_wrapper<T> ref(reference_wrapper<T>t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000066
Howard Hinnantf7724cd2011-05-28 17:59:48 +000067template <class T> reference_wrapper<const T> cref(const T& t) noexcept;
Howard Hinnantf06d9262010-08-20 19:36:46 +000068template <class T> void cref(const T&& t) = delete;
Howard Hinnantf7724cd2011-05-28 17:59:48 +000069template <class T> reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000070
Marshall Clow974bae22013-07-29 14:21:53 +000071template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000072struct plus : binary_function<T, T, T>
73{
74 T operator()(const T& x, const T& y) const;
75};
76
Marshall Clow974bae22013-07-29 14:21:53 +000077template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000078struct minus : binary_function<T, T, T>
79{
80 T operator()(const T& x, const T& y) const;
81};
82
Marshall Clow974bae22013-07-29 14:21:53 +000083template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000084struct multiplies : binary_function<T, T, T>
85{
86 T operator()(const T& x, const T& y) const;
87};
88
Marshall Clow974bae22013-07-29 14:21:53 +000089template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000090struct divides : binary_function<T, T, T>
91{
92 T operator()(const T& x, const T& y) const;
93};
94
Marshall Clow974bae22013-07-29 14:21:53 +000095template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000096struct modulus : binary_function<T, T, T>
97{
98 T operator()(const T& x, const T& y) const;
99};
100
Marshall Clow974bae22013-07-29 14:21:53 +0000101template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000102struct negate : unary_function<T, T>
103{
104 T operator()(const T& x) const;
105};
106
Marshall Clow974bae22013-07-29 14:21:53 +0000107template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000108struct equal_to : binary_function<T, T, bool>
109{
110 bool operator()(const T& x, const T& y) const;
111};
112
Marshall Clow974bae22013-07-29 14:21:53 +0000113template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000114struct not_equal_to : binary_function<T, T, bool>
115{
116 bool operator()(const T& x, const T& y) const;
117};
118
Marshall Clow974bae22013-07-29 14:21:53 +0000119template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000120struct greater : binary_function<T, T, bool>
121{
122 bool operator()(const T& x, const T& y) const;
123};
124
Marshall Clow974bae22013-07-29 14:21:53 +0000125template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000126struct less : binary_function<T, T, bool>
127{
128 bool operator()(const T& x, const T& y) const;
129};
130
Marshall Clow974bae22013-07-29 14:21:53 +0000131template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000132struct greater_equal : binary_function<T, T, bool>
133{
134 bool operator()(const T& x, const T& y) const;
135};
136
Marshall Clow974bae22013-07-29 14:21:53 +0000137template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000138struct less_equal : binary_function<T, T, bool>
139{
140 bool operator()(const T& x, const T& y) const;
141};
142
Marshall Clow974bae22013-07-29 14:21:53 +0000143template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000144struct logical_and : binary_function<T, T, bool>
145{
146 bool operator()(const T& x, const T& y) const;
147};
148
Marshall Clow974bae22013-07-29 14:21:53 +0000149template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000150struct logical_or : binary_function<T, T, bool>
151{
152 bool operator()(const T& x, const T& y) const;
153};
154
Marshall Clow974bae22013-07-29 14:21:53 +0000155template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000156struct logical_not : unary_function<T, bool>
157{
158 bool operator()(const T& x) const;
159};
160
Marshall Clow974bae22013-07-29 14:21:53 +0000161template <class T> // <class T=void> in C++14
162struct bit_and : unary_function<T, bool>
163{
164 bool operator()(const T& x, const T& y) const;
165};
166
167template <class T> // <class T=void> in C++14
168struct bit_or : unary_function<T, bool>
169{
170 bool operator()(const T& x, const T& y) const;
171};
172
173template <class T> // <class T=void> in C++14
174struct bit_xor : unary_function<T, bool>
175{
176 bool operator()(const T& x, const T& y) const;
177};
178
179template <class T=void> // C++14
180struct bit_xor : unary_function<T, bool>
181{
182 bool operator()(const T& x) const;
183};
184
Howard Hinnantc51e1022010-05-11 19:42:16 +0000185template <class Predicate>
186class unary_negate
187 : public unary_function<typename Predicate::argument_type, bool>
188{
189public:
190 explicit unary_negate(const Predicate& pred);
191 bool operator()(const typename Predicate::argument_type& x) const;
192};
193
194template <class Predicate> unary_negate<Predicate> not1(const Predicate& pred);
195
196template <class Predicate>
197class binary_negate
198 : public binary_function<typename Predicate::first_argument_type,
199 typename Predicate::second_argument_type,
200 bool>
201{
202public:
203 explicit binary_negate(const Predicate& pred);
204 bool operator()(const typename Predicate::first_argument_type& x,
205 const typename Predicate::second_argument_type& y) const;
206};
207
208template <class Predicate> binary_negate<Predicate> not2(const Predicate& pred);
209
Eric Fiselier934f63b2016-06-02 01:25:41 +0000210template <class F> unspecified not_fn(F&& f); // C++17
211
Howard Hinnantc51e1022010-05-11 19:42:16 +0000212template<class T> struct is_bind_expression;
213template<class T> struct is_placeholder;
214
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000215template<class Fn, class... BoundArgs>
Howard Hinnantf06d9262010-08-20 19:36:46 +0000216 unspecified bind(Fn&&, BoundArgs&&...);
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000217template<class R, class Fn, class... BoundArgs>
Howard Hinnantf06d9262010-08-20 19:36:46 +0000218 unspecified bind(Fn&&, BoundArgs&&...);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000219
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000220namespace placeholders {
221 // M is the implementation-defined number of placeholders
Howard Hinnantc51e1022010-05-11 19:42:16 +0000222 extern unspecified _1;
223 extern unspecified _2;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000224 .
225 .
226 .
Howard Hinnantc834c512011-11-29 18:15:50 +0000227 extern unspecified _Mp;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000228}
229
230template <class Operation>
231class binder1st
232 : public unary_function<typename Operation::second_argument_type,
233 typename Operation::result_type>
234{
235protected:
236 Operation op;
237 typename Operation::first_argument_type value;
238public:
239 binder1st(const Operation& x, const typename Operation::first_argument_type y);
240 typename Operation::result_type operator()( typename Operation::second_argument_type& x) const;
241 typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const;
242};
243
244template <class Operation, class T>
245binder1st<Operation> bind1st(const Operation& op, const T& x);
246
247template <class Operation>
248class binder2nd
249 : public unary_function<typename Operation::first_argument_type,
250 typename Operation::result_type>
251{
252protected:
253 Operation op;
254 typename Operation::second_argument_type value;
255public:
256 binder2nd(const Operation& x, const typename Operation::second_argument_type y);
257 typename Operation::result_type operator()( typename Operation::first_argument_type& x) const;
258 typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const;
259};
260
261template <class Operation, class T>
262binder2nd<Operation> bind2nd(const Operation& op, const T& x);
263
264template <class Arg, class Result>
265class pointer_to_unary_function : public unary_function<Arg, Result>
266{
267public:
268 explicit pointer_to_unary_function(Result (*f)(Arg));
269 Result operator()(Arg x) const;
270};
271
272template <class Arg, class Result>
273pointer_to_unary_function<Arg,Result> ptr_fun(Result (*f)(Arg));
274
275template <class Arg1, class Arg2, class Result>
276class pointer_to_binary_function : public binary_function<Arg1, Arg2, Result>
277{
278public:
279 explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2));
280 Result operator()(Arg1 x, Arg2 y) const;
281};
282
283template <class Arg1, class Arg2, class Result>
284pointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1,Arg2));
285
286template<class S, class T>
287class mem_fun_t : public unary_function<T*, S>
288{
289public:
290 explicit mem_fun_t(S (T::*p)());
291 S operator()(T* p) const;
292};
293
294template<class S, class T, class A>
295class mem_fun1_t : public binary_function<T*, A, S>
296{
297public:
298 explicit mem_fun1_t(S (T::*p)(A));
299 S operator()(T* p, A x) const;
300};
301
302template<class S, class T> mem_fun_t<S,T> mem_fun(S (T::*f)());
303template<class S, class T, class A> mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A));
304
305template<class S, class T>
306class mem_fun_ref_t : public unary_function<T, S>
307{
308public:
309 explicit mem_fun_ref_t(S (T::*p)());
310 S operator()(T& p) const;
311};
312
313template<class S, class T, class A>
314class mem_fun1_ref_t : public binary_function<T, A, S>
315{
316public:
317 explicit mem_fun1_ref_t(S (T::*p)(A));
318 S operator()(T& p, A x) const;
319};
320
321template<class S, class T> mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)());
322template<class S, class T, class A> mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A));
323
324template <class S, class T>
325class const_mem_fun_t : public unary_function<const T*, S>
326{
327public:
328 explicit const_mem_fun_t(S (T::*p)() const);
329 S operator()(const T* p) const;
330};
331
332template <class S, class T, class A>
333class const_mem_fun1_t : public binary_function<const T*, A, S>
334{
335public:
336 explicit const_mem_fun1_t(S (T::*p)(A) const);
337 S operator()(const T* p, A x) const;
338};
339
340template <class S, class T> const_mem_fun_t<S,T> mem_fun(S (T::*f)() const);
341template <class S, class T, class A> const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const);
342
343template <class S, class T>
344class const_mem_fun_ref_t : public unary_function<T, S>
345{
346public:
347 explicit const_mem_fun_ref_t(S (T::*p)() const);
348 S operator()(const T& p) const;
349};
350
351template <class S, class T, class A>
352class const_mem_fun1_ref_t : public binary_function<T, A, S>
353{
354public:
355 explicit const_mem_fun1_ref_t(S (T::*p)(A) const);
356 S operator()(const T& p, A x) const;
357};
358
359template <class S, class T> const_mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)() const);
360template <class S, class T, class A> const_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const);
361
Howard Hinnantf06d9262010-08-20 19:36:46 +0000362template<class R, class T> unspecified mem_fn(R T::*);
Howard Hinnantf06d9262010-08-20 19:36:46 +0000363
Howard Hinnantc51e1022010-05-11 19:42:16 +0000364class bad_function_call
365 : public exception
366{
367};
368
Howard Hinnantf06d9262010-08-20 19:36:46 +0000369template<class> class function; // undefined
Howard Hinnantc51e1022010-05-11 19:42:16 +0000370
Howard Hinnantf06d9262010-08-20 19:36:46 +0000371template<class R, class... ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000372class function<R(ArgTypes...)>
373 : public unary_function<T1, R> // iff sizeof...(ArgTypes) == 1 and
374 // ArgTypes contains T1
375 : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and
376 // ArgTypes contains T1 and T2
377{
378public:
379 typedef R result_type;
380
Howard Hinnantf06d9262010-08-20 19:36:46 +0000381 // construct/copy/destroy:
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000382 function() noexcept;
383 function(nullptr_t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000384 function(const function&);
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000385 function(function&&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000386 template<class F>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000387 function(F);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000388 template<Allocator Alloc>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000389 function(allocator_arg_t, const Alloc&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000390 template<Allocator Alloc>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000391 function(allocator_arg_t, const Alloc&, nullptr_t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000392 template<Allocator Alloc>
393 function(allocator_arg_t, const Alloc&, const function&);
394 template<Allocator Alloc>
395 function(allocator_arg_t, const Alloc&, function&&);
396 template<class F, Allocator Alloc>
397 function(allocator_arg_t, const Alloc&, F);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000398
399 function& operator=(const function&);
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000400 function& operator=(function&&) noexcept;
Howard Hinnant7b85be02011-05-29 13:53:56 +0000401 function& operator=(nullptr_t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000402 template<class F>
Howard Hinnantf06d9262010-08-20 19:36:46 +0000403 function& operator=(F&&);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000404 template<class F>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000405 function& operator=(reference_wrapper<F>) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000406
407 ~function();
408
Howard Hinnantf06d9262010-08-20 19:36:46 +0000409 // function modifiers:
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000410 void swap(function&) noexcept;
Howard Hinnantf06d9262010-08-20 19:36:46 +0000411 template<class F, class Alloc>
Marshall Clowfc8fd832016-01-25 17:29:55 +0000412 void assign(F&&, const Alloc&); // Removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000413
Howard Hinnantf06d9262010-08-20 19:36:46 +0000414 // function capacity:
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000415 explicit operator bool() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000416
Howard Hinnantf06d9262010-08-20 19:36:46 +0000417 // function invocation:
Howard Hinnantc51e1022010-05-11 19:42:16 +0000418 R operator()(ArgTypes...) const;
419
Howard Hinnantf06d9262010-08-20 19:36:46 +0000420 // function target access:
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000421 const std::type_info& target_type() const noexcept;
422 template <typename T> T* target() noexcept;
423 template <typename T> const T* target() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000424};
425
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000426// Null pointer comparisons:
427template <class R, class ... ArgTypes>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000428 bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000429
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000430template <class R, class ... ArgTypes>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000431 bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000432
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000433template <class R, class ... ArgTypes>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000434 bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000435
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000436template <class R, class ... ArgTypes>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000437 bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000438
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000439// specialized algorithms:
440template <class R, class ... ArgTypes>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000441 void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000442
443template <class T> struct hash;
444
445template <> struct hash<bool>;
446template <> struct hash<char>;
447template <> struct hash<signed char>;
448template <> struct hash<unsigned char>;
449template <> struct hash<char16_t>;
450template <> struct hash<char32_t>;
451template <> struct hash<wchar_t>;
452template <> struct hash<short>;
453template <> struct hash<unsigned short>;
454template <> struct hash<int>;
455template <> struct hash<unsigned int>;
456template <> struct hash<long>;
457template <> struct hash<long long>;
458template <> struct hash<unsigned long>;
459template <> struct hash<unsigned long long>;
460
461template <> struct hash<float>;
462template <> struct hash<double>;
463template <> struct hash<long double>;
464
465template<class T> struct hash<T*>;
466
467} // std
468
469POLICY: For non-variadic implementations, the number of arguments is limited
470 to 3. It is hoped that the need for non-variadic implementations
471 will be minimal.
472
473*/
474
475#include <__config>
476#include <type_traits>
477#include <typeinfo>
478#include <exception>
479#include <memory>
480#include <tuple>
481
482#include <__functional_base>
483
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000484#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000485#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000486#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000487
488_LIBCPP_BEGIN_NAMESPACE_STD
489
Marshall Clow974bae22013-07-29 14:21:53 +0000490#if _LIBCPP_STD_VER > 11
491template <class _Tp = void>
492#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000493template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000494#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000495struct _LIBCPP_TYPE_VIS_ONLY plus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000496{
Marshall Clowd18ee652013-09-28 19:06:12 +0000497 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
498 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000499 {return __x + __y;}
500};
501
Marshall Clow974bae22013-07-29 14:21:53 +0000502#if _LIBCPP_STD_VER > 11
503template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000504struct _LIBCPP_TYPE_VIS_ONLY plus<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000505{
506 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000507 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
508 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000509 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
510 -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
511 { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000512 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000513};
514#endif
515
516
517#if _LIBCPP_STD_VER > 11
518template <class _Tp = void>
519#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000520template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000521#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000522struct _LIBCPP_TYPE_VIS_ONLY minus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000523{
Marshall Clowd18ee652013-09-28 19:06:12 +0000524 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
525 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000526 {return __x - __y;}
527};
528
Marshall Clow974bae22013-07-29 14:21:53 +0000529#if _LIBCPP_STD_VER > 11
530template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000531struct _LIBCPP_TYPE_VIS_ONLY minus<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000532{
533 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000534 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
535 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000536 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u)))
537 -> decltype (_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u))
538 { return _VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000539 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000540};
541#endif
542
543
544#if _LIBCPP_STD_VER > 11
545template <class _Tp = void>
546#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000547template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000548#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000549struct _LIBCPP_TYPE_VIS_ONLY multiplies : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000550{
Marshall Clowd18ee652013-09-28 19:06:12 +0000551 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
552 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000553 {return __x * __y;}
554};
555
Marshall Clow974bae22013-07-29 14:21:53 +0000556#if _LIBCPP_STD_VER > 11
557template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000558struct _LIBCPP_TYPE_VIS_ONLY multiplies<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000559{
560 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000561 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
562 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000563 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u)))
564 -> decltype (_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u))
565 { return _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000566 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000567};
568#endif
569
570
571#if _LIBCPP_STD_VER > 11
572template <class _Tp = void>
573#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000574template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000575#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000576struct _LIBCPP_TYPE_VIS_ONLY divides : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000577{
Marshall Clowd18ee652013-09-28 19:06:12 +0000578 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
579 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000580 {return __x / __y;}
581};
582
Marshall Clow974bae22013-07-29 14:21:53 +0000583#if _LIBCPP_STD_VER > 11
584template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000585struct _LIBCPP_TYPE_VIS_ONLY divides<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000586{
587 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000588 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
589 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000590 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u)))
591 -> decltype (_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u))
592 { return _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000593 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000594};
595#endif
596
597
598#if _LIBCPP_STD_VER > 11
599template <class _Tp = void>
600#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000601template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000602#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000603struct _LIBCPP_TYPE_VIS_ONLY modulus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000604{
Marshall Clowd18ee652013-09-28 19:06:12 +0000605 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
606 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000607 {return __x % __y;}
608};
609
Marshall Clow974bae22013-07-29 14:21:53 +0000610#if _LIBCPP_STD_VER > 11
611template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000612struct _LIBCPP_TYPE_VIS_ONLY modulus<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000613{
614 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000615 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
616 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000617 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u)))
618 -> decltype (_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u))
619 { return _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000620 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000621};
622#endif
623
624
625#if _LIBCPP_STD_VER > 11
626template <class _Tp = void>
627#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000628template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000629#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000630struct _LIBCPP_TYPE_VIS_ONLY negate : unary_function<_Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000631{
Marshall Clowd18ee652013-09-28 19:06:12 +0000632 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
633 _Tp operator()(const _Tp& __x) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000634 {return -__x;}
635};
636
Marshall Clow974bae22013-07-29 14:21:53 +0000637#if _LIBCPP_STD_VER > 11
638template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000639struct _LIBCPP_TYPE_VIS_ONLY negate<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000640{
641 template <class _Tp>
Marshall Clowd18ee652013-09-28 19:06:12 +0000642 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
643 auto operator()(_Tp&& __x) const
Marshall Clow012ca342015-02-25 12:20:52 +0000644 _NOEXCEPT_(noexcept(- _VSTD::forward<_Tp>(__x)))
645 -> decltype (- _VSTD::forward<_Tp>(__x))
646 { return - _VSTD::forward<_Tp>(__x); }
Marshall Clowc0152142013-08-13 01:11:06 +0000647 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000648};
649#endif
650
651
652#if _LIBCPP_STD_VER > 11
653template <class _Tp = void>
654#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000655template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000656#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000657struct _LIBCPP_TYPE_VIS_ONLY equal_to : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000658{
Marshall Clowd18ee652013-09-28 19:06:12 +0000659 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
660 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000661 {return __x == __y;}
662};
663
Marshall Clow974bae22013-07-29 14:21:53 +0000664#if _LIBCPP_STD_VER > 11
665template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000666struct _LIBCPP_TYPE_VIS_ONLY equal_to<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000667{
Marshall Clowd18ee652013-09-28 19:06:12 +0000668 template <class _T1, class _T2>
669 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000670 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000671 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u)))
672 -> decltype (_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u))
673 { return _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000674 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000675};
676#endif
677
678
679#if _LIBCPP_STD_VER > 11
680template <class _Tp = void>
681#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000682template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000683#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000684struct _LIBCPP_TYPE_VIS_ONLY not_equal_to : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000685{
Marshall Clowd18ee652013-09-28 19:06:12 +0000686 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
687 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000688 {return __x != __y;}
689};
690
Marshall Clow974bae22013-07-29 14:21:53 +0000691#if _LIBCPP_STD_VER > 11
692template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000693struct _LIBCPP_TYPE_VIS_ONLY not_equal_to<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000694{
Marshall Clowd18ee652013-09-28 19:06:12 +0000695 template <class _T1, class _T2>
696 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000697 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000698 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u)))
699 -> decltype (_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u))
700 { return _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000701 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000702};
703#endif
704
705
706#if _LIBCPP_STD_VER > 11
707template <class _Tp = void>
708#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000709template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000710#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000711struct _LIBCPP_TYPE_VIS_ONLY greater : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000712{
Marshall Clowd18ee652013-09-28 19:06:12 +0000713 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
714 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000715 {return __x > __y;}
716};
717
Marshall Clow974bae22013-07-29 14:21:53 +0000718#if _LIBCPP_STD_VER > 11
719template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000720struct _LIBCPP_TYPE_VIS_ONLY greater<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000721{
Marshall Clowd18ee652013-09-28 19:06:12 +0000722 template <class _T1, class _T2>
723 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000724 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000725 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u)))
726 -> decltype (_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u))
727 { return _VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000728 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000729};
730#endif
731
732
Howard Hinnantb17caf92012-02-21 21:02:58 +0000733// less in <__functional_base>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000734
Marshall Clow974bae22013-07-29 14:21:53 +0000735#if _LIBCPP_STD_VER > 11
736template <class _Tp = void>
737#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000738template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000739#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000740struct _LIBCPP_TYPE_VIS_ONLY greater_equal : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000741{
Marshall Clowd18ee652013-09-28 19:06:12 +0000742 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
743 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000744 {return __x >= __y;}
745};
746
Marshall Clow974bae22013-07-29 14:21:53 +0000747#if _LIBCPP_STD_VER > 11
748template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000749struct _LIBCPP_TYPE_VIS_ONLY greater_equal<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000750{
Marshall Clowd18ee652013-09-28 19:06:12 +0000751 template <class _T1, class _T2>
752 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000753 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000754 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u)))
755 -> decltype (_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u))
756 { return _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000757 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000758};
759#endif
760
761
762#if _LIBCPP_STD_VER > 11
763template <class _Tp = void>
764#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000765template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000766#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000767struct _LIBCPP_TYPE_VIS_ONLY less_equal : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000768{
Marshall Clowd18ee652013-09-28 19:06:12 +0000769 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
770 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000771 {return __x <= __y;}
772};
773
Marshall Clow974bae22013-07-29 14:21:53 +0000774#if _LIBCPP_STD_VER > 11
775template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000776struct _LIBCPP_TYPE_VIS_ONLY less_equal<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000777{
Marshall Clowd18ee652013-09-28 19:06:12 +0000778 template <class _T1, class _T2>
779 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000780 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000781 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u)))
782 -> decltype (_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u))
783 { return _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000784 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000785};
786#endif
787
788
789#if _LIBCPP_STD_VER > 11
790template <class _Tp = void>
791#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000792template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000793#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000794struct _LIBCPP_TYPE_VIS_ONLY logical_and : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000795{
Marshall Clowd18ee652013-09-28 19:06:12 +0000796 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
797 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000798 {return __x && __y;}
799};
800
Marshall Clow974bae22013-07-29 14:21:53 +0000801#if _LIBCPP_STD_VER > 11
802template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000803struct _LIBCPP_TYPE_VIS_ONLY logical_and<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000804{
Marshall Clowd18ee652013-09-28 19:06:12 +0000805 template <class _T1, class _T2>
806 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000807 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000808 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u)))
809 -> decltype (_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u))
810 { return _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000811 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000812};
813#endif
814
815
816#if _LIBCPP_STD_VER > 11
817template <class _Tp = void>
818#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000819template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000820#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000821struct _LIBCPP_TYPE_VIS_ONLY logical_or : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000822{
Marshall Clowd18ee652013-09-28 19:06:12 +0000823 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
824 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000825 {return __x || __y;}
826};
827
Marshall Clow974bae22013-07-29 14:21:53 +0000828#if _LIBCPP_STD_VER > 11
829template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000830struct _LIBCPP_TYPE_VIS_ONLY logical_or<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000831{
Marshall Clowd18ee652013-09-28 19:06:12 +0000832 template <class _T1, class _T2>
833 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000834 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000835 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u)))
836 -> decltype (_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u))
837 { return _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000838 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000839};
840#endif
841
842
843#if _LIBCPP_STD_VER > 11
844template <class _Tp = void>
845#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000846template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000847#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000848struct _LIBCPP_TYPE_VIS_ONLY logical_not : unary_function<_Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000849{
Marshall Clowd18ee652013-09-28 19:06:12 +0000850 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
851 bool operator()(const _Tp& __x) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000852 {return !__x;}
853};
854
Marshall Clow974bae22013-07-29 14:21:53 +0000855#if _LIBCPP_STD_VER > 11
856template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000857struct _LIBCPP_TYPE_VIS_ONLY logical_not<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000858{
859 template <class _Tp>
Marshall Clowd18ee652013-09-28 19:06:12 +0000860 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
861 auto operator()(_Tp&& __x) const
Marshall Clow012ca342015-02-25 12:20:52 +0000862 _NOEXCEPT_(noexcept(!_VSTD::forward<_Tp>(__x)))
863 -> decltype (!_VSTD::forward<_Tp>(__x))
864 { return !_VSTD::forward<_Tp>(__x); }
Marshall Clowc0152142013-08-13 01:11:06 +0000865 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000866};
867#endif
868
869
870#if _LIBCPP_STD_VER > 11
871template <class _Tp = void>
872#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000873template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000874#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000875struct _LIBCPP_TYPE_VIS_ONLY bit_and : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000876{
Marshall Clowd18ee652013-09-28 19:06:12 +0000877 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
878 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000879 {return __x & __y;}
880};
881
Marshall Clow974bae22013-07-29 14:21:53 +0000882#if _LIBCPP_STD_VER > 11
883template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000884struct _LIBCPP_TYPE_VIS_ONLY bit_and<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000885{
Marshall Clowd18ee652013-09-28 19:06:12 +0000886 template <class _T1, class _T2>
887 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000888 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000889 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u)))
890 -> decltype (_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u))
891 { return _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000892 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000893};
894#endif
895
896
897#if _LIBCPP_STD_VER > 11
898template <class _Tp = void>
899#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000900template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000901#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000902struct _LIBCPP_TYPE_VIS_ONLY bit_or : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000903{
Marshall Clowd18ee652013-09-28 19:06:12 +0000904 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
905 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000906 {return __x | __y;}
907};
908
Marshall Clow974bae22013-07-29 14:21:53 +0000909#if _LIBCPP_STD_VER > 11
910template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000911struct _LIBCPP_TYPE_VIS_ONLY bit_or<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000912{
Marshall Clowd18ee652013-09-28 19:06:12 +0000913 template <class _T1, class _T2>
914 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000915 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000916 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u)))
917 -> decltype (_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u))
918 { return _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000919 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000920};
921#endif
922
923
924#if _LIBCPP_STD_VER > 11
925template <class _Tp = void>
926#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000927template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000928#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000929struct _LIBCPP_TYPE_VIS_ONLY bit_xor : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000930{
Marshall Clowd18ee652013-09-28 19:06:12 +0000931 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
932 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000933 {return __x ^ __y;}
934};
935
Marshall Clow974bae22013-07-29 14:21:53 +0000936#if _LIBCPP_STD_VER > 11
937template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000938struct _LIBCPP_TYPE_VIS_ONLY bit_xor<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000939{
Marshall Clowd18ee652013-09-28 19:06:12 +0000940 template <class _T1, class _T2>
941 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000942 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000943 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u)))
944 -> decltype (_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u))
945 { return _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000946 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000947};
948#endif
949
950
951#if _LIBCPP_STD_VER > 11
952template <class _Tp = void>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000953struct _LIBCPP_TYPE_VIS_ONLY bit_not : unary_function<_Tp, _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000954{
Marshall Clowd18ee652013-09-28 19:06:12 +0000955 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
956 _Tp operator()(const _Tp& __x) const
Marshall Clow974bae22013-07-29 14:21:53 +0000957 {return ~__x;}
958};
959
960template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000961struct _LIBCPP_TYPE_VIS_ONLY bit_not<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000962{
963 template <class _Tp>
Marshall Clowd18ee652013-09-28 19:06:12 +0000964 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
965 auto operator()(_Tp&& __x) const
Marshall Clow012ca342015-02-25 12:20:52 +0000966 _NOEXCEPT_(noexcept(~_VSTD::forward<_Tp>(__x)))
967 -> decltype (~_VSTD::forward<_Tp>(__x))
968 { return ~_VSTD::forward<_Tp>(__x); }
Marshall Clowc0152142013-08-13 01:11:06 +0000969 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000970};
971#endif
972
Howard Hinnantc51e1022010-05-11 19:42:16 +0000973template <class _Predicate>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000974class _LIBCPP_TYPE_VIS_ONLY unary_negate
Howard Hinnantc51e1022010-05-11 19:42:16 +0000975 : public unary_function<typename _Predicate::argument_type, bool>
976{
977 _Predicate __pred_;
978public:
Marshall Clowd18ee652013-09-28 19:06:12 +0000979 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
980 explicit unary_negate(const _Predicate& __pred)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000981 : __pred_(__pred) {}
Marshall Clowd18ee652013-09-28 19:06:12 +0000982 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
983 bool operator()(const typename _Predicate::argument_type& __x) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000984 {return !__pred_(__x);}
985};
986
987template <class _Predicate>
Marshall Clowd18ee652013-09-28 19:06:12 +0000988inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000989unary_negate<_Predicate>
990not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);}
991
992template <class _Predicate>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000993class _LIBCPP_TYPE_VIS_ONLY binary_negate
Howard Hinnantc51e1022010-05-11 19:42:16 +0000994 : public binary_function<typename _Predicate::first_argument_type,
995 typename _Predicate::second_argument_type,
996 bool>
997{
998 _Predicate __pred_;
999public:
Marshall Clowd18ee652013-09-28 19:06:12 +00001000 _LIBCPP_INLINE_VISIBILITY explicit _LIBCPP_CONSTEXPR_AFTER_CXX11
1001 binary_negate(const _Predicate& __pred) : __pred_(__pred) {}
1002
1003 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1004 bool operator()(const typename _Predicate::first_argument_type& __x,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001005 const typename _Predicate::second_argument_type& __y) const
1006 {return !__pred_(__x, __y);}
1007};
1008
1009template <class _Predicate>
Marshall Clowd18ee652013-09-28 19:06:12 +00001010inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001011binary_negate<_Predicate>
1012not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);}
1013
1014template <class __Operation>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001015class _LIBCPP_TYPE_VIS_ONLY binder1st
Howard Hinnantc51e1022010-05-11 19:42:16 +00001016 : public unary_function<typename __Operation::second_argument_type,
1017 typename __Operation::result_type>
1018{
1019protected:
1020 __Operation op;
1021 typename __Operation::first_argument_type value;
1022public:
1023 _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x,
1024 const typename __Operation::first_argument_type __y)
1025 : op(__x), value(__y) {}
1026 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1027 (typename __Operation::second_argument_type& __x) const
1028 {return op(value, __x);}
1029 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1030 (const typename __Operation::second_argument_type& __x) const
1031 {return op(value, __x);}
1032};
1033
1034template <class __Operation, class _Tp>
1035inline _LIBCPP_INLINE_VISIBILITY
1036binder1st<__Operation>
1037bind1st(const __Operation& __op, const _Tp& __x)
1038 {return binder1st<__Operation>(__op, __x);}
1039
1040template <class __Operation>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001041class _LIBCPP_TYPE_VIS_ONLY binder2nd
Howard Hinnantc51e1022010-05-11 19:42:16 +00001042 : public unary_function<typename __Operation::first_argument_type,
1043 typename __Operation::result_type>
1044{
1045protected:
1046 __Operation op;
1047 typename __Operation::second_argument_type value;
1048public:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001049 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001050 binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y)
1051 : op(__x), value(__y) {}
1052 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1053 ( typename __Operation::first_argument_type& __x) const
1054 {return op(__x, value);}
1055 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1056 (const typename __Operation::first_argument_type& __x) const
1057 {return op(__x, value);}
1058};
1059
1060template <class __Operation, class _Tp>
1061inline _LIBCPP_INLINE_VISIBILITY
1062binder2nd<__Operation>
1063bind2nd(const __Operation& __op, const _Tp& __x)
1064 {return binder2nd<__Operation>(__op, __x);}
1065
1066template <class _Arg, class _Result>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001067class _LIBCPP_TYPE_VIS_ONLY pointer_to_unary_function
Howard Hinnant4ff57432010-09-21 22:55:27 +00001068 : public unary_function<_Arg, _Result>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001069{
1070 _Result (*__f_)(_Arg);
1071public:
1072 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg))
1073 : __f_(__f) {}
1074 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const
1075 {return __f_(__x);}
1076};
1077
1078template <class _Arg, class _Result>
1079inline _LIBCPP_INLINE_VISIBILITY
1080pointer_to_unary_function<_Arg,_Result>
1081ptr_fun(_Result (*__f)(_Arg))
1082 {return pointer_to_unary_function<_Arg,_Result>(__f);}
1083
1084template <class _Arg1, class _Arg2, class _Result>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001085class _LIBCPP_TYPE_VIS_ONLY pointer_to_binary_function
Howard Hinnant4ff57432010-09-21 22:55:27 +00001086 : public binary_function<_Arg1, _Arg2, _Result>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001087{
1088 _Result (*__f_)(_Arg1, _Arg2);
1089public:
1090 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2))
1091 : __f_(__f) {}
1092 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const
1093 {return __f_(__x, __y);}
1094};
1095
1096template <class _Arg1, class _Arg2, class _Result>
1097inline _LIBCPP_INLINE_VISIBILITY
1098pointer_to_binary_function<_Arg1,_Arg2,_Result>
1099ptr_fun(_Result (*__f)(_Arg1,_Arg2))
1100 {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);}
1101
1102template<class _Sp, class _Tp>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001103class _LIBCPP_TYPE_VIS_ONLY mem_fun_t : public unary_function<_Tp*, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001104{
1105 _Sp (_Tp::*__p_)();
1106public:
1107 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)())
1108 : __p_(__p) {}
1109 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const
1110 {return (__p->*__p_)();}
1111};
1112
1113template<class _Sp, class _Tp, class _Ap>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001114class _LIBCPP_TYPE_VIS_ONLY mem_fun1_t : public binary_function<_Tp*, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001115{
1116 _Sp (_Tp::*__p_)(_Ap);
1117public:
1118 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap))
1119 : __p_(__p) {}
1120 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const
1121 {return (__p->*__p_)(__x);}
1122};
1123
1124template<class _Sp, class _Tp>
1125inline _LIBCPP_INLINE_VISIBILITY
1126mem_fun_t<_Sp,_Tp>
1127mem_fun(_Sp (_Tp::*__f)())
1128 {return mem_fun_t<_Sp,_Tp>(__f);}
1129
1130template<class _Sp, class _Tp, class _Ap>
1131inline _LIBCPP_INLINE_VISIBILITY
1132mem_fun1_t<_Sp,_Tp,_Ap>
1133mem_fun(_Sp (_Tp::*__f)(_Ap))
1134 {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1135
1136template<class _Sp, class _Tp>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001137class _LIBCPP_TYPE_VIS_ONLY mem_fun_ref_t : public unary_function<_Tp, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001138{
1139 _Sp (_Tp::*__p_)();
1140public:
1141 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)())
1142 : __p_(__p) {}
1143 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const
1144 {return (__p.*__p_)();}
1145};
1146
1147template<class _Sp, class _Tp, class _Ap>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001148class _LIBCPP_TYPE_VIS_ONLY mem_fun1_ref_t : public binary_function<_Tp, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001149{
1150 _Sp (_Tp::*__p_)(_Ap);
1151public:
1152 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap))
1153 : __p_(__p) {}
1154 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const
1155 {return (__p.*__p_)(__x);}
1156};
1157
1158template<class _Sp, class _Tp>
1159inline _LIBCPP_INLINE_VISIBILITY
1160mem_fun_ref_t<_Sp,_Tp>
1161mem_fun_ref(_Sp (_Tp::*__f)())
1162 {return mem_fun_ref_t<_Sp,_Tp>(__f);}
1163
1164template<class _Sp, class _Tp, class _Ap>
1165inline _LIBCPP_INLINE_VISIBILITY
1166mem_fun1_ref_t<_Sp,_Tp,_Ap>
1167mem_fun_ref(_Sp (_Tp::*__f)(_Ap))
1168 {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
1169
1170template <class _Sp, class _Tp>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001171class _LIBCPP_TYPE_VIS_ONLY const_mem_fun_t : public unary_function<const _Tp*, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001172{
1173 _Sp (_Tp::*__p_)() const;
1174public:
1175 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const)
1176 : __p_(__p) {}
1177 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const
1178 {return (__p->*__p_)();}
1179};
1180
1181template <class _Sp, class _Tp, class _Ap>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001182class _LIBCPP_TYPE_VIS_ONLY const_mem_fun1_t : public binary_function<const _Tp*, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001183{
1184 _Sp (_Tp::*__p_)(_Ap) const;
1185public:
1186 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const)
1187 : __p_(__p) {}
1188 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const
1189 {return (__p->*__p_)(__x);}
1190};
1191
1192template <class _Sp, class _Tp>
1193inline _LIBCPP_INLINE_VISIBILITY
1194const_mem_fun_t<_Sp,_Tp>
1195mem_fun(_Sp (_Tp::*__f)() const)
1196 {return const_mem_fun_t<_Sp,_Tp>(__f);}
1197
1198template <class _Sp, class _Tp, class _Ap>
1199inline _LIBCPP_INLINE_VISIBILITY
1200const_mem_fun1_t<_Sp,_Tp,_Ap>
1201mem_fun(_Sp (_Tp::*__f)(_Ap) const)
1202 {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1203
1204template <class _Sp, class _Tp>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001205class _LIBCPP_TYPE_VIS_ONLY const_mem_fun_ref_t : public unary_function<_Tp, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001206{
1207 _Sp (_Tp::*__p_)() const;
1208public:
1209 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const)
1210 : __p_(__p) {}
1211 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const
1212 {return (__p.*__p_)();}
1213};
1214
1215template <class _Sp, class _Tp, class _Ap>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001216class _LIBCPP_TYPE_VIS_ONLY const_mem_fun1_ref_t
Howard Hinnant4ff57432010-09-21 22:55:27 +00001217 : public binary_function<_Tp, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001218{
1219 _Sp (_Tp::*__p_)(_Ap) const;
1220public:
1221 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const)
1222 : __p_(__p) {}
1223 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const
1224 {return (__p.*__p_)(__x);}
1225};
1226
1227template <class _Sp, class _Tp>
1228inline _LIBCPP_INLINE_VISIBILITY
1229const_mem_fun_ref_t<_Sp,_Tp>
1230mem_fun_ref(_Sp (_Tp::*__f)() const)
1231 {return const_mem_fun_ref_t<_Sp,_Tp>(__f);}
1232
1233template <class _Sp, class _Tp, class _Ap>
1234inline _LIBCPP_INLINE_VISIBILITY
1235const_mem_fun1_ref_t<_Sp,_Tp,_Ap>
1236mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const)
1237 {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
1238
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001239////////////////////////////////////////////////////////////////////////////////
1240// MEMFUN
1241//==============================================================================
Howard Hinnantc51e1022010-05-11 19:42:16 +00001242
Howard Hinnantc51e1022010-05-11 19:42:16 +00001243template <class _Tp>
1244class __mem_fn
1245 : public __weak_result_type<_Tp>
1246{
1247public:
1248 // types
1249 typedef _Tp type;
1250private:
1251 type __f_;
1252
1253public:
Marshall Clowad8ff212015-10-25 20:12:16 +00001254 _LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) _NOEXCEPT : __f_(__f) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001255
Eric Fiselier2cc48332015-07-22 22:43:27 +00001256#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001257 // invoke
1258 template <class... _ArgTypes>
Eric Fiselier2cc48332015-07-22 22:43:27 +00001259 _LIBCPP_INLINE_VISIBILITY
1260 typename __invoke_return<type, _ArgTypes...>::type
1261 operator() (_ArgTypes&&... __args) const {
1262 return __invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...);
1263 }
1264#else
Eric Fiselier2cc48332015-07-22 22:43:27 +00001265
1266 template <class _A0>
Eric Fiselierce1813a2015-08-26 20:15:02 +00001267 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2cc48332015-07-22 22:43:27 +00001268 typename __invoke_return0<type, _A0>::type
1269 operator() (_A0& __a0) const {
1270 return __invoke(__f_, __a0);
1271 }
1272
Eric Fiselierce1813a2015-08-26 20:15:02 +00001273 template <class _A0>
1274 _LIBCPP_INLINE_VISIBILITY
1275 typename __invoke_return0<type, _A0 const>::type
1276 operator() (_A0 const& __a0) const {
1277 return __invoke(__f_, __a0);
1278 }
1279
Eric Fiselier2cc48332015-07-22 22:43:27 +00001280 template <class _A0, class _A1>
Eric Fiselierce1813a2015-08-26 20:15:02 +00001281 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2cc48332015-07-22 22:43:27 +00001282 typename __invoke_return1<type, _A0, _A1>::type
1283 operator() (_A0& __a0, _A1& __a1) const {
1284 return __invoke(__f_, __a0, __a1);
1285 }
1286
Eric Fiselierce1813a2015-08-26 20:15:02 +00001287 template <class _A0, class _A1>
1288 _LIBCPP_INLINE_VISIBILITY
1289 typename __invoke_return1<type, _A0 const, _A1>::type
1290 operator() (_A0 const& __a0, _A1& __a1) const {
1291 return __invoke(__f_, __a0, __a1);
1292 }
1293
1294 template <class _A0, class _A1>
1295 _LIBCPP_INLINE_VISIBILITY
1296 typename __invoke_return1<type, _A0, _A1 const>::type
1297 operator() (_A0& __a0, _A1 const& __a1) const {
1298 return __invoke(__f_, __a0, __a1);
1299 }
1300
1301 template <class _A0, class _A1>
1302 _LIBCPP_INLINE_VISIBILITY
1303 typename __invoke_return1<type, _A0 const, _A1 const>::type
1304 operator() (_A0 const& __a0, _A1 const& __a1) const {
1305 return __invoke(__f_, __a0, __a1);
1306 }
1307
Eric Fiselier2cc48332015-07-22 22:43:27 +00001308 template <class _A0, class _A1, class _A2>
Eric Fiselierce1813a2015-08-26 20:15:02 +00001309 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2cc48332015-07-22 22:43:27 +00001310 typename __invoke_return2<type, _A0, _A1, _A2>::type
1311 operator() (_A0& __a0, _A1& __a1, _A2& __a2) const {
1312 return __invoke(__f_, __a0, __a1, __a2);
1313 }
Eric Fiselierce1813a2015-08-26 20:15:02 +00001314
1315 template <class _A0, class _A1, class _A2>
1316 _LIBCPP_INLINE_VISIBILITY
1317 typename __invoke_return2<type, _A0 const, _A1, _A2>::type
1318 operator() (_A0 const& __a0, _A1& __a1, _A2& __a2) const {
1319 return __invoke(__f_, __a0, __a1, __a2);
1320 }
1321
1322 template <class _A0, class _A1, class _A2>
1323 _LIBCPP_INLINE_VISIBILITY
1324 typename __invoke_return2<type, _A0, _A1 const, _A2>::type
1325 operator() (_A0& __a0, _A1 const& __a1, _A2& __a2) const {
1326 return __invoke(__f_, __a0, __a1, __a2);
1327 }
1328
1329 template <class _A0, class _A1, class _A2>
1330 _LIBCPP_INLINE_VISIBILITY
1331 typename __invoke_return2<type, _A0, _A1, _A2 const>::type
1332 operator() (_A0& __a0, _A1& __a1, _A2 const& __a2) const {
1333 return __invoke(__f_, __a0, __a1, __a2);
1334 }
1335
1336 template <class _A0, class _A1, class _A2>
1337 _LIBCPP_INLINE_VISIBILITY
1338 typename __invoke_return2<type, _A0 const, _A1 const, _A2>::type
1339 operator() (_A0 const& __a0, _A1 const& __a1, _A2& __a2) const {
1340 return __invoke(__f_, __a0, __a1, __a2);
1341 }
1342
1343 template <class _A0, class _A1, class _A2>
1344 _LIBCPP_INLINE_VISIBILITY
1345 typename __invoke_return2<type, _A0 const, _A1, _A2 const>::type
1346 operator() (_A0 const& __a0, _A1& __a1, _A2 const& __a2) const {
1347 return __invoke(__f_, __a0, __a1, __a2);
1348 }
1349
1350 template <class _A0, class _A1, class _A2>
1351 _LIBCPP_INLINE_VISIBILITY
1352 typename __invoke_return2<type, _A0, _A1 const, _A2 const>::type
1353 operator() (_A0& __a0, _A1 const& __a1, _A2 const& __a2) const {
1354 return __invoke(__f_, __a0, __a1, __a2);
1355 }
1356
1357 template <class _A0, class _A1, class _A2>
1358 _LIBCPP_INLINE_VISIBILITY
1359 typename __invoke_return2<type, _A0 const, _A1 const, _A2 const>::type
1360 operator() (_A0 const& __a0, _A1 const& __a1, _A2 const& __a2) const {
1361 return __invoke(__f_, __a0, __a1, __a2);
1362 }
Eric Fiselier2cc48332015-07-22 22:43:27 +00001363#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001364};
1365
Howard Hinnantc834c512011-11-29 18:15:50 +00001366template<class _Rp, class _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001367inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001368__mem_fn<_Rp _Tp::*>
Marshall Clowad8ff212015-10-25 20:12:16 +00001369mem_fn(_Rp _Tp::* __pm) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001370{
Howard Hinnantc834c512011-11-29 18:15:50 +00001371 return __mem_fn<_Rp _Tp::*>(__pm);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001372}
1373
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001374////////////////////////////////////////////////////////////////////////////////
1375// FUNCTION
1376//==============================================================================
1377
Howard Hinnantc51e1022010-05-11 19:42:16 +00001378// bad_function_call
1379
Howard Hinnant4ff57432010-09-21 22:55:27 +00001380class _LIBCPP_EXCEPTION_ABI bad_function_call
Howard Hinnantc51e1022010-05-11 19:42:16 +00001381 : public exception
1382{
1383};
1384
Marshall Clow8fea1612016-08-25 15:09:01 +00001385_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
1386void __throw_bad_function_call()
1387{
1388#ifndef _LIBCPP_NO_EXCEPTIONS
1389 throw bad_function_call();
1390#else
1391 _VSTD::abort();
1392#endif
1393}
1394
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001395template<class _Fp> class _LIBCPP_TYPE_VIS_ONLY function; // undefined
Howard Hinnantc51e1022010-05-11 19:42:16 +00001396
1397namespace __function
1398{
1399
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001400template<class _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001401struct __maybe_derive_from_unary_function
1402{
1403};
1404
Howard Hinnantc834c512011-11-29 18:15:50 +00001405template<class _Rp, class _A1>
1406struct __maybe_derive_from_unary_function<_Rp(_A1)>
1407 : public unary_function<_A1, _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001408{
1409};
1410
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001411template<class _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001412struct __maybe_derive_from_binary_function
1413{
1414};
1415
Howard Hinnantc834c512011-11-29 18:15:50 +00001416template<class _Rp, class _A1, class _A2>
1417struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)>
1418 : public binary_function<_A1, _A2, _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001419{
1420};
1421
Eric Fiseliera584a1e2015-08-18 19:41:51 +00001422template <class _Fp>
1423_LIBCPP_INLINE_VISIBILITY
1424bool __not_null(_Fp const&) { return true; }
1425
1426template <class _Fp>
1427_LIBCPP_INLINE_VISIBILITY
1428bool __not_null(_Fp* __ptr) { return __ptr; }
1429
1430template <class _Ret, class _Class>
1431_LIBCPP_INLINE_VISIBILITY
1432bool __not_null(_Ret _Class::*__ptr) { return __ptr; }
1433
1434template <class _Fp>
1435_LIBCPP_INLINE_VISIBILITY
1436bool __not_null(function<_Fp> const& __f) { return !!__f; }
1437
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001438} // namespace __function
1439
1440#ifndef _LIBCPP_HAS_NO_VARIADICS
1441
1442namespace __function {
1443
Howard Hinnantc51e1022010-05-11 19:42:16 +00001444template<class _Fp> class __base;
1445
Howard Hinnantc834c512011-11-29 18:15:50 +00001446template<class _Rp, class ..._ArgTypes>
1447class __base<_Rp(_ArgTypes...)>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001448{
1449 __base(const __base&);
1450 __base& operator=(const __base&);
1451public:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001452 _LIBCPP_INLINE_VISIBILITY __base() {}
1453 _LIBCPP_INLINE_VISIBILITY virtual ~__base() {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001454 virtual __base* __clone() const = 0;
1455 virtual void __clone(__base*) const = 0;
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001456 virtual void destroy() _NOEXCEPT = 0;
1457 virtual void destroy_deallocate() _NOEXCEPT = 0;
Howard Hinnantc834c512011-11-29 18:15:50 +00001458 virtual _Rp operator()(_ArgTypes&& ...) = 0;
Howard Hinnant72f73582010-08-11 17:04:31 +00001459#ifndef _LIBCPP_NO_RTTI
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001460 virtual const void* target(const type_info&) const _NOEXCEPT = 0;
1461 virtual const std::type_info& target_type() const _NOEXCEPT = 0;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001462#endif // _LIBCPP_NO_RTTI
Howard Hinnantc51e1022010-05-11 19:42:16 +00001463};
1464
1465template<class _FD, class _Alloc, class _FB> class __func;
1466
Howard Hinnantc834c512011-11-29 18:15:50 +00001467template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1468class __func<_Fp, _Alloc, _Rp(_ArgTypes...)>
1469 : public __base<_Rp(_ArgTypes...)>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001470{
Howard Hinnantc834c512011-11-29 18:15:50 +00001471 __compressed_pair<_Fp, _Alloc> __f_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001472public:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001473 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4828c4a2012-02-28 19:47:38 +00001474 explicit __func(_Fp&& __f)
1475 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1476 _VSTD::forward_as_tuple()) {}
Howard Hinnant4ff57432010-09-21 22:55:27 +00001477 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4828c4a2012-02-28 19:47:38 +00001478 explicit __func(const _Fp& __f, const _Alloc& __a)
1479 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1480 _VSTD::forward_as_tuple(__a)) {}
1481
1482 _LIBCPP_INLINE_VISIBILITY
1483 explicit __func(const _Fp& __f, _Alloc&& __a)
1484 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1485 _VSTD::forward_as_tuple(_VSTD::move(__a))) {}
1486
1487 _LIBCPP_INLINE_VISIBILITY
1488 explicit __func(_Fp&& __f, _Alloc&& __a)
1489 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1490 _VSTD::forward_as_tuple(_VSTD::move(__a))) {}
Howard Hinnantc834c512011-11-29 18:15:50 +00001491 virtual __base<_Rp(_ArgTypes...)>* __clone() const;
1492 virtual void __clone(__base<_Rp(_ArgTypes...)>*) const;
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001493 virtual void destroy() _NOEXCEPT;
1494 virtual void destroy_deallocate() _NOEXCEPT;
Howard Hinnantc834c512011-11-29 18:15:50 +00001495 virtual _Rp operator()(_ArgTypes&& ... __arg);
Howard Hinnant72f73582010-08-11 17:04:31 +00001496#ifndef _LIBCPP_NO_RTTI
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001497 virtual const void* target(const type_info&) const _NOEXCEPT;
1498 virtual const std::type_info& target_type() const _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001499#endif // _LIBCPP_NO_RTTI
Howard Hinnantc51e1022010-05-11 19:42:16 +00001500};
1501
Howard Hinnantc834c512011-11-29 18:15:50 +00001502template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1503__base<_Rp(_ArgTypes...)>*
1504__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001505{
Eric Fiselierb5826ad2015-03-18 22:56:50 +00001506 typedef allocator_traits<_Alloc> __alloc_traits;
Marshall Clow940e01c2015-04-07 05:21:38 +00001507 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
Howard Hinnantc834c512011-11-29 18:15:50 +00001508 _Ap __a(__f_.second());
1509 typedef __allocator_destructor<_Ap> _Dp;
1510 unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001511 ::new (__hold.get()) __func(__f_.first(), _Alloc(__a));
1512 return __hold.release();
1513}
1514
Howard Hinnantc834c512011-11-29 18:15:50 +00001515template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001516void
Howard Hinnantc834c512011-11-29 18:15:50 +00001517__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001518{
1519 ::new (__p) __func(__f_.first(), __f_.second());
1520}
1521
Howard Hinnantc834c512011-11-29 18:15:50 +00001522template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001523void
Howard Hinnantc834c512011-11-29 18:15:50 +00001524__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001525{
Howard Hinnantc834c512011-11-29 18:15:50 +00001526 __f_.~__compressed_pair<_Fp, _Alloc>();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001527}
1528
Howard Hinnantc834c512011-11-29 18:15:50 +00001529template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001530void
Howard Hinnantc834c512011-11-29 18:15:50 +00001531__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001532{
Eric Fiselierb5826ad2015-03-18 22:56:50 +00001533 typedef allocator_traits<_Alloc> __alloc_traits;
Marshall Clow940e01c2015-04-07 05:21:38 +00001534 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
Howard Hinnantc834c512011-11-29 18:15:50 +00001535 _Ap __a(__f_.second());
1536 __f_.~__compressed_pair<_Fp, _Alloc>();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001537 __a.deallocate(this, 1);
1538}
1539
Howard Hinnantc834c512011-11-29 18:15:50 +00001540template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1541_Rp
1542__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001543{
Eric Fiselierea080702015-02-10 16:48:45 +00001544 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
1545 return _Invoker::__call(__f_.first(), _VSTD::forward<_ArgTypes>(__arg)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001546}
1547
Howard Hinnant72f73582010-08-11 17:04:31 +00001548#ifndef _LIBCPP_NO_RTTI
1549
Howard Hinnantc834c512011-11-29 18:15:50 +00001550template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001551const void*
Howard Hinnantc834c512011-11-29 18:15:50 +00001552__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001553{
Howard Hinnantc834c512011-11-29 18:15:50 +00001554 if (__ti == typeid(_Fp))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001555 return &__f_.first();
1556 return (const void*)0;
1557}
1558
Howard Hinnantc834c512011-11-29 18:15:50 +00001559template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001560const std::type_info&
Howard Hinnantc834c512011-11-29 18:15:50 +00001561__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001562{
Howard Hinnantc834c512011-11-29 18:15:50 +00001563 return typeid(_Fp);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001564}
1565
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001566#endif // _LIBCPP_NO_RTTI
Howard Hinnant72f73582010-08-11 17:04:31 +00001567
Howard Hinnantc51e1022010-05-11 19:42:16 +00001568} // __function
1569
Howard Hinnantc834c512011-11-29 18:15:50 +00001570template<class _Rp, class ..._ArgTypes>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001571class _LIBCPP_TYPE_VIS_ONLY function<_Rp(_ArgTypes...)>
Howard Hinnantc834c512011-11-29 18:15:50 +00001572 : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>,
1573 public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001574{
Howard Hinnantc834c512011-11-29 18:15:50 +00001575 typedef __function::__base<_Rp(_ArgTypes...)> __base;
Howard Hinnant022c7482013-01-21 17:26:55 +00001576 typename aligned_storage<3*sizeof(void*)>::type __buf_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001577 __base* __f_;
1578
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001579 _LIBCPP_NO_CFI static __base *__as_base(void *p) {
1580 return reinterpret_cast<__base*>(p);
1581 }
1582
Howard Hinnant69c06092012-07-20 18:56:07 +00001583 template <class _Fp, bool = !is_same<_Fp, function>::value &&
1584 __invokable<_Fp&, _ArgTypes...>::value>
Howard Hinnant95755932011-05-31 21:45:26 +00001585 struct __callable;
Howard Hinnantc834c512011-11-29 18:15:50 +00001586 template <class _Fp>
1587 struct __callable<_Fp, true>
Howard Hinnant95755932011-05-31 21:45:26 +00001588 {
Eric Fiselierea080702015-02-10 16:48:45 +00001589 static const bool value = is_same<void, _Rp>::value ||
Howard Hinnantc834c512011-11-29 18:15:50 +00001590 is_convertible<typename __invoke_of<_Fp&, _ArgTypes...>::type,
1591 _Rp>::value;
Howard Hinnant95755932011-05-31 21:45:26 +00001592 };
Howard Hinnantc834c512011-11-29 18:15:50 +00001593 template <class _Fp>
1594 struct __callable<_Fp, false>
Howard Hinnant95755932011-05-31 21:45:26 +00001595 {
1596 static const bool value = false;
1597 };
Howard Hinnantc51e1022010-05-11 19:42:16 +00001598public:
Howard Hinnantc834c512011-11-29 18:15:50 +00001599 typedef _Rp result_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001600
Howard Hinnantf06d9262010-08-20 19:36:46 +00001601 // construct/copy/destroy:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001602 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001603 function() _NOEXCEPT : __f_(0) {}
Howard Hinnant4ff57432010-09-21 22:55:27 +00001604 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001605 function(nullptr_t) _NOEXCEPT : __f_(0) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001606 function(const function&);
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001607 function(function&&) _NOEXCEPT;
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00001608 template<class _Fp, class = typename enable_if<
1609 __callable<_Fp>::value && !is_same<_Fp, function>::value
1610 >::type>
1611 function(_Fp);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001612
Howard Hinnantf06d9262010-08-20 19:36:46 +00001613 template<class _Alloc>
Howard Hinnant4ff57432010-09-21 22:55:27 +00001614 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001615 function(allocator_arg_t, const _Alloc&) _NOEXCEPT : __f_(0) {}
Howard Hinnantf06d9262010-08-20 19:36:46 +00001616 template<class _Alloc>
Howard Hinnant4ff57432010-09-21 22:55:27 +00001617 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001618 function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT : __f_(0) {}
Howard Hinnantf06d9262010-08-20 19:36:46 +00001619 template<class _Alloc>
1620 function(allocator_arg_t, const _Alloc&, const function&);
1621 template<class _Alloc>
1622 function(allocator_arg_t, const _Alloc&, function&&);
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00001623 template<class _Fp, class _Alloc, class = typename enable_if<__callable<_Fp>::value>::type>
1624 function(allocator_arg_t, const _Alloc& __a, _Fp __f);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001625
1626 function& operator=(const function&);
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001627 function& operator=(function&&) _NOEXCEPT;
1628 function& operator=(nullptr_t) _NOEXCEPT;
Howard Hinnantc834c512011-11-29 18:15:50 +00001629 template<class _Fp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001630 typename enable_if
1631 <
Howard Hinnantf292a922013-07-01 00:01:51 +00001632 __callable<typename decay<_Fp>::type>::value &&
1633 !is_same<typename remove_reference<_Fp>::type, function>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001634 function&
1635 >::type
Howard Hinnantc834c512011-11-29 18:15:50 +00001636 operator=(_Fp&&);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001637
1638 ~function();
1639
Howard Hinnantf06d9262010-08-20 19:36:46 +00001640 // function modifiers:
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001641 void swap(function&) _NOEXCEPT;
Marshall Clowfc8fd832016-01-25 17:29:55 +00001642
1643#if _LIBCPP_STD_VER <= 14
Howard Hinnantc834c512011-11-29 18:15:50 +00001644 template<class _Fp, class _Alloc>
Howard Hinnant4ff57432010-09-21 22:55:27 +00001645 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001646 void assign(_Fp&& __f, const _Alloc& __a)
1647 {function(allocator_arg, __a, _VSTD::forward<_Fp>(__f)).swap(*this);}
Marshall Clowfc8fd832016-01-25 17:29:55 +00001648#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001649
Howard Hinnantf06d9262010-08-20 19:36:46 +00001650 // function capacity:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001651 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant86a291f2012-02-21 21:46:43 +00001652 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return __f_;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001653
Howard Hinnantc51e1022010-05-11 19:42:16 +00001654 // deleted overloads close possible hole in the type system
1655 template<class _R2, class... _ArgTypes2>
Howard Hinnant5e9a1cf2010-09-11 15:33:21 +00001656 bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001657 template<class _R2, class... _ArgTypes2>
Howard Hinnant5e9a1cf2010-09-11 15:33:21 +00001658 bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001659public:
Howard Hinnantf06d9262010-08-20 19:36:46 +00001660 // function invocation:
Howard Hinnantc834c512011-11-29 18:15:50 +00001661 _Rp operator()(_ArgTypes...) const;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001662
Howard Hinnant72f73582010-08-11 17:04:31 +00001663#ifndef _LIBCPP_NO_RTTI
Howard Hinnantf06d9262010-08-20 19:36:46 +00001664 // function target access:
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001665 const std::type_info& target_type() const _NOEXCEPT;
Howard Hinnantc834c512011-11-29 18:15:50 +00001666 template <typename _Tp> _Tp* target() _NOEXCEPT;
1667 template <typename _Tp> const _Tp* target() const _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001668#endif // _LIBCPP_NO_RTTI
Howard Hinnantc51e1022010-05-11 19:42:16 +00001669};
1670
Howard Hinnantc834c512011-11-29 18:15:50 +00001671template<class _Rp, class ..._ArgTypes>
1672function<_Rp(_ArgTypes...)>::function(const function& __f)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001673{
1674 if (__f.__f_ == 0)
1675 __f_ = 0;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001676 else if ((void *)__f.__f_ == &__f.__buf_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001677 {
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001678 __f_ = __as_base(&__buf_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001679 __f.__f_->__clone(__f_);
1680 }
1681 else
1682 __f_ = __f.__f_->__clone();
1683}
1684
Howard Hinnantc834c512011-11-29 18:15:50 +00001685template<class _Rp, class ..._ArgTypes>
Howard Hinnantf06d9262010-08-20 19:36:46 +00001686template <class _Alloc>
Howard Hinnantc834c512011-11-29 18:15:50 +00001687function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
Howard Hinnantf06d9262010-08-20 19:36:46 +00001688 const function& __f)
1689{
1690 if (__f.__f_ == 0)
1691 __f_ = 0;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001692 else if ((void *)__f.__f_ == &__f.__buf_)
Howard Hinnantf06d9262010-08-20 19:36:46 +00001693 {
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001694 __f_ = __as_base(&__buf_);
Howard Hinnantf06d9262010-08-20 19:36:46 +00001695 __f.__f_->__clone(__f_);
1696 }
1697 else
1698 __f_ = __f.__f_->__clone();
1699}
1700
Howard Hinnantc834c512011-11-29 18:15:50 +00001701template<class _Rp, class ..._ArgTypes>
1702function<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001703{
1704 if (__f.__f_ == 0)
1705 __f_ = 0;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001706 else if ((void *)__f.__f_ == &__f.__buf_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001707 {
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001708 __f_ = __as_base(&__buf_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001709 __f.__f_->__clone(__f_);
1710 }
1711 else
1712 {
1713 __f_ = __f.__f_;
1714 __f.__f_ = 0;
1715 }
1716}
1717
Howard Hinnantc834c512011-11-29 18:15:50 +00001718template<class _Rp, class ..._ArgTypes>
Howard Hinnantf06d9262010-08-20 19:36:46 +00001719template <class _Alloc>
Howard Hinnantc834c512011-11-29 18:15:50 +00001720function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
Howard Hinnantf06d9262010-08-20 19:36:46 +00001721 function&& __f)
1722{
1723 if (__f.__f_ == 0)
1724 __f_ = 0;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001725 else if ((void *)__f.__f_ == &__f.__buf_)
Howard Hinnantf06d9262010-08-20 19:36:46 +00001726 {
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001727 __f_ = __as_base(&__buf_);
Howard Hinnantf06d9262010-08-20 19:36:46 +00001728 __f.__f_->__clone(__f_);
1729 }
1730 else
1731 {
1732 __f_ = __f.__f_;
1733 __f.__f_ = 0;
1734 }
1735}
1736
Howard Hinnantc834c512011-11-29 18:15:50 +00001737template<class _Rp, class ..._ArgTypes>
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00001738template <class _Fp, class>
1739function<_Rp(_ArgTypes...)>::function(_Fp __f)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001740 : __f_(0)
1741{
Eric Fiseliera584a1e2015-08-18 19:41:51 +00001742 if (__function::__not_null(__f))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001743 {
Howard Hinnantc834c512011-11-29 18:15:50 +00001744 typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_ArgTypes...)> _FF;
1745 if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001746 {
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001747 __f_ = ::new((void*)&__buf_) _FF(_VSTD::move(__f));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001748 }
1749 else
1750 {
Howard Hinnantc834c512011-11-29 18:15:50 +00001751 typedef allocator<_FF> _Ap;
1752 _Ap __a;
1753 typedef __allocator_destructor<_Ap> _Dp;
1754 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1755 ::new (__hold.get()) _FF(_VSTD::move(__f), allocator<_Fp>(__a));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001756 __f_ = __hold.release();
1757 }
1758 }
1759}
1760
Howard Hinnantc834c512011-11-29 18:15:50 +00001761template<class _Rp, class ..._ArgTypes>
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00001762template <class _Fp, class _Alloc, class>
1763function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f)
Howard Hinnantf06d9262010-08-20 19:36:46 +00001764 : __f_(0)
1765{
1766 typedef allocator_traits<_Alloc> __alloc_traits;
Eric Fiseliera584a1e2015-08-18 19:41:51 +00001767 if (__function::__not_null(__f))
Howard Hinnantf06d9262010-08-20 19:36:46 +00001768 {
Howard Hinnantc834c512011-11-29 18:15:50 +00001769 typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _FF;
Marshall Clow940e01c2015-04-07 05:21:38 +00001770 typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap;
Marshall Clowe2631a22014-04-18 17:23:36 +00001771 _Ap __a(__a0);
1772 if (sizeof(_FF) <= sizeof(__buf_) &&
1773 is_nothrow_copy_constructible<_Fp>::value && is_nothrow_copy_constructible<_Ap>::value)
Howard Hinnantf06d9262010-08-20 19:36:46 +00001774 {
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001775 __f_ = ::new((void*)&__buf_) _FF(_VSTD::move(__f), _Alloc(__a));
Howard Hinnantf06d9262010-08-20 19:36:46 +00001776 }
1777 else
1778 {
Howard Hinnantc834c512011-11-29 18:15:50 +00001779 typedef __allocator_destructor<_Ap> _Dp;
1780 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001781 ::new (__hold.get()) _FF(_VSTD::move(__f), _Alloc(__a));
Howard Hinnantf06d9262010-08-20 19:36:46 +00001782 __f_ = __hold.release();
1783 }
1784 }
1785}
1786
Howard Hinnantc834c512011-11-29 18:15:50 +00001787template<class _Rp, class ..._ArgTypes>
1788function<_Rp(_ArgTypes...)>&
1789function<_Rp(_ArgTypes...)>::operator=(const function& __f)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001790{
1791 function(__f).swap(*this);
1792 return *this;
1793}
1794
Howard Hinnantc834c512011-11-29 18:15:50 +00001795template<class _Rp, class ..._ArgTypes>
1796function<_Rp(_ArgTypes...)>&
1797function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001798{
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001799 if ((void *)__f_ == &__buf_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001800 __f_->destroy();
1801 else if (__f_)
1802 __f_->destroy_deallocate();
1803 __f_ = 0;
1804 if (__f.__f_ == 0)
1805 __f_ = 0;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001806 else if ((void *)__f.__f_ == &__f.__buf_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001807 {
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001808 __f_ = __as_base(&__buf_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001809 __f.__f_->__clone(__f_);
1810 }
1811 else
1812 {
1813 __f_ = __f.__f_;
1814 __f.__f_ = 0;
1815 }
Argyrios Kyrtzidisaf904652012-10-13 02:03:45 +00001816 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001817}
1818
Howard Hinnantc834c512011-11-29 18:15:50 +00001819template<class _Rp, class ..._ArgTypes>
1820function<_Rp(_ArgTypes...)>&
1821function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001822{
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001823 if ((void *)__f_ == &__buf_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001824 __f_->destroy();
1825 else if (__f_)
1826 __f_->destroy_deallocate();
1827 __f_ = 0;
Argyrios Kyrtzidisaf904652012-10-13 02:03:45 +00001828 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001829}
1830
Howard Hinnantc834c512011-11-29 18:15:50 +00001831template<class _Rp, class ..._ArgTypes>
1832template <class _Fp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001833typename enable_if
1834<
Howard Hinnantf292a922013-07-01 00:01:51 +00001835 function<_Rp(_ArgTypes...)>::template __callable<typename decay<_Fp>::type>::value &&
1836 !is_same<typename remove_reference<_Fp>::type, function<_Rp(_ArgTypes...)>>::value,
Howard Hinnantc834c512011-11-29 18:15:50 +00001837 function<_Rp(_ArgTypes...)>&
Howard Hinnantc51e1022010-05-11 19:42:16 +00001838>::type
Howard Hinnantc834c512011-11-29 18:15:50 +00001839function<_Rp(_ArgTypes...)>::operator=(_Fp&& __f)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001840{
Howard Hinnantc834c512011-11-29 18:15:50 +00001841 function(_VSTD::forward<_Fp>(__f)).swap(*this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001842 return *this;
1843}
1844
Howard Hinnantc834c512011-11-29 18:15:50 +00001845template<class _Rp, class ..._ArgTypes>
1846function<_Rp(_ArgTypes...)>::~function()
Howard Hinnantc51e1022010-05-11 19:42:16 +00001847{
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001848 if ((void *)__f_ == &__buf_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001849 __f_->destroy();
1850 else if (__f_)
1851 __f_->destroy_deallocate();
1852}
1853
Howard Hinnantc834c512011-11-29 18:15:50 +00001854template<class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001855void
Howard Hinnantc834c512011-11-29 18:15:50 +00001856function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001857{
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001858 if ((void *)__f_ == &__buf_ && (void *)__f.__f_ == &__f.__buf_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001859 {
1860 typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001861 __base* __t = __as_base(&__tempbuf);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001862 __f_->__clone(__t);
1863 __f_->destroy();
1864 __f_ = 0;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001865 __f.__f_->__clone(__as_base(&__buf_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001866 __f.__f_->destroy();
1867 __f.__f_ = 0;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001868 __f_ = __as_base(&__buf_);
1869 __t->__clone(__as_base(&__f.__buf_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001870 __t->destroy();
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001871 __f.__f_ = __as_base(&__f.__buf_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001872 }
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001873 else if ((void *)__f_ == &__buf_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001874 {
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001875 __f_->__clone(__as_base(&__f.__buf_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001876 __f_->destroy();
1877 __f_ = __f.__f_;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001878 __f.__f_ = __as_base(&__f.__buf_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001879 }
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001880 else if ((void *)__f.__f_ == &__f.__buf_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001881 {
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001882 __f.__f_->__clone(__as_base(&__buf_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001883 __f.__f_->destroy();
1884 __f.__f_ = __f_;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001885 __f_ = __as_base(&__buf_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001886 }
1887 else
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001888 _VSTD::swap(__f_, __f.__f_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001889}
1890
Howard Hinnantc834c512011-11-29 18:15:50 +00001891template<class _Rp, class ..._ArgTypes>
1892_Rp
1893function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001894{
1895 if (__f_ == 0)
Marshall Clow8fea1612016-08-25 15:09:01 +00001896 __throw_bad_function_call();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001897 return (*__f_)(_VSTD::forward<_ArgTypes>(__arg)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001898}
1899
Howard Hinnant72f73582010-08-11 17:04:31 +00001900#ifndef _LIBCPP_NO_RTTI
1901
Howard Hinnantc834c512011-11-29 18:15:50 +00001902template<class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001903const std::type_info&
Howard Hinnantc834c512011-11-29 18:15:50 +00001904function<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001905{
1906 if (__f_ == 0)
1907 return typeid(void);
1908 return __f_->target_type();
1909}
1910
Howard Hinnantc834c512011-11-29 18:15:50 +00001911template<class _Rp, class ..._ArgTypes>
1912template <typename _Tp>
1913_Tp*
1914function<_Rp(_ArgTypes...)>::target() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001915{
1916 if (__f_ == 0)
Howard Hinnantc834c512011-11-29 18:15:50 +00001917 return (_Tp*)0;
1918 return (_Tp*)__f_->target(typeid(_Tp));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001919}
1920
Howard Hinnantc834c512011-11-29 18:15:50 +00001921template<class _Rp, class ..._ArgTypes>
1922template <typename _Tp>
1923const _Tp*
1924function<_Rp(_ArgTypes...)>::target() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001925{
1926 if (__f_ == 0)
Howard Hinnantc834c512011-11-29 18:15:50 +00001927 return (const _Tp*)0;
1928 return (const _Tp*)__f_->target(typeid(_Tp));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001929}
1930
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001931#endif // _LIBCPP_NO_RTTI
Howard Hinnant72f73582010-08-11 17:04:31 +00001932
Howard Hinnantc834c512011-11-29 18:15:50 +00001933template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001934inline _LIBCPP_INLINE_VISIBILITY
1935bool
Howard Hinnantc834c512011-11-29 18:15:50 +00001936operator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001937
Howard Hinnantc834c512011-11-29 18:15:50 +00001938template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001939inline _LIBCPP_INLINE_VISIBILITY
1940bool
Howard Hinnantc834c512011-11-29 18:15:50 +00001941operator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001942
Howard Hinnantc834c512011-11-29 18:15:50 +00001943template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001944inline _LIBCPP_INLINE_VISIBILITY
1945bool
Howard Hinnantc834c512011-11-29 18:15:50 +00001946operator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001947
Howard Hinnantc834c512011-11-29 18:15:50 +00001948template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001949inline _LIBCPP_INLINE_VISIBILITY
1950bool
Howard Hinnantc834c512011-11-29 18:15:50 +00001951operator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001952
Howard Hinnantc834c512011-11-29 18:15:50 +00001953template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001954inline _LIBCPP_INLINE_VISIBILITY
1955void
Howard Hinnantc834c512011-11-29 18:15:50 +00001956swap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001957{return __x.swap(__y);}
1958
Eric Fiselier2cc48332015-07-22 22:43:27 +00001959#else // _LIBCPP_HAS_NO_VARIADICS
1960
1961#include <__functional_03>
1962
1963#endif
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001964
1965////////////////////////////////////////////////////////////////////////////////
1966// BIND
1967//==============================================================================
1968
Howard Hinnantc51e1022010-05-11 19:42:16 +00001969template<class _Tp> struct __is_bind_expression : public false_type {};
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001970template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_bind_expression
Howard Hinnantc51e1022010-05-11 19:42:16 +00001971 : public __is_bind_expression<typename remove_cv<_Tp>::type> {};
1972
1973template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {};
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001974template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_placeholder
Howard Hinnantc51e1022010-05-11 19:42:16 +00001975 : public __is_placeholder<typename remove_cv<_Tp>::type> {};
1976
1977namespace placeholders
1978{
1979
Howard Hinnantc834c512011-11-29 18:15:50 +00001980template <int _Np> struct __ph {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001981
Eric Fiselierb7f51d62016-06-26 21:01:34 +00001982#if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_BIND)
1983_LIBCPP_FUNC_VIS extern const __ph<1> _1;
1984_LIBCPP_FUNC_VIS extern const __ph<2> _2;
1985_LIBCPP_FUNC_VIS extern const __ph<3> _3;
1986_LIBCPP_FUNC_VIS extern const __ph<4> _4;
1987_LIBCPP_FUNC_VIS extern const __ph<5> _5;
1988_LIBCPP_FUNC_VIS extern const __ph<6> _6;
1989_LIBCPP_FUNC_VIS extern const __ph<7> _7;
1990_LIBCPP_FUNC_VIS extern const __ph<8> _8;
1991_LIBCPP_FUNC_VIS extern const __ph<9> _9;
1992_LIBCPP_FUNC_VIS extern const __ph<10> _10;
1993#else
1994constexpr __ph<1> _1{};
1995constexpr __ph<2> _2{};
1996constexpr __ph<3> _3{};
1997constexpr __ph<4> _4{};
1998constexpr __ph<5> _5{};
1999constexpr __ph<6> _6{};
2000constexpr __ph<7> _7{};
2001constexpr __ph<8> _8{};
2002constexpr __ph<9> _9{};
2003constexpr __ph<10> _10{};
2004#endif // defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_BIND)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002005
2006} // placeholders
2007
Howard Hinnantc834c512011-11-29 18:15:50 +00002008template<int _Np>
2009struct __is_placeholder<placeholders::__ph<_Np> >
2010 : public integral_constant<int, _Np> {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00002011
Eric Fiseliera6f61c62015-07-22 04:14:38 +00002012
2013#ifndef _LIBCPP_HAS_NO_VARIADICS
2014
Howard Hinnantc51e1022010-05-11 19:42:16 +00002015template <class _Tp, class _Uj>
2016inline _LIBCPP_INLINE_VISIBILITY
2017_Tp&
2018__mu(reference_wrapper<_Tp> __t, _Uj&)
2019{
2020 return __t.get();
2021}
2022
Howard Hinnantc51e1022010-05-11 19:42:16 +00002023template <class _Ti, class ..._Uj, size_t ..._Indx>
2024inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002025typename __invoke_of<_Ti&, _Uj...>::type
2026__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002027{
Marshall Clow60e4aa72014-06-24 00:46:19 +00002028 return __ti(_VSTD::forward<_Uj>(_VSTD::get<_Indx>(__uj))...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002029}
2030
2031template <class _Ti, class ..._Uj>
2032inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierf3a1cea2014-12-23 05:54:34 +00002033typename __lazy_enable_if
Howard Hinnantc51e1022010-05-11 19:42:16 +00002034<
2035 is_bind_expression<_Ti>::value,
Eric Fiselierf3a1cea2014-12-23 05:54:34 +00002036 __invoke_of<_Ti&, _Uj...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002037>::type
2038__mu(_Ti& __ti, tuple<_Uj...>& __uj)
2039{
2040 typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices;
2041 return __mu_expand(__ti, __uj, __indices());
2042}
2043
2044template <bool IsPh, class _Ti, class _Uj>
2045struct __mu_return2 {};
2046
2047template <class _Ti, class _Uj>
2048struct __mu_return2<true, _Ti, _Uj>
2049{
2050 typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type;
2051};
2052
2053template <class _Ti, class _Uj>
2054inline _LIBCPP_INLINE_VISIBILITY
2055typename enable_if
2056<
2057 0 < is_placeholder<_Ti>::value,
2058 typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type
2059>::type
2060__mu(_Ti&, _Uj& __uj)
2061{
2062 const size_t _Indx = is_placeholder<_Ti>::value - 1;
Marshall Clow60e4aa72014-06-24 00:46:19 +00002063 return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002064}
2065
2066template <class _Ti, class _Uj>
2067inline _LIBCPP_INLINE_VISIBILITY
2068typename enable_if
2069<
2070 !is_bind_expression<_Ti>::value &&
2071 is_placeholder<_Ti>::value == 0 &&
2072 !__is_reference_wrapper<_Ti>::value,
2073 _Ti&
2074>::type
Howard Hinnant28b24882011-12-01 20:21:04 +00002075__mu(_Ti& __ti, _Uj&)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002076{
2077 return __ti;
2078}
2079
Howard Hinnant0415d792011-05-22 15:07:43 +00002080template <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh,
2081 class _TupleUj>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002082struct ____mu_return;
2083
Howard Hinnant51dae7a2013-06-30 19:48:15 +00002084template <bool _Invokable, class _Ti, class ..._Uj>
2085struct ____mu_return_invokable // false
2086{
2087 typedef __nat type;
2088};
2089
Howard Hinnantc51e1022010-05-11 19:42:16 +00002090template <class _Ti, class ..._Uj>
Howard Hinnant51dae7a2013-06-30 19:48:15 +00002091struct ____mu_return_invokable<true, _Ti, _Uj...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002092{
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002093 typedef typename __invoke_of<_Ti&, _Uj...>::type type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002094};
2095
Howard Hinnant51dae7a2013-06-30 19:48:15 +00002096template <class _Ti, class ..._Uj>
2097struct ____mu_return<_Ti, false, true, false, tuple<_Uj...> >
2098 : public ____mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...>
2099{
2100};
2101
Howard Hinnantc51e1022010-05-11 19:42:16 +00002102template <class _Ti, class _TupleUj>
Howard Hinnant0415d792011-05-22 15:07:43 +00002103struct ____mu_return<_Ti, false, false, true, _TupleUj>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002104{
2105 typedef typename tuple_element<is_placeholder<_Ti>::value - 1,
2106 _TupleUj>::type&& type;
2107};
2108
2109template <class _Ti, class _TupleUj>
Howard Hinnant0415d792011-05-22 15:07:43 +00002110struct ____mu_return<_Ti, true, false, false, _TupleUj>
2111{
2112 typedef typename _Ti::type& type;
2113};
2114
2115template <class _Ti, class _TupleUj>
2116struct ____mu_return<_Ti, false, false, false, _TupleUj>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002117{
2118 typedef _Ti& type;
2119};
2120
2121template <class _Ti, class _TupleUj>
2122struct __mu_return
2123 : public ____mu_return<_Ti,
Howard Hinnant0415d792011-05-22 15:07:43 +00002124 __is_reference_wrapper<_Ti>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002125 is_bind_expression<_Ti>::value,
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002126 0 < is_placeholder<_Ti>::value &&
2127 is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002128 _TupleUj>
2129{
2130};
2131
Howard Hinnantc834c512011-11-29 18:15:50 +00002132template <class _Fp, class _BoundArgs, class _TupleUj>
Eric Fiselier99fffba2015-05-19 22:27:18 +00002133struct __is_valid_bind_return
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002134{
2135 static const bool value = false;
2136};
2137
2138template <class _Fp, class ..._BoundArgs, class _TupleUj>
Eric Fiselier99fffba2015-05-19 22:27:18 +00002139struct __is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002140{
2141 static const bool value = __invokable<_Fp,
2142 typename __mu_return<_BoundArgs, _TupleUj>::type...>::value;
2143};
2144
2145template <class _Fp, class ..._BoundArgs, class _TupleUj>
Eric Fiselier99fffba2015-05-19 22:27:18 +00002146struct __is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002147{
2148 static const bool value = __invokable<_Fp,
2149 typename __mu_return<const _BoundArgs, _TupleUj>::type...>::value;
2150};
2151
2152template <class _Fp, class _BoundArgs, class _TupleUj,
Eric Fiselier99fffba2015-05-19 22:27:18 +00002153 bool = __is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002154struct __bind_return;
2155
Howard Hinnantc834c512011-11-29 18:15:50 +00002156template <class _Fp, class ..._BoundArgs, class _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002157struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002158{
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002159 typedef typename __invoke_of
Howard Hinnantc51e1022010-05-11 19:42:16 +00002160 <
Howard Hinnantc834c512011-11-29 18:15:50 +00002161 _Fp&,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002162 typename __mu_return
2163 <
2164 _BoundArgs,
2165 _TupleUj
2166 >::type...
2167 >::type type;
2168};
2169
Howard Hinnantc834c512011-11-29 18:15:50 +00002170template <class _Fp, class ..._BoundArgs, class _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002171struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002172{
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002173 typedef typename __invoke_of
Howard Hinnantc51e1022010-05-11 19:42:16 +00002174 <
Howard Hinnantc834c512011-11-29 18:15:50 +00002175 _Fp&,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002176 typename __mu_return
2177 <
2178 const _BoundArgs,
2179 _TupleUj
2180 >::type...
2181 >::type type;
2182};
2183
Howard Hinnantc834c512011-11-29 18:15:50 +00002184template <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002185inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00002186typename __bind_return<_Fp, _BoundArgs, _Args>::type
2187__apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002188 _Args&& __args)
2189{
Marshall Clow60e4aa72014-06-24 00:46:19 +00002190 return __invoke(__f, __mu(_VSTD::get<_Indx>(__bound_args), __args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002191}
2192
Howard Hinnantc834c512011-11-29 18:15:50 +00002193template<class _Fp, class ..._BoundArgs>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002194class __bind
Howard Hinnantc834c512011-11-29 18:15:50 +00002195 : public __weak_result_type<typename decay<_Fp>::type>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002196{
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002197protected:
Howard Hinnantc834c512011-11-29 18:15:50 +00002198 typedef typename decay<_Fp>::type _Fd;
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002199 typedef tuple<typename decay<_BoundArgs>::type...> _Td;
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002200private:
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002201 _Fd __f_;
2202 _Td __bound_args_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002203
2204 typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices;
2205public:
Howard Hinnant7091e652011-07-02 18:22:36 +00002206#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2207
2208 _LIBCPP_INLINE_VISIBILITY
2209 __bind(const __bind& __b)
2210 : __f_(__b.__f_),
2211 __bound_args_(__b.__bound_args_) {}
2212
2213 _LIBCPP_INLINE_VISIBILITY
2214 __bind& operator=(const __bind& __b)
2215 {
2216 __f_ = __b.__f_;
2217 __bound_args_ = __b.__bound_args_;
2218 return *this;
2219 }
2220
Howard Hinnant4ff57432010-09-21 22:55:27 +00002221 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002222 __bind(__bind&& __b)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002223 : __f_(_VSTD::move(__b.__f_)),
2224 __bound_args_(_VSTD::move(__b.__bound_args_)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002225
Howard Hinnant7091e652011-07-02 18:22:36 +00002226 _LIBCPP_INLINE_VISIBILITY
2227 __bind& operator=(__bind&& __b)
2228 {
2229 __f_ = _VSTD::move(__b.__f_);
2230 __bound_args_ = _VSTD::move(__b.__bound_args_);
2231 return *this;
2232 }
2233
2234#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2235
Howard Hinnant0337ade2012-05-04 17:21:02 +00002236 template <class _Gp, class ..._BA,
2237 class = typename enable_if
2238 <
Howard Hinnantf292a922013-07-01 00:01:51 +00002239 is_constructible<_Fd, _Gp>::value &&
2240 !is_same<typename remove_reference<_Gp>::type,
2241 __bind>::value
Howard Hinnant0337ade2012-05-04 17:21:02 +00002242 >::type>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002243 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00002244 explicit __bind(_Gp&& __f, _BA&& ...__bound_args)
2245 : __f_(_VSTD::forward<_Gp>(__f)),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002246 __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002247
2248 template <class ..._Args>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002249 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002250 typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00002251 operator()(_Args&& ...__args)
2252 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002253 return __apply_functor(__f_, __bound_args_, __indices(),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002254 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002255 }
2256
2257 template <class ..._Args>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002258 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002259 typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00002260 operator()(_Args&& ...__args) const
2261 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002262 return __apply_functor(__f_, __bound_args_, __indices(),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002263 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002264 }
2265};
2266
Howard Hinnantc834c512011-11-29 18:15:50 +00002267template<class _Fp, class ..._BoundArgs>
2268struct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00002269
Howard Hinnantc834c512011-11-29 18:15:50 +00002270template<class _Rp, class _Fp, class ..._BoundArgs>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002271class __bind_r
Howard Hinnantc834c512011-11-29 18:15:50 +00002272 : public __bind<_Fp, _BoundArgs...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002273{
Howard Hinnantc834c512011-11-29 18:15:50 +00002274 typedef __bind<_Fp, _BoundArgs...> base;
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002275 typedef typename base::_Fd _Fd;
2276 typedef typename base::_Td _Td;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002277public:
Howard Hinnantc834c512011-11-29 18:15:50 +00002278 typedef _Rp result_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002279
Howard Hinnant7091e652011-07-02 18:22:36 +00002280#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2281
2282 _LIBCPP_INLINE_VISIBILITY
2283 __bind_r(const __bind_r& __b)
2284 : base(_VSTD::forward<const base&>(__b)) {}
2285
2286 _LIBCPP_INLINE_VISIBILITY
2287 __bind_r& operator=(const __bind_r& __b)
2288 {
2289 base::operator=(_VSTD::forward<const base&>(__b));
2290 return *this;
2291 }
2292
Howard Hinnantddf09282011-05-16 16:19:01 +00002293 _LIBCPP_INLINE_VISIBILITY
2294 __bind_r(__bind_r&& __b)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002295 : base(_VSTD::forward<base>(__b)) {}
Howard Hinnantddf09282011-05-16 16:19:01 +00002296
Howard Hinnant7091e652011-07-02 18:22:36 +00002297 _LIBCPP_INLINE_VISIBILITY
2298 __bind_r& operator=(__bind_r&& __b)
2299 {
2300 base::operator=(_VSTD::forward<base>(__b));
2301 return *this;
2302 }
2303
2304#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2305
Howard Hinnantf292a922013-07-01 00:01:51 +00002306 template <class _Gp, class ..._BA,
2307 class = typename enable_if
2308 <
2309 is_constructible<_Fd, _Gp>::value &&
2310 !is_same<typename remove_reference<_Gp>::type,
2311 __bind_r>::value
2312 >::type>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002313 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00002314 explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args)
2315 : base(_VSTD::forward<_Gp>(__f),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002316 _VSTD::forward<_BA>(__bound_args)...) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002317
2318 template <class ..._Args>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002319 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002320 typename enable_if
2321 <
2322 is_convertible<typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type,
Eric Fiselier7a8710a2015-07-10 23:29:18 +00002323 result_type>::value || is_void<_Rp>::value,
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002324 result_type
2325 >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00002326 operator()(_Args&& ...__args)
2327 {
Eric Fiselier7a8710a2015-07-10 23:29:18 +00002328 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
2329 return _Invoker::__call(static_cast<base&>(*this), _VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002330 }
2331
2332 template <class ..._Args>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002333 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002334 typename enable_if
2335 <
2336 is_convertible<typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type,
Eric Fiselier7a8710a2015-07-10 23:29:18 +00002337 result_type>::value || is_void<_Rp>::value,
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002338 result_type
2339 >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00002340 operator()(_Args&& ...__args) const
2341 {
Eric Fiselier7a8710a2015-07-10 23:29:18 +00002342 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
2343 return _Invoker::__call(static_cast<base const&>(*this), _VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002344 }
2345};
2346
Howard Hinnantc834c512011-11-29 18:15:50 +00002347template<class _Rp, class _Fp, class ..._BoundArgs>
2348struct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00002349
Howard Hinnantc834c512011-11-29 18:15:50 +00002350template<class _Fp, class ..._BoundArgs>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002351inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00002352__bind<_Fp, _BoundArgs...>
2353bind(_Fp&& __f, _BoundArgs&&... __bound_args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002354{
Howard Hinnantc834c512011-11-29 18:15:50 +00002355 typedef __bind<_Fp, _BoundArgs...> type;
2356 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002357}
2358
Howard Hinnantc834c512011-11-29 18:15:50 +00002359template<class _Rp, class _Fp, class ..._BoundArgs>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002360inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00002361__bind_r<_Rp, _Fp, _BoundArgs...>
2362bind(_Fp&& __f, _BoundArgs&&... __bound_args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002363{
Howard Hinnantc834c512011-11-29 18:15:50 +00002364 typedef __bind_r<_Rp, _Fp, _BoundArgs...> type;
2365 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002366}
2367
2368#endif // _LIBCPP_HAS_NO_VARIADICS
2369
2370template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002371struct _LIBCPP_TYPE_VIS_ONLY hash<bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002372 : public unary_function<bool, size_t>
2373{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002374 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002375 size_t operator()(bool __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002376};
2377
2378template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002379struct _LIBCPP_TYPE_VIS_ONLY hash<char>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002380 : public unary_function<char, size_t>
2381{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002382 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002383 size_t operator()(char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002384};
2385
2386template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002387struct _LIBCPP_TYPE_VIS_ONLY hash<signed char>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002388 : public unary_function<signed char, size_t>
2389{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002390 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002391 size_t operator()(signed char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002392};
2393
2394template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002395struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned char>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002396 : public unary_function<unsigned char, size_t>
2397{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002398 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002399 size_t operator()(unsigned char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002400};
2401
2402#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
2403
2404template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002405struct _LIBCPP_TYPE_VIS_ONLY hash<char16_t>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002406 : public unary_function<char16_t, size_t>
2407{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002408 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002409 size_t operator()(char16_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002410};
2411
2412template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002413struct _LIBCPP_TYPE_VIS_ONLY hash<char32_t>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002414 : public unary_function<char32_t, size_t>
2415{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002416 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002417 size_t operator()(char32_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002418};
2419
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002420#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002421
2422template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002423struct _LIBCPP_TYPE_VIS_ONLY hash<wchar_t>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002424 : public unary_function<wchar_t, size_t>
2425{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002426 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002427 size_t operator()(wchar_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002428};
2429
2430template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002431struct _LIBCPP_TYPE_VIS_ONLY hash<short>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002432 : public unary_function<short, size_t>
2433{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002434 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002435 size_t operator()(short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002436};
2437
2438template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002439struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned short>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002440 : public unary_function<unsigned short, size_t>
2441{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002442 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002443 size_t operator()(unsigned short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002444};
2445
2446template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002447struct _LIBCPP_TYPE_VIS_ONLY hash<int>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002448 : public unary_function<int, size_t>
2449{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002450 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002451 size_t operator()(int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002452};
2453
2454template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002455struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned int>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002456 : public unary_function<unsigned int, size_t>
2457{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002458 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002459 size_t operator()(unsigned int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002460};
2461
2462template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002463struct _LIBCPP_TYPE_VIS_ONLY hash<long>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002464 : public unary_function<long, size_t>
2465{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002466 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002467 size_t operator()(long __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002468};
2469
2470template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002471struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned long>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002472 : public unary_function<unsigned long, size_t>
2473{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002474 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002475 size_t operator()(unsigned long __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002476};
2477
2478template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002479struct _LIBCPP_TYPE_VIS_ONLY hash<long long>
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002480 : public __scalar_hash<long long>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002481{
Howard Hinnantc51e1022010-05-11 19:42:16 +00002482};
2483
2484template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002485struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned long long>
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002486 : public __scalar_hash<unsigned long long>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002487{
Howard Hinnantc51e1022010-05-11 19:42:16 +00002488};
2489
Eric Fiselier9f0e3662016-04-18 02:54:00 +00002490#ifndef _LIBCPP_HAS_NO_INT128
2491
2492template <>
2493struct _LIBCPP_TYPE_VIS_ONLY hash<__int128_t>
2494 : public __scalar_hash<__int128_t>
2495{
2496};
2497
2498template <>
2499struct _LIBCPP_TYPE_VIS_ONLY hash<__uint128_t>
2500 : public __scalar_hash<__uint128_t>
2501{
2502};
2503
2504#endif
2505
Howard Hinnantc51e1022010-05-11 19:42:16 +00002506template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002507struct _LIBCPP_TYPE_VIS_ONLY hash<float>
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002508 : public __scalar_hash<float>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002509{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002510 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002511 size_t operator()(float __v) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002512 {
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002513 // -0.0 and 0.0 should return same hash
Howard Hinnantf52511f2011-12-02 23:45:22 +00002514 if (__v == 0)
2515 return 0;
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002516 return __scalar_hash<float>::operator()(__v);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002517 }
2518};
2519
2520template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002521struct _LIBCPP_TYPE_VIS_ONLY hash<double>
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002522 : public __scalar_hash<double>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002523{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002524 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002525 size_t operator()(double __v) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002526 {
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002527 // -0.0 and 0.0 should return same hash
2528 if (__v == 0)
2529 return 0;
2530 return __scalar_hash<double>::operator()(__v);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002531 }
2532};
2533
2534template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002535struct _LIBCPP_TYPE_VIS_ONLY hash<long double>
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002536 : public __scalar_hash<long double>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002537{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002538 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002539 size_t operator()(long double __v) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002540 {
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002541 // -0.0 and 0.0 should return same hash
Howard Hinnantc51e1022010-05-11 19:42:16 +00002542 if (__v == 0)
2543 return 0;
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002544#if defined(__i386__)
2545 // Zero out padding bits
2546 union
Howard Hinnantf52511f2011-12-02 23:45:22 +00002547 {
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002548 long double __t;
2549 struct
Howard Hinnantf52511f2011-12-02 23:45:22 +00002550 {
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002551 size_t __a;
2552 size_t __b;
2553 size_t __c;
Howard Hinnantf52511f2011-12-02 23:45:22 +00002554 size_t __d;
Eric Fiseliere012bf22015-07-18 20:40:46 +00002555 } __s;
Howard Hinnantf52511f2011-12-02 23:45:22 +00002556 } __u;
Eric Fiseliere012bf22015-07-18 20:40:46 +00002557 __u.__s.__a = 0;
2558 __u.__s.__b = 0;
2559 __u.__s.__c = 0;
2560 __u.__s.__d = 0;
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002561 __u.__t = __v;
Eric Fiseliere012bf22015-07-18 20:40:46 +00002562 return __u.__s.__a ^ __u.__s.__b ^ __u.__s.__c ^ __u.__s.__d;
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002563#elif defined(__x86_64__)
2564 // Zero out padding bits
2565 union
2566 {
2567 long double __t;
2568 struct
2569 {
2570 size_t __a;
2571 size_t __b;
Eric Fiseliere012bf22015-07-18 20:40:46 +00002572 } __s;
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002573 } __u;
Eric Fiseliere012bf22015-07-18 20:40:46 +00002574 __u.__s.__a = 0;
2575 __u.__s.__b = 0;
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002576 __u.__t = __v;
Eric Fiseliere012bf22015-07-18 20:40:46 +00002577 return __u.__s.__a ^ __u.__s.__b;
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002578#else
2579 return __scalar_hash<long double>::operator()(__v);
2580#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002581 }
2582};
2583
Marshall Clowc3f19e42013-09-03 17:55:32 +00002584#if _LIBCPP_STD_VER > 11
Eric Fiselier043a7b42016-08-10 22:45:26 +00002585
2586template <class _Tp, bool = is_enum<_Tp>::value>
2587struct _LIBCPP_TYPE_VIS_ONLY __enum_hash
Marshall Clowc3f19e42013-09-03 17:55:32 +00002588 : public unary_function<_Tp, size_t>
2589{
Marshall Clowc3f19e42013-09-03 17:55:32 +00002590 _LIBCPP_INLINE_VISIBILITY
2591 size_t operator()(_Tp __v) const _NOEXCEPT
2592 {
2593 typedef typename underlying_type<_Tp>::type type;
2594 return hash<type>{}(static_cast<type>(__v));
2595 }
2596};
Eric Fiselier043a7b42016-08-10 22:45:26 +00002597template <class _Tp>
2598struct _LIBCPP_TYPE_VIS_ONLY __enum_hash<_Tp, false> {
2599 __enum_hash() = delete;
2600 __enum_hash(__enum_hash const&) = delete;
2601 __enum_hash& operator=(__enum_hash const&) = delete;
2602};
2603
2604template <class _Tp>
2605struct _LIBCPP_TYPE_VIS_ONLY hash : public __enum_hash<_Tp>
2606{
2607};
Marshall Clowc3f19e42013-09-03 17:55:32 +00002608#endif
2609
Eric Fiselier0d974f12015-07-14 20:16:15 +00002610
2611#if _LIBCPP_STD_VER > 14
Eric Fiselier934f63b2016-06-02 01:25:41 +00002612
Eric Fiselier0d974f12015-07-14 20:16:15 +00002613template <class _Fn, class ..._Args>
2614result_of_t<_Fn&&(_Args&&...)>
Eric Fiselier934f63b2016-06-02 01:25:41 +00002615invoke(_Fn&& __f, _Args&&... __args)
2616 noexcept(noexcept(_VSTD::__invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...)))
2617{
2618 return _VSTD::__invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...);
Eric Fiselier0d974f12015-07-14 20:16:15 +00002619}
Eric Fiselier934f63b2016-06-02 01:25:41 +00002620
2621template <class _DecayFunc>
2622class _LIBCPP_TYPE_VIS_ONLY __not_fn_imp {
2623 _DecayFunc __fd;
2624
2625public:
2626 __not_fn_imp() = delete;
2627
2628 template <class ..._Args>
2629 _LIBCPP_INLINE_VISIBILITY
Eric Fiseliere8303a32016-06-27 00:40:41 +00002630 auto operator()(_Args&& ...__args) &
Eric Fiselier934f63b2016-06-02 01:25:41 +00002631 noexcept(noexcept(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)))
2632 -> decltype(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...))
2633 { return !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); }
2634
2635 template <class ..._Args>
2636 _LIBCPP_INLINE_VISIBILITY
Eric Fiseliere8303a32016-06-27 00:40:41 +00002637 auto operator()(_Args&& ...__args) &&
2638 noexcept(noexcept(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)))
2639 -> decltype(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...))
2640 { return !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); }
2641
2642 template <class ..._Args>
2643 _LIBCPP_INLINE_VISIBILITY
2644 auto operator()(_Args&& ...__args) const&
Eric Fiselier934f63b2016-06-02 01:25:41 +00002645 noexcept(noexcept(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)))
2646 -> decltype(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...))
2647 { return !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); }
2648
Eric Fiseliere8303a32016-06-27 00:40:41 +00002649
2650 template <class ..._Args>
2651 _LIBCPP_INLINE_VISIBILITY
2652 auto operator()(_Args&& ...__args) const&&
2653 noexcept(noexcept(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)))
2654 -> decltype(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...))
2655 { return !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); }
2656
Eric Fiselier934f63b2016-06-02 01:25:41 +00002657private:
2658 template <class _RawFunc,
2659 class = enable_if_t<!is_same<decay_t<_RawFunc>, __not_fn_imp>::value>>
2660 _LIBCPP_INLINE_VISIBILITY
2661 explicit __not_fn_imp(_RawFunc&& __rf)
2662 : __fd(_VSTD::forward<_RawFunc>(__rf)) {}
2663
2664 template <class _RawFunc>
2665 friend inline _LIBCPP_INLINE_VISIBILITY
2666 __not_fn_imp<decay_t<_RawFunc>> not_fn(_RawFunc&&);
2667};
2668
2669template <class _RawFunc>
2670inline _LIBCPP_INLINE_VISIBILITY
2671__not_fn_imp<decay_t<_RawFunc>> not_fn(_RawFunc&& __fn) {
2672 return __not_fn_imp<decay_t<_RawFunc>>(_VSTD::forward<_RawFunc>(__fn));
2673}
2674
Eric Fiselier0d974f12015-07-14 20:16:15 +00002675#endif
2676
Howard Hinnant36b31ae2010-06-03 16:42:57 +00002677// struct hash<T*> in <memory>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002678
Howard Hinnantc51e1022010-05-11 19:42:16 +00002679_LIBCPP_END_NAMESPACE_STD
2680
2681#endif // _LIBCPP_FUNCTIONAL