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