2 //===------------------------ functional ----------------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #ifndef _LIBCPP_FUNCTIONAL
12 #define _LIBCPP_FUNCTIONAL
20 template <class Arg, class Result>
23 typedef Arg argument_type;
24 typedef Result result_type;
27 template <class Arg1, class Arg2, class Result>
28 struct binary_function
30 typedef Arg1 first_argument_type;
31 typedef Arg2 second_argument_type;
32 typedef Result result_type;
36 class 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
43 typedef see below result_type; // Not always defined
45 // construct/copy/destroy
46 reference_wrapper(T&) noexcept;
47 reference_wrapper(T&&) = delete; // do not bind to temps
48 reference_wrapper(const reference_wrapper<T>& x) noexcept;
51 reference_wrapper& operator=(const reference_wrapper<T>& x) noexcept;
54 operator T& () const noexcept;
55 T& get() const noexcept;
58 template <class... ArgTypes>
59 typename result_of<T&(ArgTypes&&...)>::type
60 operator() (ArgTypes&&...) const;
63 template <class T> reference_wrapper<T> ref(T& t) noexcept;
64 template <class T> void ref(const T&& t) = delete;
65 template <class T> reference_wrapper<T> ref(reference_wrapper<T>t) noexcept;
67 template <class T> reference_wrapper<const T> cref(const T& t) noexcept;
68 template <class T> void cref(const T&& t) = delete;
69 template <class T> reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept;
71 template <class T> // <class T=void> in C++14
72 struct plus : binary_function<T, T, T>
74 T operator()(const T& x, const T& y) const;
77 template <class T> // <class T=void> in C++14
78 struct minus : binary_function<T, T, T>
80 T operator()(const T& x, const T& y) const;
83 template <class T> // <class T=void> in C++14
84 struct multiplies : binary_function<T, T, T>
86 T operator()(const T& x, const T& y) const;
89 template <class T> // <class T=void> in C++14
90 struct divides : binary_function<T, T, T>
92 T operator()(const T& x, const T& y) const;
95 template <class T> // <class T=void> in C++14
96 struct modulus : binary_function<T, T, T>
98 T operator()(const T& x, const T& y) const;
101 template <class T> // <class T=void> in C++14
102 struct negate : unary_function<T, T>
104 T operator()(const T& x) const;
107 template <class T> // <class T=void> in C++14
108 struct equal_to : binary_function<T, T, bool>
110 bool operator()(const T& x, const T& y) const;
113 template <class T> // <class T=void> in C++14
114 struct not_equal_to : binary_function<T, T, bool>
116 bool operator()(const T& x, const T& y) const;
119 template <class T> // <class T=void> in C++14
120 struct greater : binary_function<T, T, bool>
122 bool operator()(const T& x, const T& y) const;
125 template <class T> // <class T=void> in C++14
126 struct less : binary_function<T, T, bool>
128 bool operator()(const T& x, const T& y) const;
131 template <class T> // <class T=void> in C++14
132 struct greater_equal : binary_function<T, T, bool>
134 bool operator()(const T& x, const T& y) const;
137 template <class T> // <class T=void> in C++14
138 struct less_equal : binary_function<T, T, bool>
140 bool operator()(const T& x, const T& y) const;
143 template <class T> // <class T=void> in C++14
144 struct logical_and : binary_function<T, T, bool>
146 bool operator()(const T& x, const T& y) const;
149 template <class T> // <class T=void> in C++14
150 struct logical_or : binary_function<T, T, bool>
152 bool operator()(const T& x, const T& y) const;
155 template <class T> // <class T=void> in C++14
156 struct logical_not : unary_function<T, bool>
158 bool operator()(const T& x) const;
161 template <class T> // <class T=void> in C++14
162 struct bit_and : unary_function<T, bool>
164 bool operator()(const T& x, const T& y) const;
167 template <class T> // <class T=void> in C++14
168 struct bit_or : unary_function<T, bool>
170 bool operator()(const T& x, const T& y) const;
173 template <class T> // <class T=void> in C++14
174 struct bit_xor : unary_function<T, bool>
176 bool operator()(const T& x, const T& y) const;
179 template <class T=void> // C++14
180 struct bit_xor : unary_function<T, bool>
182 bool operator()(const T& x) const;
185 template <class Predicate>
187 : public unary_function<typename Predicate::argument_type, bool>
190 explicit unary_negate(const Predicate& pred);
191 bool operator()(const typename Predicate::argument_type& x) const;
194 template <class Predicate> unary_negate<Predicate> not1(const Predicate& pred);
196 template <class Predicate>
198 : public binary_function<typename Predicate::first_argument_type,
199 typename Predicate::second_argument_type,
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;
208 template <class Predicate> binary_negate<Predicate> not2(const Predicate& pred);
210 template <class F> unspecified not_fn(F&& f); // C++17
212 template<class T> struct is_bind_expression;
213 template<class T> struct is_placeholder;
215 template<class Fn, class... BoundArgs>
216 unspecified bind(Fn&&, BoundArgs&&...);
217 template<class R, class Fn, class... BoundArgs>
218 unspecified bind(Fn&&, BoundArgs&&...);
220 namespace placeholders {
221 // M is the implementation-defined number of placeholders
222 extern unspecified _1;
223 extern unspecified _2;
227 extern unspecified _Mp;
230 template <class Operation>
232 : public unary_function<typename Operation::second_argument_type,
233 typename Operation::result_type>
237 typename Operation::first_argument_type value;
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;
244 template <class Operation, class T>
245 binder1st<Operation> bind1st(const Operation& op, const T& x);
247 template <class Operation>
249 : public unary_function<typename Operation::first_argument_type,
250 typename Operation::result_type>
254 typename Operation::second_argument_type value;
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;
261 template <class Operation, class T>
262 binder2nd<Operation> bind2nd(const Operation& op, const T& x);
264 template <class Arg, class Result>
265 class pointer_to_unary_function : public unary_function<Arg, Result>
268 explicit pointer_to_unary_function(Result (*f)(Arg));
269 Result operator()(Arg x) const;
272 template <class Arg, class Result>
273 pointer_to_unary_function<Arg,Result> ptr_fun(Result (*f)(Arg));
275 template <class Arg1, class Arg2, class Result>
276 class pointer_to_binary_function : public binary_function<Arg1, Arg2, Result>
279 explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2));
280 Result operator()(Arg1 x, Arg2 y) const;
283 template <class Arg1, class Arg2, class Result>
284 pointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1,Arg2));
286 template<class S, class T>
287 class mem_fun_t : public unary_function<T*, S>
290 explicit mem_fun_t(S (T::*p)());
291 S operator()(T* p) const;
294 template<class S, class T, class A>
295 class mem_fun1_t : public binary_function<T*, A, S>
298 explicit mem_fun1_t(S (T::*p)(A));
299 S operator()(T* p, A x) const;
302 template<class S, class T> mem_fun_t<S,T> mem_fun(S (T::*f)());
303 template<class S, class T, class A> mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A));
305 template<class S, class T>
306 class mem_fun_ref_t : public unary_function<T, S>
309 explicit mem_fun_ref_t(S (T::*p)());
310 S operator()(T& p) const;
313 template<class S, class T, class A>
314 class mem_fun1_ref_t : public binary_function<T, A, S>
317 explicit mem_fun1_ref_t(S (T::*p)(A));
318 S operator()(T& p, A x) const;
321 template<class S, class T> mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)());
322 template<class S, class T, class A> mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A));
324 template <class S, class T>
325 class const_mem_fun_t : public unary_function<const T*, S>
328 explicit const_mem_fun_t(S (T::*p)() const);
329 S operator()(const T* p) const;
332 template <class S, class T, class A>
333 class const_mem_fun1_t : public binary_function<const T*, A, S>
336 explicit const_mem_fun1_t(S (T::*p)(A) const);
337 S operator()(const T* p, A x) const;
340 template <class S, class T> const_mem_fun_t<S,T> mem_fun(S (T::*f)() const);
341 template <class S, class T, class A> const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const);
343 template <class S, class T>
344 class const_mem_fun_ref_t : public unary_function<T, S>
347 explicit const_mem_fun_ref_t(S (T::*p)() const);
348 S operator()(const T& p) const;
351 template <class S, class T, class A>
352 class const_mem_fun1_ref_t : public binary_function<T, A, S>
355 explicit const_mem_fun1_ref_t(S (T::*p)(A) const);
356 S operator()(const T& p, A x) const;
359 template <class S, class T> const_mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)() const);
360 template <class S, class T, class A> const_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const);
362 template<class R, class T> unspecified mem_fn(R T::*);
364 class bad_function_call
369 template<class> class function; // undefined
371 template<class R, class... ArgTypes>
372 class 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
379 typedef R result_type;
381 // construct/copy/destroy:
383 function(nullptr_t) noexcept;
384 function(const function&);
385 function(function&&) noexcept;
388 template<Allocator Alloc>
389 function(allocator_arg_t, const Alloc&) noexcept;
390 template<Allocator Alloc>
391 function(allocator_arg_t, const Alloc&, nullptr_t) noexcept;
392 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);
399 function& operator=(const function&);
400 function& operator=(function&&) noexcept;
401 function& operator=(nullptr_t) noexcept;
403 function& operator=(F&&);
405 function& operator=(reference_wrapper<F>) noexcept;
409 // function modifiers:
410 void swap(function&) noexcept;
411 template<class F, class Alloc>
412 void assign(F&&, const Alloc&); // Removed in C++17
414 // function capacity:
415 explicit operator bool() const noexcept;
417 // function invocation:
418 R operator()(ArgTypes...) const;
420 // function target access:
421 const std::type_info& target_type() const noexcept;
422 template <typename T> T* target() noexcept;
423 template <typename T> const T* target() const noexcept;
426 // Null pointer comparisons:
427 template <class R, class ... ArgTypes>
428 bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
430 template <class R, class ... ArgTypes>
431 bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
433 template <class R, class ... ArgTypes>
434 bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
436 template <class R, class ... ArgTypes>
437 bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
439 // specialized algorithms:
440 template <class R, class ... ArgTypes>
441 void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
443 template <class T> struct hash;
445 template <> struct hash<bool>;
446 template <> struct hash<char>;
447 template <> struct hash<signed char>;
448 template <> struct hash<unsigned char>;
449 template <> struct hash<char16_t>;
450 template <> struct hash<char32_t>;
451 template <> struct hash<wchar_t>;
452 template <> struct hash<short>;
453 template <> struct hash<unsigned short>;
454 template <> struct hash<int>;
455 template <> struct hash<unsigned int>;
456 template <> struct hash<long>;
457 template <> struct hash<long long>;
458 template <> struct hash<unsigned long>;
459 template <> struct hash<unsigned long long>;
461 template <> struct hash<float>;
462 template <> struct hash<double>;
463 template <> struct hash<long double>;
465 template<class T> struct hash<T*>;
469 POLICY: For non-variadic implementations, the number of arguments is limited
470 to 3. It is hoped that the need for non-variadic implementations
476 #include <type_traits>
482 #include <__functional_base>
484 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
485 #pragma GCC system_header
488 _LIBCPP_BEGIN_NAMESPACE_STD
490 #if _LIBCPP_STD_VER > 11
491 template <class _Tp = void>
495 struct _LIBCPP_TYPE_VIS_ONLY plus : binary_function<_Tp, _Tp, _Tp>
497 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
498 _Tp operator()(const _Tp& __x, const _Tp& __y) const
502 #if _LIBCPP_STD_VER > 11
504 struct _LIBCPP_TYPE_VIS_ONLY plus<void>
506 template <class _T1, class _T2>
507 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
508 auto operator()(_T1&& __t, _T2&& __u) const
509 _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); }
512 typedef void is_transparent;
517 #if _LIBCPP_STD_VER > 11
518 template <class _Tp = void>
522 struct _LIBCPP_TYPE_VIS_ONLY minus : binary_function<_Tp, _Tp, _Tp>
524 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
525 _Tp operator()(const _Tp& __x, const _Tp& __y) const
529 #if _LIBCPP_STD_VER > 11
531 struct _LIBCPP_TYPE_VIS_ONLY minus<void>
533 template <class _T1, class _T2>
534 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
535 auto operator()(_T1&& __t, _T2&& __u) const
536 _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); }
539 typedef void is_transparent;
544 #if _LIBCPP_STD_VER > 11
545 template <class _Tp = void>
549 struct _LIBCPP_TYPE_VIS_ONLY multiplies : binary_function<_Tp, _Tp, _Tp>
551 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
552 _Tp operator()(const _Tp& __x, const _Tp& __y) const
556 #if _LIBCPP_STD_VER > 11
558 struct _LIBCPP_TYPE_VIS_ONLY multiplies<void>
560 template <class _T1, class _T2>
561 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
562 auto operator()(_T1&& __t, _T2&& __u) const
563 _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); }
566 typedef void is_transparent;
571 #if _LIBCPP_STD_VER > 11
572 template <class _Tp = void>
576 struct _LIBCPP_TYPE_VIS_ONLY divides : binary_function<_Tp, _Tp, _Tp>
578 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
579 _Tp operator()(const _Tp& __x, const _Tp& __y) const
583 #if _LIBCPP_STD_VER > 11
585 struct _LIBCPP_TYPE_VIS_ONLY divides<void>
587 template <class _T1, class _T2>
588 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
589 auto operator()(_T1&& __t, _T2&& __u) const
590 _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); }
593 typedef void is_transparent;
598 #if _LIBCPP_STD_VER > 11
599 template <class _Tp = void>
603 struct _LIBCPP_TYPE_VIS_ONLY modulus : binary_function<_Tp, _Tp, _Tp>
605 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
606 _Tp operator()(const _Tp& __x, const _Tp& __y) const
610 #if _LIBCPP_STD_VER > 11
612 struct _LIBCPP_TYPE_VIS_ONLY modulus<void>
614 template <class _T1, class _T2>
615 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
616 auto operator()(_T1&& __t, _T2&& __u) const
617 _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); }
620 typedef void is_transparent;
625 #if _LIBCPP_STD_VER > 11
626 template <class _Tp = void>
630 struct _LIBCPP_TYPE_VIS_ONLY negate : unary_function<_Tp, _Tp>
632 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
633 _Tp operator()(const _Tp& __x) const
637 #if _LIBCPP_STD_VER > 11
639 struct _LIBCPP_TYPE_VIS_ONLY negate<void>
642 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
643 auto operator()(_Tp&& __x) const
644 _NOEXCEPT_(noexcept(- _VSTD::forward<_Tp>(__x)))
645 -> decltype (- _VSTD::forward<_Tp>(__x))
646 { return - _VSTD::forward<_Tp>(__x); }
647 typedef void is_transparent;
652 #if _LIBCPP_STD_VER > 11
653 template <class _Tp = void>
657 struct _LIBCPP_TYPE_VIS_ONLY equal_to : binary_function<_Tp, _Tp, bool>
659 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
660 bool operator()(const _Tp& __x, const _Tp& __y) const
664 #if _LIBCPP_STD_VER > 11
666 struct _LIBCPP_TYPE_VIS_ONLY equal_to<void>
668 template <class _T1, class _T2>
669 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
670 auto operator()(_T1&& __t, _T2&& __u) const
671 _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); }
674 typedef void is_transparent;
679 #if _LIBCPP_STD_VER > 11
680 template <class _Tp = void>
684 struct _LIBCPP_TYPE_VIS_ONLY not_equal_to : binary_function<_Tp, _Tp, bool>
686 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
687 bool operator()(const _Tp& __x, const _Tp& __y) const
691 #if _LIBCPP_STD_VER > 11
693 struct _LIBCPP_TYPE_VIS_ONLY not_equal_to<void>
695 template <class _T1, class _T2>
696 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
697 auto operator()(_T1&& __t, _T2&& __u) const
698 _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); }
701 typedef void is_transparent;
706 #if _LIBCPP_STD_VER > 11
707 template <class _Tp = void>
711 struct _LIBCPP_TYPE_VIS_ONLY greater : binary_function<_Tp, _Tp, bool>
713 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
714 bool operator()(const _Tp& __x, const _Tp& __y) const
718 #if _LIBCPP_STD_VER > 11
720 struct _LIBCPP_TYPE_VIS_ONLY greater<void>
722 template <class _T1, class _T2>
723 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
724 auto operator()(_T1&& __t, _T2&& __u) const
725 _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); }
728 typedef void is_transparent;
733 // less in <__functional_base>
735 #if _LIBCPP_STD_VER > 11
736 template <class _Tp = void>
740 struct _LIBCPP_TYPE_VIS_ONLY greater_equal : binary_function<_Tp, _Tp, bool>
742 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
743 bool operator()(const _Tp& __x, const _Tp& __y) const
747 #if _LIBCPP_STD_VER > 11
749 struct _LIBCPP_TYPE_VIS_ONLY greater_equal<void>
751 template <class _T1, class _T2>
752 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
753 auto operator()(_T1&& __t, _T2&& __u) const
754 _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); }
757 typedef void is_transparent;
762 #if _LIBCPP_STD_VER > 11
763 template <class _Tp = void>
767 struct _LIBCPP_TYPE_VIS_ONLY less_equal : binary_function<_Tp, _Tp, bool>
769 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
770 bool operator()(const _Tp& __x, const _Tp& __y) const
774 #if _LIBCPP_STD_VER > 11
776 struct _LIBCPP_TYPE_VIS_ONLY less_equal<void>
778 template <class _T1, class _T2>
779 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
780 auto operator()(_T1&& __t, _T2&& __u) const
781 _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); }
784 typedef void is_transparent;
789 #if _LIBCPP_STD_VER > 11
790 template <class _Tp = void>
794 struct _LIBCPP_TYPE_VIS_ONLY logical_and : binary_function<_Tp, _Tp, bool>
796 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
797 bool operator()(const _Tp& __x, const _Tp& __y) const
801 #if _LIBCPP_STD_VER > 11
803 struct _LIBCPP_TYPE_VIS_ONLY logical_and<void>
805 template <class _T1, class _T2>
806 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
807 auto operator()(_T1&& __t, _T2&& __u) const
808 _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); }
811 typedef void is_transparent;
816 #if _LIBCPP_STD_VER > 11
817 template <class _Tp = void>
821 struct _LIBCPP_TYPE_VIS_ONLY logical_or : binary_function<_Tp, _Tp, bool>
823 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
824 bool operator()(const _Tp& __x, const _Tp& __y) const
828 #if _LIBCPP_STD_VER > 11
830 struct _LIBCPP_TYPE_VIS_ONLY logical_or<void>
832 template <class _T1, class _T2>
833 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
834 auto operator()(_T1&& __t, _T2&& __u) const
835 _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); }
838 typedef void is_transparent;
843 #if _LIBCPP_STD_VER > 11
844 template <class _Tp = void>
848 struct _LIBCPP_TYPE_VIS_ONLY logical_not : unary_function<_Tp, bool>
850 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
851 bool operator()(const _Tp& __x) const
855 #if _LIBCPP_STD_VER > 11
857 struct _LIBCPP_TYPE_VIS_ONLY logical_not<void>
860 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
861 auto operator()(_Tp&& __x) const
862 _NOEXCEPT_(noexcept(!_VSTD::forward<_Tp>(__x)))
863 -> decltype (!_VSTD::forward<_Tp>(__x))
864 { return !_VSTD::forward<_Tp>(__x); }
865 typedef void is_transparent;
870 #if _LIBCPP_STD_VER > 11
871 template <class _Tp = void>
875 struct _LIBCPP_TYPE_VIS_ONLY bit_and : binary_function<_Tp, _Tp, _Tp>
877 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
878 _Tp operator()(const _Tp& __x, const _Tp& __y) const
882 #if _LIBCPP_STD_VER > 11
884 struct _LIBCPP_TYPE_VIS_ONLY bit_and<void>
886 template <class _T1, class _T2>
887 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
888 auto operator()(_T1&& __t, _T2&& __u) const
889 _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); }
892 typedef void is_transparent;
897 #if _LIBCPP_STD_VER > 11
898 template <class _Tp = void>
902 struct _LIBCPP_TYPE_VIS_ONLY bit_or : binary_function<_Tp, _Tp, _Tp>
904 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
905 _Tp operator()(const _Tp& __x, const _Tp& __y) const
909 #if _LIBCPP_STD_VER > 11
911 struct _LIBCPP_TYPE_VIS_ONLY bit_or<void>
913 template <class _T1, class _T2>
914 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
915 auto operator()(_T1&& __t, _T2&& __u) const
916 _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); }
919 typedef void is_transparent;
924 #if _LIBCPP_STD_VER > 11
925 template <class _Tp = void>
929 struct _LIBCPP_TYPE_VIS_ONLY bit_xor : binary_function<_Tp, _Tp, _Tp>
931 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
932 _Tp operator()(const _Tp& __x, const _Tp& __y) const
936 #if _LIBCPP_STD_VER > 11
938 struct _LIBCPP_TYPE_VIS_ONLY bit_xor<void>
940 template <class _T1, class _T2>
941 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
942 auto operator()(_T1&& __t, _T2&& __u) const
943 _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); }
946 typedef void is_transparent;
951 #if _LIBCPP_STD_VER > 11
952 template <class _Tp = void>
953 struct _LIBCPP_TYPE_VIS_ONLY bit_not : unary_function<_Tp, _Tp>
955 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
956 _Tp operator()(const _Tp& __x) const
961 struct _LIBCPP_TYPE_VIS_ONLY bit_not<void>
964 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
965 auto operator()(_Tp&& __x) const
966 _NOEXCEPT_(noexcept(~_VSTD::forward<_Tp>(__x)))
967 -> decltype (~_VSTD::forward<_Tp>(__x))
968 { return ~_VSTD::forward<_Tp>(__x); }
969 typedef void is_transparent;
973 template <class _Predicate>
974 class _LIBCPP_TYPE_VIS_ONLY unary_negate
975 : public unary_function<typename _Predicate::argument_type, bool>
979 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
980 explicit unary_negate(const _Predicate& __pred)
982 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
983 bool operator()(const typename _Predicate::argument_type& __x) const
984 {return !__pred_(__x);}
987 template <class _Predicate>
988 inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
989 unary_negate<_Predicate>
990 not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);}
992 template <class _Predicate>
993 class _LIBCPP_TYPE_VIS_ONLY binary_negate
994 : public binary_function<typename _Predicate::first_argument_type,
995 typename _Predicate::second_argument_type,
1000 _LIBCPP_INLINE_VISIBILITY explicit _LIBCPP_CONSTEXPR_AFTER_CXX11
1001 binary_negate(const _Predicate& __pred) : __pred_(__pred) {}
1003 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1004 bool operator()(const typename _Predicate::first_argument_type& __x,
1005 const typename _Predicate::second_argument_type& __y) const
1006 {return !__pred_(__x, __y);}
1009 template <class _Predicate>
1010 inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1011 binary_negate<_Predicate>
1012 not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);}
1014 template <class __Operation>
1015 class _LIBCPP_TYPE_VIS_ONLY binder1st
1016 : public unary_function<typename __Operation::second_argument_type,
1017 typename __Operation::result_type>
1021 typename __Operation::first_argument_type value;
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);}
1034 template <class __Operation, class _Tp>
1035 inline _LIBCPP_INLINE_VISIBILITY
1036 binder1st<__Operation>
1037 bind1st(const __Operation& __op, const _Tp& __x)
1038 {return binder1st<__Operation>(__op, __x);}
1040 template <class __Operation>
1041 class _LIBCPP_TYPE_VIS_ONLY binder2nd
1042 : public unary_function<typename __Operation::first_argument_type,
1043 typename __Operation::result_type>
1047 typename __Operation::second_argument_type value;
1049 _LIBCPP_INLINE_VISIBILITY
1050 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);}
1060 template <class __Operation, class _Tp>
1061 inline _LIBCPP_INLINE_VISIBILITY
1062 binder2nd<__Operation>
1063 bind2nd(const __Operation& __op, const _Tp& __x)
1064 {return binder2nd<__Operation>(__op, __x);}
1066 template <class _Arg, class _Result>
1067 class _LIBCPP_TYPE_VIS_ONLY pointer_to_unary_function
1068 : public unary_function<_Arg, _Result>
1070 _Result (*__f_)(_Arg);
1072 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg))
1074 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const
1078 template <class _Arg, class _Result>
1079 inline _LIBCPP_INLINE_VISIBILITY
1080 pointer_to_unary_function<_Arg,_Result>
1081 ptr_fun(_Result (*__f)(_Arg))
1082 {return pointer_to_unary_function<_Arg,_Result>(__f);}
1084 template <class _Arg1, class _Arg2, class _Result>
1085 class _LIBCPP_TYPE_VIS_ONLY pointer_to_binary_function
1086 : public binary_function<_Arg1, _Arg2, _Result>
1088 _Result (*__f_)(_Arg1, _Arg2);
1090 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2))
1092 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const
1093 {return __f_(__x, __y);}
1096 template <class _Arg1, class _Arg2, class _Result>
1097 inline _LIBCPP_INLINE_VISIBILITY
1098 pointer_to_binary_function<_Arg1,_Arg2,_Result>
1099 ptr_fun(_Result (*__f)(_Arg1,_Arg2))
1100 {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);}
1102 template<class _Sp, class _Tp>
1103 class _LIBCPP_TYPE_VIS_ONLY mem_fun_t : public unary_function<_Tp*, _Sp>
1107 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)())
1109 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const
1110 {return (__p->*__p_)();}
1113 template<class _Sp, class _Tp, class _Ap>
1114 class _LIBCPP_TYPE_VIS_ONLY mem_fun1_t : public binary_function<_Tp*, _Ap, _Sp>
1116 _Sp (_Tp::*__p_)(_Ap);
1118 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap))
1120 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const
1121 {return (__p->*__p_)(__x);}
1124 template<class _Sp, class _Tp>
1125 inline _LIBCPP_INLINE_VISIBILITY
1127 mem_fun(_Sp (_Tp::*__f)())
1128 {return mem_fun_t<_Sp,_Tp>(__f);}
1130 template<class _Sp, class _Tp, class _Ap>
1131 inline _LIBCPP_INLINE_VISIBILITY
1132 mem_fun1_t<_Sp,_Tp,_Ap>
1133 mem_fun(_Sp (_Tp::*__f)(_Ap))
1134 {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1136 template<class _Sp, class _Tp>
1137 class _LIBCPP_TYPE_VIS_ONLY mem_fun_ref_t : public unary_function<_Tp, _Sp>
1141 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)())
1143 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const
1144 {return (__p.*__p_)();}
1147 template<class _Sp, class _Tp, class _Ap>
1148 class _LIBCPP_TYPE_VIS_ONLY mem_fun1_ref_t : public binary_function<_Tp, _Ap, _Sp>
1150 _Sp (_Tp::*__p_)(_Ap);
1152 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap))
1154 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const
1155 {return (__p.*__p_)(__x);}
1158 template<class _Sp, class _Tp>
1159 inline _LIBCPP_INLINE_VISIBILITY
1160 mem_fun_ref_t<_Sp,_Tp>
1161 mem_fun_ref(_Sp (_Tp::*__f)())
1162 {return mem_fun_ref_t<_Sp,_Tp>(__f);}
1164 template<class _Sp, class _Tp, class _Ap>
1165 inline _LIBCPP_INLINE_VISIBILITY
1166 mem_fun1_ref_t<_Sp,_Tp,_Ap>
1167 mem_fun_ref(_Sp (_Tp::*__f)(_Ap))
1168 {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
1170 template <class _Sp, class _Tp>
1171 class _LIBCPP_TYPE_VIS_ONLY const_mem_fun_t : public unary_function<const _Tp*, _Sp>
1173 _Sp (_Tp::*__p_)() const;
1175 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const)
1177 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const
1178 {return (__p->*__p_)();}
1181 template <class _Sp, class _Tp, class _Ap>
1182 class _LIBCPP_TYPE_VIS_ONLY const_mem_fun1_t : public binary_function<const _Tp*, _Ap, _Sp>
1184 _Sp (_Tp::*__p_)(_Ap) const;
1186 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const)
1188 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const
1189 {return (__p->*__p_)(__x);}
1192 template <class _Sp, class _Tp>
1193 inline _LIBCPP_INLINE_VISIBILITY
1194 const_mem_fun_t<_Sp,_Tp>
1195 mem_fun(_Sp (_Tp::*__f)() const)
1196 {return const_mem_fun_t<_Sp,_Tp>(__f);}
1198 template <class _Sp, class _Tp, class _Ap>
1199 inline _LIBCPP_INLINE_VISIBILITY
1200 const_mem_fun1_t<_Sp,_Tp,_Ap>
1201 mem_fun(_Sp (_Tp::*__f)(_Ap) const)
1202 {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1204 template <class _Sp, class _Tp>
1205 class _LIBCPP_TYPE_VIS_ONLY const_mem_fun_ref_t : public unary_function<_Tp, _Sp>
1207 _Sp (_Tp::*__p_)() const;
1209 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const)
1211 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const
1212 {return (__p.*__p_)();}
1215 template <class _Sp, class _Tp, class _Ap>
1216 class _LIBCPP_TYPE_VIS_ONLY const_mem_fun1_ref_t
1217 : public binary_function<_Tp, _Ap, _Sp>
1219 _Sp (_Tp::*__p_)(_Ap) const;
1221 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const)
1223 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const
1224 {return (__p.*__p_)(__x);}
1227 template <class _Sp, class _Tp>
1228 inline _LIBCPP_INLINE_VISIBILITY
1229 const_mem_fun_ref_t<_Sp,_Tp>
1230 mem_fun_ref(_Sp (_Tp::*__f)() const)
1231 {return const_mem_fun_ref_t<_Sp,_Tp>(__f);}
1233 template <class _Sp, class _Tp, class _Ap>
1234 inline _LIBCPP_INLINE_VISIBILITY
1235 const_mem_fun1_ref_t<_Sp,_Tp,_Ap>
1236 mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const)
1237 {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
1239 ////////////////////////////////////////////////////////////////////////////////
1241 //==============================================================================
1243 template <class _Tp>
1245 : public __weak_result_type<_Tp>
1254 _LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) _NOEXCEPT : __f_(__f) {}
1256 #ifndef _LIBCPP_HAS_NO_VARIADICS
1258 template <class... _ArgTypes>
1259 _LIBCPP_INLINE_VISIBILITY
1260 typename __invoke_return<type, _ArgTypes...>::type
1261 operator() (_ArgTypes&&... __args) const {
1262 return __invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...);
1266 template <class _A0>
1267 _LIBCPP_INLINE_VISIBILITY
1268 typename __invoke_return0<type, _A0>::type
1269 operator() (_A0& __a0) const {
1270 return __invoke(__f_, __a0);
1273 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);
1280 template <class _A0, class _A1>
1281 _LIBCPP_INLINE_VISIBILITY
1282 typename __invoke_return1<type, _A0, _A1>::type
1283 operator() (_A0& __a0, _A1& __a1) const {
1284 return __invoke(__f_, __a0, __a1);
1287 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);
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);
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);
1308 template <class _A0, class _A1, class _A2>
1309 _LIBCPP_INLINE_VISIBILITY
1310 typename __invoke_return2<type, _A0, _A1, _A2>::type
1311 operator() (_A0& __a0, _A1& __a1, _A2& __a2) const {
1312 return __invoke(__f_, __a0, __a1, __a2);
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);
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);
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);
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);
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);
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);
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);
1366 template<class _Rp, class _Tp>
1367 inline _LIBCPP_INLINE_VISIBILITY
1368 __mem_fn<_Rp _Tp::*>
1369 mem_fn(_Rp _Tp::* __pm) _NOEXCEPT
1371 return __mem_fn<_Rp _Tp::*>(__pm);
1374 ////////////////////////////////////////////////////////////////////////////////
1376 //==============================================================================
1378 // bad_function_call
1380 class _LIBCPP_EXCEPTION_ABI bad_function_call
1385 template<class _Fp> class _LIBCPP_TYPE_VIS_ONLY function; // undefined
1387 namespace __function
1391 struct __maybe_derive_from_unary_function
1395 template<class _Rp, class _A1>
1396 struct __maybe_derive_from_unary_function<_Rp(_A1)>
1397 : public unary_function<_A1, _Rp>
1402 struct __maybe_derive_from_binary_function
1406 template<class _Rp, class _A1, class _A2>
1407 struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)>
1408 : public binary_function<_A1, _A2, _Rp>
1412 template <class _Fp>
1413 _LIBCPP_INLINE_VISIBILITY
1414 bool __not_null(_Fp const&) { return true; }
1416 template <class _Fp>
1417 _LIBCPP_INLINE_VISIBILITY
1418 bool __not_null(_Fp* __ptr) { return __ptr; }
1420 template <class _Ret, class _Class>
1421 _LIBCPP_INLINE_VISIBILITY
1422 bool __not_null(_Ret _Class::*__ptr) { return __ptr; }
1424 template <class _Fp>
1425 _LIBCPP_INLINE_VISIBILITY
1426 bool __not_null(function<_Fp> const& __f) { return !!__f; }
1428 } // namespace __function
1430 #ifndef _LIBCPP_HAS_NO_VARIADICS
1432 namespace __function {
1434 template<class _Fp> class __base;
1436 template<class _Rp, class ..._ArgTypes>
1437 class __base<_Rp(_ArgTypes...)>
1439 __base(const __base&);
1440 __base& operator=(const __base&);
1442 _LIBCPP_INLINE_VISIBILITY __base() {}
1443 _LIBCPP_INLINE_VISIBILITY virtual ~__base() {}
1444 virtual __base* __clone() const = 0;
1445 virtual void __clone(__base*) const = 0;
1446 virtual void destroy() _NOEXCEPT = 0;
1447 virtual void destroy_deallocate() _NOEXCEPT = 0;
1448 virtual _Rp operator()(_ArgTypes&& ...) = 0;
1449 #ifndef _LIBCPP_NO_RTTI
1450 virtual const void* target(const type_info&) const _NOEXCEPT = 0;
1451 virtual const std::type_info& target_type() const _NOEXCEPT = 0;
1452 #endif // _LIBCPP_NO_RTTI
1455 template<class _FD, class _Alloc, class _FB> class __func;
1457 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1458 class __func<_Fp, _Alloc, _Rp(_ArgTypes...)>
1459 : public __base<_Rp(_ArgTypes...)>
1461 __compressed_pair<_Fp, _Alloc> __f_;
1463 _LIBCPP_INLINE_VISIBILITY
1464 explicit __func(_Fp&& __f)
1465 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1466 _VSTD::forward_as_tuple()) {}
1467 _LIBCPP_INLINE_VISIBILITY
1468 explicit __func(const _Fp& __f, const _Alloc& __a)
1469 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1470 _VSTD::forward_as_tuple(__a)) {}
1472 _LIBCPP_INLINE_VISIBILITY
1473 explicit __func(const _Fp& __f, _Alloc&& __a)
1474 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1475 _VSTD::forward_as_tuple(_VSTD::move(__a))) {}
1477 _LIBCPP_INLINE_VISIBILITY
1478 explicit __func(_Fp&& __f, _Alloc&& __a)
1479 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1480 _VSTD::forward_as_tuple(_VSTD::move(__a))) {}
1481 virtual __base<_Rp(_ArgTypes...)>* __clone() const;
1482 virtual void __clone(__base<_Rp(_ArgTypes...)>*) const;
1483 virtual void destroy() _NOEXCEPT;
1484 virtual void destroy_deallocate() _NOEXCEPT;
1485 virtual _Rp operator()(_ArgTypes&& ... __arg);
1486 #ifndef _LIBCPP_NO_RTTI
1487 virtual const void* target(const type_info&) const _NOEXCEPT;
1488 virtual const std::type_info& target_type() const _NOEXCEPT;
1489 #endif // _LIBCPP_NO_RTTI
1492 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1493 __base<_Rp(_ArgTypes...)>*
1494 __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const
1496 typedef allocator_traits<_Alloc> __alloc_traits;
1497 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
1498 _Ap __a(__f_.second());
1499 typedef __allocator_destructor<_Ap> _Dp;
1500 unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1501 ::new (__hold.get()) __func(__f_.first(), _Alloc(__a));
1502 return __hold.release();
1505 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1507 __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const
1509 ::new (__p) __func(__f_.first(), __f_.second());
1512 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1514 __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPT
1516 __f_.~__compressed_pair<_Fp, _Alloc>();
1519 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1521 __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT
1523 typedef allocator_traits<_Alloc> __alloc_traits;
1524 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
1525 _Ap __a(__f_.second());
1526 __f_.~__compressed_pair<_Fp, _Alloc>();
1527 __a.deallocate(this, 1);
1530 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1532 __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg)
1534 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
1535 return _Invoker::__call(__f_.first(), _VSTD::forward<_ArgTypes>(__arg)...);
1538 #ifndef _LIBCPP_NO_RTTI
1540 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1542 __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT
1544 if (__ti == typeid(_Fp))
1545 return &__f_.first();
1546 return (const void*)0;
1549 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1550 const std::type_info&
1551 __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
1556 #endif // _LIBCPP_NO_RTTI
1560 template<class _Rp, class ..._ArgTypes>
1561 class _LIBCPP_TYPE_VIS_ONLY function<_Rp(_ArgTypes...)>
1562 : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>,
1563 public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)>
1565 typedef __function::__base<_Rp(_ArgTypes...)> __base;
1566 typename aligned_storage<3*sizeof(void*)>::type __buf_;
1569 _LIBCPP_NO_CFI static __base *__as_base(void *p) {
1570 return reinterpret_cast<__base*>(p);
1573 template <class _Fp, bool = !is_same<_Fp, function>::value &&
1574 __invokable<_Fp&, _ArgTypes...>::value>
1576 template <class _Fp>
1577 struct __callable<_Fp, true>
1579 static const bool value = is_same<void, _Rp>::value ||
1580 is_convertible<typename __invoke_of<_Fp&, _ArgTypes...>::type,
1583 template <class _Fp>
1584 struct __callable<_Fp, false>
1586 static const bool value = false;
1589 typedef _Rp result_type;
1591 // construct/copy/destroy:
1592 _LIBCPP_INLINE_VISIBILITY
1593 function() _NOEXCEPT : __f_(0) {}
1594 _LIBCPP_INLINE_VISIBILITY
1595 function(nullptr_t) _NOEXCEPT : __f_(0) {}
1596 function(const function&);
1597 function(function&&) _NOEXCEPT;
1599 function(_Fp, typename enable_if
1601 __callable<_Fp>::value &&
1602 !is_same<_Fp, function>::value
1605 template<class _Alloc>
1606 _LIBCPP_INLINE_VISIBILITY
1607 function(allocator_arg_t, const _Alloc&) _NOEXCEPT : __f_(0) {}
1608 template<class _Alloc>
1609 _LIBCPP_INLINE_VISIBILITY
1610 function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT : __f_(0) {}
1611 template<class _Alloc>
1612 function(allocator_arg_t, const _Alloc&, const function&);
1613 template<class _Alloc>
1614 function(allocator_arg_t, const _Alloc&, function&&);
1615 template<class _Fp, class _Alloc>
1616 function(allocator_arg_t, const _Alloc& __a, _Fp __f,
1617 typename enable_if<__callable<_Fp>::value>::type* = 0);
1619 function& operator=(const function&);
1620 function& operator=(function&&) _NOEXCEPT;
1621 function& operator=(nullptr_t) _NOEXCEPT;
1625 __callable<typename decay<_Fp>::type>::value &&
1626 !is_same<typename remove_reference<_Fp>::type, function>::value,
1633 // function modifiers:
1634 void swap(function&) _NOEXCEPT;
1636 #if _LIBCPP_STD_VER <= 14
1637 template<class _Fp, class _Alloc>
1638 _LIBCPP_INLINE_VISIBILITY
1639 void assign(_Fp&& __f, const _Alloc& __a)
1640 {function(allocator_arg, __a, _VSTD::forward<_Fp>(__f)).swap(*this);}
1643 // function capacity:
1644 _LIBCPP_INLINE_VISIBILITY
1645 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return __f_;}
1647 // deleted overloads close possible hole in the type system
1648 template<class _R2, class... _ArgTypes2>
1649 bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete;
1650 template<class _R2, class... _ArgTypes2>
1651 bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete;
1653 // function invocation:
1654 _Rp operator()(_ArgTypes...) const;
1656 #ifndef _LIBCPP_NO_RTTI
1657 // function target access:
1658 const std::type_info& target_type() const _NOEXCEPT;
1659 template <typename _Tp> _Tp* target() _NOEXCEPT;
1660 template <typename _Tp> const _Tp* target() const _NOEXCEPT;
1661 #endif // _LIBCPP_NO_RTTI
1664 template<class _Rp, class ..._ArgTypes>
1665 function<_Rp(_ArgTypes...)>::function(const function& __f)
1669 else if ((void *)__f.__f_ == &__f.__buf_)
1671 __f_ = __as_base(&__buf_);
1672 __f.__f_->__clone(__f_);
1675 __f_ = __f.__f_->__clone();
1678 template<class _Rp, class ..._ArgTypes>
1679 template <class _Alloc>
1680 function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
1681 const function& __f)
1685 else if ((void *)__f.__f_ == &__f.__buf_)
1687 __f_ = __as_base(&__buf_);
1688 __f.__f_->__clone(__f_);
1691 __f_ = __f.__f_->__clone();
1694 template<class _Rp, class ..._ArgTypes>
1695 function<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT
1699 else if ((void *)__f.__f_ == &__f.__buf_)
1701 __f_ = __as_base(&__buf_);
1702 __f.__f_->__clone(__f_);
1711 template<class _Rp, class ..._ArgTypes>
1712 template <class _Alloc>
1713 function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
1718 else if ((void *)__f.__f_ == &__f.__buf_)
1720 __f_ = __as_base(&__buf_);
1721 __f.__f_->__clone(__f_);
1730 template<class _Rp, class ..._ArgTypes>
1731 template <class _Fp>
1732 function<_Rp(_ArgTypes...)>::function(_Fp __f,
1735 __callable<_Fp>::value &&
1736 !is_same<_Fp, function>::value
1740 if (__function::__not_null(__f))
1742 typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_ArgTypes...)> _FF;
1743 if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value)
1745 __f_ = ::new((void*)&__buf_) _FF(_VSTD::move(__f));
1749 typedef allocator<_FF> _Ap;
1751 typedef __allocator_destructor<_Ap> _Dp;
1752 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1753 ::new (__hold.get()) _FF(_VSTD::move(__f), allocator<_Fp>(__a));
1754 __f_ = __hold.release();
1759 template<class _Rp, class ..._ArgTypes>
1760 template <class _Fp, class _Alloc>
1761 function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f,
1762 typename enable_if<__callable<_Fp>::value>::type*)
1765 typedef allocator_traits<_Alloc> __alloc_traits;
1766 if (__function::__not_null(__f))
1768 typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _FF;
1769 typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap;
1771 if (sizeof(_FF) <= sizeof(__buf_) &&
1772 is_nothrow_copy_constructible<_Fp>::value && is_nothrow_copy_constructible<_Ap>::value)
1774 __f_ = ::new((void*)&__buf_) _FF(_VSTD::move(__f), _Alloc(__a));
1778 typedef __allocator_destructor<_Ap> _Dp;
1779 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1780 ::new (__hold.get()) _FF(_VSTD::move(__f), _Alloc(__a));
1781 __f_ = __hold.release();
1786 template<class _Rp, class ..._ArgTypes>
1787 function<_Rp(_ArgTypes...)>&
1788 function<_Rp(_ArgTypes...)>::operator=(const function& __f)
1790 function(__f).swap(*this);
1794 template<class _Rp, class ..._ArgTypes>
1795 function<_Rp(_ArgTypes...)>&
1796 function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT
1798 if ((void *)__f_ == &__buf_)
1801 __f_->destroy_deallocate();
1805 else if ((void *)__f.__f_ == &__f.__buf_)
1807 __f_ = __as_base(&__buf_);
1808 __f.__f_->__clone(__f_);
1818 template<class _Rp, class ..._ArgTypes>
1819 function<_Rp(_ArgTypes...)>&
1820 function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT
1822 if ((void *)__f_ == &__buf_)
1825 __f_->destroy_deallocate();
1830 template<class _Rp, class ..._ArgTypes>
1831 template <class _Fp>
1834 function<_Rp(_ArgTypes...)>::template __callable<typename decay<_Fp>::type>::value &&
1835 !is_same<typename remove_reference<_Fp>::type, function<_Rp(_ArgTypes...)>>::value,
1836 function<_Rp(_ArgTypes...)>&
1838 function<_Rp(_ArgTypes...)>::operator=(_Fp&& __f)
1840 function(_VSTD::forward<_Fp>(__f)).swap(*this);
1844 template<class _Rp, class ..._ArgTypes>
1845 function<_Rp(_ArgTypes...)>::~function()
1847 if ((void *)__f_ == &__buf_)
1850 __f_->destroy_deallocate();
1853 template<class _Rp, class ..._ArgTypes>
1855 function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT
1857 if ((void *)__f_ == &__buf_ && (void *)__f.__f_ == &__f.__buf_)
1859 typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
1860 __base* __t = __as_base(&__tempbuf);
1864 __f.__f_->__clone(__as_base(&__buf_));
1865 __f.__f_->destroy();
1867 __f_ = __as_base(&__buf_);
1868 __t->__clone(__as_base(&__f.__buf_));
1870 __f.__f_ = __as_base(&__f.__buf_);
1872 else if ((void *)__f_ == &__buf_)
1874 __f_->__clone(__as_base(&__f.__buf_));
1877 __f.__f_ = __as_base(&__f.__buf_);
1879 else if ((void *)__f.__f_ == &__f.__buf_)
1881 __f.__f_->__clone(__as_base(&__buf_));
1882 __f.__f_->destroy();
1884 __f_ = __as_base(&__buf_);
1887 _VSTD::swap(__f_, __f.__f_);
1890 template<class _Rp, class ..._ArgTypes>
1892 function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const
1894 #ifndef _LIBCPP_NO_EXCEPTIONS
1896 throw bad_function_call();
1897 #endif // _LIBCPP_NO_EXCEPTIONS
1898 return (*__f_)(_VSTD::forward<_ArgTypes>(__arg)...);
1901 #ifndef _LIBCPP_NO_RTTI
1903 template<class _Rp, class ..._ArgTypes>
1904 const std::type_info&
1905 function<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
1908 return typeid(void);
1909 return __f_->target_type();
1912 template<class _Rp, class ..._ArgTypes>
1913 template <typename _Tp>
1915 function<_Rp(_ArgTypes...)>::target() _NOEXCEPT
1919 return (_Tp*)__f_->target(typeid(_Tp));
1922 template<class _Rp, class ..._ArgTypes>
1923 template <typename _Tp>
1925 function<_Rp(_ArgTypes...)>::target() const _NOEXCEPT
1928 return (const _Tp*)0;
1929 return (const _Tp*)__f_->target(typeid(_Tp));
1932 #endif // _LIBCPP_NO_RTTI
1934 template <class _Rp, class... _ArgTypes>
1935 inline _LIBCPP_INLINE_VISIBILITY
1937 operator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;}
1939 template <class _Rp, class... _ArgTypes>
1940 inline _LIBCPP_INLINE_VISIBILITY
1942 operator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;}
1944 template <class _Rp, class... _ArgTypes>
1945 inline _LIBCPP_INLINE_VISIBILITY
1947 operator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;}
1949 template <class _Rp, class... _ArgTypes>
1950 inline _LIBCPP_INLINE_VISIBILITY
1952 operator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;}
1954 template <class _Rp, class... _ArgTypes>
1955 inline _LIBCPP_INLINE_VISIBILITY
1957 swap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT
1958 {return __x.swap(__y);}
1960 #else // _LIBCPP_HAS_NO_VARIADICS
1962 #include <__functional_03>
1966 ////////////////////////////////////////////////////////////////////////////////
1968 //==============================================================================
1970 template<class _Tp> struct __is_bind_expression : public false_type {};
1971 template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_bind_expression
1972 : public __is_bind_expression<typename remove_cv<_Tp>::type> {};
1974 template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {};
1975 template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_placeholder
1976 : public __is_placeholder<typename remove_cv<_Tp>::type> {};
1978 namespace placeholders
1981 template <int _Np> struct __ph {};
1983 #if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_BIND)
1984 _LIBCPP_FUNC_VIS extern const __ph<1> _1;
1985 _LIBCPP_FUNC_VIS extern const __ph<2> _2;
1986 _LIBCPP_FUNC_VIS extern const __ph<3> _3;
1987 _LIBCPP_FUNC_VIS extern const __ph<4> _4;
1988 _LIBCPP_FUNC_VIS extern const __ph<5> _5;
1989 _LIBCPP_FUNC_VIS extern const __ph<6> _6;
1990 _LIBCPP_FUNC_VIS extern const __ph<7> _7;
1991 _LIBCPP_FUNC_VIS extern const __ph<8> _8;
1992 _LIBCPP_FUNC_VIS extern const __ph<9> _9;
1993 _LIBCPP_FUNC_VIS extern const __ph<10> _10;
1995 constexpr __ph<1> _1{};
1996 constexpr __ph<2> _2{};
1997 constexpr __ph<3> _3{};
1998 constexpr __ph<4> _4{};
1999 constexpr __ph<5> _5{};
2000 constexpr __ph<6> _6{};
2001 constexpr __ph<7> _7{};
2002 constexpr __ph<8> _8{};
2003 constexpr __ph<9> _9{};
2004 constexpr __ph<10> _10{};
2005 #endif // defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_BIND)
2010 struct __is_placeholder<placeholders::__ph<_Np> >
2011 : public integral_constant<int, _Np> {};
2014 #ifndef _LIBCPP_HAS_NO_VARIADICS
2016 template <class _Tp, class _Uj>
2017 inline _LIBCPP_INLINE_VISIBILITY
2019 __mu(reference_wrapper<_Tp> __t, _Uj&)
2024 template <class _Ti, class ..._Uj, size_t ..._Indx>
2025 inline _LIBCPP_INLINE_VISIBILITY
2026 typename __invoke_of<_Ti&, _Uj...>::type
2027 __mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>)
2029 return __ti(_VSTD::forward<_Uj>(_VSTD::get<_Indx>(__uj))...);
2032 template <class _Ti, class ..._Uj>
2033 inline _LIBCPP_INLINE_VISIBILITY
2034 typename __lazy_enable_if
2036 is_bind_expression<_Ti>::value,
2037 __invoke_of<_Ti&, _Uj...>
2039 __mu(_Ti& __ti, tuple<_Uj...>& __uj)
2041 typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices;
2042 return __mu_expand(__ti, __uj, __indices());
2045 template <bool IsPh, class _Ti, class _Uj>
2046 struct __mu_return2 {};
2048 template <class _Ti, class _Uj>
2049 struct __mu_return2<true, _Ti, _Uj>
2051 typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type;
2054 template <class _Ti, class _Uj>
2055 inline _LIBCPP_INLINE_VISIBILITY
2058 0 < is_placeholder<_Ti>::value,
2059 typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type
2061 __mu(_Ti&, _Uj& __uj)
2063 const size_t _Indx = is_placeholder<_Ti>::value - 1;
2064 return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj));
2067 template <class _Ti, class _Uj>
2068 inline _LIBCPP_INLINE_VISIBILITY
2071 !is_bind_expression<_Ti>::value &&
2072 is_placeholder<_Ti>::value == 0 &&
2073 !__is_reference_wrapper<_Ti>::value,
2076 __mu(_Ti& __ti, _Uj&)
2081 template <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh,
2083 struct ____mu_return;
2085 template <bool _Invokable, class _Ti, class ..._Uj>
2086 struct ____mu_return_invokable // false
2091 template <class _Ti, class ..._Uj>
2092 struct ____mu_return_invokable<true, _Ti, _Uj...>
2094 typedef typename __invoke_of<_Ti&, _Uj...>::type type;
2097 template <class _Ti, class ..._Uj>
2098 struct ____mu_return<_Ti, false, true, false, tuple<_Uj...> >
2099 : public ____mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...>
2103 template <class _Ti, class _TupleUj>
2104 struct ____mu_return<_Ti, false, false, true, _TupleUj>
2106 typedef typename tuple_element<is_placeholder<_Ti>::value - 1,
2107 _TupleUj>::type&& type;
2110 template <class _Ti, class _TupleUj>
2111 struct ____mu_return<_Ti, true, false, false, _TupleUj>
2113 typedef typename _Ti::type& type;
2116 template <class _Ti, class _TupleUj>
2117 struct ____mu_return<_Ti, false, false, false, _TupleUj>
2122 template <class _Ti, class _TupleUj>
2124 : public ____mu_return<_Ti,
2125 __is_reference_wrapper<_Ti>::value,
2126 is_bind_expression<_Ti>::value,
2127 0 < is_placeholder<_Ti>::value &&
2128 is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value,
2133 template <class _Fp, class _BoundArgs, class _TupleUj>
2134 struct __is_valid_bind_return
2136 static const bool value = false;
2139 template <class _Fp, class ..._BoundArgs, class _TupleUj>
2140 struct __is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj>
2142 static const bool value = __invokable<_Fp,
2143 typename __mu_return<_BoundArgs, _TupleUj>::type...>::value;
2146 template <class _Fp, class ..._BoundArgs, class _TupleUj>
2147 struct __is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj>
2149 static const bool value = __invokable<_Fp,
2150 typename __mu_return<const _BoundArgs, _TupleUj>::type...>::value;
2153 template <class _Fp, class _BoundArgs, class _TupleUj,
2154 bool = __is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value>
2155 struct __bind_return;
2157 template <class _Fp, class ..._BoundArgs, class _TupleUj>
2158 struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true>
2160 typedef typename __invoke_of
2163 typename __mu_return
2171 template <class _Fp, class ..._BoundArgs, class _TupleUj>
2172 struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true>
2174 typedef typename __invoke_of
2177 typename __mu_return
2185 template <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args>
2186 inline _LIBCPP_INLINE_VISIBILITY
2187 typename __bind_return<_Fp, _BoundArgs, _Args>::type
2188 __apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
2191 return __invoke(__f, __mu(_VSTD::get<_Indx>(__bound_args), __args)...);
2194 template<class _Fp, class ..._BoundArgs>
2196 : public __weak_result_type<typename decay<_Fp>::type>
2199 typedef typename decay<_Fp>::type _Fd;
2200 typedef tuple<typename decay<_BoundArgs>::type...> _Td;
2205 typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices;
2207 #ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2209 _LIBCPP_INLINE_VISIBILITY
2210 __bind(const __bind& __b)
2212 __bound_args_(__b.__bound_args_) {}
2214 _LIBCPP_INLINE_VISIBILITY
2215 __bind& operator=(const __bind& __b)
2218 __bound_args_ = __b.__bound_args_;
2222 _LIBCPP_INLINE_VISIBILITY
2223 __bind(__bind&& __b)
2224 : __f_(_VSTD::move(__b.__f_)),
2225 __bound_args_(_VSTD::move(__b.__bound_args_)) {}
2227 _LIBCPP_INLINE_VISIBILITY
2228 __bind& operator=(__bind&& __b)
2230 __f_ = _VSTD::move(__b.__f_);
2231 __bound_args_ = _VSTD::move(__b.__bound_args_);
2235 #endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2237 template <class _Gp, class ..._BA,
2238 class = typename enable_if
2240 is_constructible<_Fd, _Gp>::value &&
2241 !is_same<typename remove_reference<_Gp>::type,
2244 _LIBCPP_INLINE_VISIBILITY
2245 explicit __bind(_Gp&& __f, _BA&& ...__bound_args)
2246 : __f_(_VSTD::forward<_Gp>(__f)),
2247 __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {}
2249 template <class ..._Args>
2250 _LIBCPP_INLINE_VISIBILITY
2251 typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type
2252 operator()(_Args&& ...__args)
2254 return __apply_functor(__f_, __bound_args_, __indices(),
2255 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
2258 template <class ..._Args>
2259 _LIBCPP_INLINE_VISIBILITY
2260 typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type
2261 operator()(_Args&& ...__args) const
2263 return __apply_functor(__f_, __bound_args_, __indices(),
2264 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
2268 template<class _Fp, class ..._BoundArgs>
2269 struct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {};
2271 template<class _Rp, class _Fp, class ..._BoundArgs>
2273 : public __bind<_Fp, _BoundArgs...>
2275 typedef __bind<_Fp, _BoundArgs...> base;
2276 typedef typename base::_Fd _Fd;
2277 typedef typename base::_Td _Td;
2279 typedef _Rp result_type;
2281 #ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2283 _LIBCPP_INLINE_VISIBILITY
2284 __bind_r(const __bind_r& __b)
2285 : base(_VSTD::forward<const base&>(__b)) {}
2287 _LIBCPP_INLINE_VISIBILITY
2288 __bind_r& operator=(const __bind_r& __b)
2290 base::operator=(_VSTD::forward<const base&>(__b));
2294 _LIBCPP_INLINE_VISIBILITY
2295 __bind_r(__bind_r&& __b)
2296 : base(_VSTD::forward<base>(__b)) {}
2298 _LIBCPP_INLINE_VISIBILITY
2299 __bind_r& operator=(__bind_r&& __b)
2301 base::operator=(_VSTD::forward<base>(__b));
2305 #endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2307 template <class _Gp, class ..._BA,
2308 class = typename enable_if
2310 is_constructible<_Fd, _Gp>::value &&
2311 !is_same<typename remove_reference<_Gp>::type,
2314 _LIBCPP_INLINE_VISIBILITY
2315 explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args)
2316 : base(_VSTD::forward<_Gp>(__f),
2317 _VSTD::forward<_BA>(__bound_args)...) {}
2319 template <class ..._Args>
2320 _LIBCPP_INLINE_VISIBILITY
2323 is_convertible<typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type,
2324 result_type>::value || is_void<_Rp>::value,
2327 operator()(_Args&& ...__args)
2329 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
2330 return _Invoker::__call(static_cast<base&>(*this), _VSTD::forward<_Args>(__args)...);
2333 template <class ..._Args>
2334 _LIBCPP_INLINE_VISIBILITY
2337 is_convertible<typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type,
2338 result_type>::value || is_void<_Rp>::value,
2341 operator()(_Args&& ...__args) const
2343 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
2344 return _Invoker::__call(static_cast<base const&>(*this), _VSTD::forward<_Args>(__args)...);
2348 template<class _Rp, class _Fp, class ..._BoundArgs>
2349 struct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {};
2351 template<class _Fp, class ..._BoundArgs>
2352 inline _LIBCPP_INLINE_VISIBILITY
2353 __bind<_Fp, _BoundArgs...>
2354 bind(_Fp&& __f, _BoundArgs&&... __bound_args)
2356 typedef __bind<_Fp, _BoundArgs...> type;
2357 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
2360 template<class _Rp, class _Fp, class ..._BoundArgs>
2361 inline _LIBCPP_INLINE_VISIBILITY
2362 __bind_r<_Rp, _Fp, _BoundArgs...>
2363 bind(_Fp&& __f, _BoundArgs&&... __bound_args)
2365 typedef __bind_r<_Rp, _Fp, _BoundArgs...> type;
2366 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
2369 #endif // _LIBCPP_HAS_NO_VARIADICS
2372 struct _LIBCPP_TYPE_VIS_ONLY hash<bool>
2373 : public unary_function<bool, size_t>
2375 _LIBCPP_INLINE_VISIBILITY
2376 size_t operator()(bool __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
2380 struct _LIBCPP_TYPE_VIS_ONLY hash<char>
2381 : public unary_function<char, size_t>
2383 _LIBCPP_INLINE_VISIBILITY
2384 size_t operator()(char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
2388 struct _LIBCPP_TYPE_VIS_ONLY hash<signed char>
2389 : public unary_function<signed char, size_t>
2391 _LIBCPP_INLINE_VISIBILITY
2392 size_t operator()(signed char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
2396 struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned char>
2397 : public unary_function<unsigned char, size_t>
2399 _LIBCPP_INLINE_VISIBILITY
2400 size_t operator()(unsigned char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
2403 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
2406 struct _LIBCPP_TYPE_VIS_ONLY hash<char16_t>
2407 : public unary_function<char16_t, size_t>
2409 _LIBCPP_INLINE_VISIBILITY
2410 size_t operator()(char16_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
2414 struct _LIBCPP_TYPE_VIS_ONLY hash<char32_t>
2415 : public unary_function<char32_t, size_t>
2417 _LIBCPP_INLINE_VISIBILITY
2418 size_t operator()(char32_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
2421 #endif // _LIBCPP_HAS_NO_UNICODE_CHARS
2424 struct _LIBCPP_TYPE_VIS_ONLY hash<wchar_t>
2425 : public unary_function<wchar_t, size_t>
2427 _LIBCPP_INLINE_VISIBILITY
2428 size_t operator()(wchar_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
2432 struct _LIBCPP_TYPE_VIS_ONLY hash<short>
2433 : public unary_function<short, size_t>
2435 _LIBCPP_INLINE_VISIBILITY
2436 size_t operator()(short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
2440 struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned short>
2441 : public unary_function<unsigned short, size_t>
2443 _LIBCPP_INLINE_VISIBILITY
2444 size_t operator()(unsigned short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
2448 struct _LIBCPP_TYPE_VIS_ONLY hash<int>
2449 : public unary_function<int, size_t>
2451 _LIBCPP_INLINE_VISIBILITY
2452 size_t operator()(int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
2456 struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned int>
2457 : public unary_function<unsigned int, size_t>
2459 _LIBCPP_INLINE_VISIBILITY
2460 size_t operator()(unsigned int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
2464 struct _LIBCPP_TYPE_VIS_ONLY hash<long>
2465 : public unary_function<long, size_t>
2467 _LIBCPP_INLINE_VISIBILITY
2468 size_t operator()(long __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
2472 struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned long>
2473 : public unary_function<unsigned long, size_t>
2475 _LIBCPP_INLINE_VISIBILITY
2476 size_t operator()(unsigned long __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
2480 struct _LIBCPP_TYPE_VIS_ONLY hash<long long>
2481 : public __scalar_hash<long long>
2486 struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned long long>
2487 : public __scalar_hash<unsigned long long>
2491 #ifndef _LIBCPP_HAS_NO_INT128
2494 struct _LIBCPP_TYPE_VIS_ONLY hash<__int128_t>
2495 : public __scalar_hash<__int128_t>
2500 struct _LIBCPP_TYPE_VIS_ONLY hash<__uint128_t>
2501 : public __scalar_hash<__uint128_t>
2508 struct _LIBCPP_TYPE_VIS_ONLY hash<float>
2509 : public __scalar_hash<float>
2511 _LIBCPP_INLINE_VISIBILITY
2512 size_t operator()(float __v) const _NOEXCEPT
2514 // -0.0 and 0.0 should return same hash
2517 return __scalar_hash<float>::operator()(__v);
2522 struct _LIBCPP_TYPE_VIS_ONLY hash<double>
2523 : public __scalar_hash<double>
2525 _LIBCPP_INLINE_VISIBILITY
2526 size_t operator()(double __v) const _NOEXCEPT
2528 // -0.0 and 0.0 should return same hash
2531 return __scalar_hash<double>::operator()(__v);
2536 struct _LIBCPP_TYPE_VIS_ONLY hash<long double>
2537 : public __scalar_hash<long double>
2539 _LIBCPP_INLINE_VISIBILITY
2540 size_t operator()(long double __v) const _NOEXCEPT
2542 // -0.0 and 0.0 should return same hash
2545 #if defined(__i386__)
2546 // Zero out padding bits
2563 return __u.__s.__a ^ __u.__s.__b ^ __u.__s.__c ^ __u.__s.__d;
2564 #elif defined(__x86_64__)
2565 // Zero out padding bits
2578 return __u.__s.__a ^ __u.__s.__b;
2580 return __scalar_hash<long double>::operator()(__v);
2585 #if _LIBCPP_STD_VER > 11
2586 template <class _Tp>
2587 struct _LIBCPP_TYPE_VIS_ONLY hash
2588 : public unary_function<_Tp, size_t>
2590 static_assert(is_enum<_Tp>::value, "This hash only works for enumeration types");
2592 _LIBCPP_INLINE_VISIBILITY
2593 size_t operator()(_Tp __v) const _NOEXCEPT
2595 typedef typename underlying_type<_Tp>::type type;
2596 return hash<type>{}(static_cast<type>(__v));
2602 #if _LIBCPP_STD_VER > 14
2604 template <class _Fn, class ..._Args>
2605 result_of_t<_Fn&&(_Args&&...)>
2606 invoke(_Fn&& __f, _Args&&... __args)
2607 noexcept(noexcept(_VSTD::__invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...)))
2609 return _VSTD::__invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...);
2612 template <class _DecayFunc>
2613 class _LIBCPP_TYPE_VIS_ONLY __not_fn_imp {
2617 __not_fn_imp() = delete;
2619 template <class ..._Args>
2620 _LIBCPP_INLINE_VISIBILITY
2621 auto operator()(_Args&& ...__args) &
2622 noexcept(noexcept(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)))
2623 -> decltype(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...))
2624 { return !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); }
2626 template <class ..._Args>
2627 _LIBCPP_INLINE_VISIBILITY
2628 auto operator()(_Args&& ...__args) &&
2629 noexcept(noexcept(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)))
2630 -> decltype(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...))
2631 { return !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); }
2633 template <class ..._Args>
2634 _LIBCPP_INLINE_VISIBILITY
2635 auto operator()(_Args&& ...__args) const&
2636 noexcept(noexcept(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)))
2637 -> decltype(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...))
2638 { return !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); }
2641 template <class ..._Args>
2642 _LIBCPP_INLINE_VISIBILITY
2643 auto operator()(_Args&& ...__args) const&&
2644 noexcept(noexcept(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)))
2645 -> decltype(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...))
2646 { return !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); }
2649 template <class _RawFunc,
2650 class = enable_if_t<!is_same<decay_t<_RawFunc>, __not_fn_imp>::value>>
2651 _LIBCPP_INLINE_VISIBILITY
2652 explicit __not_fn_imp(_RawFunc&& __rf)
2653 : __fd(_VSTD::forward<_RawFunc>(__rf)) {}
2655 template <class _RawFunc>
2656 friend inline _LIBCPP_INLINE_VISIBILITY
2657 __not_fn_imp<decay_t<_RawFunc>> not_fn(_RawFunc&&);
2660 template <class _RawFunc>
2661 inline _LIBCPP_INLINE_VISIBILITY
2662 __not_fn_imp<decay_t<_RawFunc>> not_fn(_RawFunc&& __fn) {
2663 return __not_fn_imp<decay_t<_RawFunc>>(_VSTD::forward<_RawFunc>(__fn));
2668 // struct hash<T*> in <memory>
2670 _LIBCPP_END_NAMESPACE_STD
2672 #endif // _LIBCPP_FUNCTIONAL