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