]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/libc++/include/functional
Merge llvm, clang, lld and lldb trunk r291274, and resolve conflicts.
[FreeBSD/FreeBSD.git] / contrib / libc++ / include / functional
1 // -*- C++ -*-
2 //===------------------------ functional ----------------------------------===//
3 //
4 //                     The LLVM Compiler Infrastructure
5 //
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
8 //
9 //===----------------------------------------------------------------------===//
10
11 #ifndef _LIBCPP_FUNCTIONAL
12 #define _LIBCPP_FUNCTIONAL
13
14 /*
15     functional synopsis
16
17 namespace std
18 {
19
20 template <class Arg, class Result>
21 struct unary_function
22 {
23     typedef Arg    argument_type;
24     typedef Result result_type;
25 };
26
27 template <class Arg1, class Arg2, class Result>
28 struct binary_function
29 {
30     typedef Arg1   first_argument_type;
31     typedef Arg2   second_argument_type;
32     typedef Result result_type;
33 };
34
35 template <class T>
36 class reference_wrapper
37     : public unary_function<T1, R> // if wrapping a unary functor
38     : public binary_function<T1, T2, R> // if wraping a binary functor
39 {
40 public:
41     // types
42     typedef T type;
43     typedef see below result_type; // Not always defined
44
45     // construct/copy/destroy
46     reference_wrapper(T&) noexcept;
47     reference_wrapper(T&&) = delete; // do not bind to temps
48     reference_wrapper(const reference_wrapper<T>& x) noexcept;
49
50     // assignment
51     reference_wrapper& operator=(const reference_wrapper<T>& x) noexcept;
52
53     // access
54     operator T& () const noexcept;
55     T& get() const noexcept;
56
57     // invoke
58     template <class... ArgTypes>
59       typename result_of<T&(ArgTypes&&...)>::type
60           operator() (ArgTypes&&...) const;
61 };
62
63 template <class T> reference_wrapper<T> ref(T& t) noexcept;
64 template <class T> void ref(const T&& t) = delete;
65 template <class T> reference_wrapper<T> ref(reference_wrapper<T>t) noexcept;
66
67 template <class T> reference_wrapper<const T> cref(const T& t) noexcept;
68 template <class T> void cref(const T&& t) = delete;
69 template <class T> reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept;
70
71 template <class T> // <class T=void> in C++14
72 struct plus : binary_function<T, T, T>
73 {
74     T operator()(const T& x, const T& y) const;
75 };
76
77 template <class T> // <class T=void> in C++14
78 struct minus : binary_function<T, T, T>
79 {
80     T operator()(const T& x, const T& y) const;
81 };
82
83 template <class T> // <class T=void> in C++14
84 struct multiplies : binary_function<T, T, T>
85 {
86     T operator()(const T& x, const T& y) const;
87 };
88
89 template <class T> // <class T=void> in C++14
90 struct divides : binary_function<T, T, T>
91 {
92     T operator()(const T& x, const T& y) const;
93 };
94
95 template <class T> // <class T=void> in C++14
96 struct modulus : binary_function<T, T, T>
97 {
98     T operator()(const T& x, const T& y) const;
99 };
100
101 template <class T> // <class T=void> in C++14
102 struct negate : unary_function<T, T>
103 {
104     T operator()(const T& x) const;
105 };
106
107 template <class T> // <class T=void> in C++14
108 struct equal_to : binary_function<T, T, bool>
109 {
110     bool operator()(const T& x, const T& y) const;
111 };
112
113 template <class T> // <class T=void> in C++14
114 struct not_equal_to : binary_function<T, T, bool>
115 {
116     bool operator()(const T& x, const T& y) const;
117 };
118
119 template <class T> // <class T=void> in C++14
120 struct greater : binary_function<T, T, bool>
121 {
122     bool operator()(const T& x, const T& y) const;
123 };
124
125 template <class T> // <class T=void> in C++14
126 struct less : binary_function<T, T, bool>
127 {
128     bool operator()(const T& x, const T& y) const;
129 };
130
131 template <class T> // <class T=void> in C++14
132 struct greater_equal : binary_function<T, T, bool>
133 {
134     bool operator()(const T& x, const T& y) const;
135 };
136
137 template <class T> // <class T=void> in C++14
138 struct less_equal : binary_function<T, T, bool>
139 {
140     bool operator()(const T& x, const T& y) const;
141 };
142
143 template <class T> // <class T=void> in C++14
144 struct logical_and : binary_function<T, T, bool>
145 {
146     bool operator()(const T& x, const T& y) const;
147 };
148
149 template <class T> // <class T=void> in C++14
150 struct logical_or : binary_function<T, T, bool>
151 {
152     bool operator()(const T& x, const T& y) const;
153 };
154
155 template <class T> // <class T=void> in C++14
156 struct logical_not : unary_function<T, bool>
157 {
158     bool operator()(const T& x) const;
159 };
160
161 template <class T> // <class T=void> in C++14
162 struct bit_and : unary_function<T, bool>
163 {
164     bool operator()(const T& x, const T& y) const;
165 };
166
167 template <class T> // <class T=void> in C++14
168 struct bit_or : unary_function<T, bool>
169 {
170     bool operator()(const T& x, const T& y) const;
171 };
172
173 template <class T> // <class T=void> in C++14
174 struct bit_xor : unary_function<T, bool>
175 {
176     bool operator()(const T& x, const T& y) const;
177 };
178
179 template <class T=void> // C++14
180 struct bit_xor : unary_function<T, bool>
181 {
182     bool operator()(const T& x) const;
183 };
184
185 template <class Predicate>
186 class unary_negate
187     : public unary_function<typename Predicate::argument_type, bool>
188 {
189 public:
190     explicit unary_negate(const Predicate& pred);
191     bool operator()(const typename Predicate::argument_type& x) const;
192 };
193
194 template <class Predicate> unary_negate<Predicate> not1(const Predicate& pred);
195
196 template <class Predicate>
197 class binary_negate
198     : public binary_function<typename Predicate::first_argument_type,
199                              typename Predicate::second_argument_type,
200                              bool>
201 {
202 public:
203     explicit binary_negate(const Predicate& pred);
204     bool operator()(const typename Predicate::first_argument_type& x,
205                     const typename Predicate::second_argument_type& y) const;
206 };
207
208 template <class Predicate> binary_negate<Predicate> not2(const Predicate& pred);
209
210 template <class F> unspecified not_fn(F&& f); // C++17
211
212 template<class T> struct is_bind_expression;
213 template<class T> struct is_placeholder;
214
215 template<class Fn, class... BoundArgs>
216   unspecified bind(Fn&&, BoundArgs&&...);
217 template<class R, class Fn, class... BoundArgs>
218   unspecified bind(Fn&&, BoundArgs&&...);
219
220 namespace 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
230 template <class Operation>
231 class binder1st
232     : public unary_function<typename Operation::second_argument_type,
233                             typename Operation::result_type>
234 {
235 protected:
236     Operation                               op;
237     typename Operation::first_argument_type value;
238 public:
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
244 template <class Operation, class T>
245 binder1st<Operation> bind1st(const Operation& op, const T& x);
246
247 template <class Operation>
248 class binder2nd
249     : public unary_function<typename Operation::first_argument_type,
250                             typename Operation::result_type>
251 {
252 protected:
253     Operation                                op;
254     typename Operation::second_argument_type value;
255 public:
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
261 template <class Operation, class T>
262 binder2nd<Operation> bind2nd(const Operation& op, const T& x);
263
264 template <class Arg, class Result>
265 class pointer_to_unary_function : public unary_function<Arg, Result>
266 {
267 public:
268     explicit pointer_to_unary_function(Result (*f)(Arg));
269     Result operator()(Arg x) const;
270 };
271
272 template <class Arg, class Result>
273 pointer_to_unary_function<Arg,Result> ptr_fun(Result (*f)(Arg));
274
275 template <class Arg1, class Arg2, class Result>
276 class pointer_to_binary_function : public binary_function<Arg1, Arg2, Result>
277 {
278 public:
279     explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2));
280     Result operator()(Arg1 x, Arg2 y) const;
281 };
282
283 template <class Arg1, class Arg2, class Result>
284 pointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1,Arg2));
285
286 template<class S, class T>
287 class mem_fun_t : public unary_function<T*, S>
288 {
289 public:
290     explicit mem_fun_t(S (T::*p)());
291     S operator()(T* p) const;
292 };
293
294 template<class S, class T, class A>
295 class mem_fun1_t : public binary_function<T*, A, S>
296 {
297 public:
298     explicit mem_fun1_t(S (T::*p)(A));
299     S operator()(T* p, A x) const;
300 };
301
302 template<class S, class T>          mem_fun_t<S,T>    mem_fun(S (T::*f)());
303 template<class S, class T, class A> mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A));
304
305 template<class S, class T>
306 class mem_fun_ref_t : public unary_function<T, S>
307 {
308 public:
309     explicit mem_fun_ref_t(S (T::*p)());
310     S operator()(T& p) const;
311 };
312
313 template<class S, class T, class A>
314 class mem_fun1_ref_t : public binary_function<T, A, S>
315 {
316 public:
317     explicit mem_fun1_ref_t(S (T::*p)(A));
318     S operator()(T& p, A x) const;
319 };
320
321 template<class S, class T>          mem_fun_ref_t<S,T>    mem_fun_ref(S (T::*f)());
322 template<class S, class T, class A> mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A));
323
324 template <class S, class T>
325 class const_mem_fun_t : public unary_function<const T*, S>
326 {
327 public:
328     explicit const_mem_fun_t(S (T::*p)() const);
329     S operator()(const T* p) const;
330 };
331
332 template <class S, class T, class A>
333 class const_mem_fun1_t : public binary_function<const T*, A, S>
334 {
335 public:
336     explicit const_mem_fun1_t(S (T::*p)(A) const);
337     S operator()(const T* p, A x) const;
338 };
339
340 template <class S, class T>          const_mem_fun_t<S,T>    mem_fun(S (T::*f)() const);
341 template <class S, class T, class A> const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const);
342
343 template <class S, class T>
344 class const_mem_fun_ref_t : public unary_function<T, S>
345 {
346 public:
347     explicit const_mem_fun_ref_t(S (T::*p)() const);
348     S operator()(const T& p) const;
349 };
350
351 template <class S, class T, class A>
352 class const_mem_fun1_ref_t : public binary_function<T, A, S>
353 {
354 public:
355     explicit const_mem_fun1_ref_t(S (T::*p)(A) const);
356     S operator()(const T& p, A x) const;
357 };
358
359 template <class S, class T>          const_mem_fun_ref_t<S,T>    mem_fun_ref(S (T::*f)() const);
360 template <class S, class T, class A> const_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const);
361
362 template<class R, class T> unspecified mem_fn(R T::*);
363
364 class bad_function_call
365     : public exception
366 {
367 };
368
369 template<class> class function; // undefined
370
371 template<class R, class... ArgTypes>
372 class function<R(ArgTypes...)>
373   : public unary_function<T1, R>      // iff sizeof...(ArgTypes) == 1 and
374                                       // ArgTypes contains T1
375   : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and
376                                       // ArgTypes contains T1 and T2
377 {
378 public:
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:
427 template <class R, class ... ArgTypes>
428   bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
429
430 template <class R, class ... ArgTypes>
431   bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
432
433 template <class R, class ... ArgTypes>
434   bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
435
436 template <class  R, class ... ArgTypes>
437   bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
438
439 // specialized algorithms:
440 template <class  R, class ... ArgTypes>
441   void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
442
443 template <class T> struct hash;
444
445 template <> struct hash<bool>;
446 template <> struct hash<char>;
447 template <> struct hash<signed char>;
448 template <> struct hash<unsigned char>;
449 template <> struct hash<char16_t>;
450 template <> struct hash<char32_t>;
451 template <> struct hash<wchar_t>;
452 template <> struct hash<short>;
453 template <> struct hash<unsigned short>;
454 template <> struct hash<int>;
455 template <> struct hash<unsigned int>;
456 template <> struct hash<long>;
457 template <> struct hash<long long>;
458 template <> struct hash<unsigned long>;
459 template <> struct hash<unsigned long long>;
460
461 template <> struct hash<float>;
462 template <> struct hash<double>;
463 template <> struct hash<long double>;
464
465 template<class T> struct hash<T*>;
466
467 }  // std
468
469 POLICY:  For non-variadic implementations, the number of arguments is limited
470          to 3.  It is hoped that the need for non-variadic implementations
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
491 template <class _Tp = void>
492 #else
493 template <class _Tp>
494 #endif
495 struct _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
503 template <>
504 struct _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
518 template <class _Tp = void>
519 #else
520 template <class _Tp>
521 #endif
522 struct _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
530 template <>
531 struct _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
545 template <class _Tp = void>
546 #else
547 template <class _Tp>
548 #endif
549 struct _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
557 template <>
558 struct _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
572 template <class _Tp = void>
573 #else
574 template <class _Tp>
575 #endif
576 struct _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
584 template <>
585 struct _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
599 template <class _Tp = void>
600 #else
601 template <class _Tp>
602 #endif
603 struct _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
611 template <>
612 struct _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
626 template <class _Tp = void>
627 #else
628 template <class _Tp>
629 #endif
630 struct _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
638 template <>
639 struct _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
653 template <class _Tp = void>
654 #else
655 template <class _Tp>
656 #endif
657 struct _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
665 template <>
666 struct _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
680 template <class _Tp = void>
681 #else
682 template <class _Tp>
683 #endif
684 struct _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
692 template <>
693 struct _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
707 template <class _Tp = void>
708 #else
709 template <class _Tp>
710 #endif
711 struct _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
719 template <>
720 struct _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
736 template <class _Tp = void>
737 #else
738 template <class _Tp>
739 #endif
740 struct _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
748 template <>
749 struct _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
763 template <class _Tp = void>
764 #else
765 template <class _Tp>
766 #endif
767 struct _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
775 template <>
776 struct _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
790 template <class _Tp = void>
791 #else
792 template <class _Tp>
793 #endif
794 struct _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
802 template <>
803 struct _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
817 template <class _Tp = void>
818 #else
819 template <class _Tp>
820 #endif
821 struct _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
829 template <>
830 struct _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
844 template <class _Tp = void>
845 #else
846 template <class _Tp>
847 #endif
848 struct _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
856 template <>
857 struct _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
871 template <class _Tp = void>
872 #else
873 template <class _Tp>
874 #endif
875 struct _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
883 template <>
884 struct _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
898 template <class _Tp = void>
899 #else
900 template <class _Tp>
901 #endif
902 struct _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
910 template <>
911 struct _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
925 template <class _Tp = void>
926 #else
927 template <class _Tp>
928 #endif
929 struct _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
937 template <>
938 struct _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
952 template <class _Tp = void>
953 struct _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
960 template <>
961 struct _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
973 template <class _Predicate>
974 class _LIBCPP_TYPE_VIS_ONLY unary_negate
975     : public unary_function<typename _Predicate::argument_type, bool>
976 {
977     _Predicate __pred_;
978 public:
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
987 template <class _Predicate>
988 inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
989 unary_negate<_Predicate>
990 not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);}
991
992 template <class _Predicate>
993 class _LIBCPP_TYPE_VIS_ONLY binary_negate
994     : public binary_function<typename _Predicate::first_argument_type,
995                              typename _Predicate::second_argument_type,
996                              bool>
997 {
998     _Predicate __pred_;
999 public:
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
1009 template <class _Predicate>
1010 inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1011 binary_negate<_Predicate>
1012 not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);}
1013
1014 template <class __Operation>
1015 class _LIBCPP_TYPE_VIS_ONLY binder1st
1016     : public unary_function<typename __Operation::second_argument_type,
1017                             typename __Operation::result_type>
1018 {
1019 protected:
1020     __Operation                               op;
1021     typename __Operation::first_argument_type value;
1022 public:
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
1034 template <class __Operation, class _Tp>
1035 inline _LIBCPP_INLINE_VISIBILITY
1036 binder1st<__Operation>
1037 bind1st(const __Operation& __op, const _Tp& __x)
1038     {return binder1st<__Operation>(__op, __x);}
1039
1040 template <class __Operation>
1041 class _LIBCPP_TYPE_VIS_ONLY binder2nd
1042     : public unary_function<typename __Operation::first_argument_type,
1043                             typename __Operation::result_type>
1044 {
1045 protected:
1046     __Operation                                op;
1047     typename __Operation::second_argument_type value;
1048 public:
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
1060 template <class __Operation, class _Tp>
1061 inline _LIBCPP_INLINE_VISIBILITY
1062 binder2nd<__Operation>
1063 bind2nd(const __Operation& __op, const _Tp& __x)
1064     {return binder2nd<__Operation>(__op, __x);}
1065
1066 template <class _Arg, class _Result>
1067 class _LIBCPP_TYPE_VIS_ONLY pointer_to_unary_function
1068     : public unary_function<_Arg, _Result>
1069 {
1070     _Result (*__f_)(_Arg);
1071 public:
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
1078 template <class _Arg, class _Result>
1079 inline _LIBCPP_INLINE_VISIBILITY
1080 pointer_to_unary_function<_Arg,_Result>
1081 ptr_fun(_Result (*__f)(_Arg))
1082     {return pointer_to_unary_function<_Arg,_Result>(__f);}
1083
1084 template <class _Arg1, class _Arg2, class _Result>
1085 class _LIBCPP_TYPE_VIS_ONLY pointer_to_binary_function
1086     : public binary_function<_Arg1, _Arg2, _Result>
1087 {
1088     _Result (*__f_)(_Arg1, _Arg2);
1089 public:
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
1096 template <class _Arg1, class _Arg2, class _Result>
1097 inline _LIBCPP_INLINE_VISIBILITY
1098 pointer_to_binary_function<_Arg1,_Arg2,_Result>
1099 ptr_fun(_Result (*__f)(_Arg1,_Arg2))
1100     {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);}
1101
1102 template<class _Sp, class _Tp>
1103 class _LIBCPP_TYPE_VIS_ONLY mem_fun_t : public unary_function<_Tp*, _Sp>
1104 {
1105     _Sp (_Tp::*__p_)();
1106 public:
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
1113 template<class _Sp, class _Tp, class _Ap>
1114 class _LIBCPP_TYPE_VIS_ONLY mem_fun1_t : public binary_function<_Tp*, _Ap, _Sp>
1115 {
1116     _Sp (_Tp::*__p_)(_Ap);
1117 public:
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
1124 template<class _Sp, class _Tp>
1125 inline _LIBCPP_INLINE_VISIBILITY
1126 mem_fun_t<_Sp,_Tp>
1127 mem_fun(_Sp (_Tp::*__f)())
1128     {return mem_fun_t<_Sp,_Tp>(__f);}
1129
1130 template<class _Sp, class _Tp, class _Ap>
1131 inline _LIBCPP_INLINE_VISIBILITY
1132 mem_fun1_t<_Sp,_Tp,_Ap>
1133 mem_fun(_Sp (_Tp::*__f)(_Ap))
1134     {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1135
1136 template<class _Sp, class _Tp>
1137 class _LIBCPP_TYPE_VIS_ONLY mem_fun_ref_t : public unary_function<_Tp, _Sp>
1138 {
1139     _Sp (_Tp::*__p_)();
1140 public:
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
1147 template<class _Sp, class _Tp, class _Ap>
1148 class _LIBCPP_TYPE_VIS_ONLY mem_fun1_ref_t : public binary_function<_Tp, _Ap, _Sp>
1149 {
1150     _Sp (_Tp::*__p_)(_Ap);
1151 public:
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
1158 template<class _Sp, class _Tp>
1159 inline _LIBCPP_INLINE_VISIBILITY
1160 mem_fun_ref_t<_Sp,_Tp>
1161 mem_fun_ref(_Sp (_Tp::*__f)())
1162     {return mem_fun_ref_t<_Sp,_Tp>(__f);}
1163
1164 template<class _Sp, class _Tp, class _Ap>
1165 inline _LIBCPP_INLINE_VISIBILITY
1166 mem_fun1_ref_t<_Sp,_Tp,_Ap>
1167 mem_fun_ref(_Sp (_Tp::*__f)(_Ap))
1168     {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
1169
1170 template <class _Sp, class _Tp>
1171 class _LIBCPP_TYPE_VIS_ONLY const_mem_fun_t : public unary_function<const _Tp*, _Sp>
1172 {
1173     _Sp (_Tp::*__p_)() const;
1174 public:
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
1181 template <class _Sp, class _Tp, class _Ap>
1182 class _LIBCPP_TYPE_VIS_ONLY const_mem_fun1_t : public binary_function<const _Tp*, _Ap, _Sp>
1183 {
1184     _Sp (_Tp::*__p_)(_Ap) const;
1185 public:
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
1192 template <class _Sp, class _Tp>
1193 inline _LIBCPP_INLINE_VISIBILITY
1194 const_mem_fun_t<_Sp,_Tp>
1195 mem_fun(_Sp (_Tp::*__f)() const)
1196     {return const_mem_fun_t<_Sp,_Tp>(__f);}
1197
1198 template <class _Sp, class _Tp, class _Ap>
1199 inline _LIBCPP_INLINE_VISIBILITY
1200 const_mem_fun1_t<_Sp,_Tp,_Ap>
1201 mem_fun(_Sp (_Tp::*__f)(_Ap) const)
1202     {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1203
1204 template <class _Sp, class _Tp>
1205 class _LIBCPP_TYPE_VIS_ONLY const_mem_fun_ref_t : public unary_function<_Tp, _Sp>
1206 {
1207     _Sp (_Tp::*__p_)() const;
1208 public:
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
1215 template <class _Sp, class _Tp, class _Ap>
1216 class _LIBCPP_TYPE_VIS_ONLY const_mem_fun1_ref_t
1217     : public binary_function<_Tp, _Ap, _Sp>
1218 {
1219     _Sp (_Tp::*__p_)(_Ap) const;
1220 public:
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
1227 template <class _Sp, class _Tp>
1228 inline _LIBCPP_INLINE_VISIBILITY
1229 const_mem_fun_ref_t<_Sp,_Tp>
1230 mem_fun_ref(_Sp (_Tp::*__f)() const)
1231     {return const_mem_fun_ref_t<_Sp,_Tp>(__f);}
1232
1233 template <class _Sp, class _Tp, class _Ap>
1234 inline _LIBCPP_INLINE_VISIBILITY
1235 const_mem_fun1_ref_t<_Sp,_Tp,_Ap>
1236 mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const)
1237     {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
1238
1239 ////////////////////////////////////////////////////////////////////////////////
1240 //                                MEMFUN
1241 //==============================================================================
1242
1243 template <class _Tp>
1244 class __mem_fn
1245     : public __weak_result_type<_Tp>
1246 {
1247 public:
1248     // types
1249     typedef _Tp type;
1250 private:
1251     type __f_;
1252
1253 public:
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
1366 template<class _Rp, class _Tp>
1367 inline _LIBCPP_INLINE_VISIBILITY
1368 __mem_fn<_Rp _Tp::*>
1369 mem_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
1380 class _LIBCPP_EXCEPTION_ABI bad_function_call
1381     : public exception
1382 {
1383 };
1384
1385 template<class _Fp> class _LIBCPP_TYPE_VIS_ONLY function; // undefined
1386
1387 namespace __function
1388 {
1389
1390 template<class _Rp>
1391 struct __maybe_derive_from_unary_function
1392 {
1393 };
1394
1395 template<class _Rp, class _A1>
1396 struct __maybe_derive_from_unary_function<_Rp(_A1)>
1397     : public unary_function<_A1, _Rp>
1398 {
1399 };
1400
1401 template<class _Rp>
1402 struct __maybe_derive_from_binary_function
1403 {
1404 };
1405
1406 template<class _Rp, class _A1, class _A2>
1407 struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)>
1408     : public binary_function<_A1, _A2, _Rp>
1409 {
1410 };
1411
1412 template <class _Fp>
1413 _LIBCPP_INLINE_VISIBILITY
1414 bool __not_null(_Fp const&) { return true; }
1415
1416 template <class _Fp>
1417 _LIBCPP_INLINE_VISIBILITY
1418 bool __not_null(_Fp* __ptr) { return __ptr; }
1419
1420 template <class _Ret, class _Class>
1421 _LIBCPP_INLINE_VISIBILITY
1422 bool __not_null(_Ret _Class::*__ptr) { return __ptr; }
1423
1424 template <class _Fp>
1425 _LIBCPP_INLINE_VISIBILITY
1426 bool __not_null(function<_Fp> const& __f) { return !!__f; }
1427
1428 } // namespace __function
1429
1430 #ifndef _LIBCPP_HAS_NO_VARIADICS
1431
1432 namespace __function {
1433
1434 template<class _Fp> class __base;
1435
1436 template<class _Rp, class ..._ArgTypes>
1437 class __base<_Rp(_ArgTypes...)>
1438 {
1439     __base(const __base&);
1440     __base& operator=(const __base&);
1441 public:
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
1455 template<class _FD, class _Alloc, class _FB> class __func;
1456
1457 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1458 class __func<_Fp, _Alloc, _Rp(_ArgTypes...)>
1459     : public  __base<_Rp(_ArgTypes...)>
1460 {
1461     __compressed_pair<_Fp, _Alloc> __f_;
1462 public:
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
1492 template<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
1505 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1506 void
1507 __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const
1508 {
1509     ::new (__p) __func(__f_.first(), __f_.second());
1510 }
1511
1512 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1513 void
1514 __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPT
1515 {
1516     __f_.~__compressed_pair<_Fp, _Alloc>();
1517 }
1518
1519 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1520 void
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
1530 template<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
1540 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1541 const 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
1549 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1550 const std::type_info&
1551 __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
1552 {
1553     return typeid(_Fp);
1554 }
1555
1556 #endif  // _LIBCPP_NO_RTTI
1557
1558 }  // __function
1559
1560 template<class _Rp, class ..._ArgTypes>
1561 class _LIBCPP_TYPE_VIS_ONLY function<_Rp(_ArgTypes...)>
1562     : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>,
1563       public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)>
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         };
1588 public:
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;
1652 public:
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
1664 template<class _Rp, class ..._ArgTypes>
1665 function<_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
1678 template<class _Rp, class ..._ArgTypes>
1679 template <class _Alloc>
1680 function<_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
1694 template<class _Rp, class ..._ArgTypes>
1695 function<_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
1711 template<class _Rp, class ..._ArgTypes>
1712 template <class _Alloc>
1713 function<_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
1730 template<class _Rp, class ..._ArgTypes>
1731 template <class _Fp>
1732 function<_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
1759 template<class _Rp, class ..._ArgTypes>
1760 template <class _Fp, class _Alloc>
1761 function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f,
1762                                      typename enable_if<__callable<_Fp>::value>::type*)
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
1786 template<class _Rp, class ..._ArgTypes>
1787 function<_Rp(_ArgTypes...)>&
1788 function<_Rp(_ArgTypes...)>::operator=(const function& __f)
1789 {
1790     function(__f).swap(*this);
1791     return *this;
1792 }
1793
1794 template<class _Rp, class ..._ArgTypes>
1795 function<_Rp(_ArgTypes...)>&
1796 function<_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
1818 template<class _Rp, class ..._ArgTypes>
1819 function<_Rp(_ArgTypes...)>&
1820 function<_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
1830 template<class _Rp, class ..._ArgTypes>
1831 template <class _Fp>
1832 typename 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
1838 function<_Rp(_ArgTypes...)>::operator=(_Fp&& __f)
1839 {
1840     function(_VSTD::forward<_Fp>(__f)).swap(*this);
1841     return *this;
1842 }
1843
1844 template<class _Rp, class ..._ArgTypes>
1845 function<_Rp(_ArgTypes...)>::~function()
1846 {
1847     if ((void *)__f_ == &__buf_)
1848         __f_->destroy();
1849     else if (__f_)
1850         __f_->destroy_deallocate();
1851 }
1852
1853 template<class _Rp, class ..._ArgTypes>
1854 void
1855 function<_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
1890 template<class _Rp, class ..._ArgTypes>
1891 _Rp
1892 function<_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
1903 template<class _Rp, class ..._ArgTypes>
1904 const std::type_info&
1905 function<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
1906 {
1907     if (__f_ == 0)
1908         return typeid(void);
1909     return __f_->target_type();
1910 }
1911
1912 template<class _Rp, class ..._ArgTypes>
1913 template <typename _Tp>
1914 _Tp*
1915 function<_Rp(_ArgTypes...)>::target() _NOEXCEPT
1916 {
1917     if (__f_ == 0)
1918         return (_Tp*)0;
1919     return (_Tp*)__f_->target(typeid(_Tp));
1920 }
1921
1922 template<class _Rp, class ..._ArgTypes>
1923 template <typename _Tp>
1924 const _Tp*
1925 function<_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
1934 template <class _Rp, class... _ArgTypes>
1935 inline _LIBCPP_INLINE_VISIBILITY
1936 bool
1937 operator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;}
1938
1939 template <class _Rp, class... _ArgTypes>
1940 inline _LIBCPP_INLINE_VISIBILITY
1941 bool
1942 operator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;}
1943
1944 template <class _Rp, class... _ArgTypes>
1945 inline _LIBCPP_INLINE_VISIBILITY
1946 bool
1947 operator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;}
1948
1949 template <class _Rp, class... _ArgTypes>
1950 inline _LIBCPP_INLINE_VISIBILITY
1951 bool
1952 operator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;}
1953
1954 template <class _Rp, class... _ArgTypes>
1955 inline _LIBCPP_INLINE_VISIBILITY
1956 void
1957 swap(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
1970 template<class _Tp> struct __is_bind_expression : public false_type {};
1971 template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_bind_expression
1972     : public __is_bind_expression<typename remove_cv<_Tp>::type> {};
1973
1974 template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {};
1975 template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_placeholder
1976     : public __is_placeholder<typename remove_cv<_Tp>::type> {};
1977
1978 namespace placeholders
1979 {
1980
1981 template <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
1995 constexpr __ph<1>   _1{};
1996 constexpr __ph<2>   _2{};
1997 constexpr __ph<3>   _3{};
1998 constexpr __ph<4>   _4{};
1999 constexpr __ph<5>   _5{};
2000 constexpr __ph<6>   _6{};
2001 constexpr __ph<7>   _7{};
2002 constexpr __ph<8>   _8{};
2003 constexpr __ph<9>   _9{};
2004 constexpr __ph<10> _10{};
2005 #endif // defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_BIND)
2006
2007 }  // placeholders
2008
2009 template<int _Np>
2010 struct __is_placeholder<placeholders::__ph<_Np> >
2011     : public integral_constant<int, _Np> {};
2012
2013
2014 #ifndef _LIBCPP_HAS_NO_VARIADICS
2015
2016 template <class _Tp, class _Uj>
2017 inline _LIBCPP_INLINE_VISIBILITY
2018 _Tp&
2019 __mu(reference_wrapper<_Tp> __t, _Uj&)
2020 {
2021     return __t.get();
2022 }
2023
2024 template <class _Ti, class ..._Uj, size_t ..._Indx>
2025 inline _LIBCPP_INLINE_VISIBILITY
2026 typename __invoke_of<_Ti&, _Uj...>::type
2027 __mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>)
2028 {
2029     return __ti(_VSTD::forward<_Uj>(_VSTD::get<_Indx>(__uj))...);
2030 }
2031
2032 template <class _Ti, class ..._Uj>
2033 inline _LIBCPP_INLINE_VISIBILITY
2034 typename __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
2045 template <bool IsPh, class _Ti, class _Uj>
2046 struct __mu_return2 {};
2047
2048 template <class _Ti, class _Uj>
2049 struct __mu_return2<true, _Ti, _Uj>
2050 {
2051     typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type;
2052 };
2053
2054 template <class _Ti, class _Uj>
2055 inline _LIBCPP_INLINE_VISIBILITY
2056 typename 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
2067 template <class _Ti, class _Uj>
2068 inline _LIBCPP_INLINE_VISIBILITY
2069 typename 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
2081 template <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh,
2082           class _TupleUj>
2083 struct ____mu_return;
2084
2085 template <bool _Invokable, class _Ti, class ..._Uj>
2086 struct ____mu_return_invokable  // false
2087 {
2088     typedef __nat type;
2089 };
2090
2091 template <class _Ti, class ..._Uj>
2092 struct ____mu_return_invokable<true, _Ti, _Uj...>
2093 {
2094     typedef typename __invoke_of<_Ti&, _Uj...>::type type;
2095 };
2096
2097 template <class _Ti, class ..._Uj>
2098 struct ____mu_return<_Ti, false, true, false, tuple<_Uj...> >
2099     : public ____mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...>
2100 {
2101 };
2102
2103 template <class _Ti, class _TupleUj>
2104 struct ____mu_return<_Ti, false, false, true, _TupleUj>
2105 {
2106     typedef typename tuple_element<is_placeholder<_Ti>::value - 1,
2107                                    _TupleUj>::type&& type;
2108 };
2109
2110 template <class _Ti, class _TupleUj>
2111 struct ____mu_return<_Ti, true, false, false, _TupleUj>
2112 {
2113     typedef typename _Ti::type& type;
2114 };
2115
2116 template <class _Ti, class _TupleUj>
2117 struct ____mu_return<_Ti, false, false, false, _TupleUj>
2118 {
2119     typedef _Ti& type;
2120 };
2121
2122 template <class _Ti, class _TupleUj>
2123 struct __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
2133 template <class _Fp, class _BoundArgs, class _TupleUj>
2134 struct __is_valid_bind_return
2135 {
2136     static const bool value = false;
2137 };
2138
2139 template <class _Fp, class ..._BoundArgs, class _TupleUj>
2140 struct __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
2146 template <class _Fp, class ..._BoundArgs, class _TupleUj>
2147 struct __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
2153 template <class _Fp, class _BoundArgs, class _TupleUj,
2154           bool = __is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value>
2155 struct __bind_return;
2156
2157 template <class _Fp, class ..._BoundArgs, class _TupleUj>
2158 struct __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
2171 template <class _Fp, class ..._BoundArgs, class _TupleUj>
2172 struct __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
2185 template <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args>
2186 inline _LIBCPP_INLINE_VISIBILITY
2187 typename __bind_return<_Fp, _BoundArgs, _Args>::type
2188 __apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
2189                 _Args&& __args)
2190 {
2191     return __invoke(__f, __mu(_VSTD::get<_Indx>(__bound_args), __args)...);
2192 }
2193
2194 template<class _Fp, class ..._BoundArgs>
2195 class __bind
2196     : public __weak_result_type<typename decay<_Fp>::type>
2197 {
2198 protected:
2199     typedef typename decay<_Fp>::type _Fd;
2200     typedef tuple<typename decay<_BoundArgs>::type...> _Td;
2201 private:
2202     _Fd __f_;
2203     _Td __bound_args_;
2204
2205     typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices;
2206 public:
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
2268 template<class _Fp, class ..._BoundArgs>
2269 struct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {};
2270
2271 template<class _Rp, class _Fp, class ..._BoundArgs>
2272 class __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;
2278 public:
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
2348 template<class _Rp, class _Fp, class ..._BoundArgs>
2349 struct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {};
2350
2351 template<class _Fp, class ..._BoundArgs>
2352 inline _LIBCPP_INLINE_VISIBILITY
2353 __bind<_Fp, _BoundArgs...>
2354 bind(_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
2360 template<class _Rp, class _Fp, class ..._BoundArgs>
2361 inline _LIBCPP_INLINE_VISIBILITY
2362 __bind_r<_Rp, _Fp, _BoundArgs...>
2363 bind(_Fp&& __f, _BoundArgs&&... __bound_args)
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
2371 template <>
2372 struct _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
2379 template <>
2380 struct _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
2387 template <>
2388 struct _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
2395 template <>
2396 struct _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
2405 template <>
2406 struct _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
2413 template <>
2414 struct _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
2423 template <>
2424 struct _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
2431 template <>
2432 struct _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
2439 template <>
2440 struct _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
2447 template <>
2448 struct _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
2455 template <>
2456 struct _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
2463 template <>
2464 struct _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
2471 template <>
2472 struct _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
2479 template <>
2480 struct _LIBCPP_TYPE_VIS_ONLY hash<long long>
2481     : public __scalar_hash<long long>
2482 {
2483 };
2484
2485 template <>
2486 struct _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
2493 template <>
2494 struct _LIBCPP_TYPE_VIS_ONLY hash<__int128_t>
2495     : public __scalar_hash<__int128_t>
2496 {
2497 };
2498
2499 template <>
2500 struct _LIBCPP_TYPE_VIS_ONLY hash<__uint128_t>
2501     : public __scalar_hash<__uint128_t>
2502 {
2503 };
2504
2505 #endif
2506
2507 template <>
2508 struct _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
2521 template <>
2522 struct _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
2535 template <>
2536 struct _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
2586 template <class _Tp>
2587 struct _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
2604 template <class _Fn, class ..._Args>
2605 result_of_t<_Fn&&(_Args&&...)>
2606 invoke(_Fn&& __f, _Args&&... __args)
2607     noexcept(noexcept(_VSTD::__invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...)))
2608 {
2609     return _VSTD::__invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...);
2610 }
2611
2612 template <class _DecayFunc>
2613 class _LIBCPP_TYPE_VIS_ONLY __not_fn_imp {
2614   _DecayFunc __fd;
2615
2616 public:
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
2648 private:
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
2660 template <class _RawFunc>
2661 inline _LIBCPP_INLINE_VISIBILITY
2662 __not_fn_imp<decay_t<_RawFunc>> not_fn(_RawFunc&& __fn) {
2663     return __not_fn_imp<decay_t<_RawFunc>>(_VSTD::forward<_RawFunc>(__fn));
2664 }
2665
2666 #endif
2667
2668 // struct hash<T*> in <memory>
2669
2670 _LIBCPP_END_NAMESPACE_STD
2671
2672 #endif  // _LIBCPP_FUNCTIONAL