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