2 //===------------------------ functional ----------------------------------===//
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP_FUNCTIONAL
11 #define _LIBCPP_FUNCTIONAL
19 template <class Arg, class Result>
22 typedef Arg argument_type;
23 typedef Result result_type;
26 template <class Arg1, class Arg2, class Result>
27 struct binary_function
29 typedef Arg1 first_argument_type;
30 typedef Arg2 second_argument_type;
31 typedef Result result_type;
35 class reference_wrapper
36 : public unary_function<T1, R> // if wrapping a unary functor
37 : public binary_function<T1, T2, R> // if wraping a binary functor
42 typedef see below result_type; // Not always defined
44 // construct/copy/destroy
45 reference_wrapper(T&) noexcept;
46 reference_wrapper(T&&) = delete; // do not bind to temps
47 reference_wrapper(const reference_wrapper<T>& x) noexcept;
50 reference_wrapper& operator=(const reference_wrapper<T>& x) noexcept;
53 operator T& () const noexcept;
54 T& get() const noexcept;
57 template <class... ArgTypes>
58 typename result_of<T&(ArgTypes&&...)>::type
59 operator() (ArgTypes&&...) const;
62 template <class T> reference_wrapper<T> ref(T& t) noexcept;
63 template <class T> void ref(const T&& t) = delete;
64 template <class T> reference_wrapper<T> ref(reference_wrapper<T>t) noexcept;
66 template <class T> reference_wrapper<const T> cref(const T& t) noexcept;
67 template <class T> void cref(const T&& t) = delete;
68 template <class T> reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept;
70 template <class T> struct unwrap_reference; // since C++20
71 template <class T> struct unwrap_ref_decay : unwrap_reference<decay_t<T>> { }; // since C++20
72 template <class T> using unwrap_reference_t = typename unwrap_reference<T>::type; // since C++20
73 template <class T> using unwrap_ref_decay_t = typename unwrap_ref_decay<T>::type; // since C++20
75 template <class T> // <class T=void> in C++14
76 struct plus : binary_function<T, T, T>
78 T operator()(const T& x, const T& y) const;
81 template <class T> // <class T=void> in C++14
82 struct minus : binary_function<T, T, T>
84 T operator()(const T& x, const T& y) const;
87 template <class T> // <class T=void> in C++14
88 struct multiplies : binary_function<T, T, T>
90 T operator()(const T& x, const T& y) const;
93 template <class T> // <class T=void> in C++14
94 struct divides : binary_function<T, T, T>
96 T operator()(const T& x, const T& y) const;
99 template <class T> // <class T=void> in C++14
100 struct modulus : binary_function<T, T, T>
102 T operator()(const T& x, const T& y) const;
105 template <class T> // <class T=void> in C++14
106 struct negate : unary_function<T, T>
108 T operator()(const T& x) const;
111 template <class T> // <class T=void> in C++14
112 struct equal_to : binary_function<T, T, bool>
114 bool operator()(const T& x, const T& y) const;
117 template <class T> // <class T=void> in C++14
118 struct not_equal_to : binary_function<T, T, bool>
120 bool operator()(const T& x, const T& y) const;
123 template <class T> // <class T=void> in C++14
124 struct greater : binary_function<T, T, bool>
126 bool operator()(const T& x, const T& y) const;
129 template <class T> // <class T=void> in C++14
130 struct less : binary_function<T, T, bool>
132 bool operator()(const T& x, const T& y) const;
135 template <class T> // <class T=void> in C++14
136 struct greater_equal : binary_function<T, T, bool>
138 bool operator()(const T& x, const T& y) const;
141 template <class T> // <class T=void> in C++14
142 struct less_equal : binary_function<T, T, bool>
144 bool operator()(const T& x, const T& y) const;
147 template <class T> // <class T=void> in C++14
148 struct logical_and : binary_function<T, T, bool>
150 bool operator()(const T& x, const T& y) const;
153 template <class T> // <class T=void> in C++14
154 struct logical_or : binary_function<T, T, bool>
156 bool operator()(const T& x, const T& y) const;
159 template <class T> // <class T=void> in C++14
160 struct logical_not : unary_function<T, bool>
162 bool operator()(const T& x) const;
165 template <class T> // <class T=void> in C++14
166 struct bit_and : unary_function<T, bool>
168 bool operator()(const T& x, const T& y) const;
171 template <class T> // <class T=void> in C++14
172 struct bit_or : unary_function<T, bool>
174 bool operator()(const T& x, const T& y) const;
177 template <class T> // <class T=void> in C++14
178 struct bit_xor : unary_function<T, bool>
180 bool operator()(const T& x, const T& y) const;
183 template <class T=void> // C++14
184 struct bit_xor : unary_function<T, bool>
186 bool operator()(const T& x) const;
189 template <class Predicate>
190 class unary_negate // deprecated in C++17
191 : public unary_function<typename Predicate::argument_type, bool>
194 explicit unary_negate(const Predicate& pred);
195 bool operator()(const typename Predicate::argument_type& x) const;
198 template <class Predicate> // deprecated in C++17
199 unary_negate<Predicate> not1(const Predicate& pred);
201 template <class Predicate>
202 class binary_negate // deprecated in C++17
203 : public binary_function<typename Predicate::first_argument_type,
204 typename Predicate::second_argument_type,
208 explicit binary_negate(const Predicate& pred);
209 bool operator()(const typename Predicate::first_argument_type& x,
210 const typename Predicate::second_argument_type& y) const;
213 template <class Predicate> // deprecated in C++17
214 binary_negate<Predicate> not2(const Predicate& pred);
216 template <class F> unspecified not_fn(F&& f); // C++17
218 template<class T> struct is_bind_expression;
219 template<class T> struct is_placeholder;
221 // See C++14 20.9.9, Function object binders
222 template <class T> inline constexpr bool is_bind_expression_v
223 = is_bind_expression<T>::value; // C++17
224 template <class T> inline constexpr int is_placeholder_v
225 = is_placeholder<T>::value; // C++17
228 template<class Fn, class... BoundArgs>
229 unspecified bind(Fn&&, BoundArgs&&...);
230 template<class R, class Fn, class... BoundArgs>
231 unspecified bind(Fn&&, BoundArgs&&...);
233 template<class F, class... Args>
234 invoke_result_t<F, Args...> invoke(F&& f, Args&&... args) // C++17
235 noexcept(is_nothrow_invocable_v<F, Args...>);
237 namespace placeholders {
238 // M is the implementation-defined number of placeholders
239 extern unspecified _1;
240 extern unspecified _2;
244 extern unspecified _Mp;
247 template <class Operation>
248 class binder1st // deprecated in C++11, removed in C++17
249 : public unary_function<typename Operation::second_argument_type,
250 typename Operation::result_type>
254 typename Operation::first_argument_type value;
256 binder1st(const Operation& x, const typename Operation::first_argument_type y);
257 typename Operation::result_type operator()( typename Operation::second_argument_type& x) const;
258 typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const;
261 template <class Operation, class T>
262 binder1st<Operation> bind1st(const Operation& op, const T& x); // deprecated in C++11, removed in C++17
264 template <class Operation>
265 class binder2nd // deprecated in C++11, removed in C++17
266 : public unary_function<typename Operation::first_argument_type,
267 typename Operation::result_type>
271 typename Operation::second_argument_type value;
273 binder2nd(const Operation& x, const typename Operation::second_argument_type y);
274 typename Operation::result_type operator()( typename Operation::first_argument_type& x) const;
275 typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const;
278 template <class Operation, class T>
279 binder2nd<Operation> bind2nd(const Operation& op, const T& x); // deprecated in C++11, removed in C++17
281 template <class Arg, class Result> // deprecated in C++11, removed in C++17
282 class pointer_to_unary_function : public unary_function<Arg, Result>
285 explicit pointer_to_unary_function(Result (*f)(Arg));
286 Result operator()(Arg x) const;
289 template <class Arg, class Result>
290 pointer_to_unary_function<Arg,Result> ptr_fun(Result (*f)(Arg)); // deprecated in C++11, removed in C++17
292 template <class Arg1, class Arg2, class Result> // deprecated in C++11, removed in C++17
293 class pointer_to_binary_function : public binary_function<Arg1, Arg2, Result>
296 explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2));
297 Result operator()(Arg1 x, Arg2 y) const;
300 template <class Arg1, class Arg2, class Result>
301 pointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1,Arg2)); // deprecated in C++11, removed in C++17
303 template<class S, class T> // deprecated in C++11, removed in C++17
304 class mem_fun_t : public unary_function<T*, S>
307 explicit mem_fun_t(S (T::*p)());
308 S operator()(T* p) const;
311 template<class S, class T, class A>
312 class mem_fun1_t : public binary_function<T*, A, S> // deprecated in C++11, removed in C++17
315 explicit mem_fun1_t(S (T::*p)(A));
316 S operator()(T* p, A x) const;
319 template<class S, class T> mem_fun_t<S,T> mem_fun(S (T::*f)()); // deprecated in C++11, removed in C++17
320 template<class S, class T, class A> mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A)); // deprecated in C++11, removed in C++17
322 template<class S, class T>
323 class mem_fun_ref_t : public unary_function<T, S> // deprecated in C++11, removed in C++17
326 explicit mem_fun_ref_t(S (T::*p)());
327 S operator()(T& p) const;
330 template<class S, class T, class A>
331 class mem_fun1_ref_t : public binary_function<T, A, S> // deprecated in C++11, removed in C++17
334 explicit mem_fun1_ref_t(S (T::*p)(A));
335 S operator()(T& p, A x) const;
338 template<class S, class T> mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)()); // deprecated in C++11, removed in C++17
339 template<class S, class T, class A> mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A)); // deprecated in C++11, removed in C++17
341 template <class S, class T>
342 class const_mem_fun_t : public unary_function<const T*, S> // deprecated in C++11, removed in C++17
345 explicit const_mem_fun_t(S (T::*p)() const);
346 S operator()(const T* p) const;
349 template <class S, class T, class A>
350 class const_mem_fun1_t : public binary_function<const T*, A, S> // deprecated in C++11, removed in C++17
353 explicit const_mem_fun1_t(S (T::*p)(A) const);
354 S operator()(const T* p, A x) const;
357 template <class S, class T> const_mem_fun_t<S,T> mem_fun(S (T::*f)() const); // deprecated in C++11, removed in C++17
358 template <class S, class T, class A> const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const); // deprecated in C++11, removed in C++17
360 template <class S, class T>
361 class const_mem_fun_ref_t : public unary_function<T, S> // deprecated in C++11, removed in C++17
364 explicit const_mem_fun_ref_t(S (T::*p)() const);
365 S operator()(const T& p) const;
368 template <class S, class T, class A>
369 class const_mem_fun1_ref_t : public binary_function<T, A, S> // deprecated in C++11, removed in C++17
372 explicit const_mem_fun1_ref_t(S (T::*p)(A) const);
373 S operator()(const T& p, A x) const;
376 template <class S, class T> const_mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)() const); // deprecated in C++11, removed in C++17
377 template <class S, class T, class A> const_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const); // deprecated in C++11, removed in C++17
379 template<class R, class T> unspecified mem_fn(R T::*);
381 class bad_function_call
386 template<class> class function; // undefined
388 template<class R, class... ArgTypes>
389 class function<R(ArgTypes...)>
390 : public unary_function<T1, R> // iff sizeof...(ArgTypes) == 1 and
391 // ArgTypes contains T1
392 : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and
393 // ArgTypes contains T1 and T2
396 typedef R result_type;
398 // construct/copy/destroy:
400 function(nullptr_t) noexcept;
401 function(const function&);
402 function(function&&) noexcept;
405 template<Allocator Alloc>
406 function(allocator_arg_t, const Alloc&) noexcept; // removed in C++17
407 template<Allocator Alloc>
408 function(allocator_arg_t, const Alloc&, nullptr_t) noexcept; // removed in C++17
409 template<Allocator Alloc>
410 function(allocator_arg_t, const Alloc&, const function&); // removed in C++17
411 template<Allocator Alloc>
412 function(allocator_arg_t, const Alloc&, function&&); // removed in C++17
413 template<class F, Allocator Alloc>
414 function(allocator_arg_t, const Alloc&, F); // removed in C++17
416 function& operator=(const function&);
417 function& operator=(function&&) noexcept;
418 function& operator=(nullptr_t) noexcept;
420 function& operator=(F&&);
422 function& operator=(reference_wrapper<F>) noexcept;
426 // function modifiers:
427 void swap(function&) noexcept;
428 template<class F, class Alloc>
429 void assign(F&&, const Alloc&); // Removed in C++17
431 // function capacity:
432 explicit operator bool() const noexcept;
434 // function invocation:
435 R operator()(ArgTypes...) const;
437 // function target access:
438 const std::type_info& target_type() const noexcept;
439 template <typename T> T* target() noexcept;
440 template <typename T> const T* target() const noexcept;
443 // Null pointer comparisons:
444 template <class R, class ... ArgTypes>
445 bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
447 template <class R, class ... ArgTypes>
448 bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
450 template <class R, class ... ArgTypes>
451 bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
453 template <class R, class ... ArgTypes>
454 bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
456 // specialized algorithms:
457 template <class R, class ... ArgTypes>
458 void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
460 template <class T> struct hash;
462 template <> struct hash<bool>;
463 template <> struct hash<char>;
464 template <> struct hash<signed char>;
465 template <> struct hash<unsigned char>;
466 template <> struct hash<char16_t>;
467 template <> struct hash<char32_t>;
468 template <> struct hash<wchar_t>;
469 template <> struct hash<short>;
470 template <> struct hash<unsigned short>;
471 template <> struct hash<int>;
472 template <> struct hash<unsigned int>;
473 template <> struct hash<long>;
474 template <> struct hash<long long>;
475 template <> struct hash<unsigned long>;
476 template <> struct hash<unsigned long long>;
478 template <> struct hash<float>;
479 template <> struct hash<double>;
480 template <> struct hash<long double>;
482 template<class T> struct hash<T*>;
483 template <> struct hash<nullptr_t>; // C++17
487 POLICY: For non-variadic implementations, the number of arguments is limited
488 to 3. It is hoped that the need for non-variadic implementations
494 #include <type_traits>
502 #include <__functional_base>
504 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
505 #pragma GCC system_header
508 _LIBCPP_BEGIN_NAMESPACE_STD
510 #if _LIBCPP_STD_VER > 11
511 template <class _Tp = void>
515 struct _LIBCPP_TEMPLATE_VIS plus : binary_function<_Tp, _Tp, _Tp>
517 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
518 _Tp operator()(const _Tp& __x, const _Tp& __y) const
522 #if _LIBCPP_STD_VER > 11
524 struct _LIBCPP_TEMPLATE_VIS plus<void>
526 template <class _T1, class _T2>
527 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
528 auto operator()(_T1&& __t, _T2&& __u) const
529 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
530 -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
531 { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
532 typedef void is_transparent;
537 #if _LIBCPP_STD_VER > 11
538 template <class _Tp = void>
542 struct _LIBCPP_TEMPLATE_VIS minus : binary_function<_Tp, _Tp, _Tp>
544 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
545 _Tp operator()(const _Tp& __x, const _Tp& __y) const
549 #if _LIBCPP_STD_VER > 11
551 struct _LIBCPP_TEMPLATE_VIS minus<void>
553 template <class _T1, class _T2>
554 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
555 auto operator()(_T1&& __t, _T2&& __u) const
556 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u)))
557 -> decltype (_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u))
558 { return _VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u); }
559 typedef void is_transparent;
564 #if _LIBCPP_STD_VER > 11
565 template <class _Tp = void>
569 struct _LIBCPP_TEMPLATE_VIS multiplies : binary_function<_Tp, _Tp, _Tp>
571 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
572 _Tp operator()(const _Tp& __x, const _Tp& __y) const
576 #if _LIBCPP_STD_VER > 11
578 struct _LIBCPP_TEMPLATE_VIS multiplies<void>
580 template <class _T1, class _T2>
581 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
582 auto operator()(_T1&& __t, _T2&& __u) const
583 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u)))
584 -> decltype (_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u))
585 { return _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u); }
586 typedef void is_transparent;
591 #if _LIBCPP_STD_VER > 11
592 template <class _Tp = void>
596 struct _LIBCPP_TEMPLATE_VIS divides : binary_function<_Tp, _Tp, _Tp>
598 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
599 _Tp operator()(const _Tp& __x, const _Tp& __y) const
603 #if _LIBCPP_STD_VER > 11
605 struct _LIBCPP_TEMPLATE_VIS divides<void>
607 template <class _T1, class _T2>
608 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
609 auto operator()(_T1&& __t, _T2&& __u) const
610 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u)))
611 -> decltype (_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u))
612 { return _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u); }
613 typedef void is_transparent;
618 #if _LIBCPP_STD_VER > 11
619 template <class _Tp = void>
623 struct _LIBCPP_TEMPLATE_VIS modulus : binary_function<_Tp, _Tp, _Tp>
625 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
626 _Tp operator()(const _Tp& __x, const _Tp& __y) const
630 #if _LIBCPP_STD_VER > 11
632 struct _LIBCPP_TEMPLATE_VIS modulus<void>
634 template <class _T1, class _T2>
635 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
636 auto operator()(_T1&& __t, _T2&& __u) const
637 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u)))
638 -> decltype (_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u))
639 { return _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u); }
640 typedef void is_transparent;
645 #if _LIBCPP_STD_VER > 11
646 template <class _Tp = void>
650 struct _LIBCPP_TEMPLATE_VIS negate : unary_function<_Tp, _Tp>
652 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
653 _Tp operator()(const _Tp& __x) const
657 #if _LIBCPP_STD_VER > 11
659 struct _LIBCPP_TEMPLATE_VIS negate<void>
662 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
663 auto operator()(_Tp&& __x) const
664 _NOEXCEPT_(noexcept(- _VSTD::forward<_Tp>(__x)))
665 -> decltype (- _VSTD::forward<_Tp>(__x))
666 { return - _VSTD::forward<_Tp>(__x); }
667 typedef void is_transparent;
672 #if _LIBCPP_STD_VER > 11
673 template <class _Tp = void>
677 struct _LIBCPP_TEMPLATE_VIS equal_to : binary_function<_Tp, _Tp, bool>
679 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
680 bool operator()(const _Tp& __x, const _Tp& __y) const
684 #if _LIBCPP_STD_VER > 11
686 struct _LIBCPP_TEMPLATE_VIS equal_to<void>
688 template <class _T1, class _T2>
689 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
690 auto operator()(_T1&& __t, _T2&& __u) const
691 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u)))
692 -> decltype (_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u))
693 { return _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u); }
694 typedef void is_transparent;
699 #if _LIBCPP_STD_VER > 11
700 template <class _Tp = void>
704 struct _LIBCPP_TEMPLATE_VIS not_equal_to : binary_function<_Tp, _Tp, bool>
706 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
707 bool operator()(const _Tp& __x, const _Tp& __y) const
711 #if _LIBCPP_STD_VER > 11
713 struct _LIBCPP_TEMPLATE_VIS not_equal_to<void>
715 template <class _T1, class _T2>
716 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
717 auto operator()(_T1&& __t, _T2&& __u) const
718 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u)))
719 -> decltype (_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u))
720 { return _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u); }
721 typedef void is_transparent;
726 #if _LIBCPP_STD_VER > 11
727 template <class _Tp = void>
731 struct _LIBCPP_TEMPLATE_VIS greater : binary_function<_Tp, _Tp, bool>
733 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
734 bool operator()(const _Tp& __x, const _Tp& __y) const
738 #if _LIBCPP_STD_VER > 11
740 struct _LIBCPP_TEMPLATE_VIS greater<void>
742 template <class _T1, class _T2>
743 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
744 auto operator()(_T1&& __t, _T2&& __u) const
745 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u)))
746 -> decltype (_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u))
747 { return _VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u); }
748 typedef void is_transparent;
753 // less in <__functional_base>
755 #if _LIBCPP_STD_VER > 11
756 template <class _Tp = void>
760 struct _LIBCPP_TEMPLATE_VIS greater_equal : binary_function<_Tp, _Tp, bool>
762 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
763 bool operator()(const _Tp& __x, const _Tp& __y) const
767 #if _LIBCPP_STD_VER > 11
769 struct _LIBCPP_TEMPLATE_VIS greater_equal<void>
771 template <class _T1, class _T2>
772 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
773 auto operator()(_T1&& __t, _T2&& __u) const
774 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u)))
775 -> decltype (_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u))
776 { return _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u); }
777 typedef void is_transparent;
782 #if _LIBCPP_STD_VER > 11
783 template <class _Tp = void>
787 struct _LIBCPP_TEMPLATE_VIS less_equal : binary_function<_Tp, _Tp, bool>
789 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
790 bool operator()(const _Tp& __x, const _Tp& __y) const
794 #if _LIBCPP_STD_VER > 11
796 struct _LIBCPP_TEMPLATE_VIS less_equal<void>
798 template <class _T1, class _T2>
799 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
800 auto operator()(_T1&& __t, _T2&& __u) const
801 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u)))
802 -> decltype (_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u))
803 { return _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u); }
804 typedef void is_transparent;
809 #if _LIBCPP_STD_VER > 11
810 template <class _Tp = void>
814 struct _LIBCPP_TEMPLATE_VIS logical_and : binary_function<_Tp, _Tp, bool>
816 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
817 bool operator()(const _Tp& __x, const _Tp& __y) const
821 #if _LIBCPP_STD_VER > 11
823 struct _LIBCPP_TEMPLATE_VIS logical_and<void>
825 template <class _T1, class _T2>
826 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
827 auto operator()(_T1&& __t, _T2&& __u) const
828 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u)))
829 -> decltype (_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u))
830 { return _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u); }
831 typedef void is_transparent;
836 #if _LIBCPP_STD_VER > 11
837 template <class _Tp = void>
841 struct _LIBCPP_TEMPLATE_VIS logical_or : binary_function<_Tp, _Tp, bool>
843 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
844 bool operator()(const _Tp& __x, const _Tp& __y) const
848 #if _LIBCPP_STD_VER > 11
850 struct _LIBCPP_TEMPLATE_VIS logical_or<void>
852 template <class _T1, class _T2>
853 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
854 auto operator()(_T1&& __t, _T2&& __u) const
855 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u)))
856 -> decltype (_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u))
857 { return _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u); }
858 typedef void is_transparent;
863 #if _LIBCPP_STD_VER > 11
864 template <class _Tp = void>
868 struct _LIBCPP_TEMPLATE_VIS logical_not : unary_function<_Tp, bool>
870 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
871 bool operator()(const _Tp& __x) const
875 #if _LIBCPP_STD_VER > 11
877 struct _LIBCPP_TEMPLATE_VIS logical_not<void>
880 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
881 auto operator()(_Tp&& __x) const
882 _NOEXCEPT_(noexcept(!_VSTD::forward<_Tp>(__x)))
883 -> decltype (!_VSTD::forward<_Tp>(__x))
884 { return !_VSTD::forward<_Tp>(__x); }
885 typedef void is_transparent;
890 #if _LIBCPP_STD_VER > 11
891 template <class _Tp = void>
895 struct _LIBCPP_TEMPLATE_VIS bit_and : binary_function<_Tp, _Tp, _Tp>
897 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
898 _Tp operator()(const _Tp& __x, const _Tp& __y) const
902 #if _LIBCPP_STD_VER > 11
904 struct _LIBCPP_TEMPLATE_VIS bit_and<void>
906 template <class _T1, class _T2>
907 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
908 auto operator()(_T1&& __t, _T2&& __u) const
909 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u)))
910 -> decltype (_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u))
911 { return _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u); }
912 typedef void is_transparent;
917 #if _LIBCPP_STD_VER > 11
918 template <class _Tp = void>
922 struct _LIBCPP_TEMPLATE_VIS bit_or : binary_function<_Tp, _Tp, _Tp>
924 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
925 _Tp operator()(const _Tp& __x, const _Tp& __y) const
929 #if _LIBCPP_STD_VER > 11
931 struct _LIBCPP_TEMPLATE_VIS bit_or<void>
933 template <class _T1, class _T2>
934 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
935 auto operator()(_T1&& __t, _T2&& __u) const
936 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u)))
937 -> decltype (_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u))
938 { return _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u); }
939 typedef void is_transparent;
944 #if _LIBCPP_STD_VER > 11
945 template <class _Tp = void>
949 struct _LIBCPP_TEMPLATE_VIS bit_xor : binary_function<_Tp, _Tp, _Tp>
951 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
952 _Tp operator()(const _Tp& __x, const _Tp& __y) const
956 #if _LIBCPP_STD_VER > 11
958 struct _LIBCPP_TEMPLATE_VIS bit_xor<void>
960 template <class _T1, class _T2>
961 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
962 auto operator()(_T1&& __t, _T2&& __u) const
963 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u)))
964 -> decltype (_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u))
965 { return _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u); }
966 typedef void is_transparent;
971 #if _LIBCPP_STD_VER > 11
972 template <class _Tp = void>
973 struct _LIBCPP_TEMPLATE_VIS bit_not : unary_function<_Tp, _Tp>
975 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
976 _Tp operator()(const _Tp& __x) const
981 struct _LIBCPP_TEMPLATE_VIS bit_not<void>
984 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
985 auto operator()(_Tp&& __x) const
986 _NOEXCEPT_(noexcept(~_VSTD::forward<_Tp>(__x)))
987 -> decltype (~_VSTD::forward<_Tp>(__x))
988 { return ~_VSTD::forward<_Tp>(__x); }
989 typedef void is_transparent;
993 template <class _Predicate>
994 class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 unary_negate
995 : public unary_function<typename _Predicate::argument_type, bool>
999 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1000 explicit unary_negate(const _Predicate& __pred)
1001 : __pred_(__pred) {}
1002 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1003 bool operator()(const typename _Predicate::argument_type& __x) const
1004 {return !__pred_(__x);}
1007 template <class _Predicate>
1008 _LIBCPP_DEPRECATED_IN_CXX17 inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1009 unary_negate<_Predicate>
1010 not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);}
1012 template <class _Predicate>
1013 class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 binary_negate
1014 : public binary_function<typename _Predicate::first_argument_type,
1015 typename _Predicate::second_argument_type,
1020 _LIBCPP_INLINE_VISIBILITY explicit _LIBCPP_CONSTEXPR_AFTER_CXX11
1021 binary_negate(const _Predicate& __pred) : __pred_(__pred) {}
1023 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1024 bool operator()(const typename _Predicate::first_argument_type& __x,
1025 const typename _Predicate::second_argument_type& __y) const
1026 {return !__pred_(__x, __y);}
1029 template <class _Predicate>
1030 _LIBCPP_DEPRECATED_IN_CXX17 inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1031 binary_negate<_Predicate>
1032 not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);}
1034 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS)
1035 template <class __Operation>
1036 class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 binder1st
1037 : public unary_function<typename __Operation::second_argument_type,
1038 typename __Operation::result_type>
1042 typename __Operation::first_argument_type value;
1044 _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x,
1045 const typename __Operation::first_argument_type __y)
1046 : op(__x), value(__y) {}
1047 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1048 (typename __Operation::second_argument_type& __x) const
1049 {return op(value, __x);}
1050 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1051 (const typename __Operation::second_argument_type& __x) const
1052 {return op(value, __x);}
1055 template <class __Operation, class _Tp>
1056 _LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
1057 binder1st<__Operation>
1058 bind1st(const __Operation& __op, const _Tp& __x)
1059 {return binder1st<__Operation>(__op, __x);}
1061 template <class __Operation>
1062 class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 binder2nd
1063 : public unary_function<typename __Operation::first_argument_type,
1064 typename __Operation::result_type>
1068 typename __Operation::second_argument_type value;
1070 _LIBCPP_INLINE_VISIBILITY
1071 binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y)
1072 : op(__x), value(__y) {}
1073 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1074 ( typename __Operation::first_argument_type& __x) const
1075 {return op(__x, value);}
1076 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1077 (const typename __Operation::first_argument_type& __x) const
1078 {return op(__x, value);}
1081 template <class __Operation, class _Tp>
1082 _LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
1083 binder2nd<__Operation>
1084 bind2nd(const __Operation& __op, const _Tp& __x)
1085 {return binder2nd<__Operation>(__op, __x);}
1087 template <class _Arg, class _Result>
1088 class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 pointer_to_unary_function
1089 : public unary_function<_Arg, _Result>
1091 _Result (*__f_)(_Arg);
1093 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg))
1095 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const
1099 template <class _Arg, class _Result>
1100 _LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
1101 pointer_to_unary_function<_Arg,_Result>
1102 ptr_fun(_Result (*__f)(_Arg))
1103 {return pointer_to_unary_function<_Arg,_Result>(__f);}
1105 template <class _Arg1, class _Arg2, class _Result>
1106 class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 pointer_to_binary_function
1107 : public binary_function<_Arg1, _Arg2, _Result>
1109 _Result (*__f_)(_Arg1, _Arg2);
1111 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2))
1113 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const
1114 {return __f_(__x, __y);}
1117 template <class _Arg1, class _Arg2, class _Result>
1118 _LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
1119 pointer_to_binary_function<_Arg1,_Arg2,_Result>
1120 ptr_fun(_Result (*__f)(_Arg1,_Arg2))
1121 {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);}
1123 template<class _Sp, class _Tp>
1124 class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun_t
1125 : public unary_function<_Tp*, _Sp>
1129 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)())
1131 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const
1132 {return (__p->*__p_)();}
1135 template<class _Sp, class _Tp, class _Ap>
1136 class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun1_t
1137 : public binary_function<_Tp*, _Ap, _Sp>
1139 _Sp (_Tp::*__p_)(_Ap);
1141 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap))
1143 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const
1144 {return (__p->*__p_)(__x);}
1147 template<class _Sp, class _Tp>
1148 _LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
1150 mem_fun(_Sp (_Tp::*__f)())
1151 {return mem_fun_t<_Sp,_Tp>(__f);}
1153 template<class _Sp, class _Tp, class _Ap>
1154 _LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
1155 mem_fun1_t<_Sp,_Tp,_Ap>
1156 mem_fun(_Sp (_Tp::*__f)(_Ap))
1157 {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1159 template<class _Sp, class _Tp>
1160 class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun_ref_t
1161 : public unary_function<_Tp, _Sp>
1165 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)())
1167 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const
1168 {return (__p.*__p_)();}
1171 template<class _Sp, class _Tp, class _Ap>
1172 class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun1_ref_t
1173 : public binary_function<_Tp, _Ap, _Sp>
1175 _Sp (_Tp::*__p_)(_Ap);
1177 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap))
1179 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const
1180 {return (__p.*__p_)(__x);}
1183 template<class _Sp, class _Tp>
1184 _LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
1185 mem_fun_ref_t<_Sp,_Tp>
1186 mem_fun_ref(_Sp (_Tp::*__f)())
1187 {return mem_fun_ref_t<_Sp,_Tp>(__f);}
1189 template<class _Sp, class _Tp, class _Ap>
1190 _LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
1191 mem_fun1_ref_t<_Sp,_Tp,_Ap>
1192 mem_fun_ref(_Sp (_Tp::*__f)(_Ap))
1193 {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
1195 template <class _Sp, class _Tp>
1196 class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun_t
1197 : public unary_function<const _Tp*, _Sp>
1199 _Sp (_Tp::*__p_)() const;
1201 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const)
1203 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const
1204 {return (__p->*__p_)();}
1207 template <class _Sp, class _Tp, class _Ap>
1208 class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun1_t
1209 : public binary_function<const _Tp*, _Ap, _Sp>
1211 _Sp (_Tp::*__p_)(_Ap) const;
1213 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const)
1215 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const
1216 {return (__p->*__p_)(__x);}
1219 template <class _Sp, class _Tp>
1220 _LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
1221 const_mem_fun_t<_Sp,_Tp>
1222 mem_fun(_Sp (_Tp::*__f)() const)
1223 {return const_mem_fun_t<_Sp,_Tp>(__f);}
1225 template <class _Sp, class _Tp, class _Ap>
1226 _LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
1227 const_mem_fun1_t<_Sp,_Tp,_Ap>
1228 mem_fun(_Sp (_Tp::*__f)(_Ap) const)
1229 {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1231 template <class _Sp, class _Tp>
1232 class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun_ref_t
1233 : public unary_function<_Tp, _Sp>
1235 _Sp (_Tp::*__p_)() const;
1237 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const)
1239 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const
1240 {return (__p.*__p_)();}
1243 template <class _Sp, class _Tp, class _Ap>
1244 class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun1_ref_t
1245 : public binary_function<_Tp, _Ap, _Sp>
1247 _Sp (_Tp::*__p_)(_Ap) const;
1249 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const)
1251 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const
1252 {return (__p.*__p_)(__x);}
1255 template <class _Sp, class _Tp>
1256 _LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
1257 const_mem_fun_ref_t<_Sp,_Tp>
1258 mem_fun_ref(_Sp (_Tp::*__f)() const)
1259 {return const_mem_fun_ref_t<_Sp,_Tp>(__f);}
1261 template <class _Sp, class _Tp, class _Ap>
1262 _LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
1263 const_mem_fun1_ref_t<_Sp,_Tp,_Ap>
1264 mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const)
1265 {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
1268 ////////////////////////////////////////////////////////////////////////////////
1270 //==============================================================================
1272 template <class _Tp>
1274 : public __weak_result_type<_Tp>
1283 _LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) _NOEXCEPT : __f_(__f) {}
1285 #ifndef _LIBCPP_CXX03_LANG
1287 template <class... _ArgTypes>
1288 _LIBCPP_INLINE_VISIBILITY
1289 typename __invoke_return<type, _ArgTypes...>::type
1290 operator() (_ArgTypes&&... __args) const {
1291 return __invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...);
1295 template <class _A0>
1296 _LIBCPP_INLINE_VISIBILITY
1297 typename __invoke_return0<type, _A0>::type
1298 operator() (_A0& __a0) const {
1299 return __invoke(__f_, __a0);
1302 template <class _A0>
1303 _LIBCPP_INLINE_VISIBILITY
1304 typename __invoke_return0<type, _A0 const>::type
1305 operator() (_A0 const& __a0) const {
1306 return __invoke(__f_, __a0);
1309 template <class _A0, class _A1>
1310 _LIBCPP_INLINE_VISIBILITY
1311 typename __invoke_return1<type, _A0, _A1>::type
1312 operator() (_A0& __a0, _A1& __a1) const {
1313 return __invoke(__f_, __a0, __a1);
1316 template <class _A0, class _A1>
1317 _LIBCPP_INLINE_VISIBILITY
1318 typename __invoke_return1<type, _A0 const, _A1>::type
1319 operator() (_A0 const& __a0, _A1& __a1) const {
1320 return __invoke(__f_, __a0, __a1);
1323 template <class _A0, class _A1>
1324 _LIBCPP_INLINE_VISIBILITY
1325 typename __invoke_return1<type, _A0, _A1 const>::type
1326 operator() (_A0& __a0, _A1 const& __a1) const {
1327 return __invoke(__f_, __a0, __a1);
1330 template <class _A0, class _A1>
1331 _LIBCPP_INLINE_VISIBILITY
1332 typename __invoke_return1<type, _A0 const, _A1 const>::type
1333 operator() (_A0 const& __a0, _A1 const& __a1) const {
1334 return __invoke(__f_, __a0, __a1);
1337 template <class _A0, class _A1, class _A2>
1338 _LIBCPP_INLINE_VISIBILITY
1339 typename __invoke_return2<type, _A0, _A1, _A2>::type
1340 operator() (_A0& __a0, _A1& __a1, _A2& __a2) const {
1341 return __invoke(__f_, __a0, __a1, __a2);
1344 template <class _A0, class _A1, class _A2>
1345 _LIBCPP_INLINE_VISIBILITY
1346 typename __invoke_return2<type, _A0 const, _A1, _A2>::type
1347 operator() (_A0 const& __a0, _A1& __a1, _A2& __a2) const {
1348 return __invoke(__f_, __a0, __a1, __a2);
1351 template <class _A0, class _A1, class _A2>
1352 _LIBCPP_INLINE_VISIBILITY
1353 typename __invoke_return2<type, _A0, _A1 const, _A2>::type
1354 operator() (_A0& __a0, _A1 const& __a1, _A2& __a2) const {
1355 return __invoke(__f_, __a0, __a1, __a2);
1358 template <class _A0, class _A1, class _A2>
1359 _LIBCPP_INLINE_VISIBILITY
1360 typename __invoke_return2<type, _A0, _A1, _A2 const>::type
1361 operator() (_A0& __a0, _A1& __a1, _A2 const& __a2) const {
1362 return __invoke(__f_, __a0, __a1, __a2);
1365 template <class _A0, class _A1, class _A2>
1366 _LIBCPP_INLINE_VISIBILITY
1367 typename __invoke_return2<type, _A0 const, _A1 const, _A2>::type
1368 operator() (_A0 const& __a0, _A1 const& __a1, _A2& __a2) const {
1369 return __invoke(__f_, __a0, __a1, __a2);
1372 template <class _A0, class _A1, class _A2>
1373 _LIBCPP_INLINE_VISIBILITY
1374 typename __invoke_return2<type, _A0 const, _A1, _A2 const>::type
1375 operator() (_A0 const& __a0, _A1& __a1, _A2 const& __a2) const {
1376 return __invoke(__f_, __a0, __a1, __a2);
1379 template <class _A0, class _A1, class _A2>
1380 _LIBCPP_INLINE_VISIBILITY
1381 typename __invoke_return2<type, _A0, _A1 const, _A2 const>::type
1382 operator() (_A0& __a0, _A1 const& __a1, _A2 const& __a2) const {
1383 return __invoke(__f_, __a0, __a1, __a2);
1386 template <class _A0, class _A1, class _A2>
1387 _LIBCPP_INLINE_VISIBILITY
1388 typename __invoke_return2<type, _A0 const, _A1 const, _A2 const>::type
1389 operator() (_A0 const& __a0, _A1 const& __a1, _A2 const& __a2) const {
1390 return __invoke(__f_, __a0, __a1, __a2);
1395 template<class _Rp, class _Tp>
1396 inline _LIBCPP_INLINE_VISIBILITY
1397 __mem_fn<_Rp _Tp::*>
1398 mem_fn(_Rp _Tp::* __pm) _NOEXCEPT
1400 return __mem_fn<_Rp _Tp::*>(__pm);
1403 ////////////////////////////////////////////////////////////////////////////////
1405 //==============================================================================
1407 // bad_function_call
1409 class _LIBCPP_EXCEPTION_ABI bad_function_call
1412 #ifdef _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
1414 virtual ~bad_function_call() _NOEXCEPT;
1416 virtual const char* what() const _NOEXCEPT;
1420 _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
1421 void __throw_bad_function_call()
1423 #ifndef _LIBCPP_NO_EXCEPTIONS
1424 throw bad_function_call();
1430 template<class _Fp> class _LIBCPP_TEMPLATE_VIS function; // undefined
1432 namespace __function
1436 struct __maybe_derive_from_unary_function
1440 template<class _Rp, class _A1>
1441 struct __maybe_derive_from_unary_function<_Rp(_A1)>
1442 : public unary_function<_A1, _Rp>
1447 struct __maybe_derive_from_binary_function
1451 template<class _Rp, class _A1, class _A2>
1452 struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)>
1453 : public binary_function<_A1, _A2, _Rp>
1457 template <class _Fp>
1458 _LIBCPP_INLINE_VISIBILITY
1459 bool __not_null(_Fp const&) { return true; }
1461 template <class _Fp>
1462 _LIBCPP_INLINE_VISIBILITY
1463 bool __not_null(_Fp* __ptr) { return __ptr; }
1465 template <class _Ret, class _Class>
1466 _LIBCPP_INLINE_VISIBILITY
1467 bool __not_null(_Ret _Class::*__ptr) { return __ptr; }
1469 template <class _Fp>
1470 _LIBCPP_INLINE_VISIBILITY
1471 bool __not_null(function<_Fp> const& __f) { return !!__f; }
1473 } // namespace __function
1475 #ifndef _LIBCPP_CXX03_LANG
1477 namespace __function {
1479 // __alloc_func holds a functor and an allocator.
1481 template <class _Fp, class _Ap, class _FB> class __alloc_func;
1482 template <class _Fp, class _FB>
1483 class __default_alloc_func;
1485 template <class _Fp, class _Ap, class _Rp, class... _ArgTypes>
1486 class __alloc_func<_Fp, _Ap, _Rp(_ArgTypes...)>
1488 __compressed_pair<_Fp, _Ap> __f_;
1491 typedef _LIBCPP_NODEBUG_TYPE _Fp _Target;
1492 typedef _LIBCPP_NODEBUG_TYPE _Ap _Alloc;
1494 _LIBCPP_INLINE_VISIBILITY
1495 const _Target& __target() const { return __f_.first(); }
1497 // WIN32 APIs may define __allocator, so use __get_allocator instead.
1498 _LIBCPP_INLINE_VISIBILITY
1499 const _Alloc& __get_allocator() const { return __f_.second(); }
1501 _LIBCPP_INLINE_VISIBILITY
1502 explicit __alloc_func(_Target&& __f)
1503 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1504 _VSTD::forward_as_tuple())
1508 _LIBCPP_INLINE_VISIBILITY
1509 explicit __alloc_func(const _Target& __f, const _Alloc& __a)
1510 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1511 _VSTD::forward_as_tuple(__a))
1515 _LIBCPP_INLINE_VISIBILITY
1516 explicit __alloc_func(const _Target& __f, _Alloc&& __a)
1517 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1518 _VSTD::forward_as_tuple(_VSTD::move(__a)))
1522 _LIBCPP_INLINE_VISIBILITY
1523 explicit __alloc_func(_Target&& __f, _Alloc&& __a)
1524 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1525 _VSTD::forward_as_tuple(_VSTD::move(__a)))
1529 _LIBCPP_INLINE_VISIBILITY
1530 _Rp operator()(_ArgTypes&&... __arg)
1532 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
1533 return _Invoker::__call(__f_.first(),
1534 _VSTD::forward<_ArgTypes>(__arg)...);
1537 _LIBCPP_INLINE_VISIBILITY
1538 __alloc_func* __clone() const
1540 typedef allocator_traits<_Alloc> __alloc_traits;
1542 typename __rebind_alloc_helper<__alloc_traits, __alloc_func>::type
1544 _AA __a(__f_.second());
1545 typedef __allocator_destructor<_AA> _Dp;
1546 unique_ptr<__alloc_func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1547 ::new ((void*)__hold.get()) __alloc_func(__f_.first(), _Alloc(__a));
1548 return __hold.release();
1551 _LIBCPP_INLINE_VISIBILITY
1552 void destroy() _NOEXCEPT { __f_.~__compressed_pair<_Target, _Alloc>(); }
1554 static void __destroy_and_delete(__alloc_func* __f) {
1555 typedef allocator_traits<_Alloc> __alloc_traits;
1556 typedef typename __rebind_alloc_helper<__alloc_traits, __alloc_func>::type
1558 _FunAlloc __a(__f->__get_allocator());
1560 __a.deallocate(__f, 1);
1564 template <class _Fp, class _Rp, class... _ArgTypes>
1565 class __default_alloc_func<_Fp, _Rp(_ArgTypes...)> {
1569 typedef _LIBCPP_NODEBUG_TYPE _Fp _Target;
1571 _LIBCPP_INLINE_VISIBILITY
1572 const _Target& __target() const { return __f_; }
1574 _LIBCPP_INLINE_VISIBILITY
1575 explicit __default_alloc_func(_Target&& __f) : __f_(std::move(__f)) {}
1577 _LIBCPP_INLINE_VISIBILITY
1578 explicit __default_alloc_func(const _Target& __f) : __f_(__f) {}
1580 _LIBCPP_INLINE_VISIBILITY
1581 _Rp operator()(_ArgTypes&&... __arg) {
1582 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
1583 return _Invoker::__call(__f_, _VSTD::forward<_ArgTypes>(__arg)...);
1586 _LIBCPP_INLINE_VISIBILITY
1587 __default_alloc_func* __clone() const {
1588 __builtin_new_allocator::__holder_t __hold =
1589 __builtin_new_allocator::__allocate_type<__default_alloc_func>(1);
1590 __default_alloc_func* __res =
1591 ::new (__hold.get()) __default_alloc_func(__f_);
1592 (void)__hold.release();
1596 _LIBCPP_INLINE_VISIBILITY
1597 void destroy() _NOEXCEPT { __f_.~_Target(); }
1599 static void __destroy_and_delete(__default_alloc_func* __f) {
1601 __builtin_new_allocator::__deallocate_type<__default_alloc_func>(__f, 1);
1605 // __base provides an abstract interface for copyable functors.
1607 template<class _Fp> class __base;
1609 template<class _Rp, class ..._ArgTypes>
1610 class __base<_Rp(_ArgTypes...)>
1612 __base(const __base&);
1613 __base& operator=(const __base&);
1615 _LIBCPP_INLINE_VISIBILITY __base() {}
1616 _LIBCPP_INLINE_VISIBILITY virtual ~__base() {}
1617 virtual __base* __clone() const = 0;
1618 virtual void __clone(__base*) const = 0;
1619 virtual void destroy() _NOEXCEPT = 0;
1620 virtual void destroy_deallocate() _NOEXCEPT = 0;
1621 virtual _Rp operator()(_ArgTypes&& ...) = 0;
1622 #ifndef _LIBCPP_NO_RTTI
1623 virtual const void* target(const type_info&) const _NOEXCEPT = 0;
1624 virtual const std::type_info& target_type() const _NOEXCEPT = 0;
1625 #endif // _LIBCPP_NO_RTTI
1628 // __func implements __base for a given functor type.
1630 template<class _FD, class _Alloc, class _FB> class __func;
1632 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1633 class __func<_Fp, _Alloc, _Rp(_ArgTypes...)>
1634 : public __base<_Rp(_ArgTypes...)>
1636 __alloc_func<_Fp, _Alloc, _Rp(_ArgTypes...)> __f_;
1638 _LIBCPP_INLINE_VISIBILITY
1639 explicit __func(_Fp&& __f)
1640 : __f_(_VSTD::move(__f)) {}
1642 _LIBCPP_INLINE_VISIBILITY
1643 explicit __func(const _Fp& __f, const _Alloc& __a)
1646 _LIBCPP_INLINE_VISIBILITY
1647 explicit __func(const _Fp& __f, _Alloc&& __a)
1648 : __f_(__f, _VSTD::move(__a)) {}
1650 _LIBCPP_INLINE_VISIBILITY
1651 explicit __func(_Fp&& __f, _Alloc&& __a)
1652 : __f_(_VSTD::move(__f), _VSTD::move(__a)) {}
1654 virtual __base<_Rp(_ArgTypes...)>* __clone() const;
1655 virtual void __clone(__base<_Rp(_ArgTypes...)>*) const;
1656 virtual void destroy() _NOEXCEPT;
1657 virtual void destroy_deallocate() _NOEXCEPT;
1658 virtual _Rp operator()(_ArgTypes&&... __arg);
1659 #ifndef _LIBCPP_NO_RTTI
1660 virtual const void* target(const type_info&) const _NOEXCEPT;
1661 virtual const std::type_info& target_type() const _NOEXCEPT;
1662 #endif // _LIBCPP_NO_RTTI
1665 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1666 __base<_Rp(_ArgTypes...)>*
1667 __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const
1669 typedef allocator_traits<_Alloc> __alloc_traits;
1670 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
1671 _Ap __a(__f_.__get_allocator());
1672 typedef __allocator_destructor<_Ap> _Dp;
1673 unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1674 ::new ((void*)__hold.get()) __func(__f_.__target(), _Alloc(__a));
1675 return __hold.release();
1678 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1680 __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const
1682 ::new (__p) __func(__f_.__target(), __f_.__get_allocator());
1685 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1687 __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPT
1692 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1694 __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT
1696 typedef allocator_traits<_Alloc> __alloc_traits;
1697 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
1698 _Ap __a(__f_.__get_allocator());
1700 __a.deallocate(this, 1);
1703 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1705 __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg)
1707 return __f_(_VSTD::forward<_ArgTypes>(__arg)...);
1710 #ifndef _LIBCPP_NO_RTTI
1712 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1714 __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT
1716 if (__ti == typeid(_Fp))
1717 return &__f_.__target();
1718 return (const void*)0;
1721 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1722 const std::type_info&
1723 __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
1728 #endif // _LIBCPP_NO_RTTI
1730 // __value_func creates a value-type from a __func.
1732 template <class _Fp> class __value_func;
1734 template <class _Rp, class... _ArgTypes> class __value_func<_Rp(_ArgTypes...)>
1736 typename aligned_storage<3 * sizeof(void*)>::type __buf_;
1738 typedef __base<_Rp(_ArgTypes...)> __func;
1741 _LIBCPP_NO_CFI static __func* __as_base(void* p)
1743 return reinterpret_cast<__func*>(p);
1747 _LIBCPP_INLINE_VISIBILITY
1748 __value_func() _NOEXCEPT : __f_(0) {}
1750 template <class _Fp, class _Alloc>
1751 _LIBCPP_INLINE_VISIBILITY __value_func(_Fp&& __f, const _Alloc& __a)
1754 typedef allocator_traits<_Alloc> __alloc_traits;
1755 typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _Fun;
1756 typedef typename __rebind_alloc_helper<__alloc_traits, _Fun>::type
1759 if (__function::__not_null(__f))
1761 _FunAlloc __af(__a);
1762 if (sizeof(_Fun) <= sizeof(__buf_) &&
1763 is_nothrow_copy_constructible<_Fp>::value &&
1764 is_nothrow_copy_constructible<_FunAlloc>::value)
1767 ::new ((void*)&__buf_) _Fun(_VSTD::move(__f), _Alloc(__af));
1771 typedef __allocator_destructor<_FunAlloc> _Dp;
1772 unique_ptr<__func, _Dp> __hold(__af.allocate(1), _Dp(__af, 1));
1773 ::new ((void*)__hold.get()) _Fun(_VSTD::move(__f), _Alloc(__a));
1774 __f_ = __hold.release();
1779 template <class _Fp,
1780 class = typename enable_if<!is_same<typename decay<_Fp>::type, __value_func>::value>::type>
1781 _LIBCPP_INLINE_VISIBILITY explicit __value_func(_Fp&& __f)
1782 : __value_func(std::forward<_Fp>(__f), allocator<_Fp>()) {}
1784 _LIBCPP_INLINE_VISIBILITY
1785 __value_func(const __value_func& __f)
1789 else if ((void*)__f.__f_ == &__f.__buf_)
1791 __f_ = __as_base(&__buf_);
1792 __f.__f_->__clone(__f_);
1795 __f_ = __f.__f_->__clone();
1798 _LIBCPP_INLINE_VISIBILITY
1799 __value_func(__value_func&& __f) _NOEXCEPT
1803 else if ((void*)__f.__f_ == &__f.__buf_)
1805 __f_ = __as_base(&__buf_);
1806 __f.__f_->__clone(__f_);
1815 _LIBCPP_INLINE_VISIBILITY
1818 if ((void*)__f_ == &__buf_)
1821 __f_->destroy_deallocate();
1824 _LIBCPP_INLINE_VISIBILITY
1825 __value_func& operator=(__value_func&& __f)
1830 else if ((void*)__f.__f_ == &__f.__buf_)
1832 __f_ = __as_base(&__buf_);
1833 __f.__f_->__clone(__f_);
1843 _LIBCPP_INLINE_VISIBILITY
1844 __value_func& operator=(nullptr_t)
1848 if ((void*)__f == &__buf_)
1851 __f->destroy_deallocate();
1855 _LIBCPP_INLINE_VISIBILITY
1856 _Rp operator()(_ArgTypes&&... __args) const
1859 __throw_bad_function_call();
1860 return (*__f_)(_VSTD::forward<_ArgTypes>(__args)...);
1863 _LIBCPP_INLINE_VISIBILITY
1864 void swap(__value_func& __f) _NOEXCEPT
1868 if ((void*)__f_ == &__buf_ && (void*)__f.__f_ == &__f.__buf_)
1870 typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
1871 __func* __t = __as_base(&__tempbuf);
1875 __f.__f_->__clone(__as_base(&__buf_));
1876 __f.__f_->destroy();
1878 __f_ = __as_base(&__buf_);
1879 __t->__clone(__as_base(&__f.__buf_));
1881 __f.__f_ = __as_base(&__f.__buf_);
1883 else if ((void*)__f_ == &__buf_)
1885 __f_->__clone(__as_base(&__f.__buf_));
1888 __f.__f_ = __as_base(&__f.__buf_);
1890 else if ((void*)__f.__f_ == &__f.__buf_)
1892 __f.__f_->__clone(__as_base(&__buf_));
1893 __f.__f_->destroy();
1895 __f_ = __as_base(&__buf_);
1898 _VSTD::swap(__f_, __f.__f_);
1901 _LIBCPP_INLINE_VISIBILITY
1902 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT { return __f_ != 0; }
1904 #ifndef _LIBCPP_NO_RTTI
1905 _LIBCPP_INLINE_VISIBILITY
1906 const std::type_info& target_type() const _NOEXCEPT
1909 return typeid(void);
1910 return __f_->target_type();
1913 template <typename _Tp>
1914 _LIBCPP_INLINE_VISIBILITY const _Tp* target() const _NOEXCEPT
1918 return (const _Tp*)__f_->target(typeid(_Tp));
1920 #endif // _LIBCPP_NO_RTTI
1923 // Storage for a functor object, to be used with __policy to manage copy and
1925 union __policy_storage
1927 mutable char __small[sizeof(void*) * 2];
1931 // True if _Fun can safely be held in __policy_storage.__small.
1932 template <typename _Fun>
1933 struct __use_small_storage
1934 : public _VSTD::integral_constant<
1935 bool, sizeof(_Fun) <= sizeof(__policy_storage) &&
1936 _LIBCPP_ALIGNOF(_Fun) <= _LIBCPP_ALIGNOF(__policy_storage) &&
1937 _VSTD::is_trivially_copy_constructible<_Fun>::value &&
1938 _VSTD::is_trivially_destructible<_Fun>::value> {};
1940 // Policy contains information about how to copy, destroy, and move the
1941 // underlying functor. You can think of it as a vtable of sorts.
1944 // Used to copy or destroy __large values. null for trivial objects.
1945 void* (*const __clone)(const void*);
1946 void (*const __destroy)(void*);
1948 // True if this is the null policy (no value).
1949 const bool __is_null;
1951 // The target type. May be null if RTTI is disabled.
1952 const std::type_info* const __type_info;
1954 // Returns a pointer to a static policy object suitable for the functor
1956 template <typename _Fun>
1957 _LIBCPP_INLINE_VISIBILITY static const __policy* __create()
1959 return __choose_policy<_Fun>(__use_small_storage<_Fun>());
1962 _LIBCPP_INLINE_VISIBILITY
1963 static const __policy* __create_empty()
1965 static const _LIBCPP_CONSTEXPR __policy __policy_ = {nullptr, nullptr,
1967 #ifndef _LIBCPP_NO_RTTI
1977 template <typename _Fun> static void* __large_clone(const void* __s)
1979 const _Fun* __f = static_cast<const _Fun*>(__s);
1980 return __f->__clone();
1983 template <typename _Fun>
1984 static void __large_destroy(void* __s) {
1985 _Fun::__destroy_and_delete(static_cast<_Fun*>(__s));
1988 template <typename _Fun>
1989 _LIBCPP_INLINE_VISIBILITY static const __policy*
1990 __choose_policy(/* is_small = */ false_type) {
1991 static const _LIBCPP_CONSTEXPR __policy __policy_ = {
1992 &__large_clone<_Fun>, &__large_destroy<_Fun>, false,
1993 #ifndef _LIBCPP_NO_RTTI
1994 &typeid(typename _Fun::_Target)
2002 template <typename _Fun>
2003 _LIBCPP_INLINE_VISIBILITY static const __policy*
2004 __choose_policy(/* is_small = */ true_type)
2006 static const _LIBCPP_CONSTEXPR __policy __policy_ = {
2007 nullptr, nullptr, false,
2008 #ifndef _LIBCPP_NO_RTTI
2009 &typeid(typename _Fun::_Target)
2018 // Used to choose between perfect forwarding or pass-by-value. Pass-by-value is
2019 // faster for types that can be passed in registers.
2020 template <typename _Tp>
2021 using __fast_forward =
2022 typename _VSTD::conditional<_VSTD::is_scalar<_Tp>::value, _Tp, _Tp&&>::type;
2024 // __policy_invoker calls an instance of __alloc_func held in __policy_storage.
2026 template <class _Fp> struct __policy_invoker;
2028 template <class _Rp, class... _ArgTypes>
2029 struct __policy_invoker<_Rp(_ArgTypes...)>
2031 typedef _Rp (*__Call)(const __policy_storage*,
2032 __fast_forward<_ArgTypes>...);
2036 // Creates an invoker that throws bad_function_call.
2037 _LIBCPP_INLINE_VISIBILITY
2038 __policy_invoker() : __call_(&__call_empty) {}
2040 // Creates an invoker that calls the given instance of __func.
2041 template <typename _Fun>
2042 _LIBCPP_INLINE_VISIBILITY static __policy_invoker __create()
2044 return __policy_invoker(&__call_impl<_Fun>);
2048 _LIBCPP_INLINE_VISIBILITY
2049 explicit __policy_invoker(__Call __c) : __call_(__c) {}
2051 static _Rp __call_empty(const __policy_storage*,
2052 __fast_forward<_ArgTypes>...)
2054 __throw_bad_function_call();
2057 template <typename _Fun>
2058 static _Rp __call_impl(const __policy_storage* __buf,
2059 __fast_forward<_ArgTypes>... __args)
2061 _Fun* __f = reinterpret_cast<_Fun*>(__use_small_storage<_Fun>::value
2064 return (*__f)(_VSTD::forward<_ArgTypes>(__args)...);
2068 // __policy_func uses a __policy and __policy_invoker to create a type-erased,
2069 // copyable functor.
2071 template <class _Fp> class __policy_func;
2073 template <class _Rp, class... _ArgTypes> class __policy_func<_Rp(_ArgTypes...)>
2075 // Inline storage for small objects.
2076 __policy_storage __buf_;
2078 // Calls the value stored in __buf_. This could technically be part of
2079 // policy, but storing it here eliminates a level of indirection inside
2081 typedef __function::__policy_invoker<_Rp(_ArgTypes...)> __invoker;
2082 __invoker __invoker_;
2084 // The policy that describes how to move / copy / destroy __buf_. Never
2085 // null, even if the function is empty.
2086 const __policy* __policy_;
2089 _LIBCPP_INLINE_VISIBILITY
2090 __policy_func() : __policy_(__policy::__create_empty()) {}
2092 template <class _Fp, class _Alloc>
2093 _LIBCPP_INLINE_VISIBILITY __policy_func(_Fp&& __f, const _Alloc& __a)
2094 : __policy_(__policy::__create_empty())
2096 typedef __alloc_func<_Fp, _Alloc, _Rp(_ArgTypes...)> _Fun;
2097 typedef allocator_traits<_Alloc> __alloc_traits;
2098 typedef typename __rebind_alloc_helper<__alloc_traits, _Fun>::type
2101 if (__function::__not_null(__f))
2103 __invoker_ = __invoker::template __create<_Fun>();
2104 __policy_ = __policy::__create<_Fun>();
2106 _FunAlloc __af(__a);
2107 if (__use_small_storage<_Fun>())
2109 ::new ((void*)&__buf_.__small)
2110 _Fun(_VSTD::move(__f), _Alloc(__af));
2114 typedef __allocator_destructor<_FunAlloc> _Dp;
2115 unique_ptr<_Fun, _Dp> __hold(__af.allocate(1), _Dp(__af, 1));
2116 ::new ((void*)__hold.get())
2117 _Fun(_VSTD::move(__f), _Alloc(__af));
2118 __buf_.__large = __hold.release();
2123 template <class _Fp, class = typename enable_if<!is_same<typename decay<_Fp>::type, __policy_func>::value>::type>
2124 _LIBCPP_INLINE_VISIBILITY explicit __policy_func(_Fp&& __f)
2125 : __policy_(__policy::__create_empty()) {
2126 typedef __default_alloc_func<_Fp, _Rp(_ArgTypes...)> _Fun;
2128 if (__function::__not_null(__f)) {
2129 __invoker_ = __invoker::template __create<_Fun>();
2130 __policy_ = __policy::__create<_Fun>();
2131 if (__use_small_storage<_Fun>()) {
2132 ::new ((void*)&__buf_.__small) _Fun(_VSTD::move(__f));
2134 __builtin_new_allocator::__holder_t __hold =
2135 __builtin_new_allocator::__allocate_type<_Fun>(1);
2136 __buf_.__large = ::new (__hold.get()) _Fun(_VSTD::move(__f));
2137 (void)__hold.release();
2142 _LIBCPP_INLINE_VISIBILITY
2143 __policy_func(const __policy_func& __f)
2144 : __buf_(__f.__buf_), __invoker_(__f.__invoker_),
2145 __policy_(__f.__policy_)
2147 if (__policy_->__clone)
2148 __buf_.__large = __policy_->__clone(__f.__buf_.__large);
2151 _LIBCPP_INLINE_VISIBILITY
2152 __policy_func(__policy_func&& __f)
2153 : __buf_(__f.__buf_), __invoker_(__f.__invoker_),
2154 __policy_(__f.__policy_)
2156 if (__policy_->__destroy)
2158 __f.__policy_ = __policy::__create_empty();
2159 __f.__invoker_ = __invoker();
2163 _LIBCPP_INLINE_VISIBILITY
2166 if (__policy_->__destroy)
2167 __policy_->__destroy(__buf_.__large);
2170 _LIBCPP_INLINE_VISIBILITY
2171 __policy_func& operator=(__policy_func&& __f)
2174 __buf_ = __f.__buf_;
2175 __invoker_ = __f.__invoker_;
2176 __policy_ = __f.__policy_;
2177 __f.__policy_ = __policy::__create_empty();
2178 __f.__invoker_ = __invoker();
2182 _LIBCPP_INLINE_VISIBILITY
2183 __policy_func& operator=(nullptr_t)
2185 const __policy* __p = __policy_;
2186 __policy_ = __policy::__create_empty();
2187 __invoker_ = __invoker();
2189 __p->__destroy(__buf_.__large);
2193 _LIBCPP_INLINE_VISIBILITY
2194 _Rp operator()(_ArgTypes&&... __args) const
2196 return __invoker_.__call_(_VSTD::addressof(__buf_),
2197 _VSTD::forward<_ArgTypes>(__args)...);
2200 _LIBCPP_INLINE_VISIBILITY
2201 void swap(__policy_func& __f)
2203 _VSTD::swap(__invoker_, __f.__invoker_);
2204 _VSTD::swap(__policy_, __f.__policy_);
2205 _VSTD::swap(__buf_, __f.__buf_);
2208 _LIBCPP_INLINE_VISIBILITY
2209 explicit operator bool() const _NOEXCEPT
2211 return !__policy_->__is_null;
2214 #ifndef _LIBCPP_NO_RTTI
2215 _LIBCPP_INLINE_VISIBILITY
2216 const std::type_info& target_type() const _NOEXCEPT
2218 return *__policy_->__type_info;
2221 template <typename _Tp>
2222 _LIBCPP_INLINE_VISIBILITY const _Tp* target() const _NOEXCEPT
2224 if (__policy_->__is_null || typeid(_Tp) != *__policy_->__type_info)
2226 if (__policy_->__clone) // Out of line storage.
2227 return reinterpret_cast<const _Tp*>(__buf_.__large);
2229 return reinterpret_cast<const _Tp*>(&__buf_.__small);
2231 #endif // _LIBCPP_NO_RTTI
2236 template<class _Rp, class ..._ArgTypes>
2237 class _LIBCPP_TEMPLATE_VIS function<_Rp(_ArgTypes...)>
2238 : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>,
2239 public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)>
2241 #ifndef _LIBCPP_ABI_OPTIMIZED_FUNCTION
2242 typedef __function::__value_func<_Rp(_ArgTypes...)> __func;
2244 typedef __function::__policy_func<_Rp(_ArgTypes...)> __func;
2249 template <class _Fp, bool = _And<
2250 _IsNotSame<__uncvref_t<_Fp>, function>,
2251 __invokable<_Fp&, _ArgTypes...>
2254 template <class _Fp>
2255 struct __callable<_Fp, true>
2257 static const bool value = is_same<void, _Rp>::value ||
2258 is_convertible<typename __invoke_of<_Fp&, _ArgTypes...>::type,
2261 template <class _Fp>
2262 struct __callable<_Fp, false>
2264 static const bool value = false;
2267 template <class _Fp>
2268 using _EnableIfCallable = typename enable_if<__callable<_Fp>::value>::type;
2270 typedef _Rp result_type;
2272 // construct/copy/destroy:
2273 _LIBCPP_INLINE_VISIBILITY
2274 function() _NOEXCEPT { }
2275 _LIBCPP_INLINE_VISIBILITY
2276 function(nullptr_t) _NOEXCEPT {}
2277 function(const function&);
2278 function(function&&) _NOEXCEPT;
2279 template<class _Fp, class = _EnableIfCallable<_Fp>>
2282 #if _LIBCPP_STD_VER <= 14
2283 template<class _Alloc>
2284 _LIBCPP_INLINE_VISIBILITY
2285 function(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
2286 template<class _Alloc>
2287 _LIBCPP_INLINE_VISIBILITY
2288 function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT {}
2289 template<class _Alloc>
2290 function(allocator_arg_t, const _Alloc&, const function&);
2291 template<class _Alloc>
2292 function(allocator_arg_t, const _Alloc&, function&&);
2293 template<class _Fp, class _Alloc, class = _EnableIfCallable<_Fp>>
2294 function(allocator_arg_t, const _Alloc& __a, _Fp __f);
2297 function& operator=(const function&);
2298 function& operator=(function&&) _NOEXCEPT;
2299 function& operator=(nullptr_t) _NOEXCEPT;
2300 template<class _Fp, class = _EnableIfCallable<_Fp>>
2301 function& operator=(_Fp&&);
2305 // function modifiers:
2306 void swap(function&) _NOEXCEPT;
2308 #if _LIBCPP_STD_VER <= 14
2309 template<class _Fp, class _Alloc>
2310 _LIBCPP_INLINE_VISIBILITY
2311 void assign(_Fp&& __f, const _Alloc& __a)
2312 {function(allocator_arg, __a, _VSTD::forward<_Fp>(__f)).swap(*this);}
2315 // function capacity:
2316 _LIBCPP_INLINE_VISIBILITY
2317 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {
2318 return static_cast<bool>(__f_);
2321 // deleted overloads close possible hole in the type system
2322 template<class _R2, class... _ArgTypes2>
2323 bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete;
2324 template<class _R2, class... _ArgTypes2>
2325 bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete;
2327 // function invocation:
2328 _Rp operator()(_ArgTypes...) const;
2330 #ifndef _LIBCPP_NO_RTTI
2331 // function target access:
2332 const std::type_info& target_type() const _NOEXCEPT;
2333 template <typename _Tp> _Tp* target() _NOEXCEPT;
2334 template <typename _Tp> const _Tp* target() const _NOEXCEPT;
2335 #endif // _LIBCPP_NO_RTTI
2338 template<class _Rp, class ..._ArgTypes>
2339 function<_Rp(_ArgTypes...)>::function(const function& __f) : __f_(__f.__f_) {}
2341 #if _LIBCPP_STD_VER <= 14
2342 template<class _Rp, class ..._ArgTypes>
2343 template <class _Alloc>
2344 function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
2345 const function& __f) : __f_(__f.__f_) {}
2348 template <class _Rp, class... _ArgTypes>
2349 function<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT
2350 : __f_(_VSTD::move(__f.__f_)) {}
2352 #if _LIBCPP_STD_VER <= 14
2353 template<class _Rp, class ..._ArgTypes>
2354 template <class _Alloc>
2355 function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
2357 : __f_(_VSTD::move(__f.__f_)) {}
2360 template <class _Rp, class... _ArgTypes>
2361 template <class _Fp, class>
2362 function<_Rp(_ArgTypes...)>::function(_Fp __f) : __f_(_VSTD::move(__f)) {}
2364 #if _LIBCPP_STD_VER <= 14
2365 template <class _Rp, class... _ArgTypes>
2366 template <class _Fp, class _Alloc, class>
2367 function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a,
2369 : __f_(_VSTD::move(__f), __a) {}
2372 template<class _Rp, class ..._ArgTypes>
2373 function<_Rp(_ArgTypes...)>&
2374 function<_Rp(_ArgTypes...)>::operator=(const function& __f)
2376 function(__f).swap(*this);
2380 template<class _Rp, class ..._ArgTypes>
2381 function<_Rp(_ArgTypes...)>&
2382 function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT
2384 __f_ = std::move(__f.__f_);
2388 template<class _Rp, class ..._ArgTypes>
2389 function<_Rp(_ArgTypes...)>&
2390 function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT
2396 template<class _Rp, class ..._ArgTypes>
2397 template <class _Fp, class>
2398 function<_Rp(_ArgTypes...)>&
2399 function<_Rp(_ArgTypes...)>::operator=(_Fp&& __f)
2401 function(_VSTD::forward<_Fp>(__f)).swap(*this);
2405 template<class _Rp, class ..._ArgTypes>
2406 function<_Rp(_ArgTypes...)>::~function() {}
2408 template<class _Rp, class ..._ArgTypes>
2410 function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT
2412 __f_.swap(__f.__f_);
2415 template<class _Rp, class ..._ArgTypes>
2417 function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const
2419 return __f_(_VSTD::forward<_ArgTypes>(__arg)...);
2422 #ifndef _LIBCPP_NO_RTTI
2424 template<class _Rp, class ..._ArgTypes>
2425 const std::type_info&
2426 function<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
2428 return __f_.target_type();
2431 template<class _Rp, class ..._ArgTypes>
2432 template <typename _Tp>
2434 function<_Rp(_ArgTypes...)>::target() _NOEXCEPT
2436 return (_Tp*)(__f_.template target<_Tp>());
2439 template<class _Rp, class ..._ArgTypes>
2440 template <typename _Tp>
2442 function<_Rp(_ArgTypes...)>::target() const _NOEXCEPT
2444 return __f_.template target<_Tp>();
2447 #endif // _LIBCPP_NO_RTTI
2449 template <class _Rp, class... _ArgTypes>
2450 inline _LIBCPP_INLINE_VISIBILITY
2452 operator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;}
2454 template <class _Rp, class... _ArgTypes>
2455 inline _LIBCPP_INLINE_VISIBILITY
2457 operator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;}
2459 template <class _Rp, class... _ArgTypes>
2460 inline _LIBCPP_INLINE_VISIBILITY
2462 operator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;}
2464 template <class _Rp, class... _ArgTypes>
2465 inline _LIBCPP_INLINE_VISIBILITY
2467 operator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;}
2469 template <class _Rp, class... _ArgTypes>
2470 inline _LIBCPP_INLINE_VISIBILITY
2472 swap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT
2473 {return __x.swap(__y);}
2475 #else // _LIBCPP_CXX03_LANG
2477 #include <__functional_03>
2481 ////////////////////////////////////////////////////////////////////////////////
2483 //==============================================================================
2485 template<class _Tp> struct __is_bind_expression : public false_type {};
2486 template<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_bind_expression
2487 : public __is_bind_expression<typename remove_cv<_Tp>::type> {};
2489 #if _LIBCPP_STD_VER > 14
2490 template <class _Tp>
2491 _LIBCPP_INLINE_VAR constexpr size_t is_bind_expression_v = is_bind_expression<_Tp>::value;
2494 template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {};
2495 template<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_placeholder
2496 : public __is_placeholder<typename remove_cv<_Tp>::type> {};
2498 #if _LIBCPP_STD_VER > 14
2499 template <class _Tp>
2500 _LIBCPP_INLINE_VAR constexpr size_t is_placeholder_v = is_placeholder<_Tp>::value;
2503 namespace placeholders
2506 template <int _Np> struct __ph {};
2508 #if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY)
2509 _LIBCPP_FUNC_VIS extern const __ph<1> _1;
2510 _LIBCPP_FUNC_VIS extern const __ph<2> _2;
2511 _LIBCPP_FUNC_VIS extern const __ph<3> _3;
2512 _LIBCPP_FUNC_VIS extern const __ph<4> _4;
2513 _LIBCPP_FUNC_VIS extern const __ph<5> _5;
2514 _LIBCPP_FUNC_VIS extern const __ph<6> _6;
2515 _LIBCPP_FUNC_VIS extern const __ph<7> _7;
2516 _LIBCPP_FUNC_VIS extern const __ph<8> _8;
2517 _LIBCPP_FUNC_VIS extern const __ph<9> _9;
2518 _LIBCPP_FUNC_VIS extern const __ph<10> _10;
2520 /* _LIBCPP_INLINE_VAR */ constexpr __ph<1> _1{};
2521 /* _LIBCPP_INLINE_VAR */ constexpr __ph<2> _2{};
2522 /* _LIBCPP_INLINE_VAR */ constexpr __ph<3> _3{};
2523 /* _LIBCPP_INLINE_VAR */ constexpr __ph<4> _4{};
2524 /* _LIBCPP_INLINE_VAR */ constexpr __ph<5> _5{};
2525 /* _LIBCPP_INLINE_VAR */ constexpr __ph<6> _6{};
2526 /* _LIBCPP_INLINE_VAR */ constexpr __ph<7> _7{};
2527 /* _LIBCPP_INLINE_VAR */ constexpr __ph<8> _8{};
2528 /* _LIBCPP_INLINE_VAR */ constexpr __ph<9> _9{};
2529 /* _LIBCPP_INLINE_VAR */ constexpr __ph<10> _10{};
2530 #endif // defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY)
2535 struct __is_placeholder<placeholders::__ph<_Np> >
2536 : public integral_constant<int, _Np> {};
2539 #ifndef _LIBCPP_CXX03_LANG
2541 template <class _Tp, class _Uj>
2542 inline _LIBCPP_INLINE_VISIBILITY
2544 __mu(reference_wrapper<_Tp> __t, _Uj&)
2549 template <class _Ti, class ..._Uj, size_t ..._Indx>
2550 inline _LIBCPP_INLINE_VISIBILITY
2551 typename __invoke_of<_Ti&, _Uj...>::type
2552 __mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>)
2554 return __ti(_VSTD::forward<_Uj>(_VSTD::get<_Indx>(__uj))...);
2557 template <class _Ti, class ..._Uj>
2558 inline _LIBCPP_INLINE_VISIBILITY
2561 is_bind_expression<_Ti>::value,
2562 __invoke_of<_Ti&, _Uj...>
2564 __mu(_Ti& __ti, tuple<_Uj...>& __uj)
2566 typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices;
2567 return __mu_expand(__ti, __uj, __indices());
2570 template <bool IsPh, class _Ti, class _Uj>
2571 struct __mu_return2 {};
2573 template <class _Ti, class _Uj>
2574 struct __mu_return2<true, _Ti, _Uj>
2576 typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type;
2579 template <class _Ti, class _Uj>
2580 inline _LIBCPP_INLINE_VISIBILITY
2583 0 < is_placeholder<_Ti>::value,
2584 typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type
2586 __mu(_Ti&, _Uj& __uj)
2588 const size_t _Indx = is_placeholder<_Ti>::value - 1;
2589 return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj));
2592 template <class _Ti, class _Uj>
2593 inline _LIBCPP_INLINE_VISIBILITY
2596 !is_bind_expression<_Ti>::value &&
2597 is_placeholder<_Ti>::value == 0 &&
2598 !__is_reference_wrapper<_Ti>::value,
2601 __mu(_Ti& __ti, _Uj&)
2606 template <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh,
2608 struct __mu_return_impl;
2610 template <bool _Invokable, class _Ti, class ..._Uj>
2611 struct __mu_return_invokable // false
2616 template <class _Ti, class ..._Uj>
2617 struct __mu_return_invokable<true, _Ti, _Uj...>
2619 typedef typename __invoke_of<_Ti&, _Uj...>::type type;
2622 template <class _Ti, class ..._Uj>
2623 struct __mu_return_impl<_Ti, false, true, false, tuple<_Uj...> >
2624 : public __mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...>
2628 template <class _Ti, class _TupleUj>
2629 struct __mu_return_impl<_Ti, false, false, true, _TupleUj>
2631 typedef typename tuple_element<is_placeholder<_Ti>::value - 1,
2632 _TupleUj>::type&& type;
2635 template <class _Ti, class _TupleUj>
2636 struct __mu_return_impl<_Ti, true, false, false, _TupleUj>
2638 typedef typename _Ti::type& type;
2641 template <class _Ti, class _TupleUj>
2642 struct __mu_return_impl<_Ti, false, false, false, _TupleUj>
2647 template <class _Ti, class _TupleUj>
2649 : public __mu_return_impl<_Ti,
2650 __is_reference_wrapper<_Ti>::value,
2651 is_bind_expression<_Ti>::value,
2652 0 < is_placeholder<_Ti>::value &&
2653 is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value,
2658 template <class _Fp, class _BoundArgs, class _TupleUj>
2659 struct __is_valid_bind_return
2661 static const bool value = false;
2664 template <class _Fp, class ..._BoundArgs, class _TupleUj>
2665 struct __is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj>
2667 static const bool value = __invokable<_Fp,
2668 typename __mu_return<_BoundArgs, _TupleUj>::type...>::value;
2671 template <class _Fp, class ..._BoundArgs, class _TupleUj>
2672 struct __is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj>
2674 static const bool value = __invokable<_Fp,
2675 typename __mu_return<const _BoundArgs, _TupleUj>::type...>::value;
2678 template <class _Fp, class _BoundArgs, class _TupleUj,
2679 bool = __is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value>
2680 struct __bind_return;
2682 template <class _Fp, class ..._BoundArgs, class _TupleUj>
2683 struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true>
2685 typedef typename __invoke_of
2688 typename __mu_return
2696 template <class _Fp, class ..._BoundArgs, class _TupleUj>
2697 struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true>
2699 typedef typename __invoke_of
2702 typename __mu_return
2710 template <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args>
2711 inline _LIBCPP_INLINE_VISIBILITY
2712 typename __bind_return<_Fp, _BoundArgs, _Args>::type
2713 __apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
2716 return _VSTD::__invoke(__f, _VSTD::__mu(_VSTD::get<_Indx>(__bound_args), __args)...);
2719 template<class _Fp, class ..._BoundArgs>
2721 : public __weak_result_type<typename decay<_Fp>::type>
2724 typedef typename decay<_Fp>::type _Fd;
2725 typedef tuple<typename decay<_BoundArgs>::type...> _Td;
2730 typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices;
2732 template <class _Gp, class ..._BA,
2733 class = typename enable_if
2735 is_constructible<_Fd, _Gp>::value &&
2736 !is_same<typename remove_reference<_Gp>::type,
2739 _LIBCPP_INLINE_VISIBILITY
2740 explicit __bind(_Gp&& __f, _BA&& ...__bound_args)
2741 : __f_(_VSTD::forward<_Gp>(__f)),
2742 __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {}
2744 template <class ..._Args>
2745 _LIBCPP_INLINE_VISIBILITY
2746 typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type
2747 operator()(_Args&& ...__args)
2749 return _VSTD::__apply_functor(__f_, __bound_args_, __indices(),
2750 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
2753 template <class ..._Args>
2754 _LIBCPP_INLINE_VISIBILITY
2755 typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type
2756 operator()(_Args&& ...__args) const
2758 return _VSTD::__apply_functor(__f_, __bound_args_, __indices(),
2759 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
2763 template<class _Fp, class ..._BoundArgs>
2764 struct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {};
2766 template<class _Rp, class _Fp, class ..._BoundArgs>
2768 : public __bind<_Fp, _BoundArgs...>
2770 typedef __bind<_Fp, _BoundArgs...> base;
2771 typedef typename base::_Fd _Fd;
2772 typedef typename base::_Td _Td;
2774 typedef _Rp result_type;
2777 template <class _Gp, class ..._BA,
2778 class = typename enable_if
2780 is_constructible<_Fd, _Gp>::value &&
2781 !is_same<typename remove_reference<_Gp>::type,
2784 _LIBCPP_INLINE_VISIBILITY
2785 explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args)
2786 : base(_VSTD::forward<_Gp>(__f),
2787 _VSTD::forward<_BA>(__bound_args)...) {}
2789 template <class ..._Args>
2790 _LIBCPP_INLINE_VISIBILITY
2793 is_convertible<typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type,
2794 result_type>::value || is_void<_Rp>::value,
2797 operator()(_Args&& ...__args)
2799 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
2800 return _Invoker::__call(static_cast<base&>(*this), _VSTD::forward<_Args>(__args)...);
2803 template <class ..._Args>
2804 _LIBCPP_INLINE_VISIBILITY
2807 is_convertible<typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type,
2808 result_type>::value || is_void<_Rp>::value,
2811 operator()(_Args&& ...__args) const
2813 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
2814 return _Invoker::__call(static_cast<base const&>(*this), _VSTD::forward<_Args>(__args)...);
2818 template<class _Rp, class _Fp, class ..._BoundArgs>
2819 struct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {};
2821 template<class _Fp, class ..._BoundArgs>
2822 inline _LIBCPP_INLINE_VISIBILITY
2823 __bind<_Fp, _BoundArgs...>
2824 bind(_Fp&& __f, _BoundArgs&&... __bound_args)
2826 typedef __bind<_Fp, _BoundArgs...> type;
2827 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
2830 template<class _Rp, class _Fp, class ..._BoundArgs>
2831 inline _LIBCPP_INLINE_VISIBILITY
2832 __bind_r<_Rp, _Fp, _BoundArgs...>
2833 bind(_Fp&& __f, _BoundArgs&&... __bound_args)
2835 typedef __bind_r<_Rp, _Fp, _BoundArgs...> type;
2836 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
2839 #endif // _LIBCPP_CXX03_LANG
2841 #if _LIBCPP_STD_VER > 14
2843 template <class _Fn, class ..._Args>
2844 invoke_result_t<_Fn, _Args...>
2845 invoke(_Fn&& __f, _Args&&... __args)
2846 noexcept(is_nothrow_invocable_v<_Fn, _Args...>)
2848 return _VSTD::__invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...);
2851 template <class _DecayFunc>
2852 class _LIBCPP_TEMPLATE_VIS __not_fn_imp {
2856 __not_fn_imp() = delete;
2858 template <class ..._Args>
2859 _LIBCPP_INLINE_VISIBILITY
2860 auto operator()(_Args&& ...__args) &
2861 noexcept(noexcept(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)))
2862 -> decltype( !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...))
2863 { return !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); }
2865 template <class ..._Args>
2866 _LIBCPP_INLINE_VISIBILITY
2867 auto operator()(_Args&& ...__args) &&
2868 noexcept(noexcept(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)))
2869 -> decltype( !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...))
2870 { return !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); }
2872 template <class ..._Args>
2873 _LIBCPP_INLINE_VISIBILITY
2874 auto operator()(_Args&& ...__args) const&
2875 noexcept(noexcept(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)))
2876 -> decltype( !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...))
2877 { return !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); }
2880 template <class ..._Args>
2881 _LIBCPP_INLINE_VISIBILITY
2882 auto operator()(_Args&& ...__args) const&&
2883 noexcept(noexcept(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)))
2884 -> decltype( !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...))
2885 { return !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); }
2888 template <class _RawFunc,
2889 class = enable_if_t<!is_same<decay_t<_RawFunc>, __not_fn_imp>::value>>
2890 _LIBCPP_INLINE_VISIBILITY
2891 explicit __not_fn_imp(_RawFunc&& __rf)
2892 : __fd(_VSTD::forward<_RawFunc>(__rf)) {}
2894 template <class _RawFunc>
2895 friend inline _LIBCPP_INLINE_VISIBILITY
2896 __not_fn_imp<decay_t<_RawFunc>> not_fn(_RawFunc&&);
2899 template <class _RawFunc>
2900 inline _LIBCPP_INLINE_VISIBILITY
2901 __not_fn_imp<decay_t<_RawFunc>> not_fn(_RawFunc&& __fn) {
2902 return __not_fn_imp<decay_t<_RawFunc>>(_VSTD::forward<_RawFunc>(__fn));
2907 // struct hash<T*> in <memory>
2909 template <class _BinaryPredicate, class _ForwardIterator1, class _ForwardIterator2>
2910 pair<_ForwardIterator1, _ForwardIterator1> _LIBCPP_CONSTEXPR_AFTER_CXX11
2911 __search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
2912 _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred,
2913 forward_iterator_tag, forward_iterator_tag)
2915 if (__first2 == __last2)
2916 return make_pair(__first1, __first1); // Everything matches an empty sequence
2919 // Find first element in sequence 1 that matchs *__first2, with a mininum of loop checks
2922 if (__first1 == __last1) // return __last1 if no element matches *__first2
2923 return make_pair(__last1, __last1);
2924 if (__pred(*__first1, *__first2))
2928 // *__first1 matches *__first2, now match elements after here
2929 _ForwardIterator1 __m1 = __first1;
2930 _ForwardIterator2 __m2 = __first2;
2933 if (++__m2 == __last2) // If pattern exhausted, __first1 is the answer (works for 1 element pattern)
2934 return make_pair(__first1, __m1);
2935 if (++__m1 == __last1) // Otherwise if source exhaused, pattern not found
2936 return make_pair(__last1, __last1);
2937 if (!__pred(*__m1, *__m2)) // if there is a mismatch, restart with a new __first1
2941 } // else there is a match, check next elements
2946 template <class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2>
2947 _LIBCPP_CONSTEXPR_AFTER_CXX11
2948 pair<_RandomAccessIterator1, _RandomAccessIterator1>
2949 __search(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1,
2950 _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __pred,
2951 random_access_iterator_tag, random_access_iterator_tag)
2953 typedef typename iterator_traits<_RandomAccessIterator1>::difference_type _D1;
2954 typedef typename iterator_traits<_RandomAccessIterator2>::difference_type _D2;
2955 // Take advantage of knowing source and pattern lengths. Stop short when source is smaller than pattern
2956 const _D2 __len2 = __last2 - __first2;
2958 return make_pair(__first1, __first1);
2959 const _D1 __len1 = __last1 - __first1;
2960 if (__len1 < __len2)
2961 return make_pair(__last1, __last1);
2962 const _RandomAccessIterator1 __s = __last1 - (__len2 - 1); // Start of pattern match can't go beyond here
2968 if (__first1 == __s)
2969 return make_pair(__last1, __last1);
2970 if (__pred(*__first1, *__first2))
2975 _RandomAccessIterator1 __m1 = __first1;
2976 _RandomAccessIterator2 __m2 = __first2;
2979 if (++__m2 == __last2)
2980 return make_pair(__first1, __first1 + __len2);
2981 ++__m1; // no need to check range on __m1 because __s guarantees we have enough source
2982 if (!__pred(*__m1, *__m2))
2991 #if _LIBCPP_STD_VER > 14
2994 template<class _ForwardIterator, class _BinaryPredicate = equal_to<>>
2995 class _LIBCPP_TYPE_VIS default_searcher {
2997 _LIBCPP_INLINE_VISIBILITY
2998 default_searcher(_ForwardIterator __f, _ForwardIterator __l,
2999 _BinaryPredicate __p = _BinaryPredicate())
3000 : __first_(__f), __last_(__l), __pred_(__p) {}
3002 template <typename _ForwardIterator2>
3003 _LIBCPP_INLINE_VISIBILITY
3004 pair<_ForwardIterator2, _ForwardIterator2>
3005 operator () (_ForwardIterator2 __f, _ForwardIterator2 __l) const
3007 return _VSTD::__search(__f, __l, __first_, __last_, __pred_,
3008 typename _VSTD::iterator_traits<_ForwardIterator>::iterator_category(),
3009 typename _VSTD::iterator_traits<_ForwardIterator2>::iterator_category());
3013 _ForwardIterator __first_;
3014 _ForwardIterator __last_;
3015 _BinaryPredicate __pred_;
3018 #endif // _LIBCPP_STD_VER > 14
3020 #if _LIBCPP_STD_VER > 17
3021 template <class _Tp>
3022 using unwrap_reference_t = typename unwrap_reference<_Tp>::type;
3024 template <class _Tp>
3025 using unwrap_ref_decay_t = typename unwrap_ref_decay<_Tp>::type;
3028 template <class _Container, class _Predicate>
3029 inline void __libcpp_erase_if_container( _Container& __c, _Predicate __pred)
3031 for (typename _Container::iterator __iter = __c.begin(), __last = __c.end(); __iter != __last;)
3033 if (__pred(*__iter))
3034 __iter = __c.erase(__iter);
3040 _LIBCPP_END_NAMESPACE_STD
3042 #endif // _LIBCPP_FUNCTIONAL