functional revision 232950
1227825Stheraven// -*- C++ -*-
2227825Stheraven//===------------------------ functional ----------------------------------===//
3227825Stheraven//
4227825Stheraven//                     The LLVM Compiler Infrastructure
5227825Stheraven//
6227825Stheraven// This file is dual licensed under the MIT and the University of Illinois Open
7227825Stheraven// Source Licenses. See LICENSE.TXT for details.
8227825Stheraven//
9227825Stheraven//===----------------------------------------------------------------------===//
10227825Stheraven
11227825Stheraven#ifndef _LIBCPP_FUNCTIONAL
12227825Stheraven#define _LIBCPP_FUNCTIONAL
13227825Stheraven
14227825Stheraven/*
15227825Stheraven    functional synopsis
16227825Stheraven
17227825Stheravennamespace std
18227825Stheraven{
19227825Stheraven
20227825Stheraventemplate <class Arg, class Result>
21227825Stheravenstruct unary_function
22227825Stheraven{
23227825Stheraven    typedef Arg    argument_type;
24227825Stheraven    typedef Result result_type;
25227825Stheraven};
26227825Stheraven
27227825Stheraventemplate <class Arg1, class Arg2, class Result>
28227825Stheravenstruct binary_function
29227825Stheraven{
30227825Stheraven    typedef Arg1   first_argument_type;
31227825Stheraven    typedef Arg2   second_argument_type;
32227825Stheraven    typedef Result result_type;
33227825Stheraven};
34227825Stheraven
35227825Stheraventemplate <class T>
36227825Stheravenclass reference_wrapper
37227825Stheraven    : public unary_function<T1, R> // if wrapping a unary functor
38227825Stheraven    : public binary_function<T1, T2, R> // if wraping a binary functor
39227825Stheraven{
40227825Stheravenpublic:
41227825Stheraven    // types
42227825Stheraven    typedef T type;
43227825Stheraven    typedef see below result_type; // Not always defined
44227825Stheraven
45227825Stheraven    // construct/copy/destroy
46227825Stheraven    reference_wrapper(T&) noexcept;
47227825Stheraven    reference_wrapper(T&&) = delete; // do not bind to temps
48227825Stheraven    reference_wrapper(const reference_wrapper<T>& x) noexcept;
49227825Stheraven
50227825Stheraven    // assignment
51227825Stheraven    reference_wrapper& operator=(const reference_wrapper<T>& x) noexcept;
52227825Stheraven
53227825Stheraven    // access
54227825Stheraven    operator T& () const noexcept;
55227825Stheraven    T& get() const noexcept;
56227825Stheraven
57227825Stheraven    // invoke
58227825Stheraven    template <class... ArgTypes>
59227825Stheraven      typename result_of<T(ArgTypes...)>::type
60227825Stheraven          operator() (ArgTypes&&...) const;
61227825Stheraven};
62227825Stheraven
63227825Stheraventemplate <class T> reference_wrapper<T> ref(T& t) noexcept;
64227825Stheraventemplate <class T> void ref(const T&& t) = delete;
65227825Stheraventemplate <class T> reference_wrapper<T> ref(reference_wrapper<T>t) noexcept;
66227825Stheraven
67227825Stheraventemplate <class T> reference_wrapper<const T> cref(const T& t) noexcept;
68227825Stheraventemplate <class T> void cref(const T&& t) = delete;
69227825Stheraventemplate <class T> reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept;
70227825Stheraven
71227825Stheraventemplate <class T>
72227825Stheravenstruct plus : binary_function<T, T, T>
73227825Stheraven{
74227825Stheraven    T operator()(const T& x, const T& y) const;
75227825Stheraven};
76227825Stheraven
77227825Stheraventemplate <class T>
78227825Stheravenstruct minus : binary_function<T, T, T>
79227825Stheraven{
80227825Stheraven    T operator()(const T& x, const T& y) const;
81227825Stheraven};
82227825Stheraven
83227825Stheraventemplate <class T>
84227825Stheravenstruct multiplies : binary_function<T, T, T>
85227825Stheraven{
86227825Stheraven    T operator()(const T& x, const T& y) const;
87227825Stheraven};
88227825Stheraven
89227825Stheraventemplate <class T>
90227825Stheravenstruct divides : binary_function<T, T, T>
91227825Stheraven{
92227825Stheraven    T operator()(const T& x, const T& y) const;
93227825Stheraven};
94227825Stheraven
95227825Stheraventemplate <class T>
96227825Stheravenstruct modulus : binary_function<T, T, T>
97227825Stheraven{
98227825Stheraven    T operator()(const T& x, const T& y) const;
99227825Stheraven};
100227825Stheraven
101227825Stheraventemplate <class T>
102227825Stheravenstruct negate : unary_function<T, T>
103227825Stheraven{
104227825Stheraven    T operator()(const T& x) const;
105227825Stheraven};
106227825Stheraven
107227825Stheraventemplate <class T>
108227825Stheravenstruct equal_to : binary_function<T, T, bool>
109227825Stheraven{
110227825Stheraven    bool operator()(const T& x, const T& y) const;
111227825Stheraven};
112227825Stheraven
113227825Stheraventemplate <class T>
114227825Stheravenstruct not_equal_to : binary_function<T, T, bool>
115227825Stheraven{
116227825Stheraven    bool operator()(const T& x, const T& y) const;
117227825Stheraven};
118227825Stheraven
119227825Stheraventemplate <class T>
120227825Stheravenstruct greater : binary_function<T, T, bool>
121227825Stheraven{
122227825Stheraven    bool operator()(const T& x, const T& y) const;
123227825Stheraven};
124227825Stheraven
125227825Stheraventemplate <class T>
126227825Stheravenstruct less : binary_function<T, T, bool>
127227825Stheraven{
128227825Stheraven    bool operator()(const T& x, const T& y) const;
129227825Stheraven};
130227825Stheraven
131227825Stheraventemplate <class T>
132227825Stheravenstruct greater_equal : binary_function<T, T, bool>
133227825Stheraven{
134227825Stheraven    bool operator()(const T& x, const T& y) const;
135227825Stheraven};
136227825Stheraven
137227825Stheraventemplate <class T>
138227825Stheravenstruct less_equal : binary_function<T, T, bool>
139227825Stheraven{
140227825Stheraven    bool operator()(const T& x, const T& y) const;
141227825Stheraven};
142227825Stheraven
143227825Stheraventemplate <class T>
144227825Stheravenstruct logical_and : binary_function<T, T, bool>
145227825Stheraven{
146227825Stheraven    bool operator()(const T& x, const T& y) const;
147227825Stheraven};
148227825Stheraven
149227825Stheraventemplate <class T>
150227825Stheravenstruct logical_or : binary_function<T, T, bool>
151227825Stheraven{
152227825Stheraven    bool operator()(const T& x, const T& y) const;
153227825Stheraven};
154227825Stheraven
155227825Stheraventemplate <class T>
156227825Stheravenstruct logical_not : unary_function<T, bool>
157227825Stheraven{
158227825Stheraven    bool operator()(const T& x) const;
159227825Stheraven};
160227825Stheraven
161227825Stheraventemplate <class Predicate>
162227825Stheravenclass unary_negate
163227825Stheraven    : public unary_function<typename Predicate::argument_type, bool>
164227825Stheraven{
165227825Stheravenpublic:
166227825Stheraven    explicit unary_negate(const Predicate& pred);
167227825Stheraven    bool operator()(const typename Predicate::argument_type& x) const;
168227825Stheraven};
169227825Stheraven
170227825Stheraventemplate <class Predicate> unary_negate<Predicate> not1(const Predicate& pred);
171227825Stheraven
172227825Stheraventemplate <class Predicate>
173227825Stheravenclass binary_negate
174227825Stheraven    : public binary_function<typename Predicate::first_argument_type,
175227825Stheraven                             typename Predicate::second_argument_type,
176227825Stheraven                             bool>
177227825Stheraven{
178227825Stheravenpublic:
179227825Stheraven    explicit binary_negate(const Predicate& pred);
180227825Stheraven    bool operator()(const typename Predicate::first_argument_type& x,
181227825Stheraven                    const typename Predicate::second_argument_type& y) const;
182227825Stheraven};
183227825Stheraven
184227825Stheraventemplate <class Predicate> binary_negate<Predicate> not2(const Predicate& pred);
185227825Stheraven
186227825Stheraventemplate<class T> struct is_bind_expression;
187227825Stheraventemplate<class T> struct is_placeholder;
188227825Stheraven
189227825Stheraventemplate<class Fn, class... BoundArgs>
190227825Stheraven  unspecified bind(Fn&&, BoundArgs&&...);
191227825Stheraventemplate<class R, class Fn, class... BoundArgs>
192227825Stheraven  unspecified bind(Fn&&, BoundArgs&&...);
193227825Stheraven
194227825Stheravennamespace placeholders {
195227825Stheraven  // M is the implementation-defined number of placeholders
196227825Stheraven  extern unspecified _1;
197227825Stheraven  extern unspecified _2;
198227825Stheraven  .
199227825Stheraven  .
200227825Stheraven  .
201232950Stheraven  extern unspecified _Mp;
202227825Stheraven}
203227825Stheraven
204227825Stheraventemplate <class Operation>
205227825Stheravenclass binder1st
206227825Stheraven    : public unary_function<typename Operation::second_argument_type,
207227825Stheraven                            typename Operation::result_type>
208227825Stheraven{
209227825Stheravenprotected:
210227825Stheraven    Operation                               op;
211227825Stheraven    typename Operation::first_argument_type value;
212227825Stheravenpublic:
213227825Stheraven    binder1st(const Operation& x, const typename Operation::first_argument_type y);
214227825Stheraven    typename Operation::result_type operator()(      typename Operation::second_argument_type& x) const;
215227825Stheraven    typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const;
216227825Stheraven};
217227825Stheraven
218227825Stheraventemplate <class Operation, class T>
219227825Stheravenbinder1st<Operation> bind1st(const Operation& op, const T& x);
220227825Stheraven
221227825Stheraventemplate <class Operation>
222227825Stheravenclass binder2nd
223227825Stheraven    : public unary_function<typename Operation::first_argument_type,
224227825Stheraven                            typename Operation::result_type>
225227825Stheraven{
226227825Stheravenprotected:
227227825Stheraven    Operation                                op;
228227825Stheraven    typename Operation::second_argument_type value;
229227825Stheravenpublic:
230227825Stheraven    binder2nd(const Operation& x, const typename Operation::second_argument_type y);
231227825Stheraven    typename Operation::result_type operator()(      typename Operation::first_argument_type& x) const;
232227825Stheraven    typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const;
233227825Stheraven};
234227825Stheraven
235227825Stheraventemplate <class Operation, class T>
236227825Stheravenbinder2nd<Operation> bind2nd(const Operation& op, const T& x);
237227825Stheraven
238227825Stheraventemplate <class Arg, class Result>
239227825Stheravenclass pointer_to_unary_function : public unary_function<Arg, Result>
240227825Stheraven{
241227825Stheravenpublic:
242227825Stheraven    explicit pointer_to_unary_function(Result (*f)(Arg));
243227825Stheraven    Result operator()(Arg x) const;
244227825Stheraven};
245227825Stheraven
246227825Stheraventemplate <class Arg, class Result>
247227825Stheravenpointer_to_unary_function<Arg,Result> ptr_fun(Result (*f)(Arg));
248227825Stheraven
249227825Stheraventemplate <class Arg1, class Arg2, class Result>
250227825Stheravenclass pointer_to_binary_function : public binary_function<Arg1, Arg2, Result>
251227825Stheraven{
252227825Stheravenpublic:
253227825Stheraven    explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2));
254227825Stheraven    Result operator()(Arg1 x, Arg2 y) const;
255227825Stheraven};
256227825Stheraven
257227825Stheraventemplate <class Arg1, class Arg2, class Result>
258227825Stheravenpointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1,Arg2));
259227825Stheraven
260227825Stheraventemplate<class S, class T>
261227825Stheravenclass mem_fun_t : public unary_function<T*, S>
262227825Stheraven{
263227825Stheravenpublic:
264227825Stheraven    explicit mem_fun_t(S (T::*p)());
265227825Stheraven    S operator()(T* p) const;
266227825Stheraven};
267227825Stheraven
268227825Stheraventemplate<class S, class T, class A>
269227825Stheravenclass mem_fun1_t : public binary_function<T*, A, S>
270227825Stheraven{
271227825Stheravenpublic:
272227825Stheraven    explicit mem_fun1_t(S (T::*p)(A));
273227825Stheraven    S operator()(T* p, A x) const;
274227825Stheraven};
275227825Stheraven
276227825Stheraventemplate<class S, class T>          mem_fun_t<S,T>    mem_fun(S (T::*f)());
277227825Stheraventemplate<class S, class T, class A> mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A));
278227825Stheraven
279227825Stheraventemplate<class S, class T>
280227825Stheravenclass mem_fun_ref_t : public unary_function<T, S>
281227825Stheraven{
282227825Stheravenpublic:
283227825Stheraven    explicit mem_fun_ref_t(S (T::*p)());
284227825Stheraven    S operator()(T& p) const;
285227825Stheraven};
286227825Stheraven
287227825Stheraventemplate<class S, class T, class A>
288227825Stheravenclass mem_fun1_ref_t : public binary_function<T, A, S>
289227825Stheraven{
290227825Stheravenpublic:
291227825Stheraven    explicit mem_fun1_ref_t(S (T::*p)(A));
292227825Stheraven    S operator()(T& p, A x) const;
293227825Stheraven};
294227825Stheraven
295227825Stheraventemplate<class S, class T>          mem_fun_ref_t<S,T>    mem_fun_ref(S (T::*f)());
296227825Stheraventemplate<class S, class T, class A> mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A));
297227825Stheraven
298227825Stheraventemplate <class S, class T>
299227825Stheravenclass const_mem_fun_t : public unary_function<const T*, S>
300227825Stheraven{
301227825Stheravenpublic:
302227825Stheraven    explicit const_mem_fun_t(S (T::*p)() const);
303227825Stheraven    S operator()(const T* p) const;
304227825Stheraven};
305227825Stheraven
306227825Stheraventemplate <class S, class T, class A>
307227825Stheravenclass const_mem_fun1_t : public binary_function<const T*, A, S>
308227825Stheraven{
309227825Stheravenpublic:
310227825Stheraven    explicit const_mem_fun1_t(S (T::*p)(A) const);
311227825Stheraven    S operator()(const T* p, A x) const;
312227825Stheraven};
313227825Stheraven
314227825Stheraventemplate <class S, class T>          const_mem_fun_t<S,T>    mem_fun(S (T::*f)() const);
315227825Stheraventemplate <class S, class T, class A> const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const);
316227825Stheraven
317227825Stheraventemplate <class S, class T>
318227825Stheravenclass const_mem_fun_ref_t : public unary_function<T, S>
319227825Stheraven{
320227825Stheravenpublic:
321227825Stheraven    explicit const_mem_fun_ref_t(S (T::*p)() const);
322227825Stheraven    S operator()(const T& p) const;
323227825Stheraven};
324227825Stheraven
325227825Stheraventemplate <class S, class T, class A>
326227825Stheravenclass const_mem_fun1_ref_t : public binary_function<T, A, S>
327227825Stheraven{
328227825Stheravenpublic:
329227825Stheraven    explicit const_mem_fun1_ref_t(S (T::*p)(A) const);
330227825Stheraven    S operator()(const T& p, A x) const;
331227825Stheraven};
332227825Stheraven
333227825Stheraventemplate <class S, class T>          const_mem_fun_ref_t<S,T>    mem_fun_ref(S (T::*f)() const);
334227825Stheraventemplate <class S, class T, class A> const_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const);
335227825Stheraven
336227825Stheraventemplate<class R, class T> unspecified mem_fn(R T::*);
337227825Stheraventemplate<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...));
338227825Stheraventemplate<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const);
339227825Stheraventemplate<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) volatile);
340227825Stheraventemplate<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const volatile);
341227825Stheraventemplate<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) &);
342227825Stheraventemplate<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const &);
343227825Stheraventemplate<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) volatile &);
344227825Stheraventemplate<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const volatile &);
345227825Stheraventemplate<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) &&);
346227825Stheraventemplate<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const &&);
347227825Stheraventemplate<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) volatile &&);
348227825Stheraventemplate<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const volatile &&);
349227825Stheraven
350227825Stheravenclass bad_function_call
351227825Stheraven    : public exception
352227825Stheraven{
353227825Stheraven};
354227825Stheraven
355227825Stheraventemplate<class> class function; // undefined
356227825Stheraven
357227825Stheraventemplate<class R, class... ArgTypes>
358227825Stheravenclass function<R(ArgTypes...)>
359227825Stheraven  : public unary_function<T1, R>      // iff sizeof...(ArgTypes) == 1 and
360227825Stheraven                                      // ArgTypes contains T1
361227825Stheraven  : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and
362227825Stheraven                                      // ArgTypes contains T1 and T2
363227825Stheraven{
364227825Stheravenpublic:
365227825Stheraven    typedef R result_type;
366227825Stheraven
367227825Stheraven    // construct/copy/destroy:
368227825Stheraven    function() noexcept;
369227825Stheraven    function(nullptr_t) noexcept;
370227825Stheraven    function(const function&);
371227825Stheraven    function(function&&) noexcept;
372227825Stheraven    template<class F>
373227825Stheraven      function(F);
374227825Stheraven    template<Allocator Alloc>
375227825Stheraven      function(allocator_arg_t, const Alloc&) noexcept;
376227825Stheraven    template<Allocator Alloc>
377227825Stheraven      function(allocator_arg_t, const Alloc&, nullptr_t) noexcept;
378227825Stheraven    template<Allocator Alloc>
379227825Stheraven      function(allocator_arg_t, const Alloc&, const function&);
380227825Stheraven    template<Allocator Alloc>
381227825Stheraven      function(allocator_arg_t, const Alloc&, function&&);
382227825Stheraven    template<class F, Allocator Alloc>
383227825Stheraven      function(allocator_arg_t, const Alloc&, F);
384227825Stheraven
385227825Stheraven    function& operator=(const function&);
386227825Stheraven    function& operator=(function&&) noexcept;
387227825Stheraven    function& operator=(nullptr_t) noexcept;
388227825Stheraven    template<class F>
389227825Stheraven      function& operator=(F&&);
390227825Stheraven    template<class F>
391227825Stheraven      function& operator=(reference_wrapper<F>) noexcept;
392227825Stheraven
393227825Stheraven    ~function();
394227825Stheraven
395227825Stheraven    // function modifiers:
396227825Stheraven    void swap(function&) noexcept;
397227825Stheraven    template<class F, class Alloc>
398227825Stheraven      void assign(F&&, const Alloc&);
399227825Stheraven
400227825Stheraven    // function capacity:
401227825Stheraven    explicit operator bool() const noexcept;
402227825Stheraven
403227825Stheraven    // function invocation:
404227825Stheraven    R operator()(ArgTypes...) const;
405227825Stheraven
406227825Stheraven    // function target access:
407227825Stheraven    const std::type_info& target_type() const noexcept;
408227825Stheraven    template <typename T>       T* target() noexcept;
409227825Stheraven    template <typename T> const T* target() const noexcept;
410227825Stheraven};
411227825Stheraven
412227825Stheraven// Null pointer comparisons:
413227825Stheraventemplate <class R, class ... ArgTypes>
414227825Stheraven  bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
415227825Stheraven
416227825Stheraventemplate <class R, class ... ArgTypes>
417227825Stheraven  bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
418227825Stheraven
419227825Stheraventemplate <class R, class ... ArgTypes>
420227825Stheraven  bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
421227825Stheraven
422227825Stheraventemplate <class  R, class ... ArgTypes>
423227825Stheraven  bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
424227825Stheraven
425227825Stheraven// specialized algorithms:
426227825Stheraventemplate <class  R, class ... ArgTypes>
427227825Stheraven  void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
428227825Stheraven
429227825Stheraventemplate <class T> struct hash;
430227825Stheraven
431227825Stheraventemplate <> struct hash<bool>;
432227825Stheraventemplate <> struct hash<char>;
433227825Stheraventemplate <> struct hash<signed char>;
434227825Stheraventemplate <> struct hash<unsigned char>;
435227825Stheraventemplate <> struct hash<char16_t>;
436227825Stheraventemplate <> struct hash<char32_t>;
437227825Stheraventemplate <> struct hash<wchar_t>;
438227825Stheraventemplate <> struct hash<short>;
439227825Stheraventemplate <> struct hash<unsigned short>;
440227825Stheraventemplate <> struct hash<int>;
441227825Stheraventemplate <> struct hash<unsigned int>;
442227825Stheraventemplate <> struct hash<long>;
443227825Stheraventemplate <> struct hash<long long>;
444227825Stheraventemplate <> struct hash<unsigned long>;
445227825Stheraventemplate <> struct hash<unsigned long long>;
446227825Stheraven
447227825Stheraventemplate <> struct hash<float>;
448227825Stheraventemplate <> struct hash<double>;
449227825Stheraventemplate <> struct hash<long double>;
450227825Stheraven
451227825Stheraventemplate<class T> struct hash<T*>;
452227825Stheraven
453227825Stheraven}  // std
454227825Stheraven
455227825StheravenPOLICY:  For non-variadic implementations, the number of arguments is limited
456227825Stheraven         to 3.  It is hoped that the need for non-variadic implementations
457227825Stheraven         will be minimal.
458227825Stheraven
459227825Stheraven*/
460227825Stheraven
461227825Stheraven#include <__config>
462227825Stheraven#include <type_traits>
463227825Stheraven#include <typeinfo>
464227825Stheraven#include <exception>
465227825Stheraven#include <memory>
466227825Stheraven#include <tuple>
467227825Stheraven
468227825Stheraven#include <__functional_base>
469227825Stheraven
470227825Stheraven#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
471227825Stheraven#pragma GCC system_header
472227825Stheraven#endif
473227825Stheraven
474227825Stheraven_LIBCPP_BEGIN_NAMESPACE_STD
475227825Stheraven
476227825Stheraventemplate <class _Tp>
477227825Stheravenstruct _LIBCPP_VISIBLE plus : binary_function<_Tp, _Tp, _Tp>
478227825Stheraven{
479227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
480227825Stheraven        {return __x + __y;}
481227825Stheraven};
482227825Stheraven
483227825Stheraventemplate <class _Tp>
484227825Stheravenstruct _LIBCPP_VISIBLE minus : binary_function<_Tp, _Tp, _Tp>
485227825Stheraven{
486227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
487227825Stheraven        {return __x - __y;}
488227825Stheraven};
489227825Stheraven
490227825Stheraventemplate <class _Tp>
491227825Stheravenstruct _LIBCPP_VISIBLE multiplies : binary_function<_Tp, _Tp, _Tp>
492227825Stheraven{
493227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
494227825Stheraven        {return __x * __y;}
495227825Stheraven};
496227825Stheraven
497227825Stheraventemplate <class _Tp>
498227825Stheravenstruct _LIBCPP_VISIBLE divides : binary_function<_Tp, _Tp, _Tp>
499227825Stheraven{
500227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
501227825Stheraven        {return __x / __y;}
502227825Stheraven};
503227825Stheraven
504227825Stheraventemplate <class _Tp>
505227825Stheravenstruct _LIBCPP_VISIBLE modulus : binary_function<_Tp, _Tp, _Tp>
506227825Stheraven{
507227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
508227825Stheraven        {return __x % __y;}
509227825Stheraven};
510227825Stheraven
511227825Stheraventemplate <class _Tp>
512227825Stheravenstruct _LIBCPP_VISIBLE negate : unary_function<_Tp, _Tp>
513227825Stheraven{
514227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x) const
515227825Stheraven        {return -__x;}
516227825Stheraven};
517227825Stheraven
518227825Stheraventemplate <class _Tp>
519227825Stheravenstruct _LIBCPP_VISIBLE equal_to : binary_function<_Tp, _Tp, bool>
520227825Stheraven{
521227825Stheraven    _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
522227825Stheraven        {return __x == __y;}
523227825Stheraven};
524227825Stheraven
525227825Stheraventemplate <class _Tp>
526227825Stheravenstruct _LIBCPP_VISIBLE not_equal_to : binary_function<_Tp, _Tp, bool>
527227825Stheraven{
528227825Stheraven    _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
529227825Stheraven        {return __x != __y;}
530227825Stheraven};
531227825Stheraven
532227825Stheraventemplate <class _Tp>
533227825Stheravenstruct _LIBCPP_VISIBLE greater : binary_function<_Tp, _Tp, bool>
534227825Stheraven{
535227825Stheraven    _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
536227825Stheraven        {return __x > __y;}
537227825Stheraven};
538227825Stheraven
539232950Stheraven// less in <__functional_base>
540227825Stheraven
541227825Stheraventemplate <class _Tp>
542227825Stheravenstruct _LIBCPP_VISIBLE greater_equal : binary_function<_Tp, _Tp, bool>
543227825Stheraven{
544227825Stheraven    _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
545227825Stheraven        {return __x >= __y;}
546227825Stheraven};
547227825Stheraven
548227825Stheraventemplate <class _Tp>
549227825Stheravenstruct _LIBCPP_VISIBLE less_equal : binary_function<_Tp, _Tp, bool>
550227825Stheraven{
551227825Stheraven    _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
552227825Stheraven        {return __x <= __y;}
553227825Stheraven};
554227825Stheraven
555227825Stheraventemplate <class _Tp>
556227825Stheravenstruct _LIBCPP_VISIBLE logical_and : binary_function<_Tp, _Tp, bool>
557227825Stheraven{
558227825Stheraven    _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
559227825Stheraven        {return __x && __y;}
560227825Stheraven};
561227825Stheraven
562227825Stheraventemplate <class _Tp>
563227825Stheravenstruct _LIBCPP_VISIBLE logical_or : binary_function<_Tp, _Tp, bool>
564227825Stheraven{
565227825Stheraven    _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
566227825Stheraven        {return __x || __y;}
567227825Stheraven};
568227825Stheraven
569227825Stheraventemplate <class _Tp>
570227825Stheravenstruct _LIBCPP_VISIBLE logical_not : unary_function<_Tp, bool>
571227825Stheraven{
572227825Stheraven    _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x) const
573227825Stheraven        {return !__x;}
574227825Stheraven};
575227825Stheraven
576227825Stheraventemplate <class _Tp>
577227825Stheravenstruct _LIBCPP_VISIBLE bit_and : binary_function<_Tp, _Tp, _Tp>
578227825Stheraven{
579227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
580227825Stheraven        {return __x & __y;}
581227825Stheraven};
582227825Stheraven
583227825Stheraventemplate <class _Tp>
584227825Stheravenstruct _LIBCPP_VISIBLE bit_or : binary_function<_Tp, _Tp, _Tp>
585227825Stheraven{
586227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
587227825Stheraven        {return __x | __y;}
588227825Stheraven};
589227825Stheraven
590227825Stheraventemplate <class _Tp>
591227825Stheravenstruct _LIBCPP_VISIBLE bit_xor : binary_function<_Tp, _Tp, _Tp>
592227825Stheraven{
593227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
594227825Stheraven        {return __x ^ __y;}
595227825Stheraven};
596227825Stheraven
597227825Stheraventemplate <class _Predicate>
598227825Stheravenclass _LIBCPP_VISIBLE unary_negate
599227825Stheraven    : public unary_function<typename _Predicate::argument_type, bool>
600227825Stheraven{
601227825Stheraven    _Predicate __pred_;
602227825Stheravenpublic:
603227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit unary_negate(const _Predicate& __pred)
604227825Stheraven        : __pred_(__pred) {}
605227825Stheraven    _LIBCPP_INLINE_VISIBILITY bool operator()(const typename _Predicate::argument_type& __x) const
606227825Stheraven        {return !__pred_(__x);}
607227825Stheraven};
608227825Stheraven
609227825Stheraventemplate <class _Predicate>
610227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
611227825Stheravenunary_negate<_Predicate>
612227825Stheravennot1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);}
613227825Stheraven
614227825Stheraventemplate <class _Predicate>
615227825Stheravenclass _LIBCPP_VISIBLE binary_negate
616227825Stheraven    : public binary_function<typename _Predicate::first_argument_type,
617227825Stheraven                             typename _Predicate::second_argument_type,
618227825Stheraven                             bool>
619227825Stheraven{
620227825Stheraven    _Predicate __pred_;
621227825Stheravenpublic:
622227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit binary_negate(const _Predicate& __pred)
623227825Stheraven        : __pred_(__pred) {}
624227825Stheraven    _LIBCPP_INLINE_VISIBILITY bool operator()(const typename _Predicate::first_argument_type& __x,
625227825Stheraven                    const typename _Predicate::second_argument_type& __y) const
626227825Stheraven        {return !__pred_(__x, __y);}
627227825Stheraven};
628227825Stheraven
629227825Stheraventemplate <class _Predicate>
630227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
631227825Stheravenbinary_negate<_Predicate>
632227825Stheravennot2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);}
633227825Stheraven
634227825Stheraventemplate <class __Operation>
635227825Stheravenclass _LIBCPP_VISIBLE binder1st
636227825Stheraven    : public unary_function<typename __Operation::second_argument_type,
637227825Stheraven                            typename __Operation::result_type>
638227825Stheraven{
639227825Stheravenprotected:
640227825Stheraven    __Operation                               op;
641227825Stheraven    typename __Operation::first_argument_type value;
642227825Stheravenpublic:
643227825Stheraven    _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x,
644227825Stheraven                               const typename __Operation::first_argument_type __y)
645227825Stheraven        : op(__x), value(__y) {}
646227825Stheraven    _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
647227825Stheraven        (typename __Operation::second_argument_type& __x) const
648227825Stheraven            {return op(value, __x);}
649227825Stheraven    _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
650227825Stheraven        (const typename __Operation::second_argument_type& __x) const
651227825Stheraven            {return op(value, __x);}
652227825Stheraven};
653227825Stheraven
654227825Stheraventemplate <class __Operation, class _Tp>
655227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
656227825Stheravenbinder1st<__Operation>
657227825Stheravenbind1st(const __Operation& __op, const _Tp& __x)
658227825Stheraven    {return binder1st<__Operation>(__op, __x);}
659227825Stheraven
660227825Stheraventemplate <class __Operation>
661227825Stheravenclass _LIBCPP_VISIBLE binder2nd
662227825Stheraven    : public unary_function<typename __Operation::first_argument_type,
663227825Stheraven                            typename __Operation::result_type>
664227825Stheraven{
665227825Stheravenprotected:
666227825Stheraven    __Operation                                op;
667227825Stheraven    typename __Operation::second_argument_type value;
668227825Stheravenpublic:
669227825Stheraven    _LIBCPP_INLINE_VISIBILITY
670227825Stheraven    binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y)
671227825Stheraven        : op(__x), value(__y) {}
672227825Stheraven    _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
673227825Stheraven        (      typename __Operation::first_argument_type& __x) const
674227825Stheraven            {return op(__x, value);}
675227825Stheraven    _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
676227825Stheraven        (const typename __Operation::first_argument_type& __x) const
677227825Stheraven            {return op(__x, value);}
678227825Stheraven};
679227825Stheraven
680227825Stheraventemplate <class __Operation, class _Tp>
681227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
682227825Stheravenbinder2nd<__Operation>
683227825Stheravenbind2nd(const __Operation& __op, const _Tp& __x)
684227825Stheraven    {return binder2nd<__Operation>(__op, __x);}
685227825Stheraven
686227825Stheraventemplate <class _Arg, class _Result>
687227825Stheravenclass _LIBCPP_VISIBLE pointer_to_unary_function
688227825Stheraven    : public unary_function<_Arg, _Result>
689227825Stheraven{
690227825Stheraven    _Result (*__f_)(_Arg);
691227825Stheravenpublic:
692227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg))
693227825Stheraven        : __f_(__f) {}
694227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const
695227825Stheraven        {return __f_(__x);}
696227825Stheraven};
697227825Stheraven
698227825Stheraventemplate <class _Arg, class _Result>
699227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
700227825Stheravenpointer_to_unary_function<_Arg,_Result>
701227825Stheravenptr_fun(_Result (*__f)(_Arg))
702227825Stheraven    {return pointer_to_unary_function<_Arg,_Result>(__f);}
703227825Stheraven
704227825Stheraventemplate <class _Arg1, class _Arg2, class _Result>
705227825Stheravenclass _LIBCPP_VISIBLE pointer_to_binary_function
706227825Stheraven    : public binary_function<_Arg1, _Arg2, _Result>
707227825Stheraven{
708227825Stheraven    _Result (*__f_)(_Arg1, _Arg2);
709227825Stheravenpublic:
710227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2))
711227825Stheraven        : __f_(__f) {}
712227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const
713227825Stheraven        {return __f_(__x, __y);}
714227825Stheraven};
715227825Stheraven
716227825Stheraventemplate <class _Arg1, class _Arg2, class _Result>
717227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
718227825Stheravenpointer_to_binary_function<_Arg1,_Arg2,_Result>
719227825Stheravenptr_fun(_Result (*__f)(_Arg1,_Arg2))
720227825Stheraven    {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);}
721227825Stheraven
722227825Stheraventemplate<class _Sp, class _Tp>
723227825Stheravenclass _LIBCPP_VISIBLE mem_fun_t : public unary_function<_Tp*, _Sp>
724227825Stheraven{
725227825Stheraven    _Sp (_Tp::*__p_)();
726227825Stheravenpublic:
727227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)())
728227825Stheraven        : __p_(__p) {}
729227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const
730227825Stheraven        {return (__p->*__p_)();}
731227825Stheraven};
732227825Stheraven
733227825Stheraventemplate<class _Sp, class _Tp, class _Ap>
734227825Stheravenclass _LIBCPP_VISIBLE mem_fun1_t : public binary_function<_Tp*, _Ap, _Sp>
735227825Stheraven{
736227825Stheraven    _Sp (_Tp::*__p_)(_Ap);
737227825Stheravenpublic:
738227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap))
739227825Stheraven        : __p_(__p) {}
740227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const
741227825Stheraven        {return (__p->*__p_)(__x);}
742227825Stheraven};
743227825Stheraven
744227825Stheraventemplate<class _Sp, class _Tp>
745227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
746227825Stheravenmem_fun_t<_Sp,_Tp>
747227825Stheravenmem_fun(_Sp (_Tp::*__f)())
748227825Stheraven    {return mem_fun_t<_Sp,_Tp>(__f);}
749227825Stheraven
750227825Stheraventemplate<class _Sp, class _Tp, class _Ap>
751227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
752227825Stheravenmem_fun1_t<_Sp,_Tp,_Ap>
753227825Stheravenmem_fun(_Sp (_Tp::*__f)(_Ap))
754227825Stheraven    {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
755227825Stheraven
756227825Stheraventemplate<class _Sp, class _Tp>
757227825Stheravenclass _LIBCPP_VISIBLE mem_fun_ref_t : public unary_function<_Tp, _Sp>
758227825Stheraven{
759227825Stheraven    _Sp (_Tp::*__p_)();
760227825Stheravenpublic:
761227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)())
762227825Stheraven        : __p_(__p) {}
763227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const
764227825Stheraven        {return (__p.*__p_)();}
765227825Stheraven};
766227825Stheraven
767227825Stheraventemplate<class _Sp, class _Tp, class _Ap>
768227825Stheravenclass _LIBCPP_VISIBLE mem_fun1_ref_t : public binary_function<_Tp, _Ap, _Sp>
769227825Stheraven{
770227825Stheraven    _Sp (_Tp::*__p_)(_Ap);
771227825Stheravenpublic:
772227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap))
773227825Stheraven        : __p_(__p) {}
774227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const
775227825Stheraven        {return (__p.*__p_)(__x);}
776227825Stheraven};
777227825Stheraven
778227825Stheraventemplate<class _Sp, class _Tp>
779227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
780227825Stheravenmem_fun_ref_t<_Sp,_Tp>
781227825Stheravenmem_fun_ref(_Sp (_Tp::*__f)())
782227825Stheraven    {return mem_fun_ref_t<_Sp,_Tp>(__f);}
783227825Stheraven
784227825Stheraventemplate<class _Sp, class _Tp, class _Ap>
785227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
786227825Stheravenmem_fun1_ref_t<_Sp,_Tp,_Ap>
787227825Stheravenmem_fun_ref(_Sp (_Tp::*__f)(_Ap))
788227825Stheraven    {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
789227825Stheraven
790227825Stheraventemplate <class _Sp, class _Tp>
791227825Stheravenclass _LIBCPP_VISIBLE const_mem_fun_t : public unary_function<const _Tp*, _Sp>
792227825Stheraven{
793227825Stheraven    _Sp (_Tp::*__p_)() const;
794227825Stheravenpublic:
795227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const)
796227825Stheraven        : __p_(__p) {}
797227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const
798227825Stheraven        {return (__p->*__p_)();}
799227825Stheraven};
800227825Stheraven
801227825Stheraventemplate <class _Sp, class _Tp, class _Ap>
802227825Stheravenclass _LIBCPP_VISIBLE const_mem_fun1_t : public binary_function<const _Tp*, _Ap, _Sp>
803227825Stheraven{
804227825Stheraven    _Sp (_Tp::*__p_)(_Ap) const;
805227825Stheravenpublic:
806227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const)
807227825Stheraven        : __p_(__p) {}
808227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const
809227825Stheraven        {return (__p->*__p_)(__x);}
810227825Stheraven};
811227825Stheraven
812227825Stheraventemplate <class _Sp, class _Tp>
813227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
814227825Stheravenconst_mem_fun_t<_Sp,_Tp>
815227825Stheravenmem_fun(_Sp (_Tp::*__f)() const)
816227825Stheraven    {return const_mem_fun_t<_Sp,_Tp>(__f);}
817227825Stheraven
818227825Stheraventemplate <class _Sp, class _Tp, class _Ap>
819227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
820227825Stheravenconst_mem_fun1_t<_Sp,_Tp,_Ap>
821227825Stheravenmem_fun(_Sp (_Tp::*__f)(_Ap) const)
822227825Stheraven    {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
823227825Stheraven
824227825Stheraventemplate <class _Sp, class _Tp>
825227825Stheravenclass _LIBCPP_VISIBLE const_mem_fun_ref_t : public unary_function<_Tp, _Sp>
826227825Stheraven{
827227825Stheraven    _Sp (_Tp::*__p_)() const;
828227825Stheravenpublic:
829227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const)
830227825Stheraven        : __p_(__p) {}
831227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const
832227825Stheraven        {return (__p.*__p_)();}
833227825Stheraven};
834227825Stheraven
835227825Stheraventemplate <class _Sp, class _Tp, class _Ap>
836227825Stheravenclass _LIBCPP_VISIBLE const_mem_fun1_ref_t
837227825Stheraven    : public binary_function<_Tp, _Ap, _Sp>
838227825Stheraven{
839227825Stheraven    _Sp (_Tp::*__p_)(_Ap) const;
840227825Stheravenpublic:
841227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const)
842227825Stheraven        : __p_(__p) {}
843227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const
844227825Stheraven        {return (__p.*__p_)(__x);}
845227825Stheraven};
846227825Stheraven
847227825Stheraventemplate <class _Sp, class _Tp>
848227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
849227825Stheravenconst_mem_fun_ref_t<_Sp,_Tp>
850227825Stheravenmem_fun_ref(_Sp (_Tp::*__f)() const)
851227825Stheraven    {return const_mem_fun_ref_t<_Sp,_Tp>(__f);}
852227825Stheraven
853227825Stheraventemplate <class _Sp, class _Tp, class _Ap>
854227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
855227825Stheravenconst_mem_fun1_ref_t<_Sp,_Tp,_Ap>
856227825Stheravenmem_fun_ref(_Sp (_Tp::*__f)(_Ap) const)
857227825Stheraven    {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
858227825Stheraven
859227825Stheraven#ifdef _LIBCPP_HAS_NO_VARIADICS
860227825Stheraven
861227825Stheraven#include <__functional_03>
862227825Stheraven
863227825Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
864227825Stheraven
865227825Stheraventemplate <class _Tp>
866227825Stheravenclass __mem_fn
867227825Stheraven    : public __weak_result_type<_Tp>
868227825Stheraven{
869227825Stheravenpublic:
870227825Stheraven    // types
871227825Stheraven    typedef _Tp type;
872227825Stheravenprivate:
873227825Stheraven    type __f_;
874227825Stheraven
875227825Stheravenpublic:
876227825Stheraven    _LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) : __f_(__f) {}
877227825Stheraven
878227825Stheraven    // invoke
879227825Stheraven    template <class... _ArgTypes>
880227825Stheraven       _LIBCPP_INLINE_VISIBILITY
881227825Stheraven       typename __invoke_return<type, _ArgTypes...>::type
882227825Stheraven          operator() (_ArgTypes&&... __args)
883227825Stheraven          {
884227825Stheraven              return __invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...);
885227825Stheraven          }
886227825Stheraven};
887227825Stheraven
888232950Stheraventemplate<class _Rp, class _Tp>
889227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
890232950Stheraven__mem_fn<_Rp _Tp::*>
891232950Stheravenmem_fn(_Rp _Tp::* __pm)
892227825Stheraven{
893232950Stheraven    return __mem_fn<_Rp _Tp::*>(__pm);
894227825Stheraven}
895227825Stheraven
896232950Stheraventemplate<class _Rp, class _Tp, class ..._Args>
897227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
898232950Stheraven__mem_fn<_Rp (_Tp::*)(_Args...)>
899232950Stheravenmem_fn(_Rp (_Tp::* __pm)(_Args...))
900227825Stheraven{
901232950Stheraven    return __mem_fn<_Rp (_Tp::*)(_Args...)>(__pm);
902227825Stheraven}
903227825Stheraven
904232950Stheraventemplate<class _Rp, class _Tp, class ..._Args>
905227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
906232950Stheraven__mem_fn<_Rp (_Tp::*)(_Args...) const>
907232950Stheravenmem_fn(_Rp (_Tp::* __pm)(_Args...) const)
908227825Stheraven{
909232950Stheraven    return __mem_fn<_Rp (_Tp::*)(_Args...) const>(__pm);
910227825Stheraven}
911227825Stheraven
912232950Stheraventemplate<class _Rp, class _Tp, class ..._Args>
913227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
914232950Stheraven__mem_fn<_Rp (_Tp::*)(_Args...) volatile>
915232950Stheravenmem_fn(_Rp (_Tp::* __pm)(_Args...) volatile)
916227825Stheraven{
917232950Stheraven    return __mem_fn<_Rp (_Tp::*)(_Args...) volatile>(__pm);
918227825Stheraven}
919227825Stheraven
920232950Stheraventemplate<class _Rp, class _Tp, class ..._Args>
921227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
922232950Stheraven__mem_fn<_Rp (_Tp::*)(_Args...) const volatile>
923232950Stheravenmem_fn(_Rp (_Tp::* __pm)(_Args...) const volatile)
924227825Stheraven{
925232950Stheraven    return __mem_fn<_Rp (_Tp::*)(_Args...) const volatile>(__pm);
926227825Stheraven}
927227825Stheraven
928227825Stheraven// bad_function_call
929227825Stheraven
930227825Stheravenclass _LIBCPP_EXCEPTION_ABI bad_function_call
931227825Stheraven    : public exception
932227825Stheraven{
933227825Stheraven};
934227825Stheraven
935227825Stheraventemplate<class _Fp> class _LIBCPP_VISIBLE function; // undefined
936227825Stheraven
937227825Stheravennamespace __function
938227825Stheraven{
939227825Stheraven
940232950Stheraventemplate<class _Rp, class ..._ArgTypes>
941227825Stheravenstruct __maybe_derive_from_unary_function
942227825Stheraven{
943227825Stheraven};
944227825Stheraven
945232950Stheraventemplate<class _Rp, class _A1>
946232950Stheravenstruct __maybe_derive_from_unary_function<_Rp(_A1)>
947232950Stheraven    : public unary_function<_A1, _Rp>
948227825Stheraven{
949227825Stheraven};
950227825Stheraven
951232950Stheraventemplate<class _Rp, class ..._ArgTypes>
952227825Stheravenstruct __maybe_derive_from_binary_function
953227825Stheraven{
954227825Stheraven};
955227825Stheraven
956232950Stheraventemplate<class _Rp, class _A1, class _A2>
957232950Stheravenstruct __maybe_derive_from_binary_function<_Rp(_A1, _A2)>
958232950Stheraven    : public binary_function<_A1, _A2, _Rp>
959227825Stheraven{
960227825Stheraven};
961227825Stheraven
962227825Stheraventemplate<class _Fp> class __base;
963227825Stheraven
964232950Stheraventemplate<class _Rp, class ..._ArgTypes>
965232950Stheravenclass __base<_Rp(_ArgTypes...)>
966227825Stheraven{
967227825Stheraven    __base(const __base&);
968227825Stheraven    __base& operator=(const __base&);
969227825Stheravenpublic:
970227825Stheraven    _LIBCPP_INLINE_VISIBILITY __base() {}
971227825Stheraven    _LIBCPP_INLINE_VISIBILITY virtual ~__base() {}
972227825Stheraven    virtual __base* __clone() const = 0;
973227825Stheraven    virtual void __clone(__base*) const = 0;
974227825Stheraven    virtual void destroy() _NOEXCEPT = 0;
975227825Stheraven    virtual void destroy_deallocate() _NOEXCEPT = 0;
976232950Stheraven    virtual _Rp operator()(_ArgTypes&& ...) = 0;
977227825Stheraven#ifndef _LIBCPP_NO_RTTI
978227825Stheraven    virtual const void* target(const type_info&) const _NOEXCEPT = 0;
979227825Stheraven    virtual const std::type_info& target_type() const _NOEXCEPT = 0;
980227825Stheraven#endif  // _LIBCPP_NO_RTTI
981227825Stheraven};
982227825Stheraven
983227825Stheraventemplate<class _FD, class _Alloc, class _FB> class __func;
984227825Stheraven
985232950Stheraventemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
986232950Stheravenclass __func<_Fp, _Alloc, _Rp(_ArgTypes...)>
987232950Stheraven    : public  __base<_Rp(_ArgTypes...)>
988227825Stheraven{
989232950Stheraven    __compressed_pair<_Fp, _Alloc> __f_;
990227825Stheravenpublic:
991227825Stheraven    _LIBCPP_INLINE_VISIBILITY
992232950Stheraven    explicit __func(_Fp&& __f)
993232950Stheraven        : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
994232950Stheraven                                    _VSTD::forward_as_tuple()) {}
995227825Stheraven    _LIBCPP_INLINE_VISIBILITY
996232950Stheraven    explicit __func(const _Fp& __f, const _Alloc& __a)
997232950Stheraven        : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
998232950Stheraven                                    _VSTD::forward_as_tuple(__a)) {}
999232950Stheraven
1000232950Stheraven    _LIBCPP_INLINE_VISIBILITY
1001232950Stheraven    explicit __func(const _Fp& __f, _Alloc&& __a)
1002232950Stheraven        : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1003232950Stheraven                                    _VSTD::forward_as_tuple(_VSTD::move(__a))) {}
1004232950Stheraven
1005232950Stheraven    _LIBCPP_INLINE_VISIBILITY
1006232950Stheraven    explicit __func(_Fp&& __f, _Alloc&& __a)
1007232950Stheraven        : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1008232950Stheraven                                    _VSTD::forward_as_tuple(_VSTD::move(__a))) {}
1009232950Stheraven    virtual __base<_Rp(_ArgTypes...)>* __clone() const;
1010232950Stheraven    virtual void __clone(__base<_Rp(_ArgTypes...)>*) const;
1011227825Stheraven    virtual void destroy() _NOEXCEPT;
1012227825Stheraven    virtual void destroy_deallocate() _NOEXCEPT;
1013232950Stheraven    virtual _Rp operator()(_ArgTypes&& ... __arg);
1014227825Stheraven#ifndef _LIBCPP_NO_RTTI
1015227825Stheraven    virtual const void* target(const type_info&) const _NOEXCEPT;
1016227825Stheraven    virtual const std::type_info& target_type() const _NOEXCEPT;
1017227825Stheraven#endif  // _LIBCPP_NO_RTTI
1018227825Stheraven};
1019227825Stheraven
1020232950Stheraventemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1021232950Stheraven__base<_Rp(_ArgTypes...)>*
1022232950Stheraven__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const
1023227825Stheraven{
1024232950Stheraven    typedef typename _Alloc::template rebind<__func>::other _Ap;
1025232950Stheraven    _Ap __a(__f_.second());
1026232950Stheraven    typedef __allocator_destructor<_Ap> _Dp;
1027232950Stheraven    unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1028227825Stheraven    ::new (__hold.get()) __func(__f_.first(), _Alloc(__a));
1029227825Stheraven    return __hold.release();
1030227825Stheraven}
1031227825Stheraven
1032232950Stheraventemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1033227825Stheravenvoid
1034232950Stheraven__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const
1035227825Stheraven{
1036227825Stheraven    ::new (__p) __func(__f_.first(), __f_.second());
1037227825Stheraven}
1038227825Stheraven
1039232950Stheraventemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1040227825Stheravenvoid
1041232950Stheraven__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPT
1042227825Stheraven{
1043232950Stheraven    __f_.~__compressed_pair<_Fp, _Alloc>();
1044227825Stheraven}
1045227825Stheraven
1046232950Stheraventemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1047227825Stheravenvoid
1048232950Stheraven__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT
1049227825Stheraven{
1050232950Stheraven    typedef typename _Alloc::template rebind<__func>::other _Ap;
1051232950Stheraven    _Ap __a(__f_.second());
1052232950Stheraven    __f_.~__compressed_pair<_Fp, _Alloc>();
1053227825Stheraven    __a.deallocate(this, 1);
1054227825Stheraven}
1055227825Stheraven
1056232950Stheraventemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1057232950Stheraven_Rp
1058232950Stheraven__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg)
1059227825Stheraven{
1060227825Stheraven    return __invoke(__f_.first(), _VSTD::forward<_ArgTypes>(__arg)...);
1061227825Stheraven}
1062227825Stheraven
1063227825Stheraven#ifndef _LIBCPP_NO_RTTI
1064227825Stheraven
1065232950Stheraventemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1066227825Stheravenconst void*
1067232950Stheraven__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT
1068227825Stheraven{
1069232950Stheraven    if (__ti == typeid(_Fp))
1070227825Stheraven        return &__f_.first();
1071227825Stheraven    return (const void*)0;
1072227825Stheraven}
1073227825Stheraven
1074232950Stheraventemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1075227825Stheravenconst std::type_info&
1076232950Stheraven__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
1077227825Stheraven{
1078232950Stheraven    return typeid(_Fp);
1079227825Stheraven}
1080227825Stheraven
1081227825Stheraven#endif  // _LIBCPP_NO_RTTI
1082227825Stheraven
1083227825Stheraven}  // __function
1084227825Stheraven
1085232950Stheraventemplate<class _Rp, class ..._ArgTypes>
1086232950Stheravenclass _LIBCPP_VISIBLE function<_Rp(_ArgTypes...)>
1087232950Stheraven    : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>,
1088232950Stheraven      public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)>
1089227825Stheraven{
1090232950Stheraven    typedef __function::__base<_Rp(_ArgTypes...)> __base;
1091227825Stheraven    aligned_storage<3*sizeof(void*)>::type __buf_;
1092227825Stheraven    __base* __f_;
1093227825Stheraven
1094232950Stheraven    template <class _Fp>
1095227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1096232950Stheraven        static bool __not_null(const _Fp&) {return true;}
1097232950Stheraven    template <class _R2, class ..._Ap>
1098227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1099232950Stheraven        static bool __not_null(_R2 (*__p)(_Ap...)) {return __p;}
1100232950Stheraven    template <class _R2, class _Cp, class ..._Ap>
1101227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1102232950Stheraven        static bool __not_null(_R2 (_Cp::*__p)(_Ap...)) {return __p;}
1103232950Stheraven    template <class _R2, class _Cp, class ..._Ap>
1104227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1105232950Stheraven        static bool __not_null(_R2 (_Cp::*__p)(_Ap...) const) {return __p;}
1106232950Stheraven    template <class _R2, class _Cp, class ..._Ap>
1107227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1108232950Stheraven        static bool __not_null(_R2 (_Cp::*__p)(_Ap...) volatile) {return __p;}
1109232950Stheraven    template <class _R2, class _Cp, class ..._Ap>
1110227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1111232950Stheraven        static bool __not_null(_R2 (_Cp::*__p)(_Ap...) const volatile) {return __p;}
1112232950Stheraven    template <class _R2, class ..._Ap>
1113227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1114232950Stheraven        static bool __not_null(const function<_Rp(_Ap...)>& __p) {return __p;}
1115227825Stheraven
1116232950Stheraven    template <class _Fp, bool = __invokable<_Fp&, _ArgTypes...>::value>
1117227825Stheraven        struct __callable;
1118232950Stheraven    template <class _Fp>
1119232950Stheraven        struct __callable<_Fp, true>
1120227825Stheraven        {
1121227825Stheraven            static const bool value =
1122232950Stheraven                is_convertible<typename __invoke_of<_Fp&, _ArgTypes...>::type,
1123232950Stheraven                               _Rp>::value;
1124227825Stheraven        };
1125232950Stheraven    template <class _Fp>
1126232950Stheraven        struct __callable<_Fp, false>
1127227825Stheraven        {
1128227825Stheraven            static const bool value = false;
1129227825Stheraven        };
1130227825Stheravenpublic:
1131232950Stheraven    typedef _Rp result_type;
1132227825Stheraven
1133227825Stheraven    // construct/copy/destroy:
1134227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1135227825Stheraven    function() _NOEXCEPT : __f_(0) {}
1136227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1137227825Stheraven    function(nullptr_t) _NOEXCEPT : __f_(0) {}
1138227825Stheraven    function(const function&);
1139227825Stheraven    function(function&&) _NOEXCEPT;
1140232950Stheraven    template<class _Fp>
1141232950Stheraven      function(_Fp,
1142232950Stheraven               typename enable_if<__callable<_Fp>::value>::type* = 0);
1143227825Stheraven
1144227825Stheraven    template<class _Alloc>
1145227825Stheraven      _LIBCPP_INLINE_VISIBILITY
1146227825Stheraven      function(allocator_arg_t, const _Alloc&) _NOEXCEPT : __f_(0) {}
1147227825Stheraven    template<class _Alloc>
1148227825Stheraven      _LIBCPP_INLINE_VISIBILITY
1149227825Stheraven      function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT : __f_(0) {}
1150227825Stheraven    template<class _Alloc>
1151227825Stheraven      function(allocator_arg_t, const _Alloc&, const function&);
1152227825Stheraven    template<class _Alloc>
1153227825Stheraven      function(allocator_arg_t, const _Alloc&, function&&);
1154232950Stheraven    template<class _Fp, class _Alloc>
1155232950Stheraven      function(allocator_arg_t, const _Alloc& __a, _Fp __f,
1156232950Stheraven               typename enable_if<__callable<_Fp>::value>::type* = 0);
1157227825Stheraven
1158227825Stheraven    function& operator=(const function&);
1159227825Stheraven    function& operator=(function&&) _NOEXCEPT;
1160227825Stheraven    function& operator=(nullptr_t) _NOEXCEPT;
1161232950Stheraven    template<class _Fp>
1162227825Stheraven      typename enable_if
1163227825Stheraven      <
1164232950Stheraven        __callable<typename decay<_Fp>::type>::value,
1165227825Stheraven        function&
1166227825Stheraven      >::type
1167232950Stheraven      operator=(_Fp&&);
1168227825Stheraven
1169227825Stheraven    ~function();
1170227825Stheraven
1171227825Stheraven    // function modifiers:
1172227825Stheraven    void swap(function&) _NOEXCEPT;
1173232950Stheraven    template<class _Fp, class _Alloc>
1174227825Stheraven      _LIBCPP_INLINE_VISIBILITY
1175232950Stheraven      void assign(_Fp&& __f, const _Alloc& __a)
1176232950Stheraven        {function(allocator_arg, __a, _VSTD::forward<_Fp>(__f)).swap(*this);}
1177227825Stheraven
1178227825Stheraven    // function capacity:
1179227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1180232950Stheraven        _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return __f_;}
1181227825Stheraven
1182227825Stheraven    // deleted overloads close possible hole in the type system
1183227825Stheraven    template<class _R2, class... _ArgTypes2>
1184227825Stheraven      bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete;
1185227825Stheraven    template<class _R2, class... _ArgTypes2>
1186227825Stheraven      bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete;
1187227825Stheravenpublic:
1188227825Stheraven    // function invocation:
1189232950Stheraven    _Rp operator()(_ArgTypes...) const;
1190227825Stheraven
1191227825Stheraven#ifndef _LIBCPP_NO_RTTI
1192227825Stheraven    // function target access:
1193227825Stheraven    const std::type_info& target_type() const _NOEXCEPT;
1194232950Stheraven    template <typename _Tp> _Tp* target() _NOEXCEPT;
1195232950Stheraven    template <typename _Tp> const _Tp* target() const _NOEXCEPT;
1196227825Stheraven#endif  // _LIBCPP_NO_RTTI
1197227825Stheraven};
1198227825Stheraven
1199232950Stheraventemplate<class _Rp, class ..._ArgTypes>
1200232950Stheravenfunction<_Rp(_ArgTypes...)>::function(const function& __f)
1201227825Stheraven{
1202227825Stheraven    if (__f.__f_ == 0)
1203227825Stheraven        __f_ = 0;
1204227825Stheraven    else if (__f.__f_ == (const __base*)&__f.__buf_)
1205227825Stheraven    {
1206227825Stheraven        __f_ = (__base*)&__buf_;
1207227825Stheraven        __f.__f_->__clone(__f_);
1208227825Stheraven    }
1209227825Stheraven    else
1210227825Stheraven        __f_ = __f.__f_->__clone();
1211227825Stheraven}
1212227825Stheraven
1213232950Stheraventemplate<class _Rp, class ..._ArgTypes>
1214227825Stheraventemplate <class _Alloc>
1215232950Stheravenfunction<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
1216227825Stheraven                                     const function& __f)
1217227825Stheraven{
1218227825Stheraven    if (__f.__f_ == 0)
1219227825Stheraven        __f_ = 0;
1220227825Stheraven    else if (__f.__f_ == (const __base*)&__f.__buf_)
1221227825Stheraven    {
1222227825Stheraven        __f_ = (__base*)&__buf_;
1223227825Stheraven        __f.__f_->__clone(__f_);
1224227825Stheraven    }
1225227825Stheraven    else
1226227825Stheraven        __f_ = __f.__f_->__clone();
1227227825Stheraven}
1228227825Stheraven
1229232950Stheraventemplate<class _Rp, class ..._ArgTypes>
1230232950Stheravenfunction<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT
1231227825Stheraven{
1232227825Stheraven    if (__f.__f_ == 0)
1233227825Stheraven        __f_ = 0;
1234227825Stheraven    else if (__f.__f_ == (__base*)&__f.__buf_)
1235227825Stheraven    {
1236227825Stheraven        __f_ = (__base*)&__buf_;
1237227825Stheraven        __f.__f_->__clone(__f_);
1238227825Stheraven    }
1239227825Stheraven    else
1240227825Stheraven    {
1241227825Stheraven        __f_ = __f.__f_;
1242227825Stheraven        __f.__f_ = 0;
1243227825Stheraven    }
1244227825Stheraven}
1245227825Stheraven
1246232950Stheraventemplate<class _Rp, class ..._ArgTypes>
1247227825Stheraventemplate <class _Alloc>
1248232950Stheravenfunction<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
1249227825Stheraven                                     function&& __f)
1250227825Stheraven{
1251227825Stheraven    if (__f.__f_ == 0)
1252227825Stheraven        __f_ = 0;
1253227825Stheraven    else if (__f.__f_ == (__base*)&__f.__buf_)
1254227825Stheraven    {
1255227825Stheraven        __f_ = (__base*)&__buf_;
1256227825Stheraven        __f.__f_->__clone(__f_);
1257227825Stheraven    }
1258227825Stheraven    else
1259227825Stheraven    {
1260227825Stheraven        __f_ = __f.__f_;
1261227825Stheraven        __f.__f_ = 0;
1262227825Stheraven    }
1263227825Stheraven}
1264227825Stheraven
1265232950Stheraventemplate<class _Rp, class ..._ArgTypes>
1266232950Stheraventemplate <class _Fp>
1267232950Stheravenfunction<_Rp(_ArgTypes...)>::function(_Fp __f,
1268232950Stheraven                                     typename enable_if<__callable<_Fp>::value>::type*)
1269227825Stheraven    : __f_(0)
1270227825Stheraven{
1271227825Stheraven    if (__not_null(__f))
1272227825Stheraven    {
1273232950Stheraven        typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_ArgTypes...)> _FF;
1274232950Stheraven        if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value)
1275227825Stheraven        {
1276227825Stheraven            __f_ = (__base*)&__buf_;
1277227825Stheraven            ::new (__f_) _FF(_VSTD::move(__f));
1278227825Stheraven        }
1279227825Stheraven        else
1280227825Stheraven        {
1281232950Stheraven            typedef allocator<_FF> _Ap;
1282232950Stheraven            _Ap __a;
1283232950Stheraven            typedef __allocator_destructor<_Ap> _Dp;
1284232950Stheraven            unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1285232950Stheraven            ::new (__hold.get()) _FF(_VSTD::move(__f), allocator<_Fp>(__a));
1286227825Stheraven            __f_ = __hold.release();
1287227825Stheraven        }
1288227825Stheraven    }
1289227825Stheraven}
1290227825Stheraven
1291232950Stheraventemplate<class _Rp, class ..._ArgTypes>
1292232950Stheraventemplate <class _Fp, class _Alloc>
1293232950Stheravenfunction<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f,
1294232950Stheraven                                     typename enable_if<__callable<_Fp>::value>::type*)
1295227825Stheraven    : __f_(0)
1296227825Stheraven{
1297227825Stheraven    typedef allocator_traits<_Alloc> __alloc_traits;
1298227825Stheraven    if (__not_null(__f))
1299227825Stheraven    {
1300232950Stheraven        typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _FF;
1301232950Stheraven        if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value)
1302227825Stheraven        {
1303227825Stheraven            __f_ = (__base*)&__buf_;
1304227825Stheraven            ::new (__f_) _FF(_VSTD::move(__f));
1305227825Stheraven        }
1306227825Stheraven        else
1307227825Stheraven        {
1308227825Stheraven            typedef typename __alloc_traits::template
1309227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1310227825Stheraven                rebind_alloc<_FF>
1311227825Stheraven#else
1312227825Stheraven                rebind_alloc<_FF>::other
1313227825Stheraven#endif
1314232950Stheraven                                                         _Ap;
1315232950Stheraven            _Ap __a(__a0);
1316232950Stheraven            typedef __allocator_destructor<_Ap> _Dp;
1317232950Stheraven            unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1318227825Stheraven            ::new (__hold.get()) _FF(_VSTD::move(__f), _Alloc(__a));
1319227825Stheraven            __f_ = __hold.release();
1320227825Stheraven        }
1321227825Stheraven    }
1322227825Stheraven}
1323227825Stheraven
1324232950Stheraventemplate<class _Rp, class ..._ArgTypes>
1325232950Stheravenfunction<_Rp(_ArgTypes...)>&
1326232950Stheravenfunction<_Rp(_ArgTypes...)>::operator=(const function& __f)
1327227825Stheraven{
1328227825Stheraven    function(__f).swap(*this);
1329227825Stheraven    return *this;
1330227825Stheraven}
1331227825Stheraven
1332232950Stheraventemplate<class _Rp, class ..._ArgTypes>
1333232950Stheravenfunction<_Rp(_ArgTypes...)>&
1334232950Stheravenfunction<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT
1335227825Stheraven{
1336227825Stheraven    if (__f_ == (__base*)&__buf_)
1337227825Stheraven        __f_->destroy();
1338227825Stheraven    else if (__f_)
1339227825Stheraven        __f_->destroy_deallocate();
1340227825Stheraven    __f_ = 0;
1341227825Stheraven    if (__f.__f_ == 0)
1342227825Stheraven        __f_ = 0;
1343227825Stheraven    else if (__f.__f_ == (__base*)&__f.__buf_)
1344227825Stheraven    {
1345227825Stheraven        __f_ = (__base*)&__buf_;
1346227825Stheraven        __f.__f_->__clone(__f_);
1347227825Stheraven    }
1348227825Stheraven    else
1349227825Stheraven    {
1350227825Stheraven        __f_ = __f.__f_;
1351227825Stheraven        __f.__f_ = 0;
1352227825Stheraven    }
1353227825Stheraven}
1354227825Stheraven
1355232950Stheraventemplate<class _Rp, class ..._ArgTypes>
1356232950Stheravenfunction<_Rp(_ArgTypes...)>&
1357232950Stheravenfunction<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT
1358227825Stheraven{
1359227825Stheraven    if (__f_ == (__base*)&__buf_)
1360227825Stheraven        __f_->destroy();
1361227825Stheraven    else if (__f_)
1362227825Stheraven        __f_->destroy_deallocate();
1363227825Stheraven    __f_ = 0;
1364227825Stheraven}
1365227825Stheraven
1366232950Stheraventemplate<class _Rp, class ..._ArgTypes>
1367232950Stheraventemplate <class _Fp>
1368227825Stheraventypename enable_if
1369227825Stheraven<
1370232950Stheraven    function<_Rp(_ArgTypes...)>::template __callable<typename decay<_Fp>::type>::value,
1371232950Stheraven    function<_Rp(_ArgTypes...)>&
1372227825Stheraven>::type
1373232950Stheravenfunction<_Rp(_ArgTypes...)>::operator=(_Fp&& __f)
1374227825Stheraven{
1375232950Stheraven    function(_VSTD::forward<_Fp>(__f)).swap(*this);
1376227825Stheraven    return *this;
1377227825Stheraven}
1378227825Stheraven
1379232950Stheraventemplate<class _Rp, class ..._ArgTypes>
1380232950Stheravenfunction<_Rp(_ArgTypes...)>::~function()
1381227825Stheraven{
1382227825Stheraven    if (__f_ == (__base*)&__buf_)
1383227825Stheraven        __f_->destroy();
1384227825Stheraven    else if (__f_)
1385227825Stheraven        __f_->destroy_deallocate();
1386227825Stheraven}
1387227825Stheraven
1388232950Stheraventemplate<class _Rp, class ..._ArgTypes>
1389227825Stheravenvoid
1390232950Stheravenfunction<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT
1391227825Stheraven{
1392227825Stheraven    if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_)
1393227825Stheraven    {
1394227825Stheraven        typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
1395227825Stheraven        __base* __t = (__base*)&__tempbuf;
1396227825Stheraven        __f_->__clone(__t);
1397227825Stheraven        __f_->destroy();
1398227825Stheraven        __f_ = 0;
1399227825Stheraven        __f.__f_->__clone((__base*)&__buf_);
1400227825Stheraven        __f.__f_->destroy();
1401227825Stheraven        __f.__f_ = 0;
1402227825Stheraven        __f_ = (__base*)&__buf_;
1403227825Stheraven        __t->__clone((__base*)&__f.__buf_);
1404227825Stheraven        __t->destroy();
1405227825Stheraven        __f.__f_ = (__base*)&__f.__buf_;
1406227825Stheraven    }
1407227825Stheraven    else if (__f_ == (__base*)&__buf_)
1408227825Stheraven    {
1409227825Stheraven        __f_->__clone((__base*)&__f.__buf_);
1410227825Stheraven        __f_->destroy();
1411227825Stheraven        __f_ = __f.__f_;
1412227825Stheraven        __f.__f_ = (__base*)&__f.__buf_;
1413227825Stheraven    }
1414227825Stheraven    else if (__f.__f_ == (__base*)&__f.__buf_)
1415227825Stheraven    {
1416227825Stheraven        __f.__f_->__clone((__base*)&__buf_);
1417227825Stheraven        __f.__f_->destroy();
1418227825Stheraven        __f.__f_ = __f_;
1419227825Stheraven        __f_ = (__base*)&__buf_;
1420227825Stheraven    }
1421227825Stheraven    else
1422227825Stheraven        _VSTD::swap(__f_, __f.__f_);
1423227825Stheraven}
1424227825Stheraven
1425232950Stheraventemplate<class _Rp, class ..._ArgTypes>
1426232950Stheraven_Rp
1427232950Stheravenfunction<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const
1428227825Stheraven{
1429227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
1430227825Stheraven    if (__f_ == 0)
1431227825Stheraven        throw bad_function_call();
1432227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
1433227825Stheraven    return (*__f_)(_VSTD::forward<_ArgTypes>(__arg)...);
1434227825Stheraven}
1435227825Stheraven
1436227825Stheraven#ifndef _LIBCPP_NO_RTTI
1437227825Stheraven
1438232950Stheraventemplate<class _Rp, class ..._ArgTypes>
1439227825Stheravenconst std::type_info&
1440232950Stheravenfunction<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
1441227825Stheraven{
1442227825Stheraven    if (__f_ == 0)
1443227825Stheraven        return typeid(void);
1444227825Stheraven    return __f_->target_type();
1445227825Stheraven}
1446227825Stheraven
1447232950Stheraventemplate<class _Rp, class ..._ArgTypes>
1448232950Stheraventemplate <typename _Tp>
1449232950Stheraven_Tp*
1450232950Stheravenfunction<_Rp(_ArgTypes...)>::target() _NOEXCEPT
1451227825Stheraven{
1452227825Stheraven    if (__f_ == 0)
1453232950Stheraven        return (_Tp*)0;
1454232950Stheraven    return (_Tp*)__f_->target(typeid(_Tp));
1455227825Stheraven}
1456227825Stheraven
1457232950Stheraventemplate<class _Rp, class ..._ArgTypes>
1458232950Stheraventemplate <typename _Tp>
1459232950Stheravenconst _Tp*
1460232950Stheravenfunction<_Rp(_ArgTypes...)>::target() const _NOEXCEPT
1461227825Stheraven{
1462227825Stheraven    if (__f_ == 0)
1463232950Stheraven        return (const _Tp*)0;
1464232950Stheraven    return (const _Tp*)__f_->target(typeid(_Tp));
1465227825Stheraven}
1466227825Stheraven
1467227825Stheraven#endif  // _LIBCPP_NO_RTTI
1468227825Stheraven
1469232950Stheraventemplate <class _Rp, class... _ArgTypes>
1470227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1471227825Stheravenbool
1472232950Stheravenoperator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;}
1473227825Stheraven
1474232950Stheraventemplate <class _Rp, class... _ArgTypes>
1475227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1476227825Stheravenbool
1477232950Stheravenoperator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;}
1478227825Stheraven
1479232950Stheraventemplate <class _Rp, class... _ArgTypes>
1480227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1481227825Stheravenbool
1482232950Stheravenoperator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;}
1483227825Stheraven
1484232950Stheraventemplate <class _Rp, class... _ArgTypes>
1485227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1486227825Stheravenbool
1487232950Stheravenoperator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;}
1488227825Stheraven
1489232950Stheraventemplate <class _Rp, class... _ArgTypes>
1490227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1491227825Stheravenvoid
1492232950Stheravenswap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT
1493227825Stheraven{return __x.swap(__y);}
1494227825Stheraven
1495227825Stheraventemplate<class _Tp> struct __is_bind_expression : public false_type {};
1496227825Stheraventemplate<class _Tp> struct _LIBCPP_VISIBLE is_bind_expression
1497227825Stheraven    : public __is_bind_expression<typename remove_cv<_Tp>::type> {};
1498227825Stheraven
1499227825Stheraventemplate<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {};
1500227825Stheraventemplate<class _Tp> struct _LIBCPP_VISIBLE is_placeholder
1501227825Stheraven    : public __is_placeholder<typename remove_cv<_Tp>::type> {};
1502227825Stheraven
1503227825Stheravennamespace placeholders
1504227825Stheraven{
1505227825Stheraven
1506232950Stheraventemplate <int _Np> struct __ph {};
1507227825Stheraven
1508227825Stheravenextern __ph<1>   _1;
1509227825Stheravenextern __ph<2>   _2;
1510227825Stheravenextern __ph<3>   _3;
1511227825Stheravenextern __ph<4>   _4;
1512227825Stheravenextern __ph<5>   _5;
1513227825Stheravenextern __ph<6>   _6;
1514227825Stheravenextern __ph<7>   _7;
1515227825Stheravenextern __ph<8>   _8;
1516227825Stheravenextern __ph<9>   _9;
1517227825Stheravenextern __ph<10> _10;
1518227825Stheraven
1519227825Stheraven}  // placeholders
1520227825Stheraven
1521232950Stheraventemplate<int _Np>
1522232950Stheravenstruct __is_placeholder<placeholders::__ph<_Np> >
1523232950Stheraven    : public integral_constant<int, _Np> {};
1524227825Stheraven
1525227825Stheraventemplate <class _Tp, class _Uj>
1526227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1527227825Stheraven_Tp&
1528227825Stheraven__mu(reference_wrapper<_Tp> __t, _Uj&)
1529227825Stheraven{
1530227825Stheraven    return __t.get();
1531227825Stheraven}
1532227825Stheraven
1533227825Stheraventemplate <class _Ti, class ..._Uj, size_t ..._Indx>
1534227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1535227825Stheraventypename __invoke_of<_Ti&, _Uj...>::type
1536227825Stheraven__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>)
1537227825Stheraven{
1538227825Stheraven    return __ti(_VSTD::forward<_Uj>(get<_Indx>(__uj))...);
1539227825Stheraven}
1540227825Stheraven
1541227825Stheraventemplate <class _Ti, class ..._Uj>
1542227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1543227825Stheraventypename enable_if
1544227825Stheraven<
1545227825Stheraven    is_bind_expression<_Ti>::value,
1546227825Stheraven    typename __invoke_of<_Ti&, _Uj...>::type
1547227825Stheraven>::type
1548227825Stheraven__mu(_Ti& __ti, tuple<_Uj...>& __uj)
1549227825Stheraven{
1550227825Stheraven    typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices;
1551227825Stheraven    return  __mu_expand(__ti, __uj, __indices());
1552227825Stheraven}
1553227825Stheraven
1554227825Stheraventemplate <bool IsPh, class _Ti, class _Uj>
1555227825Stheravenstruct __mu_return2 {};
1556227825Stheraven
1557227825Stheraventemplate <class _Ti, class _Uj>
1558227825Stheravenstruct __mu_return2<true, _Ti, _Uj>
1559227825Stheraven{
1560227825Stheraven    typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type;
1561227825Stheraven};
1562227825Stheraven
1563227825Stheraventemplate <class _Ti, class _Uj>
1564227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1565227825Stheraventypename enable_if
1566227825Stheraven<
1567227825Stheraven    0 < is_placeholder<_Ti>::value,
1568227825Stheraven    typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type
1569227825Stheraven>::type
1570227825Stheraven__mu(_Ti&, _Uj& __uj)
1571227825Stheraven{
1572227825Stheraven    const size_t _Indx = is_placeholder<_Ti>::value - 1;
1573227825Stheraven    return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(get<_Indx>(__uj));
1574227825Stheraven}
1575227825Stheraven
1576227825Stheraventemplate <class _Ti, class _Uj>
1577227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1578227825Stheraventypename enable_if
1579227825Stheraven<
1580227825Stheraven    !is_bind_expression<_Ti>::value &&
1581227825Stheraven    is_placeholder<_Ti>::value == 0 &&
1582227825Stheraven    !__is_reference_wrapper<_Ti>::value,
1583227825Stheraven    _Ti&
1584227825Stheraven>::type
1585232950Stheraven__mu(_Ti& __ti, _Uj&)
1586227825Stheraven{
1587227825Stheraven    return __ti;
1588227825Stheraven}
1589227825Stheraven
1590227825Stheraventemplate <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh,
1591227825Stheraven          class _TupleUj>
1592227825Stheravenstruct ____mu_return;
1593227825Stheraven
1594227825Stheraventemplate <class _Ti, class ..._Uj>
1595227825Stheravenstruct ____mu_return<_Ti, false, true, false, tuple<_Uj...> >
1596227825Stheraven{
1597227825Stheraven    typedef typename __invoke_of<_Ti&, _Uj...>::type type;
1598227825Stheraven};
1599227825Stheraven
1600227825Stheraventemplate <class _Ti, class _TupleUj>
1601227825Stheravenstruct ____mu_return<_Ti, false, false, true, _TupleUj>
1602227825Stheraven{
1603227825Stheraven    typedef typename tuple_element<is_placeholder<_Ti>::value - 1,
1604227825Stheraven                                   _TupleUj>::type&& type;
1605227825Stheraven};
1606227825Stheraven
1607227825Stheraventemplate <class _Ti, class _TupleUj>
1608227825Stheravenstruct ____mu_return<_Ti, true, false, false, _TupleUj>
1609227825Stheraven{
1610227825Stheraven    typedef typename _Ti::type& type;
1611227825Stheraven};
1612227825Stheraven
1613227825Stheraventemplate <class _Ti, class _TupleUj>
1614227825Stheravenstruct ____mu_return<_Ti, false, false, false, _TupleUj>
1615227825Stheraven{
1616227825Stheraven    typedef _Ti& type;
1617227825Stheraven};
1618227825Stheraven
1619227825Stheraventemplate <class _Ti, class _TupleUj>
1620227825Stheravenstruct __mu_return
1621227825Stheraven    : public ____mu_return<_Ti,
1622227825Stheraven                           __is_reference_wrapper<_Ti>::value,
1623227825Stheraven                           is_bind_expression<_Ti>::value,
1624227825Stheraven                           0 < is_placeholder<_Ti>::value,
1625227825Stheraven                           _TupleUj>
1626227825Stheraven{
1627227825Stheraven};
1628227825Stheraven
1629232950Stheraventemplate <class _Fp, class _BoundArgs, class _TupleUj>
1630227825Stheravenstruct __bind_return;
1631227825Stheraven
1632232950Stheraventemplate <class _Fp, class ..._BoundArgs, class _TupleUj>
1633232950Stheravenstruct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj>
1634227825Stheraven{
1635227825Stheraven    typedef typename __invoke_of
1636227825Stheraven    <
1637232950Stheraven        _Fp&,
1638227825Stheraven        typename __mu_return
1639227825Stheraven        <
1640227825Stheraven            _BoundArgs,
1641227825Stheraven            _TupleUj
1642227825Stheraven        >::type...
1643227825Stheraven    >::type type;
1644227825Stheraven};
1645227825Stheraven
1646232950Stheraventemplate <class _Fp, class ..._BoundArgs, class _TupleUj>
1647232950Stheravenstruct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj>
1648227825Stheraven{
1649227825Stheraven    typedef typename __invoke_of
1650227825Stheraven    <
1651232950Stheraven        _Fp&,
1652227825Stheraven        typename __mu_return
1653227825Stheraven        <
1654227825Stheraven            const _BoundArgs,
1655227825Stheraven            _TupleUj
1656227825Stheraven        >::type...
1657227825Stheraven    >::type type;
1658227825Stheraven};
1659227825Stheraven
1660232950Stheraventemplate <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args>
1661227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1662232950Stheraventypename __bind_return<_Fp, _BoundArgs, _Args>::type
1663232950Stheraven__apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
1664227825Stheraven                _Args&& __args)
1665227825Stheraven{
1666227825Stheraven    return __invoke(__f, __mu(get<_Indx>(__bound_args), __args)...);
1667227825Stheraven}
1668227825Stheraven
1669232950Stheraventemplate<class _Fp, class ..._BoundArgs>
1670227825Stheravenclass __bind
1671232950Stheraven    : public __weak_result_type<typename decay<_Fp>::type>
1672227825Stheraven{
1673232950Stheraven    typedef typename decay<_Fp>::type _Fd;
1674227825Stheraven    typedef tuple<typename decay<_BoundArgs>::type...> _Td;
1675227825Stheraven    _Fd __f_;
1676227825Stheraven    _Td __bound_args_;
1677227825Stheraven
1678227825Stheraven    typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices;
1679227825Stheravenpublic:
1680227825Stheraven#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
1681227825Stheraven
1682227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1683227825Stheraven    __bind(const __bind& __b)
1684227825Stheraven        : __f_(__b.__f_),
1685227825Stheraven          __bound_args_(__b.__bound_args_) {}
1686227825Stheraven
1687227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1688227825Stheraven    __bind& operator=(const __bind& __b)
1689227825Stheraven    {
1690227825Stheraven        __f_ = __b.__f_;
1691227825Stheraven        __bound_args_ = __b.__bound_args_;
1692227825Stheraven        return *this;
1693227825Stheraven    }
1694227825Stheraven
1695227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1696227825Stheraven    __bind(__bind&& __b)
1697227825Stheraven        : __f_(_VSTD::move(__b.__f_)),
1698227825Stheraven          __bound_args_(_VSTD::move(__b.__bound_args_)) {}
1699227825Stheraven
1700227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1701227825Stheraven    __bind& operator=(__bind&& __b)
1702227825Stheraven    {
1703227825Stheraven        __f_ = _VSTD::move(__b.__f_);
1704227825Stheraven        __bound_args_ = _VSTD::move(__b.__bound_args_);
1705227825Stheraven        return *this;
1706227825Stheraven    }
1707227825Stheraven
1708227825Stheraven#endif  // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
1709227825Stheraven
1710232950Stheraven    template <class _Gp, class ..._BA>
1711227825Stheraven      _LIBCPP_INLINE_VISIBILITY
1712232950Stheraven      explicit __bind(_Gp&& __f, _BA&& ...__bound_args)
1713232950Stheraven        : __f_(_VSTD::forward<_Gp>(__f)),
1714227825Stheraven          __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {}
1715227825Stheraven
1716227825Stheraven    template <class ..._Args>
1717227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1718227825Stheraven        typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type
1719227825Stheraven        operator()(_Args&& ...__args)
1720227825Stheraven        {
1721227825Stheraven            return __apply_functor(__f_, __bound_args_, __indices(),
1722227825Stheraven                                  tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
1723227825Stheraven        }
1724227825Stheraven
1725227825Stheraven    template <class ..._Args>
1726227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1727227825Stheraven        typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type
1728227825Stheraven        operator()(_Args&& ...__args) const
1729227825Stheraven        {
1730227825Stheraven            return __apply_functor(__f_, __bound_args_, __indices(),
1731227825Stheraven                                   tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
1732227825Stheraven        }
1733227825Stheraven};
1734227825Stheraven
1735232950Stheraventemplate<class _Fp, class ..._BoundArgs>
1736232950Stheravenstruct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {};
1737227825Stheraven
1738232950Stheraventemplate<class _Rp, class _Fp, class ..._BoundArgs>
1739227825Stheravenclass __bind_r
1740232950Stheraven    : public __bind<_Fp, _BoundArgs...>
1741227825Stheraven{
1742232950Stheraven    typedef __bind<_Fp, _BoundArgs...> base;
1743227825Stheravenpublic:
1744232950Stheraven    typedef _Rp result_type;
1745227825Stheraven
1746227825Stheraven#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
1747227825Stheraven
1748227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1749227825Stheraven    __bind_r(const __bind_r& __b)
1750227825Stheraven        : base(_VSTD::forward<const base&>(__b)) {}
1751227825Stheraven
1752227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1753227825Stheraven    __bind_r& operator=(const __bind_r& __b)
1754227825Stheraven    {
1755227825Stheraven        base::operator=(_VSTD::forward<const base&>(__b));
1756227825Stheraven        return *this;
1757227825Stheraven    }
1758227825Stheraven
1759227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1760227825Stheraven    __bind_r(__bind_r&& __b)
1761227825Stheraven        : base(_VSTD::forward<base>(__b)) {}
1762227825Stheraven
1763227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1764227825Stheraven    __bind_r& operator=(__bind_r&& __b)
1765227825Stheraven    {
1766227825Stheraven        base::operator=(_VSTD::forward<base>(__b));
1767227825Stheraven        return *this;
1768227825Stheraven    }
1769227825Stheraven
1770227825Stheraven#endif  // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
1771227825Stheraven
1772232950Stheraven    template <class _Gp, class ..._BA>
1773227825Stheraven      _LIBCPP_INLINE_VISIBILITY
1774232950Stheraven      explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args)
1775232950Stheraven        : base(_VSTD::forward<_Gp>(__f),
1776227825Stheraven               _VSTD::forward<_BA>(__bound_args)...) {}
1777227825Stheraven
1778227825Stheraven    template <class ..._Args>
1779227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1780227825Stheraven        result_type
1781227825Stheraven        operator()(_Args&& ...__args)
1782227825Stheraven        {
1783227825Stheraven            return base::operator()(_VSTD::forward<_Args>(__args)...);
1784227825Stheraven        }
1785227825Stheraven
1786227825Stheraven    template <class ..._Args>
1787227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1788227825Stheraven        result_type
1789227825Stheraven        operator()(_Args&& ...__args) const
1790227825Stheraven        {
1791227825Stheraven            return base::operator()(_VSTD::forward<_Args>(__args)...);
1792227825Stheraven        }
1793227825Stheraven};
1794227825Stheraven
1795232950Stheraventemplate<class _Rp, class _Fp, class ..._BoundArgs>
1796232950Stheravenstruct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {};
1797227825Stheraven
1798232950Stheraventemplate<class _Fp, class ..._BoundArgs>
1799227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1800232950Stheraven__bind<_Fp, _BoundArgs...>
1801232950Stheravenbind(_Fp&& __f, _BoundArgs&&... __bound_args)
1802227825Stheraven{
1803232950Stheraven    typedef __bind<_Fp, _BoundArgs...> type;
1804232950Stheraven    return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
1805227825Stheraven}
1806227825Stheraven
1807232950Stheraventemplate<class _Rp, class _Fp, class ..._BoundArgs>
1808227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1809232950Stheraven__bind_r<_Rp, _Fp, _BoundArgs...>
1810232950Stheravenbind(_Fp&& __f, _BoundArgs&&... __bound_args)
1811227825Stheraven{
1812232950Stheraven    typedef __bind_r<_Rp, _Fp, _BoundArgs...> type;
1813232950Stheraven    return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
1814227825Stheraven}
1815227825Stheraven
1816227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
1817227825Stheraven
1818227825Stheraventemplate <>
1819227825Stheravenstruct _LIBCPP_VISIBLE hash<bool>
1820227825Stheraven    : public unary_function<bool, size_t>
1821227825Stheraven{
1822227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1823227825Stheraven    size_t operator()(bool __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1824227825Stheraven};
1825227825Stheraven
1826227825Stheraventemplate <>
1827227825Stheravenstruct _LIBCPP_VISIBLE hash<char>
1828227825Stheraven    : public unary_function<char, size_t>
1829227825Stheraven{
1830227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1831227825Stheraven    size_t operator()(char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1832227825Stheraven};
1833227825Stheraven
1834227825Stheraventemplate <>
1835227825Stheravenstruct _LIBCPP_VISIBLE hash<signed char>
1836227825Stheraven    : public unary_function<signed char, size_t>
1837227825Stheraven{
1838227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1839227825Stheraven    size_t operator()(signed char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1840227825Stheraven};
1841227825Stheraven
1842227825Stheraventemplate <>
1843227825Stheravenstruct _LIBCPP_VISIBLE hash<unsigned char>
1844227825Stheraven    : public unary_function<unsigned char, size_t>
1845227825Stheraven{
1846227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1847227825Stheraven    size_t operator()(unsigned char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1848227825Stheraven};
1849227825Stheraven
1850227825Stheraven#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
1851227825Stheraven
1852227825Stheraventemplate <>
1853227825Stheravenstruct _LIBCPP_VISIBLE hash<char16_t>
1854227825Stheraven    : public unary_function<char16_t, size_t>
1855227825Stheraven{
1856227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1857227825Stheraven    size_t operator()(char16_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1858227825Stheraven};
1859227825Stheraven
1860227825Stheraventemplate <>
1861227825Stheravenstruct _LIBCPP_VISIBLE hash<char32_t>
1862227825Stheraven    : public unary_function<char32_t, size_t>
1863227825Stheraven{
1864227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1865227825Stheraven    size_t operator()(char32_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1866227825Stheraven};
1867227825Stheraven
1868227825Stheraven#endif  // _LIBCPP_HAS_NO_UNICODE_CHARS
1869227825Stheraven
1870227825Stheraventemplate <>
1871227825Stheravenstruct _LIBCPP_VISIBLE hash<wchar_t>
1872227825Stheraven    : public unary_function<wchar_t, size_t>
1873227825Stheraven{
1874227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1875227825Stheraven    size_t operator()(wchar_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1876227825Stheraven};
1877227825Stheraven
1878227825Stheraventemplate <>
1879227825Stheravenstruct _LIBCPP_VISIBLE hash<short>
1880227825Stheraven    : public unary_function<short, size_t>
1881227825Stheraven{
1882227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1883227825Stheraven    size_t operator()(short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1884227825Stheraven};
1885227825Stheraven
1886227825Stheraventemplate <>
1887227825Stheravenstruct _LIBCPP_VISIBLE hash<unsigned short>
1888227825Stheraven    : public unary_function<unsigned short, size_t>
1889227825Stheraven{
1890227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1891227825Stheraven    size_t operator()(unsigned short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1892227825Stheraven};
1893227825Stheraven
1894227825Stheraventemplate <>
1895227825Stheravenstruct _LIBCPP_VISIBLE hash<int>
1896227825Stheraven    : public unary_function<int, size_t>
1897227825Stheraven{
1898227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1899227825Stheraven    size_t operator()(int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1900227825Stheraven};
1901227825Stheraven
1902227825Stheraventemplate <>
1903227825Stheravenstruct _LIBCPP_VISIBLE hash<unsigned int>
1904227825Stheraven    : public unary_function<unsigned int, size_t>
1905227825Stheraven{
1906227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1907227825Stheraven    size_t operator()(unsigned int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1908227825Stheraven};
1909227825Stheraven
1910227825Stheraventemplate <>
1911227825Stheravenstruct _LIBCPP_VISIBLE hash<long>
1912227825Stheraven    : public unary_function<long, size_t>
1913227825Stheraven{
1914227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1915227825Stheraven    size_t operator()(long __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1916227825Stheraven};
1917227825Stheraven
1918227825Stheraventemplate <>
1919227825Stheravenstruct _LIBCPP_VISIBLE hash<unsigned long>
1920227825Stheraven    : public unary_function<unsigned long, size_t>
1921227825Stheraven{
1922227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1923227825Stheraven    size_t operator()(unsigned long __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1924227825Stheraven};
1925227825Stheraven
1926227825Stheraventemplate <>
1927227825Stheravenstruct _LIBCPP_VISIBLE hash<long long>
1928232950Stheraven    : public __scalar_hash<long long>
1929227825Stheraven{
1930227825Stheraven};
1931227825Stheraven
1932227825Stheraventemplate <>
1933227825Stheravenstruct _LIBCPP_VISIBLE hash<unsigned long long>
1934232950Stheraven    : public __scalar_hash<unsigned long long>
1935227825Stheraven{
1936227825Stheraven};
1937227825Stheraven
1938227825Stheraventemplate <>
1939227825Stheravenstruct _LIBCPP_VISIBLE hash<float>
1940232950Stheraven    : public __scalar_hash<float>
1941227825Stheraven{
1942227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1943227825Stheraven    size_t operator()(float __v) const _NOEXCEPT
1944227825Stheraven    {
1945232950Stheraven        // -0.0 and 0.0 should return same hash
1946232950Stheraven       if (__v == 0)
1947232950Stheraven           return 0;
1948232950Stheraven        return __scalar_hash<float>::operator()(__v);
1949227825Stheraven    }
1950227825Stheraven};
1951227825Stheraven
1952227825Stheraventemplate <>
1953227825Stheravenstruct _LIBCPP_VISIBLE hash<double>
1954232950Stheraven    : public __scalar_hash<double>
1955227825Stheraven{
1956227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1957227825Stheraven    size_t operator()(double __v) const _NOEXCEPT
1958227825Stheraven    {
1959232950Stheraven        // -0.0 and 0.0 should return same hash
1960232950Stheraven       if (__v == 0)
1961232950Stheraven           return 0;
1962232950Stheraven        return __scalar_hash<double>::operator()(__v);
1963227825Stheraven    }
1964227825Stheraven};
1965227825Stheraven
1966227825Stheraventemplate <>
1967227825Stheravenstruct _LIBCPP_VISIBLE hash<long double>
1968232950Stheraven    : public __scalar_hash<long double>
1969227825Stheraven{
1970227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1971227825Stheraven    size_t operator()(long double __v) const _NOEXCEPT
1972227825Stheraven    {
1973232950Stheraven        // -0.0 and 0.0 should return same hash
1974227825Stheraven        if (__v == 0)
1975227825Stheraven            return 0;
1976232950Stheraven#if defined(__i386__)
1977232950Stheraven        // Zero out padding bits
1978232950Stheraven        union
1979232950Stheraven        {
1980232950Stheraven            long double __t;
1981232950Stheraven            struct
1982232950Stheraven            {
1983232950Stheraven                size_t __a;
1984232950Stheraven                size_t __b;
1985232950Stheraven                size_t __c;
1986232950Stheraven                size_t __d;
1987232950Stheraven            };
1988232950Stheraven        } __u;
1989232950Stheraven        __u.__a = 0;
1990232950Stheraven        __u.__b = 0;
1991232950Stheraven        __u.__c = 0;
1992232950Stheraven        __u.__d = 0;
1993232950Stheraven        __u.__t = __v;
1994232950Stheraven        return __u.__a ^ __u.__b ^ __u.__c ^ __u.__d;
1995232950Stheraven#elif defined(__x86_64__)
1996232950Stheraven        // Zero out padding bits
1997232950Stheraven        union
1998232950Stheraven        {
1999232950Stheraven            long double __t;
2000232950Stheraven            struct
2001232950Stheraven            {
2002232950Stheraven                size_t __a;
2003232950Stheraven                size_t __b;
2004232950Stheraven            };
2005232950Stheraven        } __u;
2006232950Stheraven        __u.__a = 0;
2007232950Stheraven        __u.__b = 0;
2008232950Stheraven        __u.__t = __v;
2009232950Stheraven        return __u.__a ^ __u.__b;
2010232950Stheraven#else
2011232950Stheraven        return __scalar_hash<long double>::operator()(__v);
2012232950Stheraven#endif
2013227825Stheraven    }
2014227825Stheraven};
2015227825Stheraven
2016227825Stheraven// struct hash<T*> in <memory>
2017227825Stheraven
2018227825Stheraven_LIBCPP_END_NAMESPACE_STD
2019227825Stheraven
2020227825Stheraven#endif  // _LIBCPP_FUNCTIONAL
2021