Home | History | Annotate | Download | only in v1
      1 // -*- C++ -*-
      2 //===------------------------ functional ----------------------------------===//
      3 //
      4 //                     The LLVM Compiler Infrastructure
      5 //
      6 // This file is dual licensed under the MIT and the University of Illinois Open
      7 // Source Licenses. See LICENSE.TXT for details.
      8 //
      9 //===----------------------------------------------------------------------===//
     10 
     11 #ifndef _LIBCPP_FUNCTIONAL
     12 #define _LIBCPP_FUNCTIONAL
     13 
     14 /*
     15     functional synopsis
     16 
     17 namespace std
     18 {
     19 
     20 template <class Arg, class Result>
     21 struct unary_function
     22 {
     23     typedef Arg    argument_type;
     24     typedef Result result_type;
     25 };
     26 
     27 template <class Arg1, class Arg2, class Result>
     28 struct binary_function
     29 {
     30     typedef Arg1   first_argument_type;
     31     typedef Arg2   second_argument_type;
     32     typedef Result result_type;
     33 };
     34 
     35 template <class T>
     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
     39 {
     40 public:
     41     // types
     42     typedef T type;
     43     typedef see below result_type; // Not always defined
     44 
     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;
     49 
     50     // assignment
     51     reference_wrapper& operator=(const reference_wrapper<T>& x) noexcept;
     52 
     53     // access
     54     operator T& () const noexcept;
     55     T& get() const noexcept;
     56 
     57     // invoke
     58     template <class... ArgTypes>
     59       typename result_of<T&(ArgTypes&&...)>::type
     60           operator() (ArgTypes&&...) const;
     61 };
     62 
     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;
     66 
     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;
     70 
     71 template <class T> // <class T=void> in C++14
     72 struct plus : binary_function<T, T, T>
     73 {
     74     T operator()(const T& x, const T& y) const;
     75 };
     76 
     77 template <class T> // <class T=void> in C++14
     78 struct minus : binary_function<T, T, T>
     79 {
     80     T operator()(const T& x, const T& y) const;
     81 };
     82 
     83 template <class T> // <class T=void> in C++14
     84 struct multiplies : binary_function<T, T, T>
     85 {
     86     T operator()(const T& x, const T& y) const;
     87 };
     88 
     89 template <class T> // <class T=void> in C++14
     90 struct divides : binary_function<T, T, T>
     91 {
     92     T operator()(const T& x, const T& y) const;
     93 };
     94 
     95 template <class T> // <class T=void> in C++14
     96 struct modulus : binary_function<T, T, T>
     97 {
     98     T operator()(const T& x, const T& y) const;
     99 };
    100 
    101 template <class T> // <class T=void> in C++14
    102 struct negate : unary_function<T, T>
    103 {
    104     T operator()(const T& x) const;
    105 };
    106 
    107 template <class T> // <class T=void> in C++14
    108 struct equal_to : binary_function<T, T, bool>
    109 {
    110     bool operator()(const T& x, const T& y) const;
    111 };
    112 
    113 template <class T> // <class T=void> in C++14
    114 struct not_equal_to : binary_function<T, T, bool>
    115 {
    116     bool operator()(const T& x, const T& y) const;
    117 };
    118 
    119 template <class T> // <class T=void> in C++14
    120 struct greater : binary_function<T, T, bool>
    121 {
    122     bool operator()(const T& x, const T& y) const;
    123 };
    124 
    125 template <class T> // <class T=void> in C++14
    126 struct less : binary_function<T, T, bool>
    127 {
    128     bool operator()(const T& x, const T& y) const;
    129 };
    130 
    131 template <class T> // <class T=void> in C++14
    132 struct greater_equal : binary_function<T, T, bool>
    133 {
    134     bool operator()(const T& x, const T& y) const;
    135 };
    136 
    137 template <class T> // <class T=void> in C++14
    138 struct less_equal : binary_function<T, T, bool>
    139 {
    140     bool operator()(const T& x, const T& y) const;
    141 };
    142 
    143 template <class T> // <class T=void> in C++14
    144 struct logical_and : binary_function<T, T, bool>
    145 {
    146     bool operator()(const T& x, const T& y) const;
    147 };
    148 
    149 template <class T> // <class T=void> in C++14
    150 struct logical_or : binary_function<T, T, bool>
    151 {
    152     bool operator()(const T& x, const T& y) const;
    153 };
    154 
    155 template <class T> // <class T=void> in C++14
    156 struct logical_not : unary_function<T, bool>
    157 {
    158     bool operator()(const T& x) const;
    159 };
    160 
    161 template <class T> // <class T=void> in C++14
    162 struct bit_and : unary_function<T, bool>
    163 {
    164     bool operator()(const T& x, const T& y) const;
    165 };
    166 
    167 template <class T> // <class T=void> in C++14
    168 struct bit_or : unary_function<T, bool>
    169 {
    170     bool operator()(const T& x, const T& y) const;
    171 };
    172 
    173 template <class T> // <class T=void> in C++14
    174 struct bit_xor : unary_function<T, bool>
    175 {
    176     bool operator()(const T& x, const T& y) const;
    177 };
    178 
    179 template <class T=void> // C++14
    180 struct bit_xor : unary_function<T, bool>
    181 {
    182     bool operator()(const T& x) const;
    183 };
    184 
    185 template <class Predicate>
    186 class unary_negate
    187     : public unary_function<typename Predicate::argument_type, bool>
    188 {
    189 public:
    190     explicit unary_negate(const Predicate& pred);
    191     bool operator()(const typename Predicate::argument_type& x) const;
    192 };
    193 
    194 template <class Predicate> unary_negate<Predicate> not1(const Predicate& pred);
    195 
    196 template <class Predicate>
    197 class binary_negate
    198     : public binary_function<typename Predicate::first_argument_type,
    199                              typename Predicate::second_argument_type,
    200                              bool>
    201 {
    202 public:
    203     explicit binary_negate(const Predicate& pred);
    204     bool operator()(const typename Predicate::first_argument_type& x,
    205                     const typename Predicate::second_argument_type& y) const;
    206 };
    207 
    208 template <class Predicate> binary_negate<Predicate> not2(const Predicate& pred);
    209 
    210 template <class F> unspecified not_fn(F&& f); // C++17
    211 
    212 template<class T> struct is_bind_expression;
    213 template<class T> struct is_placeholder;
    214 
    215     // See C++14 20.9.9, Function object binders
    216 template <class T> constexpr bool is_bind_expression_v
    217   = is_bind_expression<T>::value; // C++17
    218 template <class T> constexpr int is_placeholder_v
    219   = is_placeholder<T>::value; // C++17
    220 
    221 
    222 template<class Fn, class... BoundArgs>
    223   unspecified bind(Fn&&, BoundArgs&&...);
    224 template<class R, class Fn, class... BoundArgs>
    225   unspecified bind(Fn&&, BoundArgs&&...);
    226 
    227 namespace placeholders {
    228   // M is the implementation-defined number of placeholders
    229   extern unspecified _1;
    230   extern unspecified _2;
    231   .
    232   .
    233   .
    234   extern unspecified _Mp;
    235 }
    236 
    237 template <class Operation>
    238 class binder1st
    239     : public unary_function<typename Operation::second_argument_type,
    240                             typename Operation::result_type>
    241 {
    242 protected:
    243     Operation                               op;
    244     typename Operation::first_argument_type value;
    245 public:
    246     binder1st(const Operation& x, const typename Operation::first_argument_type y);
    247     typename Operation::result_type operator()(      typename Operation::second_argument_type& x) const;
    248     typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const;
    249 };
    250 
    251 template <class Operation, class T>
    252 binder1st<Operation> bind1st(const Operation& op, const T& x);
    253 
    254 template <class Operation>
    255 class binder2nd
    256     : public unary_function<typename Operation::first_argument_type,
    257                             typename Operation::result_type>
    258 {
    259 protected:
    260     Operation                                op;
    261     typename Operation::second_argument_type value;
    262 public:
    263     binder2nd(const Operation& x, const typename Operation::second_argument_type y);
    264     typename Operation::result_type operator()(      typename Operation::first_argument_type& x) const;
    265     typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const;
    266 };
    267 
    268 template <class Operation, class T>
    269 binder2nd<Operation> bind2nd(const Operation& op, const T& x);
    270 
    271 template <class Arg, class Result>
    272 class pointer_to_unary_function : public unary_function<Arg, Result>
    273 {
    274 public:
    275     explicit pointer_to_unary_function(Result (*f)(Arg));
    276     Result operator()(Arg x) const;
    277 };
    278 
    279 template <class Arg, class Result>
    280 pointer_to_unary_function<Arg,Result> ptr_fun(Result (*f)(Arg));
    281 
    282 template <class Arg1, class Arg2, class Result>
    283 class pointer_to_binary_function : public binary_function<Arg1, Arg2, Result>
    284 {
    285 public:
    286     explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2));
    287     Result operator()(Arg1 x, Arg2 y) const;
    288 };
    289 
    290 template <class Arg1, class Arg2, class Result>
    291 pointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1,Arg2));
    292 
    293 template<class S, class T>
    294 class mem_fun_t : public unary_function<T*, S>
    295 {
    296 public:
    297     explicit mem_fun_t(S (T::*p)());
    298     S operator()(T* p) const;
    299 };
    300 
    301 template<class S, class T, class A>
    302 class mem_fun1_t : public binary_function<T*, A, S>
    303 {
    304 public:
    305     explicit mem_fun1_t(S (T::*p)(A));
    306     S operator()(T* p, A x) const;
    307 };
    308 
    309 template<class S, class T>          mem_fun_t<S,T>    mem_fun(S (T::*f)());
    310 template<class S, class T, class A> mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A));
    311 
    312 template<class S, class T>
    313 class mem_fun_ref_t : public unary_function<T, S>
    314 {
    315 public:
    316     explicit mem_fun_ref_t(S (T::*p)());
    317     S operator()(T& p) const;
    318 };
    319 
    320 template<class S, class T, class A>
    321 class mem_fun1_ref_t : public binary_function<T, A, S>
    322 {
    323 public:
    324     explicit mem_fun1_ref_t(S (T::*p)(A));
    325     S operator()(T& p, A x) const;
    326 };
    327 
    328 template<class S, class T>          mem_fun_ref_t<S,T>    mem_fun_ref(S (T::*f)());
    329 template<class S, class T, class A> mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A));
    330 
    331 template <class S, class T>
    332 class const_mem_fun_t : public unary_function<const T*, S>
    333 {
    334 public:
    335     explicit const_mem_fun_t(S (T::*p)() const);
    336     S operator()(const T* p) const;
    337 };
    338 
    339 template <class S, class T, class A>
    340 class const_mem_fun1_t : public binary_function<const T*, A, S>
    341 {
    342 public:
    343     explicit const_mem_fun1_t(S (T::*p)(A) const);
    344     S operator()(const T* p, A x) const;
    345 };
    346 
    347 template <class S, class T>          const_mem_fun_t<S,T>    mem_fun(S (T::*f)() const);
    348 template <class S, class T, class A> const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const);
    349 
    350 template <class S, class T>
    351 class const_mem_fun_ref_t : public unary_function<T, S>
    352 {
    353 public:
    354     explicit const_mem_fun_ref_t(S (T::*p)() const);
    355     S operator()(const T& p) const;
    356 };
    357 
    358 template <class S, class T, class A>
    359 class const_mem_fun1_ref_t : public binary_function<T, A, S>
    360 {
    361 public:
    362     explicit const_mem_fun1_ref_t(S (T::*p)(A) const);
    363     S operator()(const T& p, A x) const;
    364 };
    365 
    366 template <class S, class T>          const_mem_fun_ref_t<S,T>    mem_fun_ref(S (T::*f)() const);
    367 template <class S, class T, class A> const_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const);
    368 
    369 template<class R, class T> unspecified mem_fn(R T::*);
    370 
    371 class bad_function_call
    372     : public exception
    373 {
    374 };
    375 
    376 template<class> class function; // undefined
    377 
    378 template<class R, class... ArgTypes>
    379 class function<R(ArgTypes...)>
    380   : public unary_function<T1, R>      // iff sizeof...(ArgTypes) == 1 and
    381                                       // ArgTypes contains T1
    382   : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and
    383                                       // ArgTypes contains T1 and T2
    384 {
    385 public:
    386     typedef R result_type;
    387 
    388     // construct/copy/destroy:
    389     function() noexcept;
    390     function(nullptr_t) noexcept;
    391     function(const function&);
    392     function(function&&) noexcept;
    393     template<class F>
    394       function(F);
    395     template<Allocator Alloc>
    396       function(allocator_arg_t, const Alloc&) noexcept;            // removed in C++17
    397     template<Allocator Alloc>
    398       function(allocator_arg_t, const Alloc&, nullptr_t) noexcept; // removed in C++17
    399     template<Allocator Alloc>
    400       function(allocator_arg_t, const Alloc&, const function&);    // removed in C++17
    401     template<Allocator Alloc>
    402       function(allocator_arg_t, const Alloc&, function&&);         // removed in C++17
    403     template<class F, Allocator Alloc>
    404       function(allocator_arg_t, const Alloc&, F);                  // removed in C++17
    405 
    406     function& operator=(const function&);
    407     function& operator=(function&&) noexcept;
    408     function& operator=(nullptr_t) noexcept;
    409     template<class F>
    410       function& operator=(F&&);
    411     template<class F>
    412       function& operator=(reference_wrapper<F>) noexcept;
    413 
    414     ~function();
    415 
    416     // function modifiers:
    417     void swap(function&) noexcept;
    418     template<class F, class Alloc>
    419       void assign(F&&, const Alloc&);                 // Removed in C++17
    420 
    421     // function capacity:
    422     explicit operator bool() const noexcept;
    423 
    424     // function invocation:
    425     R operator()(ArgTypes...) const;
    426 
    427     // function target access:
    428     const std::type_info& target_type() const noexcept;
    429     template <typename T>       T* target() noexcept;
    430     template <typename T> const T* target() const noexcept;
    431 };
    432 
    433 // Null pointer comparisons:
    434 template <class R, class ... ArgTypes>
    435   bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
    436 
    437 template <class R, class ... ArgTypes>
    438   bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
    439 
    440 template <class R, class ... ArgTypes>
    441   bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
    442 
    443 template <class  R, class ... ArgTypes>
    444   bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
    445 
    446 // specialized algorithms:
    447 template <class  R, class ... ArgTypes>
    448   void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
    449 
    450 template <class T> struct hash;
    451 
    452 template <> struct hash<bool>;
    453 template <> struct hash<char>;
    454 template <> struct hash<signed char>;
    455 template <> struct hash<unsigned char>;
    456 template <> struct hash<char16_t>;
    457 template <> struct hash<char32_t>;
    458 template <> struct hash<wchar_t>;
    459 template <> struct hash<short>;
    460 template <> struct hash<unsigned short>;
    461 template <> struct hash<int>;
    462 template <> struct hash<unsigned int>;
    463 template <> struct hash<long>;
    464 template <> struct hash<long long>;
    465 template <> struct hash<unsigned long>;
    466 template <> struct hash<unsigned long long>;
    467 
    468 template <> struct hash<float>;
    469 template <> struct hash<double>;
    470 template <> struct hash<long double>;
    471 
    472 template<class T> struct hash<T*>;
    473 
    474 }  // std
    475 
    476 POLICY:  For non-variadic implementations, the number of arguments is limited
    477          to 3.  It is hoped that the need for non-variadic implementations
    478          will be minimal.
    479 
    480 */
    481 
    482 #include <__config>
    483 #include <type_traits>
    484 #include <typeinfo>
    485 #include <exception>
    486 #include <memory>
    487 #include <tuple>
    488 #include <utility>
    489 
    490 #include <__functional_base>
    491 
    492 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
    493 #pragma GCC system_header
    494 #endif
    495 
    496 _LIBCPP_BEGIN_NAMESPACE_STD
    497 
    498 #if _LIBCPP_STD_VER > 11
    499 template <class _Tp = void>
    500 #else
    501 template <class _Tp>
    502 #endif
    503 struct _LIBCPP_TEMPLATE_VIS plus : binary_function<_Tp, _Tp, _Tp>
    504 {
    505     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
    506     _Tp operator()(const _Tp& __x, const _Tp& __y) const
    507         {return __x + __y;}
    508 };
    509 
    510 #if _LIBCPP_STD_VER > 11
    511 template <>
    512 struct _LIBCPP_TEMPLATE_VIS plus<void>
    513 {
    514     template <class _T1, class _T2>
    515     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
    516     auto operator()(_T1&& __t, _T2&& __u) const
    517     _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
    518     -> decltype        (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
    519         { return        _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
    520     typedef void is_transparent;
    521 };
    522 #endif
    523 
    524 
    525 #if _LIBCPP_STD_VER > 11
    526 template <class _Tp = void>
    527 #else
    528 template <class _Tp>
    529 #endif
    530 struct _LIBCPP_TEMPLATE_VIS minus : binary_function<_Tp, _Tp, _Tp>
    531 {
    532     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
    533     _Tp operator()(const _Tp& __x, const _Tp& __y) const
    534         {return __x - __y;}
    535 };
    536 
    537 #if _LIBCPP_STD_VER > 11
    538 template <>
    539 struct _LIBCPP_TEMPLATE_VIS minus<void>
    540 {
    541     template <class _T1, class _T2>
    542     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
    543     auto operator()(_T1&& __t, _T2&& __u) const
    544     _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u)))
    545     -> decltype        (_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u))
    546         { return        _VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u); }
    547     typedef void is_transparent;
    548 };
    549 #endif
    550 
    551 
    552 #if _LIBCPP_STD_VER > 11
    553 template <class _Tp = void>
    554 #else
    555 template <class _Tp>
    556 #endif
    557 struct _LIBCPP_TEMPLATE_VIS multiplies : binary_function<_Tp, _Tp, _Tp>
    558 {
    559     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
    560     _Tp operator()(const _Tp& __x, const _Tp& __y) const
    561         {return __x * __y;}
    562 };
    563 
    564 #if _LIBCPP_STD_VER > 11
    565 template <>
    566 struct _LIBCPP_TEMPLATE_VIS multiplies<void>
    567 {
    568     template <class _T1, class _T2>
    569     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
    570     auto operator()(_T1&& __t, _T2&& __u) const
    571     _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u)))
    572     -> decltype        (_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u))
    573         { return        _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u); }
    574     typedef void is_transparent;
    575 };
    576 #endif
    577 
    578 
    579 #if _LIBCPP_STD_VER > 11
    580 template <class _Tp = void>
    581 #else
    582 template <class _Tp>
    583 #endif
    584 struct _LIBCPP_TEMPLATE_VIS divides : binary_function<_Tp, _Tp, _Tp>
    585 {
    586     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
    587     _Tp operator()(const _Tp& __x, const _Tp& __y) const
    588         {return __x / __y;}
    589 };
    590 
    591 #if _LIBCPP_STD_VER > 11
    592 template <>
    593 struct _LIBCPP_TEMPLATE_VIS divides<void>
    594 {
    595     template <class _T1, class _T2>
    596     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
    597     auto operator()(_T1&& __t, _T2&& __u) const
    598     _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u)))
    599     -> decltype        (_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u))
    600         { return        _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u); }
    601     typedef void is_transparent;
    602 };
    603 #endif
    604 
    605 
    606 #if _LIBCPP_STD_VER > 11
    607 template <class _Tp = void>
    608 #else
    609 template <class _Tp>
    610 #endif
    611 struct _LIBCPP_TEMPLATE_VIS modulus : binary_function<_Tp, _Tp, _Tp>
    612 {
    613     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
    614     _Tp operator()(const _Tp& __x, const _Tp& __y) const
    615         {return __x % __y;}
    616 };
    617 
    618 #if _LIBCPP_STD_VER > 11
    619 template <>
    620 struct _LIBCPP_TEMPLATE_VIS modulus<void>
    621 {
    622     template <class _T1, class _T2>
    623     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
    624     auto operator()(_T1&& __t, _T2&& __u) const
    625     _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u)))
    626     -> decltype        (_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u))
    627         { return        _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u); }
    628     typedef void is_transparent;
    629 };
    630 #endif
    631 
    632 
    633 #if _LIBCPP_STD_VER > 11
    634 template <class _Tp = void>
    635 #else
    636 template <class _Tp>
    637 #endif
    638 struct _LIBCPP_TEMPLATE_VIS negate : unary_function<_Tp, _Tp>
    639 {
    640     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
    641     _Tp operator()(const _Tp& __x) const
    642         {return -__x;}
    643 };
    644 
    645 #if _LIBCPP_STD_VER > 11
    646 template <>
    647 struct _LIBCPP_TEMPLATE_VIS negate<void>
    648 {
    649     template <class _Tp>
    650     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
    651     auto operator()(_Tp&& __x) const
    652     _NOEXCEPT_(noexcept(- _VSTD::forward<_Tp>(__x)))
    653     -> decltype        (- _VSTD::forward<_Tp>(__x))
    654         { return        - _VSTD::forward<_Tp>(__x); }
    655     typedef void is_transparent;
    656 };
    657 #endif
    658 
    659 
    660 #if _LIBCPP_STD_VER > 11
    661 template <class _Tp = void>
    662 #else
    663 template <class _Tp>
    664 #endif
    665 struct _LIBCPP_TEMPLATE_VIS equal_to : binary_function<_Tp, _Tp, bool>
    666 {
    667     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
    668     bool operator()(const _Tp& __x, const _Tp& __y) const
    669         {return __x == __y;}
    670 };
    671 
    672 #if _LIBCPP_STD_VER > 11
    673 template <>
    674 struct _LIBCPP_TEMPLATE_VIS equal_to<void>
    675 {
    676     template <class _T1, class _T2>
    677     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
    678     auto operator()(_T1&& __t, _T2&& __u) const
    679     _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u)))
    680     -> decltype        (_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u))
    681         { return        _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u); }
    682     typedef void is_transparent;
    683 };
    684 #endif
    685 
    686 
    687 #if _LIBCPP_STD_VER > 11
    688 template <class _Tp = void>
    689 #else
    690 template <class _Tp>
    691 #endif
    692 struct _LIBCPP_TEMPLATE_VIS not_equal_to : binary_function<_Tp, _Tp, bool>
    693 {
    694     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
    695     bool operator()(const _Tp& __x, const _Tp& __y) const
    696         {return __x != __y;}
    697 };
    698 
    699 #if _LIBCPP_STD_VER > 11
    700 template <>
    701 struct _LIBCPP_TEMPLATE_VIS not_equal_to<void>
    702 {
    703     template <class _T1, class _T2>
    704     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
    705     auto operator()(_T1&& __t, _T2&& __u) const
    706     _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u)))
    707     -> decltype        (_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u))
    708         { return        _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u); }
    709     typedef void is_transparent;
    710 };
    711 #endif
    712 
    713 
    714 #if _LIBCPP_STD_VER > 11
    715 template <class _Tp = void>
    716 #else
    717 template <class _Tp>
    718 #endif
    719 struct _LIBCPP_TEMPLATE_VIS greater : binary_function<_Tp, _Tp, bool>
    720 {
    721     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
    722     bool operator()(const _Tp& __x, const _Tp& __y) const
    723         {return __x > __y;}
    724 };
    725 
    726 #if _LIBCPP_STD_VER > 11
    727 template <>
    728 struct _LIBCPP_TEMPLATE_VIS greater<void>
    729 {
    730     template <class _T1, class _T2>
    731     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
    732     auto operator()(_T1&& __t, _T2&& __u) const
    733     _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u)))
    734     -> decltype        (_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u))
    735         { return        _VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u); }
    736     typedef void is_transparent;
    737 };
    738 #endif
    739 
    740 
    741 // less in <__functional_base>
    742 
    743 #if _LIBCPP_STD_VER > 11
    744 template <class _Tp = void>
    745 #else
    746 template <class _Tp>
    747 #endif
    748 struct _LIBCPP_TEMPLATE_VIS greater_equal : binary_function<_Tp, _Tp, bool>
    749 {
    750     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
    751     bool operator()(const _Tp& __x, const _Tp& __y) const
    752         {return __x >= __y;}
    753 };
    754 
    755 #if _LIBCPP_STD_VER > 11
    756 template <>
    757 struct _LIBCPP_TEMPLATE_VIS greater_equal<void>
    758 {
    759     template <class _T1, class _T2>
    760     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
    761     auto operator()(_T1&& __t, _T2&& __u) const
    762     _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u)))
    763     -> decltype        (_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u))
    764         { return        _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u); }
    765     typedef void is_transparent;
    766 };
    767 #endif
    768 
    769 
    770 #if _LIBCPP_STD_VER > 11
    771 template <class _Tp = void>
    772 #else
    773 template <class _Tp>
    774 #endif
    775 struct _LIBCPP_TEMPLATE_VIS less_equal : binary_function<_Tp, _Tp, bool>
    776 {
    777     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
    778     bool operator()(const _Tp& __x, const _Tp& __y) const
    779         {return __x <= __y;}
    780 };
    781 
    782 #if _LIBCPP_STD_VER > 11
    783 template <>
    784 struct _LIBCPP_TEMPLATE_VIS less_equal<void>
    785 {
    786     template <class _T1, class _T2>
    787     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
    788     auto operator()(_T1&& __t, _T2&& __u) const
    789     _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u)))
    790     -> decltype        (_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u))
    791         { return        _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u); }
    792     typedef void is_transparent;
    793 };
    794 #endif
    795 
    796 
    797 #if _LIBCPP_STD_VER > 11
    798 template <class _Tp = void>
    799 #else
    800 template <class _Tp>
    801 #endif
    802 struct _LIBCPP_TEMPLATE_VIS logical_and : binary_function<_Tp, _Tp, bool>
    803 {
    804     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
    805     bool operator()(const _Tp& __x, const _Tp& __y) const
    806         {return __x && __y;}
    807 };
    808 
    809 #if _LIBCPP_STD_VER > 11
    810 template <>
    811 struct _LIBCPP_TEMPLATE_VIS logical_and<void>
    812 {
    813     template <class _T1, class _T2>
    814     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
    815     auto operator()(_T1&& __t, _T2&& __u) const
    816     _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u)))
    817     -> decltype        (_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u))
    818         { return        _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u); }
    819     typedef void is_transparent;
    820 };
    821 #endif
    822 
    823 
    824 #if _LIBCPP_STD_VER > 11
    825 template <class _Tp = void>
    826 #else
    827 template <class _Tp>
    828 #endif
    829 struct _LIBCPP_TEMPLATE_VIS logical_or : binary_function<_Tp, _Tp, bool>
    830 {
    831     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
    832     bool operator()(const _Tp& __x, const _Tp& __y) const
    833         {return __x || __y;}
    834 };
    835 
    836 #if _LIBCPP_STD_VER > 11
    837 template <>
    838 struct _LIBCPP_TEMPLATE_VIS logical_or<void>
    839 {
    840     template <class _T1, class _T2>
    841     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
    842     auto operator()(_T1&& __t, _T2&& __u) const
    843     _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u)))
    844     -> decltype        (_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u))
    845         { return        _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u); }
    846     typedef void is_transparent;
    847 };
    848 #endif
    849 
    850 
    851 #if _LIBCPP_STD_VER > 11
    852 template <class _Tp = void>
    853 #else
    854 template <class _Tp>
    855 #endif
    856 struct _LIBCPP_TEMPLATE_VIS logical_not : unary_function<_Tp, bool>
    857 {
    858     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
    859     bool operator()(const _Tp& __x) const
    860         {return !__x;}
    861 };
    862 
    863 #if _LIBCPP_STD_VER > 11
    864 template <>
    865 struct _LIBCPP_TEMPLATE_VIS logical_not<void>
    866 {
    867     template <class _Tp>
    868     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
    869     auto operator()(_Tp&& __x) const
    870     _NOEXCEPT_(noexcept(!_VSTD::forward<_Tp>(__x)))
    871     -> decltype        (!_VSTD::forward<_Tp>(__x))
    872         { return        !_VSTD::forward<_Tp>(__x); }
    873     typedef void is_transparent;
    874 };
    875 #endif
    876 
    877 
    878 #if _LIBCPP_STD_VER > 11
    879 template <class _Tp = void>
    880 #else
    881 template <class _Tp>
    882 #endif
    883 struct _LIBCPP_TEMPLATE_VIS bit_and : binary_function<_Tp, _Tp, _Tp>
    884 {
    885     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
    886     _Tp operator()(const _Tp& __x, const _Tp& __y) const
    887         {return __x & __y;}
    888 };
    889 
    890 #if _LIBCPP_STD_VER > 11
    891 template <>
    892 struct _LIBCPP_TEMPLATE_VIS bit_and<void>
    893 {
    894     template <class _T1, class _T2>
    895     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
    896     auto operator()(_T1&& __t, _T2&& __u) const
    897     _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u)))
    898     -> decltype        (_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u))
    899         { return        _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u); }
    900     typedef void is_transparent;
    901 };
    902 #endif
    903 
    904 
    905 #if _LIBCPP_STD_VER > 11
    906 template <class _Tp = void>
    907 #else
    908 template <class _Tp>
    909 #endif
    910 struct _LIBCPP_TEMPLATE_VIS bit_or : binary_function<_Tp, _Tp, _Tp>
    911 {
    912     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
    913     _Tp operator()(const _Tp& __x, const _Tp& __y) const
    914         {return __x | __y;}
    915 };
    916 
    917 #if _LIBCPP_STD_VER > 11
    918 template <>
    919 struct _LIBCPP_TEMPLATE_VIS bit_or<void>
    920 {
    921     template <class _T1, class _T2>
    922     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
    923     auto operator()(_T1&& __t, _T2&& __u) const
    924     _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u)))
    925     -> decltype        (_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u))
    926         { return        _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u); }
    927     typedef void is_transparent;
    928 };
    929 #endif
    930 
    931 
    932 #if _LIBCPP_STD_VER > 11
    933 template <class _Tp = void>
    934 #else
    935 template <class _Tp>
    936 #endif
    937 struct _LIBCPP_TEMPLATE_VIS bit_xor : binary_function<_Tp, _Tp, _Tp>
    938 {
    939     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
    940     _Tp operator()(const _Tp& __x, const _Tp& __y) const
    941         {return __x ^ __y;}
    942 };
    943 
    944 #if _LIBCPP_STD_VER > 11
    945 template <>
    946 struct _LIBCPP_TEMPLATE_VIS bit_xor<void>
    947 {
    948     template <class _T1, class _T2>
    949     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
    950     auto operator()(_T1&& __t, _T2&& __u) const
    951     _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u)))
    952     -> decltype        (_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u))
    953         { return        _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u); }
    954     typedef void is_transparent;
    955 };
    956 #endif
    957 
    958 
    959 #if _LIBCPP_STD_VER > 11
    960 template <class _Tp = void>
    961 struct _LIBCPP_TEMPLATE_VIS bit_not : unary_function<_Tp, _Tp>
    962 {
    963     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
    964     _Tp operator()(const _Tp& __x) const
    965         {return ~__x;}
    966 };
    967 
    968 template <>
    969 struct _LIBCPP_TEMPLATE_VIS bit_not<void>
    970 {
    971     template <class _Tp>
    972     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
    973     auto operator()(_Tp&& __x) const
    974     _NOEXCEPT_(noexcept(~_VSTD::forward<_Tp>(__x)))
    975     -> decltype        (~_VSTD::forward<_Tp>(__x))
    976         { return        ~_VSTD::forward<_Tp>(__x); }
    977     typedef void is_transparent;
    978 };
    979 #endif
    980 
    981 template <class _Predicate>
    982 class _LIBCPP_TEMPLATE_VIS unary_negate
    983     : public unary_function<typename _Predicate::argument_type, bool>
    984 {
    985     _Predicate __pred_;
    986 public:
    987     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
    988     explicit unary_negate(const _Predicate& __pred)
    989         : __pred_(__pred) {}
    990     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
    991     bool operator()(const typename _Predicate::argument_type& __x) const
    992         {return !__pred_(__x);}
    993 };
    994 
    995 template <class _Predicate>
    996 inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
    997 unary_negate<_Predicate>
    998 not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);}
    999 
   1000 template <class _Predicate>
   1001 class _LIBCPP_TEMPLATE_VIS binary_negate
   1002     : public binary_function<typename _Predicate::first_argument_type,
   1003                              typename _Predicate::second_argument_type,
   1004                              bool>
   1005 {
   1006     _Predicate __pred_;
   1007 public:
   1008     _LIBCPP_INLINE_VISIBILITY explicit _LIBCPP_CONSTEXPR_AFTER_CXX11 
   1009     binary_negate(const _Predicate& __pred) : __pred_(__pred) {}
   1010 
   1011     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
   1012     bool operator()(const typename _Predicate::first_argument_type& __x,
   1013                     const typename _Predicate::second_argument_type& __y) const
   1014         {return !__pred_(__x, __y);}
   1015 };
   1016 
   1017 template <class _Predicate>
   1018 inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
   1019 binary_negate<_Predicate>
   1020 not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);}
   1021 
   1022 template <class __Operation>
   1023 class _LIBCPP_TEMPLATE_VIS binder1st
   1024     : public unary_function<typename __Operation::second_argument_type,
   1025                             typename __Operation::result_type>
   1026 {
   1027 protected:
   1028     __Operation                               op;
   1029     typename __Operation::first_argument_type value;
   1030 public:
   1031     _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x,
   1032                                const typename __Operation::first_argument_type __y)
   1033         : op(__x), value(__y) {}
   1034     _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
   1035         (typename __Operation::second_argument_type& __x) const
   1036             {return op(value, __x);}
   1037     _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
   1038         (const typename __Operation::second_argument_type& __x) const
   1039             {return op(value, __x);}
   1040 };
   1041 
   1042 template <class __Operation, class _Tp>
   1043 inline _LIBCPP_INLINE_VISIBILITY
   1044 binder1st<__Operation>
   1045 bind1st(const __Operation& __op, const _Tp& __x)
   1046     {return binder1st<__Operation>(__op, __x);}
   1047 
   1048 template <class __Operation>
   1049 class _LIBCPP_TEMPLATE_VIS binder2nd
   1050     : public unary_function<typename __Operation::first_argument_type,
   1051                             typename __Operation::result_type>
   1052 {
   1053 protected:
   1054     __Operation                                op;
   1055     typename __Operation::second_argument_type value;
   1056 public:
   1057     _LIBCPP_INLINE_VISIBILITY
   1058     binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y)
   1059         : op(__x), value(__y) {}
   1060     _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
   1061         (      typename __Operation::first_argument_type& __x) const
   1062             {return op(__x, value);}
   1063     _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
   1064         (const typename __Operation::first_argument_type& __x) const
   1065             {return op(__x, value);}
   1066 };
   1067 
   1068 template <class __Operation, class _Tp>
   1069 inline _LIBCPP_INLINE_VISIBILITY
   1070 binder2nd<__Operation>
   1071 bind2nd(const __Operation& __op, const _Tp& __x)
   1072     {return binder2nd<__Operation>(__op, __x);}
   1073 
   1074 template <class _Arg, class _Result>
   1075 class _LIBCPP_TEMPLATE_VIS pointer_to_unary_function
   1076     : public unary_function<_Arg, _Result>
   1077 {
   1078     _Result (*__f_)(_Arg);
   1079 public:
   1080     _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg))
   1081         : __f_(__f) {}
   1082     _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const
   1083         {return __f_(__x);}
   1084 };
   1085 
   1086 template <class _Arg, class _Result>
   1087 inline _LIBCPP_INLINE_VISIBILITY
   1088 pointer_to_unary_function<_Arg,_Result>
   1089 ptr_fun(_Result (*__f)(_Arg))
   1090     {return pointer_to_unary_function<_Arg,_Result>(__f);}
   1091 
   1092 template <class _Arg1, class _Arg2, class _Result>
   1093 class _LIBCPP_TEMPLATE_VIS pointer_to_binary_function
   1094     : public binary_function<_Arg1, _Arg2, _Result>
   1095 {
   1096     _Result (*__f_)(_Arg1, _Arg2);
   1097 public:
   1098     _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2))
   1099         : __f_(__f) {}
   1100     _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const
   1101         {return __f_(__x, __y);}
   1102 };
   1103 
   1104 template <class _Arg1, class _Arg2, class _Result>
   1105 inline _LIBCPP_INLINE_VISIBILITY
   1106 pointer_to_binary_function<_Arg1,_Arg2,_Result>
   1107 ptr_fun(_Result (*__f)(_Arg1,_Arg2))
   1108     {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);}
   1109 
   1110 template<class _Sp, class _Tp>
   1111 class _LIBCPP_TEMPLATE_VIS mem_fun_t : public unary_function<_Tp*, _Sp>
   1112 {
   1113     _Sp (_Tp::*__p_)();
   1114 public:
   1115     _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)())
   1116         : __p_(__p) {}
   1117     _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const
   1118         {return (__p->*__p_)();}
   1119 };
   1120 
   1121 template<class _Sp, class _Tp, class _Ap>
   1122 class _LIBCPP_TEMPLATE_VIS mem_fun1_t : public binary_function<_Tp*, _Ap, _Sp>
   1123 {
   1124     _Sp (_Tp::*__p_)(_Ap);
   1125 public:
   1126     _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap))
   1127         : __p_(__p) {}
   1128     _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const
   1129         {return (__p->*__p_)(__x);}
   1130 };
   1131 
   1132 template<class _Sp, class _Tp>
   1133 inline _LIBCPP_INLINE_VISIBILITY
   1134 mem_fun_t<_Sp,_Tp>
   1135 mem_fun(_Sp (_Tp::*__f)())
   1136     {return mem_fun_t<_Sp,_Tp>(__f);}
   1137 
   1138 template<class _Sp, class _Tp, class _Ap>
   1139 inline _LIBCPP_INLINE_VISIBILITY
   1140 mem_fun1_t<_Sp,_Tp,_Ap>
   1141 mem_fun(_Sp (_Tp::*__f)(_Ap))
   1142     {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
   1143 
   1144 template<class _Sp, class _Tp>
   1145 class _LIBCPP_TEMPLATE_VIS mem_fun_ref_t : public unary_function<_Tp, _Sp>
   1146 {
   1147     _Sp (_Tp::*__p_)();
   1148 public:
   1149     _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)())
   1150         : __p_(__p) {}
   1151     _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const
   1152         {return (__p.*__p_)();}
   1153 };
   1154 
   1155 template<class _Sp, class _Tp, class _Ap>
   1156 class _LIBCPP_TEMPLATE_VIS mem_fun1_ref_t : public binary_function<_Tp, _Ap, _Sp>
   1157 {
   1158     _Sp (_Tp::*__p_)(_Ap);
   1159 public:
   1160     _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap))
   1161         : __p_(__p) {}
   1162     _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const
   1163         {return (__p.*__p_)(__x);}
   1164 };
   1165 
   1166 template<class _Sp, class _Tp>
   1167 inline _LIBCPP_INLINE_VISIBILITY
   1168 mem_fun_ref_t<_Sp,_Tp>
   1169 mem_fun_ref(_Sp (_Tp::*__f)())
   1170     {return mem_fun_ref_t<_Sp,_Tp>(__f);}
   1171 
   1172 template<class _Sp, class _Tp, class _Ap>
   1173 inline _LIBCPP_INLINE_VISIBILITY
   1174 mem_fun1_ref_t<_Sp,_Tp,_Ap>
   1175 mem_fun_ref(_Sp (_Tp::*__f)(_Ap))
   1176     {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
   1177 
   1178 template <class _Sp, class _Tp>
   1179 class _LIBCPP_TEMPLATE_VIS const_mem_fun_t : public unary_function<const _Tp*, _Sp>
   1180 {
   1181     _Sp (_Tp::*__p_)() const;
   1182 public:
   1183     _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const)
   1184         : __p_(__p) {}
   1185     _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const
   1186         {return (__p->*__p_)();}
   1187 };
   1188 
   1189 template <class _Sp, class _Tp, class _Ap>
   1190 class _LIBCPP_TEMPLATE_VIS const_mem_fun1_t : public binary_function<const _Tp*, _Ap, _Sp>
   1191 {
   1192     _Sp (_Tp::*__p_)(_Ap) const;
   1193 public:
   1194     _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const)
   1195         : __p_(__p) {}
   1196     _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const
   1197         {return (__p->*__p_)(__x);}
   1198 };
   1199 
   1200 template <class _Sp, class _Tp>
   1201 inline _LIBCPP_INLINE_VISIBILITY
   1202 const_mem_fun_t<_Sp,_Tp>
   1203 mem_fun(_Sp (_Tp::*__f)() const)
   1204     {return const_mem_fun_t<_Sp,_Tp>(__f);}
   1205 
   1206 template <class _Sp, class _Tp, class _Ap>
   1207 inline _LIBCPP_INLINE_VISIBILITY
   1208 const_mem_fun1_t<_Sp,_Tp,_Ap>
   1209 mem_fun(_Sp (_Tp::*__f)(_Ap) const)
   1210     {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
   1211 
   1212 template <class _Sp, class _Tp>
   1213 class _LIBCPP_TEMPLATE_VIS const_mem_fun_ref_t : public unary_function<_Tp, _Sp>
   1214 {
   1215     _Sp (_Tp::*__p_)() const;
   1216 public:
   1217     _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const)
   1218         : __p_(__p) {}
   1219     _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const
   1220         {return (__p.*__p_)();}
   1221 };
   1222 
   1223 template <class _Sp, class _Tp, class _Ap>
   1224 class _LIBCPP_TEMPLATE_VIS const_mem_fun1_ref_t
   1225     : public binary_function<_Tp, _Ap, _Sp>
   1226 {
   1227     _Sp (_Tp::*__p_)(_Ap) const;
   1228 public:
   1229     _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const)
   1230         : __p_(__p) {}
   1231     _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const
   1232         {return (__p.*__p_)(__x);}
   1233 };
   1234 
   1235 template <class _Sp, class _Tp>
   1236 inline _LIBCPP_INLINE_VISIBILITY
   1237 const_mem_fun_ref_t<_Sp,_Tp>
   1238 mem_fun_ref(_Sp (_Tp::*__f)() const)
   1239     {return const_mem_fun_ref_t<_Sp,_Tp>(__f);}
   1240 
   1241 template <class _Sp, class _Tp, class _Ap>
   1242 inline _LIBCPP_INLINE_VISIBILITY
   1243 const_mem_fun1_ref_t<_Sp,_Tp,_Ap>
   1244 mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const)
   1245     {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
   1246 
   1247 ////////////////////////////////////////////////////////////////////////////////
   1248 //                                MEMFUN
   1249 //==============================================================================
   1250 
   1251 template <class _Tp>
   1252 class __mem_fn
   1253     : public __weak_result_type<_Tp>
   1254 {
   1255 public:
   1256     // types
   1257     typedef _Tp type;
   1258 private:
   1259     type __f_;
   1260 
   1261 public:
   1262     _LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) _NOEXCEPT : __f_(__f) {}
   1263 
   1264 #ifndef _LIBCPP_HAS_NO_VARIADICS
   1265     // invoke
   1266     template <class... _ArgTypes>
   1267     _LIBCPP_INLINE_VISIBILITY
   1268     typename __invoke_return<type, _ArgTypes...>::type
   1269     operator() (_ArgTypes&&... __args) const {
   1270         return __invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...);
   1271     }
   1272 #else
   1273 
   1274     template <class _A0>
   1275     _LIBCPP_INLINE_VISIBILITY
   1276     typename __invoke_return0<type, _A0>::type
   1277     operator() (_A0& __a0) const {
   1278         return __invoke(__f_, __a0);
   1279     }
   1280 
   1281     template <class _A0>
   1282     _LIBCPP_INLINE_VISIBILITY
   1283     typename __invoke_return0<type, _A0 const>::type
   1284     operator() (_A0 const& __a0) const {
   1285         return __invoke(__f_, __a0);
   1286     }
   1287 
   1288     template <class _A0, class _A1>
   1289     _LIBCPP_INLINE_VISIBILITY
   1290     typename __invoke_return1<type, _A0, _A1>::type
   1291     operator() (_A0& __a0, _A1& __a1) const {
   1292         return __invoke(__f_, __a0, __a1);
   1293     }
   1294 
   1295     template <class _A0, class _A1>
   1296     _LIBCPP_INLINE_VISIBILITY
   1297     typename __invoke_return1<type, _A0 const, _A1>::type
   1298     operator() (_A0 const& __a0, _A1& __a1) const {
   1299         return __invoke(__f_, __a0, __a1);
   1300     }
   1301 
   1302     template <class _A0, class _A1>
   1303     _LIBCPP_INLINE_VISIBILITY
   1304     typename __invoke_return1<type, _A0, _A1 const>::type
   1305     operator() (_A0& __a0, _A1 const& __a1) const {
   1306         return __invoke(__f_, __a0, __a1);
   1307     }
   1308 
   1309     template <class _A0, class _A1>
   1310     _LIBCPP_INLINE_VISIBILITY
   1311     typename __invoke_return1<type, _A0 const, _A1 const>::type
   1312     operator() (_A0 const& __a0, _A1 const& __a1) const {
   1313         return __invoke(__f_, __a0, __a1);
   1314     }
   1315 
   1316     template <class _A0, class _A1, class _A2>
   1317     _LIBCPP_INLINE_VISIBILITY
   1318     typename __invoke_return2<type, _A0, _A1, _A2>::type
   1319     operator() (_A0& __a0, _A1& __a1, _A2& __a2) const {
   1320         return __invoke(__f_, __a0, __a1, __a2);
   1321     }
   1322 
   1323     template <class _A0, class _A1, class _A2>
   1324     _LIBCPP_INLINE_VISIBILITY
   1325     typename __invoke_return2<type, _A0 const, _A1, _A2>::type
   1326     operator() (_A0 const& __a0, _A1& __a1, _A2& __a2) const {
   1327         return __invoke(__f_, __a0, __a1, __a2);
   1328     }
   1329 
   1330     template <class _A0, class _A1, class _A2>
   1331     _LIBCPP_INLINE_VISIBILITY
   1332     typename __invoke_return2<type, _A0, _A1 const, _A2>::type
   1333     operator() (_A0& __a0, _A1 const& __a1, _A2& __a2) const {
   1334         return __invoke(__f_, __a0, __a1, __a2);
   1335     }
   1336 
   1337     template <class _A0, class _A1, class _A2>
   1338     _LIBCPP_INLINE_VISIBILITY
   1339     typename __invoke_return2<type, _A0, _A1, _A2 const>::type
   1340     operator() (_A0& __a0, _A1& __a1, _A2 const& __a2) const {
   1341         return __invoke(__f_, __a0, __a1, __a2);
   1342     }
   1343 
   1344     template <class _A0, class _A1, class _A2>
   1345     _LIBCPP_INLINE_VISIBILITY
   1346     typename __invoke_return2<type, _A0 const, _A1 const, _A2>::type
   1347     operator() (_A0 const& __a0, _A1 const& __a1, _A2& __a2) const {
   1348         return __invoke(__f_, __a0, __a1, __a2);
   1349     }
   1350 
   1351     template <class _A0, class _A1, class _A2>
   1352     _LIBCPP_INLINE_VISIBILITY
   1353     typename __invoke_return2<type, _A0 const, _A1, _A2 const>::type
   1354     operator() (_A0 const& __a0, _A1& __a1, _A2 const& __a2) const {
   1355         return __invoke(__f_, __a0, __a1, __a2);
   1356     }
   1357 
   1358     template <class _A0, class _A1, class _A2>
   1359     _LIBCPP_INLINE_VISIBILITY
   1360     typename __invoke_return2<type, _A0, _A1 const, _A2 const>::type
   1361     operator() (_A0& __a0, _A1 const& __a1, _A2 const& __a2) const {
   1362         return __invoke(__f_, __a0, __a1, __a2);
   1363     }
   1364 
   1365     template <class _A0, class _A1, class _A2>
   1366     _LIBCPP_INLINE_VISIBILITY
   1367     typename __invoke_return2<type, _A0 const, _A1 const, _A2 const>::type
   1368     operator() (_A0 const& __a0, _A1 const& __a1, _A2 const& __a2) const {
   1369         return __invoke(__f_, __a0, __a1, __a2);
   1370     }
   1371 #endif
   1372 };
   1373 
   1374 template<class _Rp, class _Tp>
   1375 inline _LIBCPP_INLINE_VISIBILITY
   1376 __mem_fn<_Rp _Tp::*>
   1377 mem_fn(_Rp _Tp::* __pm) _NOEXCEPT
   1378 {
   1379     return __mem_fn<_Rp _Tp::*>(__pm);
   1380 }
   1381 
   1382 ////////////////////////////////////////////////////////////////////////////////
   1383 //                                FUNCTION
   1384 //==============================================================================
   1385 
   1386 // bad_function_call
   1387 
   1388 class _LIBCPP_EXCEPTION_ABI bad_function_call
   1389     : public exception
   1390 {
   1391 };
   1392 
   1393 _LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
   1394 void __throw_bad_function_call()
   1395 {
   1396 #ifndef _LIBCPP_NO_EXCEPTIONS
   1397     throw bad_function_call();
   1398 #else
   1399 	_VSTD::abort();
   1400 #endif
   1401 }
   1402 
   1403 template<class _Fp> class _LIBCPP_TEMPLATE_VIS function; // undefined
   1404 
   1405 namespace __function
   1406 {
   1407 
   1408 template<class _Rp>
   1409 struct __maybe_derive_from_unary_function
   1410 {
   1411 };
   1412 
   1413 template<class _Rp, class _A1>
   1414 struct __maybe_derive_from_unary_function<_Rp(_A1)>
   1415     : public unary_function<_A1, _Rp>
   1416 {
   1417 };
   1418 
   1419 template<class _Rp>
   1420 struct __maybe_derive_from_binary_function
   1421 {
   1422 };
   1423 
   1424 template<class _Rp, class _A1, class _A2>
   1425 struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)>
   1426     : public binary_function<_A1, _A2, _Rp>
   1427 {
   1428 };
   1429 
   1430 template <class _Fp>
   1431 _LIBCPP_INLINE_VISIBILITY
   1432 bool __not_null(_Fp const&) { return true; }
   1433 
   1434 template <class _Fp>
   1435 _LIBCPP_INLINE_VISIBILITY
   1436 bool __not_null(_Fp* __ptr) { return __ptr; }
   1437 
   1438 template <class _Ret, class _Class>
   1439 _LIBCPP_INLINE_VISIBILITY
   1440 bool __not_null(_Ret _Class::*__ptr) { return __ptr; }
   1441 
   1442 template <class _Fp>
   1443 _LIBCPP_INLINE_VISIBILITY
   1444 bool __not_null(function<_Fp> const& __f) { return !!__f; }
   1445 
   1446 } // namespace __function
   1447 
   1448 #ifndef _LIBCPP_HAS_NO_VARIADICS
   1449 
   1450 namespace __function {
   1451 
   1452 template<class _Fp> class __base;
   1453 
   1454 template<class _Rp, class ..._ArgTypes>
   1455 class __base<_Rp(_ArgTypes...)>
   1456 {
   1457     __base(const __base&);
   1458     __base& operator=(const __base&);
   1459 public:
   1460     _LIBCPP_INLINE_VISIBILITY __base() {}
   1461     _LIBCPP_INLINE_VISIBILITY virtual ~__base() {}
   1462     virtual __base* __clone() const = 0;
   1463     virtual void __clone(__base*) const = 0;
   1464     virtual void destroy() _NOEXCEPT = 0;
   1465     virtual void destroy_deallocate() _NOEXCEPT = 0;
   1466     virtual _Rp operator()(_ArgTypes&& ...) = 0;
   1467 #ifndef _LIBCPP_NO_RTTI
   1468     virtual const void* target(const type_info&) const _NOEXCEPT = 0;
   1469     virtual const std::type_info& target_type() const _NOEXCEPT = 0;
   1470 #endif  // _LIBCPP_NO_RTTI
   1471 };
   1472 
   1473 template<class _FD, class _Alloc, class _FB> class __func;
   1474 
   1475 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
   1476 class __func<_Fp, _Alloc, _Rp(_ArgTypes...)>
   1477     : public  __base<_Rp(_ArgTypes...)>
   1478 {
   1479     __compressed_pair<_Fp, _Alloc> __f_;
   1480 public:
   1481     _LIBCPP_INLINE_VISIBILITY
   1482     explicit __func(_Fp&& __f)
   1483         : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
   1484                                     _VSTD::forward_as_tuple()) {}
   1485     _LIBCPP_INLINE_VISIBILITY
   1486     explicit __func(const _Fp& __f, const _Alloc& __a)
   1487         : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
   1488                                     _VSTD::forward_as_tuple(__a)) {}
   1489 
   1490     _LIBCPP_INLINE_VISIBILITY
   1491     explicit __func(const _Fp& __f, _Alloc&& __a)
   1492         : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
   1493                                     _VSTD::forward_as_tuple(_VSTD::move(__a))) {}
   1494 
   1495     _LIBCPP_INLINE_VISIBILITY
   1496     explicit __func(_Fp&& __f, _Alloc&& __a)
   1497         : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
   1498                                     _VSTD::forward_as_tuple(_VSTD::move(__a))) {}
   1499     virtual __base<_Rp(_ArgTypes...)>* __clone() const;
   1500     virtual void __clone(__base<_Rp(_ArgTypes...)>*) const;
   1501     virtual void destroy() _NOEXCEPT;
   1502     virtual void destroy_deallocate() _NOEXCEPT;
   1503     virtual _Rp operator()(_ArgTypes&& ... __arg);
   1504 #ifndef _LIBCPP_NO_RTTI
   1505     virtual const void* target(const type_info&) const _NOEXCEPT;
   1506     virtual const std::type_info& target_type() const _NOEXCEPT;
   1507 #endif  // _LIBCPP_NO_RTTI
   1508 };
   1509 
   1510 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
   1511 __base<_Rp(_ArgTypes...)>*
   1512 __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const
   1513 {
   1514     typedef allocator_traits<_Alloc> __alloc_traits;
   1515     typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
   1516     _Ap __a(__f_.second());
   1517     typedef __allocator_destructor<_Ap> _Dp;
   1518     unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
   1519     ::new (__hold.get()) __func(__f_.first(), _Alloc(__a));
   1520     return __hold.release();
   1521 }
   1522 
   1523 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
   1524 void
   1525 __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const
   1526 {
   1527     ::new (__p) __func(__f_.first(), __f_.second());
   1528 }
   1529 
   1530 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
   1531 void
   1532 __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPT
   1533 {
   1534     __f_.~__compressed_pair<_Fp, _Alloc>();
   1535 }
   1536 
   1537 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
   1538 void
   1539 __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT
   1540 {
   1541     typedef allocator_traits<_Alloc> __alloc_traits;
   1542     typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
   1543     _Ap __a(__f_.second());
   1544     __f_.~__compressed_pair<_Fp, _Alloc>();
   1545     __a.deallocate(this, 1);
   1546 }
   1547 
   1548 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
   1549 _Rp
   1550 __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg)
   1551 {
   1552     typedef __invoke_void_return_wrapper<_Rp> _Invoker;
   1553     return _Invoker::__call(__f_.first(), _VSTD::forward<_ArgTypes>(__arg)...);
   1554 }
   1555 
   1556 #ifndef _LIBCPP_NO_RTTI
   1557 
   1558 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
   1559 const void*
   1560 __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT
   1561 {
   1562     if (__ti == typeid(_Fp))
   1563         return &__f_.first();
   1564     return (const void*)0;
   1565 }
   1566 
   1567 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
   1568 const std::type_info&
   1569 __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
   1570 {
   1571     return typeid(_Fp);
   1572 }
   1573 
   1574 #endif  // _LIBCPP_NO_RTTI
   1575 
   1576 }  // __function
   1577 
   1578 template<class _Rp, class ..._ArgTypes>
   1579 class _LIBCPP_TEMPLATE_VIS function<_Rp(_ArgTypes...)>
   1580     : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>,
   1581       public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)>
   1582 {
   1583     typedef __function::__base<_Rp(_ArgTypes...)> __base;
   1584     typename aligned_storage<3*sizeof(void*)>::type __buf_;
   1585     __base* __f_;
   1586 
   1587     _LIBCPP_NO_CFI static __base *__as_base(void *p) {
   1588       return reinterpret_cast<__base*>(p);
   1589     }
   1590 
   1591     template <class _Fp, bool = !is_same<_Fp, function>::value &&
   1592                                 __invokable<_Fp&, _ArgTypes...>::value>
   1593         struct __callable;
   1594     template <class _Fp>
   1595         struct __callable<_Fp, true>
   1596         {
   1597             static const bool value = is_same<void, _Rp>::value ||
   1598                 is_convertible<typename __invoke_of<_Fp&, _ArgTypes...>::type,
   1599                                _Rp>::value;
   1600         };
   1601     template <class _Fp>
   1602         struct __callable<_Fp, false>
   1603         {
   1604             static const bool value = false;
   1605         };
   1606 public:
   1607     typedef _Rp result_type;
   1608 
   1609     // construct/copy/destroy:
   1610     _LIBCPP_INLINE_VISIBILITY
   1611     function() _NOEXCEPT : __f_(0) {}
   1612     _LIBCPP_INLINE_VISIBILITY
   1613     function(nullptr_t) _NOEXCEPT : __f_(0) {}
   1614     function(const function&);
   1615     function(function&&) _NOEXCEPT;
   1616     template<class _Fp, class = typename enable_if<
   1617         __callable<_Fp>::value && !is_same<_Fp, function>::value
   1618     >::type>
   1619     function(_Fp);
   1620 
   1621 #if _LIBCPP_STD_VER <= 14
   1622     template<class _Alloc>
   1623       _LIBCPP_INLINE_VISIBILITY
   1624       function(allocator_arg_t, const _Alloc&) _NOEXCEPT : __f_(0) {}
   1625     template<class _Alloc>
   1626       _LIBCPP_INLINE_VISIBILITY
   1627       function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT : __f_(0) {}
   1628     template<class _Alloc>
   1629       function(allocator_arg_t, const _Alloc&, const function&);
   1630     template<class _Alloc>
   1631       function(allocator_arg_t, const _Alloc&, function&&);
   1632     template<class _Fp, class _Alloc, class = typename enable_if<__callable<_Fp>::value>::type>
   1633       function(allocator_arg_t, const _Alloc& __a, _Fp __f);
   1634 #endif
   1635 
   1636     function& operator=(const function&);
   1637     function& operator=(function&&) _NOEXCEPT;
   1638     function& operator=(nullptr_t) _NOEXCEPT;
   1639     template<class _Fp>
   1640       typename enable_if
   1641       <
   1642         __callable<typename decay<_Fp>::type>::value &&
   1643         !is_same<typename remove_reference<_Fp>::type, function>::value,
   1644         function&
   1645       >::type
   1646       operator=(_Fp&&);
   1647 
   1648     ~function();
   1649 
   1650     // function modifiers:
   1651     void swap(function&) _NOEXCEPT;
   1652 
   1653 #if _LIBCPP_STD_VER <= 14
   1654     template<class _Fp, class _Alloc>
   1655       _LIBCPP_INLINE_VISIBILITY
   1656       void assign(_Fp&& __f, const _Alloc& __a)
   1657         {function(allocator_arg, __a, _VSTD::forward<_Fp>(__f)).swap(*this);}
   1658 #endif
   1659 
   1660     // function capacity:
   1661     _LIBCPP_INLINE_VISIBILITY
   1662         _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return __f_;}
   1663 
   1664     // deleted overloads close possible hole in the type system
   1665     template<class _R2, class... _ArgTypes2>
   1666       bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete;
   1667     template<class _R2, class... _ArgTypes2>
   1668       bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete;
   1669 public:
   1670     // function invocation:
   1671     _Rp operator()(_ArgTypes...) const;
   1672 
   1673 #ifndef _LIBCPP_NO_RTTI
   1674     // function target access:
   1675     const std::type_info& target_type() const _NOEXCEPT;
   1676     template <typename _Tp> _Tp* target() _NOEXCEPT;
   1677     template <typename _Tp> const _Tp* target() const _NOEXCEPT;
   1678 #endif  // _LIBCPP_NO_RTTI
   1679 };
   1680 
   1681 template<class _Rp, class ..._ArgTypes>
   1682 function<_Rp(_ArgTypes...)>::function(const function& __f)
   1683 {
   1684     if (__f.__f_ == 0)
   1685         __f_ = 0;
   1686     else if ((void *)__f.__f_ == &__f.__buf_)
   1687     {
   1688         __f_ = __as_base(&__buf_);
   1689         __f.__f_->__clone(__f_);
   1690     }
   1691     else
   1692         __f_ = __f.__f_->__clone();
   1693 }
   1694 
   1695 #if _LIBCPP_STD_VER <= 14
   1696 template<class _Rp, class ..._ArgTypes>
   1697 template <class _Alloc>
   1698 function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
   1699                                      const function& __f)
   1700 {
   1701     if (__f.__f_ == 0)
   1702         __f_ = 0;
   1703     else if ((void *)__f.__f_ == &__f.__buf_)
   1704     {
   1705         __f_ = __as_base(&__buf_);
   1706         __f.__f_->__clone(__f_);
   1707     }
   1708     else
   1709         __f_ = __f.__f_->__clone();
   1710 }
   1711 #endif
   1712 
   1713 template<class _Rp, class ..._ArgTypes>
   1714 function<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT
   1715 {
   1716     if (__f.__f_ == 0)
   1717         __f_ = 0;
   1718     else if ((void *)__f.__f_ == &__f.__buf_)
   1719     {
   1720         __f_ = __as_base(&__buf_);
   1721         __f.__f_->__clone(__f_);
   1722     }
   1723     else
   1724     {
   1725         __f_ = __f.__f_;
   1726         __f.__f_ = 0;
   1727     }
   1728 }
   1729 
   1730 #if _LIBCPP_STD_VER <= 14
   1731 template<class _Rp, class ..._ArgTypes>
   1732 template <class _Alloc>
   1733 function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
   1734                                      function&& __f)
   1735 {
   1736     if (__f.__f_ == 0)
   1737         __f_ = 0;
   1738     else if ((void *)__f.__f_ == &__f.__buf_)
   1739     {
   1740         __f_ = __as_base(&__buf_);
   1741         __f.__f_->__clone(__f_);
   1742     }
   1743     else
   1744     {
   1745         __f_ = __f.__f_;
   1746         __f.__f_ = 0;
   1747     }
   1748 }
   1749 #endif
   1750 
   1751 template<class _Rp, class ..._ArgTypes>
   1752 template <class _Fp, class>
   1753 function<_Rp(_ArgTypes...)>::function(_Fp __f)
   1754     : __f_(0)
   1755 {
   1756     if (__function::__not_null(__f))
   1757     {
   1758         typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_ArgTypes...)> _FF;
   1759         if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value)
   1760         {
   1761             __f_ = ::new((void*)&__buf_) _FF(_VSTD::move(__f));
   1762         }
   1763         else
   1764         {
   1765             typedef allocator<_FF> _Ap;
   1766             _Ap __a;
   1767             typedef __allocator_destructor<_Ap> _Dp;
   1768             unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
   1769             ::new (__hold.get()) _FF(_VSTD::move(__f), allocator<_Fp>(__a));
   1770             __f_ = __hold.release();
   1771         }
   1772     }
   1773 }
   1774 
   1775 #if _LIBCPP_STD_VER <= 14
   1776 template<class _Rp, class ..._ArgTypes>
   1777 template <class _Fp, class _Alloc, class>
   1778 function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f)
   1779     : __f_(0)
   1780 {
   1781     typedef allocator_traits<_Alloc> __alloc_traits;
   1782     if (__function::__not_null(__f))
   1783     {
   1784         typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _FF;
   1785         typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap;
   1786         _Ap __a(__a0);
   1787         if (sizeof(_FF) <= sizeof(__buf_) && 
   1788             is_nothrow_copy_constructible<_Fp>::value && is_nothrow_copy_constructible<_Ap>::value)
   1789         {
   1790             __f_ = ::new((void*)&__buf_) _FF(_VSTD::move(__f), _Alloc(__a));
   1791         }
   1792         else
   1793         {
   1794             typedef __allocator_destructor<_Ap> _Dp;
   1795             unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
   1796             ::new (__hold.get()) _FF(_VSTD::move(__f), _Alloc(__a));
   1797             __f_ = __hold.release();
   1798         }
   1799     }
   1800 }
   1801 #endif
   1802 
   1803 template<class _Rp, class ..._ArgTypes>
   1804 function<_Rp(_ArgTypes...)>&
   1805 function<_Rp(_ArgTypes...)>::operator=(const function& __f)
   1806 {
   1807     function(__f).swap(*this);
   1808     return *this;
   1809 }
   1810 
   1811 template<class _Rp, class ..._ArgTypes>
   1812 function<_Rp(_ArgTypes...)>&
   1813 function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT
   1814 {
   1815     if ((void *)__f_ == &__buf_)
   1816         __f_->destroy();
   1817     else if (__f_)
   1818         __f_->destroy_deallocate();
   1819     __f_ = 0;
   1820     if (__f.__f_ == 0)
   1821         __f_ = 0;
   1822     else if ((void *)__f.__f_ == &__f.__buf_)
   1823     {
   1824         __f_ = __as_base(&__buf_);
   1825         __f.__f_->__clone(__f_);
   1826     }
   1827     else
   1828     {
   1829         __f_ = __f.__f_;
   1830         __f.__f_ = 0;
   1831     }
   1832     return *this;
   1833 }
   1834 
   1835 template<class _Rp, class ..._ArgTypes>
   1836 function<_Rp(_ArgTypes...)>&
   1837 function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT
   1838 {
   1839     if ((void *)__f_ == &__buf_)
   1840         __f_->destroy();
   1841     else if (__f_)
   1842         __f_->destroy_deallocate();
   1843     __f_ = 0;
   1844     return *this;
   1845 }
   1846 
   1847 template<class _Rp, class ..._ArgTypes>
   1848 template <class _Fp>
   1849 typename enable_if
   1850 <
   1851     function<_Rp(_ArgTypes...)>::template __callable<typename decay<_Fp>::type>::value &&
   1852     !is_same<typename remove_reference<_Fp>::type, function<_Rp(_ArgTypes...)>>::value,
   1853     function<_Rp(_ArgTypes...)>&
   1854 >::type
   1855 function<_Rp(_ArgTypes...)>::operator=(_Fp&& __f)
   1856 {
   1857     function(_VSTD::forward<_Fp>(__f)).swap(*this);
   1858     return *this;
   1859 }
   1860 
   1861 template<class _Rp, class ..._ArgTypes>
   1862 function<_Rp(_ArgTypes...)>::~function()
   1863 {
   1864     if ((void *)__f_ == &__buf_)
   1865         __f_->destroy();
   1866     else if (__f_)
   1867         __f_->destroy_deallocate();
   1868 }
   1869 
   1870 template<class _Rp, class ..._ArgTypes>
   1871 void
   1872 function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT
   1873 {
   1874     if (_VSTD::addressof(__f) == this)
   1875       return;
   1876     if ((void *)__f_ == &__buf_ && (void *)__f.__f_ == &__f.__buf_)
   1877     {
   1878         typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
   1879         __base* __t = __as_base(&__tempbuf);
   1880         __f_->__clone(__t);
   1881         __f_->destroy();
   1882         __f_ = 0;
   1883         __f.__f_->__clone(__as_base(&__buf_));
   1884         __f.__f_->destroy();
   1885         __f.__f_ = 0;
   1886         __f_ = __as_base(&__buf_);
   1887         __t->__clone(__as_base(&__f.__buf_));
   1888         __t->destroy();
   1889         __f.__f_ = __as_base(&__f.__buf_);
   1890     }
   1891     else if ((void *)__f_ == &__buf_)
   1892     {
   1893         __f_->__clone(__as_base(&__f.__buf_));
   1894         __f_->destroy();
   1895         __f_ = __f.__f_;
   1896         __f.__f_ = __as_base(&__f.__buf_);
   1897     }
   1898     else if ((void *)__f.__f_ == &__f.__buf_)
   1899     {
   1900         __f.__f_->__clone(__as_base(&__buf_));
   1901         __f.__f_->destroy();
   1902         __f.__f_ = __f_;
   1903         __f_ = __as_base(&__buf_);
   1904     }
   1905     else
   1906         _VSTD::swap(__f_, __f.__f_);
   1907 }
   1908 
   1909 template<class _Rp, class ..._ArgTypes>
   1910 _Rp
   1911 function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const
   1912 {
   1913     if (__f_ == 0)
   1914         __throw_bad_function_call();
   1915     return (*__f_)(_VSTD::forward<_ArgTypes>(__arg)...);
   1916 }
   1917 
   1918 #ifndef _LIBCPP_NO_RTTI
   1919 
   1920 template<class _Rp, class ..._ArgTypes>
   1921 const std::type_info&
   1922 function<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
   1923 {
   1924     if (__f_ == 0)
   1925         return typeid(void);
   1926     return __f_->target_type();
   1927 }
   1928 
   1929 template<class _Rp, class ..._ArgTypes>
   1930 template <typename _Tp>
   1931 _Tp*
   1932 function<_Rp(_ArgTypes...)>::target() _NOEXCEPT
   1933 {
   1934     if (__f_ == 0)
   1935         return (_Tp*)0;
   1936     return (_Tp*)__f_->target(typeid(_Tp));
   1937 }
   1938 
   1939 template<class _Rp, class ..._ArgTypes>
   1940 template <typename _Tp>
   1941 const _Tp*
   1942 function<_Rp(_ArgTypes...)>::target() const _NOEXCEPT
   1943 {
   1944     if (__f_ == 0)
   1945         return (const _Tp*)0;
   1946     return (const _Tp*)__f_->target(typeid(_Tp));
   1947 }
   1948 
   1949 #endif  // _LIBCPP_NO_RTTI
   1950 
   1951 template <class _Rp, class... _ArgTypes>
   1952 inline _LIBCPP_INLINE_VISIBILITY
   1953 bool
   1954 operator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;}
   1955 
   1956 template <class _Rp, class... _ArgTypes>
   1957 inline _LIBCPP_INLINE_VISIBILITY
   1958 bool
   1959 operator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;}
   1960 
   1961 template <class _Rp, class... _ArgTypes>
   1962 inline _LIBCPP_INLINE_VISIBILITY
   1963 bool
   1964 operator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;}
   1965 
   1966 template <class _Rp, class... _ArgTypes>
   1967 inline _LIBCPP_INLINE_VISIBILITY
   1968 bool
   1969 operator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;}
   1970 
   1971 template <class _Rp, class... _ArgTypes>
   1972 inline _LIBCPP_INLINE_VISIBILITY
   1973 void
   1974 swap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT
   1975 {return __x.swap(__y);}
   1976 
   1977 #else // _LIBCPP_HAS_NO_VARIADICS
   1978 
   1979 #include <__functional_03>
   1980 
   1981 #endif
   1982 
   1983 ////////////////////////////////////////////////////////////////////////////////
   1984 //                                  BIND
   1985 //==============================================================================
   1986 
   1987 template<class _Tp> struct __is_bind_expression : public false_type {};
   1988 template<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_bind_expression
   1989     : public __is_bind_expression<typename remove_cv<_Tp>::type> {};
   1990 
   1991 #if _LIBCPP_STD_VER > 14
   1992 template <class _Tp>
   1993 constexpr size_t is_bind_expression_v = is_bind_expression<_Tp>::value;
   1994 #endif
   1995 
   1996 template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {};
   1997 template<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_placeholder
   1998     : public __is_placeholder<typename remove_cv<_Tp>::type> {};
   1999 
   2000 #if _LIBCPP_STD_VER > 14
   2001 template <class _Tp>
   2002 constexpr size_t is_placeholder_v = is_placeholder<_Tp>::value;
   2003 #endif
   2004 
   2005 namespace placeholders
   2006 {
   2007 
   2008 template <int _Np> struct __ph {};
   2009 
   2010 #if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_BIND)
   2011 _LIBCPP_FUNC_VIS extern const __ph<1>   _1;
   2012 _LIBCPP_FUNC_VIS extern const __ph<2>   _2;
   2013 _LIBCPP_FUNC_VIS extern const __ph<3>   _3;
   2014 _LIBCPP_FUNC_VIS extern const __ph<4>   _4;
   2015 _LIBCPP_FUNC_VIS extern const __ph<5>   _5;
   2016 _LIBCPP_FUNC_VIS extern const __ph<6>   _6;
   2017 _LIBCPP_FUNC_VIS extern const __ph<7>   _7;
   2018 _LIBCPP_FUNC_VIS extern const __ph<8>   _8;
   2019 _LIBCPP_FUNC_VIS extern const __ph<9>   _9;
   2020 _LIBCPP_FUNC_VIS extern const __ph<10> _10;
   2021 #else
   2022 constexpr __ph<1>   _1{};
   2023 constexpr __ph<2>   _2{};
   2024 constexpr __ph<3>   _3{};
   2025 constexpr __ph<4>   _4{};
   2026 constexpr __ph<5>   _5{};
   2027 constexpr __ph<6>   _6{};
   2028 constexpr __ph<7>   _7{};
   2029 constexpr __ph<8>   _8{};
   2030 constexpr __ph<9>   _9{};
   2031 constexpr __ph<10> _10{};
   2032 #endif // defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_BIND)
   2033 
   2034 }  // placeholders
   2035 
   2036 template<int _Np>
   2037 struct __is_placeholder<placeholders::__ph<_Np> >
   2038     : public integral_constant<int, _Np> {};
   2039 
   2040 
   2041 #ifndef _LIBCPP_HAS_NO_VARIADICS
   2042 
   2043 template <class _Tp, class _Uj>
   2044 inline _LIBCPP_INLINE_VISIBILITY
   2045 _Tp&
   2046 __mu(reference_wrapper<_Tp> __t, _Uj&)
   2047 {
   2048     return __t.get();
   2049 }
   2050 
   2051 template <class _Ti, class ..._Uj, size_t ..._Indx>
   2052 inline _LIBCPP_INLINE_VISIBILITY
   2053 typename __invoke_of<_Ti&, _Uj...>::type
   2054 __mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>)
   2055 {
   2056     return __ti(_VSTD::forward<_Uj>(_VSTD::get<_Indx>(__uj))...);
   2057 }
   2058 
   2059 template <class _Ti, class ..._Uj>
   2060 inline _LIBCPP_INLINE_VISIBILITY
   2061 typename __lazy_enable_if
   2062 <
   2063     is_bind_expression<_Ti>::value,
   2064     __invoke_of<_Ti&, _Uj...>
   2065 >::type
   2066 __mu(_Ti& __ti, tuple<_Uj...>& __uj)
   2067 {
   2068     typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices;
   2069     return  __mu_expand(__ti, __uj, __indices());
   2070 }
   2071 
   2072 template <bool IsPh, class _Ti, class _Uj>
   2073 struct __mu_return2 {};
   2074 
   2075 template <class _Ti, class _Uj>
   2076 struct __mu_return2<true, _Ti, _Uj>
   2077 {
   2078     typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type;
   2079 };
   2080 
   2081 template <class _Ti, class _Uj>
   2082 inline _LIBCPP_INLINE_VISIBILITY
   2083 typename enable_if
   2084 <
   2085     0 < is_placeholder<_Ti>::value,
   2086     typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type
   2087 >::type
   2088 __mu(_Ti&, _Uj& __uj)
   2089 {
   2090     const size_t _Indx = is_placeholder<_Ti>::value - 1;
   2091     return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj));
   2092 }
   2093 
   2094 template <class _Ti, class _Uj>
   2095 inline _LIBCPP_INLINE_VISIBILITY
   2096 typename enable_if
   2097 <
   2098     !is_bind_expression<_Ti>::value &&
   2099     is_placeholder<_Ti>::value == 0 &&
   2100     !__is_reference_wrapper<_Ti>::value,
   2101     _Ti&
   2102 >::type
   2103 __mu(_Ti& __ti, _Uj&)
   2104 {
   2105     return __ti;
   2106 }
   2107 
   2108 template <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh,
   2109           class _TupleUj>
   2110 struct ____mu_return;
   2111 
   2112 template <bool _Invokable, class _Ti, class ..._Uj>
   2113 struct ____mu_return_invokable  // false
   2114 {
   2115     typedef __nat type;
   2116 };
   2117 
   2118 template <class _Ti, class ..._Uj>
   2119 struct ____mu_return_invokable<true, _Ti, _Uj...>
   2120 {
   2121     typedef typename __invoke_of<_Ti&, _Uj...>::type type;
   2122 };
   2123 
   2124 template <class _Ti, class ..._Uj>
   2125 struct ____mu_return<_Ti, false, true, false, tuple<_Uj...> >
   2126     : public ____mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...>
   2127 {
   2128 };
   2129 
   2130 template <class _Ti, class _TupleUj>
   2131 struct ____mu_return<_Ti, false, false, true, _TupleUj>
   2132 {
   2133     typedef typename tuple_element<is_placeholder<_Ti>::value - 1,
   2134                                    _TupleUj>::type&& type;
   2135 };
   2136 
   2137 template <class _Ti, class _TupleUj>
   2138 struct ____mu_return<_Ti, true, false, false, _TupleUj>
   2139 {
   2140     typedef typename _Ti::type& type;
   2141 };
   2142 
   2143 template <class _Ti, class _TupleUj>
   2144 struct ____mu_return<_Ti, false, false, false, _TupleUj>
   2145 {
   2146     typedef _Ti& type;
   2147 };
   2148 
   2149 template <class _Ti, class _TupleUj>
   2150 struct __mu_return
   2151     : public ____mu_return<_Ti,
   2152                            __is_reference_wrapper<_Ti>::value,
   2153                            is_bind_expression<_Ti>::value,
   2154                            0 < is_placeholder<_Ti>::value &&
   2155                            is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value,
   2156                            _TupleUj>
   2157 {
   2158 };
   2159 
   2160 template <class _Fp, class _BoundArgs, class _TupleUj>
   2161 struct __is_valid_bind_return
   2162 {
   2163     static const bool value = false;
   2164 };
   2165 
   2166 template <class _Fp, class ..._BoundArgs, class _TupleUj>
   2167 struct __is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj>
   2168 {
   2169     static const bool value = __invokable<_Fp,
   2170                     typename __mu_return<_BoundArgs, _TupleUj>::type...>::value;
   2171 };
   2172 
   2173 template <class _Fp, class ..._BoundArgs, class _TupleUj>
   2174 struct __is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj>
   2175 {
   2176     static const bool value = __invokable<_Fp,
   2177                     typename __mu_return<const _BoundArgs, _TupleUj>::type...>::value;
   2178 };
   2179 
   2180 template <class _Fp, class _BoundArgs, class _TupleUj,
   2181           bool = __is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value>
   2182 struct __bind_return;
   2183 
   2184 template <class _Fp, class ..._BoundArgs, class _TupleUj>
   2185 struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true>
   2186 {
   2187     typedef typename __invoke_of
   2188     <
   2189         _Fp&,
   2190         typename __mu_return
   2191         <
   2192             _BoundArgs,
   2193             _TupleUj
   2194         >::type...
   2195     >::type type;
   2196 };
   2197 
   2198 template <class _Fp, class ..._BoundArgs, class _TupleUj>
   2199 struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true>
   2200 {
   2201     typedef typename __invoke_of
   2202     <
   2203         _Fp&,
   2204         typename __mu_return
   2205         <
   2206             const _BoundArgs,
   2207             _TupleUj
   2208         >::type...
   2209     >::type type;
   2210 };
   2211 
   2212 template <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args>
   2213 inline _LIBCPP_INLINE_VISIBILITY
   2214 typename __bind_return<_Fp, _BoundArgs, _Args>::type
   2215 __apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
   2216                 _Args&& __args)
   2217 {
   2218     return __invoke(__f, __mu(_VSTD::get<_Indx>(__bound_args), __args)...);
   2219 }
   2220 
   2221 template<class _Fp, class ..._BoundArgs>
   2222 class __bind
   2223     : public __weak_result_type<typename decay<_Fp>::type>
   2224 {
   2225 protected:
   2226     typedef typename decay<_Fp>::type _Fd;
   2227     typedef tuple<typename decay<_BoundArgs>::type...> _Td;
   2228 private:
   2229     _Fd __f_;
   2230     _Td __bound_args_;
   2231 
   2232     typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices;
   2233 public:
   2234     template <class _Gp, class ..._BA,
   2235               class = typename enable_if
   2236                                <
   2237                                   is_constructible<_Fd, _Gp>::value &&
   2238                                   !is_same<typename remove_reference<_Gp>::type,
   2239                                            __bind>::value
   2240                                >::type>
   2241       _LIBCPP_INLINE_VISIBILITY
   2242       explicit __bind(_Gp&& __f, _BA&& ...__bound_args)
   2243         : __f_(_VSTD::forward<_Gp>(__f)),
   2244           __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {}
   2245 
   2246     template <class ..._Args>
   2247         _LIBCPP_INLINE_VISIBILITY
   2248         typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type
   2249         operator()(_Args&& ...__args)
   2250         {
   2251             return __apply_functor(__f_, __bound_args_, __indices(),
   2252                                   tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
   2253         }
   2254 
   2255     template <class ..._Args>
   2256         _LIBCPP_INLINE_VISIBILITY
   2257         typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type
   2258         operator()(_Args&& ...__args) const
   2259         {
   2260             return __apply_functor(__f_, __bound_args_, __indices(),
   2261                                    tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
   2262         }
   2263 };
   2264 
   2265 template<class _Fp, class ..._BoundArgs>
   2266 struct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {};
   2267 
   2268 template<class _Rp, class _Fp, class ..._BoundArgs>
   2269 class __bind_r
   2270     : public __bind<_Fp, _BoundArgs...>
   2271 {
   2272     typedef __bind<_Fp, _BoundArgs...> base;
   2273     typedef typename base::_Fd _Fd;
   2274     typedef typename base::_Td _Td;
   2275 public:
   2276     typedef _Rp result_type;
   2277 
   2278 
   2279     template <class _Gp, class ..._BA,
   2280               class = typename enable_if
   2281                                <
   2282                                   is_constructible<_Fd, _Gp>::value &&
   2283                                   !is_same<typename remove_reference<_Gp>::type,
   2284                                            __bind_r>::value
   2285                                >::type>
   2286       _LIBCPP_INLINE_VISIBILITY
   2287       explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args)
   2288         : base(_VSTD::forward<_Gp>(__f),
   2289                _VSTD::forward<_BA>(__bound_args)...) {}
   2290 
   2291     template <class ..._Args>
   2292         _LIBCPP_INLINE_VISIBILITY
   2293         typename enable_if
   2294         <
   2295             is_convertible<typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type,
   2296                            result_type>::value || is_void<_Rp>::value,
   2297             result_type
   2298         >::type
   2299         operator()(_Args&& ...__args)
   2300         {
   2301             typedef __invoke_void_return_wrapper<_Rp> _Invoker;
   2302             return _Invoker::__call(static_cast<base&>(*this), _VSTD::forward<_Args>(__args)...);
   2303         }
   2304 
   2305     template <class ..._Args>
   2306         _LIBCPP_INLINE_VISIBILITY
   2307         typename enable_if
   2308         <
   2309             is_convertible<typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type,
   2310                            result_type>::value || is_void<_Rp>::value,
   2311             result_type
   2312         >::type
   2313         operator()(_Args&& ...__args) const
   2314         {
   2315             typedef __invoke_void_return_wrapper<_Rp> _Invoker;
   2316             return _Invoker::__call(static_cast<base const&>(*this), _VSTD::forward<_Args>(__args)...);
   2317         }
   2318 };
   2319 
   2320 template<class _Rp, class _Fp, class ..._BoundArgs>
   2321 struct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {};
   2322 
   2323 template<class _Fp, class ..._BoundArgs>
   2324 inline _LIBCPP_INLINE_VISIBILITY
   2325 __bind<_Fp, _BoundArgs...>
   2326 bind(_Fp&& __f, _BoundArgs&&... __bound_args)
   2327 {
   2328     typedef __bind<_Fp, _BoundArgs...> type;
   2329     return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
   2330 }
   2331 
   2332 template<class _Rp, class _Fp, class ..._BoundArgs>
   2333 inline _LIBCPP_INLINE_VISIBILITY
   2334 __bind_r<_Rp, _Fp, _BoundArgs...>
   2335 bind(_Fp&& __f, _BoundArgs&&... __bound_args)
   2336 {
   2337     typedef __bind_r<_Rp, _Fp, _BoundArgs...> type;
   2338     return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
   2339 }
   2340 
   2341 #endif  // _LIBCPP_HAS_NO_VARIADICS
   2342 
   2343 #if _LIBCPP_STD_VER > 14
   2344 
   2345 #define __cpp_lib_invoke 201411
   2346 
   2347 template <class _Fn, class ..._Args>
   2348 result_of_t<_Fn&&(_Args&&...)>
   2349 invoke(_Fn&& __f, _Args&&... __args)
   2350     noexcept(noexcept(_VSTD::__invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...)))
   2351 {
   2352     return _VSTD::__invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...);
   2353 }
   2354 
   2355 template <class _DecayFunc>
   2356 class _LIBCPP_TEMPLATE_VIS __not_fn_imp {
   2357   _DecayFunc __fd;
   2358 
   2359 public:
   2360     __not_fn_imp() = delete;
   2361 
   2362     template <class ..._Args>
   2363     _LIBCPP_INLINE_VISIBILITY
   2364     auto operator()(_Args&& ...__args) &
   2365             noexcept(noexcept(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)))
   2366         -> decltype(          !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...))
   2367         { return              !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); }
   2368 
   2369     template <class ..._Args>
   2370     _LIBCPP_INLINE_VISIBILITY
   2371     auto operator()(_Args&& ...__args) &&
   2372             noexcept(noexcept(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)))
   2373         -> decltype(          !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...))
   2374         { return              !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); }
   2375 
   2376     template <class ..._Args>
   2377     _LIBCPP_INLINE_VISIBILITY
   2378     auto operator()(_Args&& ...__args) const&
   2379             noexcept(noexcept(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)))
   2380         -> decltype(          !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...))
   2381         { return              !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); }
   2382 
   2383 
   2384     template <class ..._Args>
   2385     _LIBCPP_INLINE_VISIBILITY
   2386     auto operator()(_Args&& ...__args) const&&
   2387             noexcept(noexcept(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)))
   2388         -> decltype(          !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...))
   2389         { return              !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); }
   2390 
   2391 private:
   2392     template <class _RawFunc,
   2393               class = enable_if_t<!is_same<decay_t<_RawFunc>, __not_fn_imp>::value>>
   2394     _LIBCPP_INLINE_VISIBILITY
   2395     explicit __not_fn_imp(_RawFunc&& __rf)
   2396         : __fd(_VSTD::forward<_RawFunc>(__rf)) {}
   2397 
   2398     template <class _RawFunc>
   2399     friend inline _LIBCPP_INLINE_VISIBILITY
   2400     __not_fn_imp<decay_t<_RawFunc>> not_fn(_RawFunc&&);
   2401 };
   2402 
   2403 template <class _RawFunc>
   2404 inline _LIBCPP_INLINE_VISIBILITY
   2405 __not_fn_imp<decay_t<_RawFunc>> not_fn(_RawFunc&& __fn) {
   2406     return __not_fn_imp<decay_t<_RawFunc>>(_VSTD::forward<_RawFunc>(__fn));
   2407 }
   2408 
   2409 #endif
   2410 
   2411 // struct hash<T*> in <memory>
   2412 
   2413 _LIBCPP_END_NAMESPACE_STD
   2414 
   2415 #endif  // _LIBCPP_FUNCTIONAL
   2416