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