functional revision 227825
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  .
201227825Stheraven  extern unspecified _M;
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
539227825Stheraventemplate <class _Tp>
540227825Stheravenstruct _LIBCPP_VISIBLE less : binary_function<_Tp, _Tp, bool>
541227825Stheraven{
542227825Stheraven    _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
543227825Stheraven        {return __x < __y;}
544227825Stheraven};
545227825Stheraven
546227825Stheraventemplate <class _Tp>
547227825Stheravenstruct _LIBCPP_VISIBLE greater_equal : binary_function<_Tp, _Tp, bool>
548227825Stheraven{
549227825Stheraven    _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
550227825Stheraven        {return __x >= __y;}
551227825Stheraven};
552227825Stheraven
553227825Stheraventemplate <class _Tp>
554227825Stheravenstruct _LIBCPP_VISIBLE less_equal : binary_function<_Tp, _Tp, bool>
555227825Stheraven{
556227825Stheraven    _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
557227825Stheraven        {return __x <= __y;}
558227825Stheraven};
559227825Stheraven
560227825Stheraventemplate <class _Tp>
561227825Stheravenstruct _LIBCPP_VISIBLE logical_and : binary_function<_Tp, _Tp, bool>
562227825Stheraven{
563227825Stheraven    _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
564227825Stheraven        {return __x && __y;}
565227825Stheraven};
566227825Stheraven
567227825Stheraventemplate <class _Tp>
568227825Stheravenstruct _LIBCPP_VISIBLE logical_or : binary_function<_Tp, _Tp, bool>
569227825Stheraven{
570227825Stheraven    _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
571227825Stheraven        {return __x || __y;}
572227825Stheraven};
573227825Stheraven
574227825Stheraventemplate <class _Tp>
575227825Stheravenstruct _LIBCPP_VISIBLE logical_not : unary_function<_Tp, bool>
576227825Stheraven{
577227825Stheraven    _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x) const
578227825Stheraven        {return !__x;}
579227825Stheraven};
580227825Stheraven
581227825Stheraventemplate <class _Tp>
582227825Stheravenstruct _LIBCPP_VISIBLE bit_and : binary_function<_Tp, _Tp, _Tp>
583227825Stheraven{
584227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
585227825Stheraven        {return __x & __y;}
586227825Stheraven};
587227825Stheraven
588227825Stheraventemplate <class _Tp>
589227825Stheravenstruct _LIBCPP_VISIBLE bit_or : binary_function<_Tp, _Tp, _Tp>
590227825Stheraven{
591227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
592227825Stheraven        {return __x | __y;}
593227825Stheraven};
594227825Stheraven
595227825Stheraventemplate <class _Tp>
596227825Stheravenstruct _LIBCPP_VISIBLE bit_xor : binary_function<_Tp, _Tp, _Tp>
597227825Stheraven{
598227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
599227825Stheraven        {return __x ^ __y;}
600227825Stheraven};
601227825Stheraven
602227825Stheraventemplate <class _Predicate>
603227825Stheravenclass _LIBCPP_VISIBLE unary_negate
604227825Stheraven    : public unary_function<typename _Predicate::argument_type, bool>
605227825Stheraven{
606227825Stheraven    _Predicate __pred_;
607227825Stheravenpublic:
608227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit unary_negate(const _Predicate& __pred)
609227825Stheraven        : __pred_(__pred) {}
610227825Stheraven    _LIBCPP_INLINE_VISIBILITY bool operator()(const typename _Predicate::argument_type& __x) const
611227825Stheraven        {return !__pred_(__x);}
612227825Stheraven};
613227825Stheraven
614227825Stheraventemplate <class _Predicate>
615227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
616227825Stheravenunary_negate<_Predicate>
617227825Stheravennot1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);}
618227825Stheraven
619227825Stheraventemplate <class _Predicate>
620227825Stheravenclass _LIBCPP_VISIBLE binary_negate
621227825Stheraven    : public binary_function<typename _Predicate::first_argument_type,
622227825Stheraven                             typename _Predicate::second_argument_type,
623227825Stheraven                             bool>
624227825Stheraven{
625227825Stheraven    _Predicate __pred_;
626227825Stheravenpublic:
627227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit binary_negate(const _Predicate& __pred)
628227825Stheraven        : __pred_(__pred) {}
629227825Stheraven    _LIBCPP_INLINE_VISIBILITY bool operator()(const typename _Predicate::first_argument_type& __x,
630227825Stheraven                    const typename _Predicate::second_argument_type& __y) const
631227825Stheraven        {return !__pred_(__x, __y);}
632227825Stheraven};
633227825Stheraven
634227825Stheraventemplate <class _Predicate>
635227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
636227825Stheravenbinary_negate<_Predicate>
637227825Stheravennot2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);}
638227825Stheraven
639227825Stheraventemplate <class __Operation>
640227825Stheravenclass _LIBCPP_VISIBLE binder1st
641227825Stheraven    : public unary_function<typename __Operation::second_argument_type,
642227825Stheraven                            typename __Operation::result_type>
643227825Stheraven{
644227825Stheravenprotected:
645227825Stheraven    __Operation                               op;
646227825Stheraven    typename __Operation::first_argument_type value;
647227825Stheravenpublic:
648227825Stheraven    _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x,
649227825Stheraven                               const typename __Operation::first_argument_type __y)
650227825Stheraven        : op(__x), value(__y) {}
651227825Stheraven    _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
652227825Stheraven        (typename __Operation::second_argument_type& __x) const
653227825Stheraven            {return op(value, __x);}
654227825Stheraven    _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
655227825Stheraven        (const typename __Operation::second_argument_type& __x) const
656227825Stheraven            {return op(value, __x);}
657227825Stheraven};
658227825Stheraven
659227825Stheraventemplate <class __Operation, class _Tp>
660227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
661227825Stheravenbinder1st<__Operation>
662227825Stheravenbind1st(const __Operation& __op, const _Tp& __x)
663227825Stheraven    {return binder1st<__Operation>(__op, __x);}
664227825Stheraven
665227825Stheraventemplate <class __Operation>
666227825Stheravenclass _LIBCPP_VISIBLE binder2nd
667227825Stheraven    : public unary_function<typename __Operation::first_argument_type,
668227825Stheraven                            typename __Operation::result_type>
669227825Stheraven{
670227825Stheravenprotected:
671227825Stheraven    __Operation                                op;
672227825Stheraven    typename __Operation::second_argument_type value;
673227825Stheravenpublic:
674227825Stheraven    _LIBCPP_INLINE_VISIBILITY
675227825Stheraven    binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y)
676227825Stheraven        : op(__x), value(__y) {}
677227825Stheraven    _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
678227825Stheraven        (      typename __Operation::first_argument_type& __x) const
679227825Stheraven            {return op(__x, value);}
680227825Stheraven    _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
681227825Stheraven        (const typename __Operation::first_argument_type& __x) const
682227825Stheraven            {return op(__x, value);}
683227825Stheraven};
684227825Stheraven
685227825Stheraventemplate <class __Operation, class _Tp>
686227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
687227825Stheravenbinder2nd<__Operation>
688227825Stheravenbind2nd(const __Operation& __op, const _Tp& __x)
689227825Stheraven    {return binder2nd<__Operation>(__op, __x);}
690227825Stheraven
691227825Stheraventemplate <class _Arg, class _Result>
692227825Stheravenclass _LIBCPP_VISIBLE pointer_to_unary_function
693227825Stheraven    : public unary_function<_Arg, _Result>
694227825Stheraven{
695227825Stheraven    _Result (*__f_)(_Arg);
696227825Stheravenpublic:
697227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg))
698227825Stheraven        : __f_(__f) {}
699227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const
700227825Stheraven        {return __f_(__x);}
701227825Stheraven};
702227825Stheraven
703227825Stheraventemplate <class _Arg, class _Result>
704227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
705227825Stheravenpointer_to_unary_function<_Arg,_Result>
706227825Stheravenptr_fun(_Result (*__f)(_Arg))
707227825Stheraven    {return pointer_to_unary_function<_Arg,_Result>(__f);}
708227825Stheraven
709227825Stheraventemplate <class _Arg1, class _Arg2, class _Result>
710227825Stheravenclass _LIBCPP_VISIBLE pointer_to_binary_function
711227825Stheraven    : public binary_function<_Arg1, _Arg2, _Result>
712227825Stheraven{
713227825Stheraven    _Result (*__f_)(_Arg1, _Arg2);
714227825Stheravenpublic:
715227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2))
716227825Stheraven        : __f_(__f) {}
717227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const
718227825Stheraven        {return __f_(__x, __y);}
719227825Stheraven};
720227825Stheraven
721227825Stheraventemplate <class _Arg1, class _Arg2, class _Result>
722227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
723227825Stheravenpointer_to_binary_function<_Arg1,_Arg2,_Result>
724227825Stheravenptr_fun(_Result (*__f)(_Arg1,_Arg2))
725227825Stheraven    {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);}
726227825Stheraven
727227825Stheraventemplate<class _Sp, class _Tp>
728227825Stheravenclass _LIBCPP_VISIBLE mem_fun_t : public unary_function<_Tp*, _Sp>
729227825Stheraven{
730227825Stheraven    _Sp (_Tp::*__p_)();
731227825Stheravenpublic:
732227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)())
733227825Stheraven        : __p_(__p) {}
734227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const
735227825Stheraven        {return (__p->*__p_)();}
736227825Stheraven};
737227825Stheraven
738227825Stheraventemplate<class _Sp, class _Tp, class _Ap>
739227825Stheravenclass _LIBCPP_VISIBLE mem_fun1_t : public binary_function<_Tp*, _Ap, _Sp>
740227825Stheraven{
741227825Stheraven    _Sp (_Tp::*__p_)(_Ap);
742227825Stheravenpublic:
743227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap))
744227825Stheraven        : __p_(__p) {}
745227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const
746227825Stheraven        {return (__p->*__p_)(__x);}
747227825Stheraven};
748227825Stheraven
749227825Stheraventemplate<class _Sp, class _Tp>
750227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
751227825Stheravenmem_fun_t<_Sp,_Tp>
752227825Stheravenmem_fun(_Sp (_Tp::*__f)())
753227825Stheraven    {return mem_fun_t<_Sp,_Tp>(__f);}
754227825Stheraven
755227825Stheraventemplate<class _Sp, class _Tp, class _Ap>
756227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
757227825Stheravenmem_fun1_t<_Sp,_Tp,_Ap>
758227825Stheravenmem_fun(_Sp (_Tp::*__f)(_Ap))
759227825Stheraven    {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
760227825Stheraven
761227825Stheraventemplate<class _Sp, class _Tp>
762227825Stheravenclass _LIBCPP_VISIBLE mem_fun_ref_t : public unary_function<_Tp, _Sp>
763227825Stheraven{
764227825Stheraven    _Sp (_Tp::*__p_)();
765227825Stheravenpublic:
766227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)())
767227825Stheraven        : __p_(__p) {}
768227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const
769227825Stheraven        {return (__p.*__p_)();}
770227825Stheraven};
771227825Stheraven
772227825Stheraventemplate<class _Sp, class _Tp, class _Ap>
773227825Stheravenclass _LIBCPP_VISIBLE mem_fun1_ref_t : public binary_function<_Tp, _Ap, _Sp>
774227825Stheraven{
775227825Stheraven    _Sp (_Tp::*__p_)(_Ap);
776227825Stheravenpublic:
777227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap))
778227825Stheraven        : __p_(__p) {}
779227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const
780227825Stheraven        {return (__p.*__p_)(__x);}
781227825Stheraven};
782227825Stheraven
783227825Stheraventemplate<class _Sp, class _Tp>
784227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
785227825Stheravenmem_fun_ref_t<_Sp,_Tp>
786227825Stheravenmem_fun_ref(_Sp (_Tp::*__f)())
787227825Stheraven    {return mem_fun_ref_t<_Sp,_Tp>(__f);}
788227825Stheraven
789227825Stheraventemplate<class _Sp, class _Tp, class _Ap>
790227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
791227825Stheravenmem_fun1_ref_t<_Sp,_Tp,_Ap>
792227825Stheravenmem_fun_ref(_Sp (_Tp::*__f)(_Ap))
793227825Stheraven    {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
794227825Stheraven
795227825Stheraventemplate <class _Sp, class _Tp>
796227825Stheravenclass _LIBCPP_VISIBLE const_mem_fun_t : public unary_function<const _Tp*, _Sp>
797227825Stheraven{
798227825Stheraven    _Sp (_Tp::*__p_)() const;
799227825Stheravenpublic:
800227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const)
801227825Stheraven        : __p_(__p) {}
802227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const
803227825Stheraven        {return (__p->*__p_)();}
804227825Stheraven};
805227825Stheraven
806227825Stheraventemplate <class _Sp, class _Tp, class _Ap>
807227825Stheravenclass _LIBCPP_VISIBLE const_mem_fun1_t : public binary_function<const _Tp*, _Ap, _Sp>
808227825Stheraven{
809227825Stheraven    _Sp (_Tp::*__p_)(_Ap) const;
810227825Stheravenpublic:
811227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const)
812227825Stheraven        : __p_(__p) {}
813227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const
814227825Stheraven        {return (__p->*__p_)(__x);}
815227825Stheraven};
816227825Stheraven
817227825Stheraventemplate <class _Sp, class _Tp>
818227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
819227825Stheravenconst_mem_fun_t<_Sp,_Tp>
820227825Stheravenmem_fun(_Sp (_Tp::*__f)() const)
821227825Stheraven    {return const_mem_fun_t<_Sp,_Tp>(__f);}
822227825Stheraven
823227825Stheraventemplate <class _Sp, class _Tp, class _Ap>
824227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
825227825Stheravenconst_mem_fun1_t<_Sp,_Tp,_Ap>
826227825Stheravenmem_fun(_Sp (_Tp::*__f)(_Ap) const)
827227825Stheraven    {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
828227825Stheraven
829227825Stheraventemplate <class _Sp, class _Tp>
830227825Stheravenclass _LIBCPP_VISIBLE const_mem_fun_ref_t : public unary_function<_Tp, _Sp>
831227825Stheraven{
832227825Stheraven    _Sp (_Tp::*__p_)() const;
833227825Stheravenpublic:
834227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const)
835227825Stheraven        : __p_(__p) {}
836227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const
837227825Stheraven        {return (__p.*__p_)();}
838227825Stheraven};
839227825Stheraven
840227825Stheraventemplate <class _Sp, class _Tp, class _Ap>
841227825Stheravenclass _LIBCPP_VISIBLE const_mem_fun1_ref_t
842227825Stheraven    : public binary_function<_Tp, _Ap, _Sp>
843227825Stheraven{
844227825Stheraven    _Sp (_Tp::*__p_)(_Ap) const;
845227825Stheravenpublic:
846227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const)
847227825Stheraven        : __p_(__p) {}
848227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const
849227825Stheraven        {return (__p.*__p_)(__x);}
850227825Stheraven};
851227825Stheraven
852227825Stheraventemplate <class _Sp, class _Tp>
853227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
854227825Stheravenconst_mem_fun_ref_t<_Sp,_Tp>
855227825Stheravenmem_fun_ref(_Sp (_Tp::*__f)() const)
856227825Stheraven    {return const_mem_fun_ref_t<_Sp,_Tp>(__f);}
857227825Stheraven
858227825Stheraventemplate <class _Sp, class _Tp, class _Ap>
859227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
860227825Stheravenconst_mem_fun1_ref_t<_Sp,_Tp,_Ap>
861227825Stheravenmem_fun_ref(_Sp (_Tp::*__f)(_Ap) const)
862227825Stheraven    {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
863227825Stheraven
864227825Stheraven#ifdef _LIBCPP_HAS_NO_VARIADICS
865227825Stheraven
866227825Stheraven#include <__functional_03>
867227825Stheraven
868227825Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
869227825Stheraven
870227825Stheraventemplate <class _Tp>
871227825Stheravenclass __mem_fn
872227825Stheraven    : public __weak_result_type<_Tp>
873227825Stheraven{
874227825Stheravenpublic:
875227825Stheraven    // types
876227825Stheraven    typedef _Tp type;
877227825Stheravenprivate:
878227825Stheraven    type __f_;
879227825Stheraven
880227825Stheravenpublic:
881227825Stheraven    _LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) : __f_(__f) {}
882227825Stheraven
883227825Stheraven    // invoke
884227825Stheraven    template <class... _ArgTypes>
885227825Stheraven       _LIBCPP_INLINE_VISIBILITY
886227825Stheraven       typename __invoke_return<type, _ArgTypes...>::type
887227825Stheraven          operator() (_ArgTypes&&... __args)
888227825Stheraven          {
889227825Stheraven              return __invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...);
890227825Stheraven          }
891227825Stheraven};
892227825Stheraven
893227825Stheraventemplate<class _R, class _T>
894227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
895227825Stheraven__mem_fn<_R _T::*>
896227825Stheravenmem_fn(_R _T::* __pm)
897227825Stheraven{
898227825Stheraven    return __mem_fn<_R _T::*>(__pm);
899227825Stheraven}
900227825Stheraven
901227825Stheraventemplate<class _R, class _T, class ..._Args>
902227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
903227825Stheraven__mem_fn<_R (_T::*)(_Args...)>
904227825Stheravenmem_fn(_R (_T::* __pm)(_Args...))
905227825Stheraven{
906227825Stheraven    return __mem_fn<_R (_T::*)(_Args...)>(__pm);
907227825Stheraven}
908227825Stheraven
909227825Stheraventemplate<class _R, class _T, class ..._Args>
910227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
911227825Stheraven__mem_fn<_R (_T::*)(_Args...) const>
912227825Stheravenmem_fn(_R (_T::* __pm)(_Args...) const)
913227825Stheraven{
914227825Stheraven    return __mem_fn<_R (_T::*)(_Args...) const>(__pm);
915227825Stheraven}
916227825Stheraven
917227825Stheraventemplate<class _R, class _T, class ..._Args>
918227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
919227825Stheraven__mem_fn<_R (_T::*)(_Args...) volatile>
920227825Stheravenmem_fn(_R (_T::* __pm)(_Args...) volatile)
921227825Stheraven{
922227825Stheraven    return __mem_fn<_R (_T::*)(_Args...) volatile>(__pm);
923227825Stheraven}
924227825Stheraven
925227825Stheraventemplate<class _R, class _T, class ..._Args>
926227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
927227825Stheraven__mem_fn<_R (_T::*)(_Args...) const volatile>
928227825Stheravenmem_fn(_R (_T::* __pm)(_Args...) const volatile)
929227825Stheraven{
930227825Stheraven    return __mem_fn<_R (_T::*)(_Args...) const volatile>(__pm);
931227825Stheraven}
932227825Stheraven
933227825Stheraven// bad_function_call
934227825Stheraven
935227825Stheravenclass _LIBCPP_EXCEPTION_ABI bad_function_call
936227825Stheraven    : public exception
937227825Stheraven{
938227825Stheraven};
939227825Stheraven
940227825Stheraventemplate<class _Fp> class _LIBCPP_VISIBLE function; // undefined
941227825Stheraven
942227825Stheravennamespace __function
943227825Stheraven{
944227825Stheraven
945227825Stheraventemplate<class _R, class ..._ArgTypes>
946227825Stheravenstruct __maybe_derive_from_unary_function
947227825Stheraven{
948227825Stheraven};
949227825Stheraven
950227825Stheraventemplate<class _R, class _A1>
951227825Stheravenstruct __maybe_derive_from_unary_function<_R(_A1)>
952227825Stheraven    : public unary_function<_A1, _R>
953227825Stheraven{
954227825Stheraven};
955227825Stheraven
956227825Stheraventemplate<class _R, class ..._ArgTypes>
957227825Stheravenstruct __maybe_derive_from_binary_function
958227825Stheraven{
959227825Stheraven};
960227825Stheraven
961227825Stheraventemplate<class _R, class _A1, class _A2>
962227825Stheravenstruct __maybe_derive_from_binary_function<_R(_A1, _A2)>
963227825Stheraven    : public binary_function<_A1, _A2, _R>
964227825Stheraven{
965227825Stheraven};
966227825Stheraven
967227825Stheraventemplate<class _Fp> class __base;
968227825Stheraven
969227825Stheraventemplate<class _R, class ..._ArgTypes>
970227825Stheravenclass __base<_R(_ArgTypes...)>
971227825Stheraven{
972227825Stheraven    __base(const __base&);
973227825Stheraven    __base& operator=(const __base&);
974227825Stheravenpublic:
975227825Stheraven    _LIBCPP_INLINE_VISIBILITY __base() {}
976227825Stheraven    _LIBCPP_INLINE_VISIBILITY virtual ~__base() {}
977227825Stheraven    virtual __base* __clone() const = 0;
978227825Stheraven    virtual void __clone(__base*) const = 0;
979227825Stheraven    virtual void destroy() _NOEXCEPT = 0;
980227825Stheraven    virtual void destroy_deallocate() _NOEXCEPT = 0;
981227825Stheraven    virtual _R operator()(_ArgTypes&& ...) = 0;
982227825Stheraven#ifndef _LIBCPP_NO_RTTI
983227825Stheraven    virtual const void* target(const type_info&) const _NOEXCEPT = 0;
984227825Stheraven    virtual const std::type_info& target_type() const _NOEXCEPT = 0;
985227825Stheraven#endif  // _LIBCPP_NO_RTTI
986227825Stheraven};
987227825Stheraven
988227825Stheraventemplate<class _FD, class _Alloc, class _FB> class __func;
989227825Stheraven
990227825Stheraventemplate<class _F, class _Alloc, class _R, class ..._ArgTypes>
991227825Stheravenclass __func<_F, _Alloc, _R(_ArgTypes...)>
992227825Stheraven    : public  __base<_R(_ArgTypes...)>
993227825Stheraven{
994227825Stheraven    __compressed_pair<_F, _Alloc> __f_;
995227825Stheravenpublic:
996227825Stheraven    _LIBCPP_INLINE_VISIBILITY
997227825Stheraven    explicit __func(_F __f) : __f_(_VSTD::move(__f)) {}
998227825Stheraven    _LIBCPP_INLINE_VISIBILITY
999227825Stheraven    explicit __func(_F __f, _Alloc __a) : __f_(_VSTD::move(__f), _VSTD::move(__a)) {}
1000227825Stheraven    virtual __base<_R(_ArgTypes...)>* __clone() const;
1001227825Stheraven    virtual void __clone(__base<_R(_ArgTypes...)>*) const;
1002227825Stheraven    virtual void destroy() _NOEXCEPT;
1003227825Stheraven    virtual void destroy_deallocate() _NOEXCEPT;
1004227825Stheraven    virtual _R operator()(_ArgTypes&& ... __arg);
1005227825Stheraven#ifndef _LIBCPP_NO_RTTI
1006227825Stheraven    virtual const void* target(const type_info&) const _NOEXCEPT;
1007227825Stheraven    virtual const std::type_info& target_type() const _NOEXCEPT;
1008227825Stheraven#endif  // _LIBCPP_NO_RTTI
1009227825Stheraven};
1010227825Stheraven
1011227825Stheraventemplate<class _F, class _Alloc, class _R, class ..._ArgTypes>
1012227825Stheraven__base<_R(_ArgTypes...)>*
1013227825Stheraven__func<_F, _Alloc, _R(_ArgTypes...)>::__clone() const
1014227825Stheraven{
1015227825Stheraven    typedef typename _Alloc::template rebind<__func>::other _A;
1016227825Stheraven    _A __a(__f_.second());
1017227825Stheraven    typedef __allocator_destructor<_A> _D;
1018227825Stheraven    unique_ptr<__func, _D> __hold(__a.allocate(1), _D(__a, 1));
1019227825Stheraven    ::new (__hold.get()) __func(__f_.first(), _Alloc(__a));
1020227825Stheraven    return __hold.release();
1021227825Stheraven}
1022227825Stheraven
1023227825Stheraventemplate<class _F, class _Alloc, class _R, class ..._ArgTypes>
1024227825Stheravenvoid
1025227825Stheraven__func<_F, _Alloc, _R(_ArgTypes...)>::__clone(__base<_R(_ArgTypes...)>* __p) const
1026227825Stheraven{
1027227825Stheraven    ::new (__p) __func(__f_.first(), __f_.second());
1028227825Stheraven}
1029227825Stheraven
1030227825Stheraventemplate<class _F, class _Alloc, class _R, class ..._ArgTypes>
1031227825Stheravenvoid
1032227825Stheraven__func<_F, _Alloc, _R(_ArgTypes...)>::destroy() _NOEXCEPT
1033227825Stheraven{
1034227825Stheraven    __f_.~__compressed_pair<_F, _Alloc>();
1035227825Stheraven}
1036227825Stheraven
1037227825Stheraventemplate<class _F, class _Alloc, class _R, class ..._ArgTypes>
1038227825Stheravenvoid
1039227825Stheraven__func<_F, _Alloc, _R(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT
1040227825Stheraven{
1041227825Stheraven    typedef typename _Alloc::template rebind<__func>::other _A;
1042227825Stheraven    _A __a(__f_.second());
1043227825Stheraven    __f_.~__compressed_pair<_F, _Alloc>();
1044227825Stheraven    __a.deallocate(this, 1);
1045227825Stheraven}
1046227825Stheraven
1047227825Stheraventemplate<class _F, class _Alloc, class _R, class ..._ArgTypes>
1048227825Stheraven_R
1049227825Stheraven__func<_F, _Alloc, _R(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg)
1050227825Stheraven{
1051227825Stheraven    return __invoke(__f_.first(), _VSTD::forward<_ArgTypes>(__arg)...);
1052227825Stheraven}
1053227825Stheraven
1054227825Stheraven#ifndef _LIBCPP_NO_RTTI
1055227825Stheraven
1056227825Stheraventemplate<class _F, class _Alloc, class _R, class ..._ArgTypes>
1057227825Stheravenconst void*
1058227825Stheraven__func<_F, _Alloc, _R(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT
1059227825Stheraven{
1060227825Stheraven    if (__ti == typeid(_F))
1061227825Stheraven        return &__f_.first();
1062227825Stheraven    return (const void*)0;
1063227825Stheraven}
1064227825Stheraven
1065227825Stheraventemplate<class _F, class _Alloc, class _R, class ..._ArgTypes>
1066227825Stheravenconst std::type_info&
1067227825Stheraven__func<_F, _Alloc, _R(_ArgTypes...)>::target_type() const _NOEXCEPT
1068227825Stheraven{
1069227825Stheraven    return typeid(_F);
1070227825Stheraven}
1071227825Stheraven
1072227825Stheraven#endif  // _LIBCPP_NO_RTTI
1073227825Stheraven
1074227825Stheraven}  // __function
1075227825Stheraven
1076227825Stheraventemplate<class _R, class ..._ArgTypes>
1077227825Stheravenclass _LIBCPP_VISIBLE function<_R(_ArgTypes...)>
1078227825Stheraven    : public __function::__maybe_derive_from_unary_function<_R(_ArgTypes...)>,
1079227825Stheraven      public __function::__maybe_derive_from_binary_function<_R(_ArgTypes...)>
1080227825Stheraven{
1081227825Stheraven    typedef __function::__base<_R(_ArgTypes...)> __base;
1082227825Stheraven    aligned_storage<3*sizeof(void*)>::type __buf_;
1083227825Stheraven    __base* __f_;
1084227825Stheraven
1085227825Stheraven    template <class _F>
1086227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1087227825Stheraven        static bool __not_null(const _F&) {return true;}
1088227825Stheraven    template <class _R2, class ..._A>
1089227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1090227825Stheraven        static bool __not_null(_R2 (*__p)(_A...)) {return __p;}
1091227825Stheraven    template <class _R2, class _C, class ..._A>
1092227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1093227825Stheraven        static bool __not_null(_R2 (_C::*__p)(_A...)) {return __p;}
1094227825Stheraven    template <class _R2, class _C, class ..._A>
1095227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1096227825Stheraven        static bool __not_null(_R2 (_C::*__p)(_A...) const) {return __p;}
1097227825Stheraven    template <class _R2, class _C, class ..._A>
1098227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1099227825Stheraven        static bool __not_null(_R2 (_C::*__p)(_A...) volatile) {return __p;}
1100227825Stheraven    template <class _R2, class _C, class ..._A>
1101227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1102227825Stheraven        static bool __not_null(_R2 (_C::*__p)(_A...) const volatile) {return __p;}
1103227825Stheraven    template <class _R2, class ..._A>
1104227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1105227825Stheraven        static bool __not_null(const function<_R(_A...)>& __p) {return __p;}
1106227825Stheraven
1107227825Stheraven    template <class _F, bool = __invokable<_F&, _ArgTypes...>::value>
1108227825Stheraven        struct __callable;
1109227825Stheraven    template <class _F>
1110227825Stheraven        struct __callable<_F, true>
1111227825Stheraven        {
1112227825Stheraven            static const bool value =
1113227825Stheraven                is_convertible<typename __invoke_of<_F&, _ArgTypes...>::type,
1114227825Stheraven                               _R>::value;
1115227825Stheraven        };
1116227825Stheraven    template <class _F>
1117227825Stheraven        struct __callable<_F, false>
1118227825Stheraven        {
1119227825Stheraven            static const bool value = false;
1120227825Stheraven        };
1121227825Stheravenpublic:
1122227825Stheraven    typedef _R result_type;
1123227825Stheraven
1124227825Stheraven    // construct/copy/destroy:
1125227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1126227825Stheraven    function() _NOEXCEPT : __f_(0) {}
1127227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1128227825Stheraven    function(nullptr_t) _NOEXCEPT : __f_(0) {}
1129227825Stheraven    function(const function&);
1130227825Stheraven    function(function&&) _NOEXCEPT;
1131227825Stheraven    template<class _F>
1132227825Stheraven      function(_F,
1133227825Stheraven               typename enable_if<__callable<_F>::value>::type* = 0);
1134227825Stheraven
1135227825Stheraven    template<class _Alloc>
1136227825Stheraven      _LIBCPP_INLINE_VISIBILITY
1137227825Stheraven      function(allocator_arg_t, const _Alloc&) _NOEXCEPT : __f_(0) {}
1138227825Stheraven    template<class _Alloc>
1139227825Stheraven      _LIBCPP_INLINE_VISIBILITY
1140227825Stheraven      function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT : __f_(0) {}
1141227825Stheraven    template<class _Alloc>
1142227825Stheraven      function(allocator_arg_t, const _Alloc&, const function&);
1143227825Stheraven    template<class _Alloc>
1144227825Stheraven      function(allocator_arg_t, const _Alloc&, function&&);
1145227825Stheraven    template<class _F, class _Alloc>
1146227825Stheraven      function(allocator_arg_t, const _Alloc& __a, _F __f,
1147227825Stheraven               typename enable_if<__callable<_F>::value>::type* = 0);
1148227825Stheraven
1149227825Stheraven    function& operator=(const function&);
1150227825Stheraven    function& operator=(function&&) _NOEXCEPT;
1151227825Stheraven    function& operator=(nullptr_t) _NOEXCEPT;
1152227825Stheraven    template<class _F>
1153227825Stheraven      typename enable_if
1154227825Stheraven      <
1155227825Stheraven        __callable<typename decay<_F>::type>::value,
1156227825Stheraven        function&
1157227825Stheraven      >::type
1158227825Stheraven      operator=(_F&&);
1159227825Stheraven
1160227825Stheraven    ~function();
1161227825Stheraven
1162227825Stheraven    // function modifiers:
1163227825Stheraven    void swap(function&) _NOEXCEPT;
1164227825Stheraven    template<class _F, class _Alloc>
1165227825Stheraven      _LIBCPP_INLINE_VISIBILITY
1166227825Stheraven      void assign(_F&& __f, const _Alloc& __a)
1167227825Stheraven        {function(allocator_arg, __a, _VSTD::forward<_F>(__f)).swap(*this);}
1168227825Stheraven
1169227825Stheraven    // function capacity:
1170227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1171227825Stheraven    /*explicit*/ operator bool() const _NOEXCEPT {return __f_;}
1172227825Stheraven
1173227825Stheraven    // deleted overloads close possible hole in the type system
1174227825Stheraven    template<class _R2, class... _ArgTypes2>
1175227825Stheraven      bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete;
1176227825Stheraven    template<class _R2, class... _ArgTypes2>
1177227825Stheraven      bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete;
1178227825Stheravenpublic:
1179227825Stheraven    // function invocation:
1180227825Stheraven    _R operator()(_ArgTypes...) const;
1181227825Stheraven
1182227825Stheraven#ifndef _LIBCPP_NO_RTTI
1183227825Stheraven    // function target access:
1184227825Stheraven    const std::type_info& target_type() const _NOEXCEPT;
1185227825Stheraven    template <typename _T> _T* target() _NOEXCEPT;
1186227825Stheraven    template <typename _T> const _T* target() const _NOEXCEPT;
1187227825Stheraven#endif  // _LIBCPP_NO_RTTI
1188227825Stheraven};
1189227825Stheraven
1190227825Stheraventemplate<class _R, class ..._ArgTypes>
1191227825Stheravenfunction<_R(_ArgTypes...)>::function(const function& __f)
1192227825Stheraven{
1193227825Stheraven    if (__f.__f_ == 0)
1194227825Stheraven        __f_ = 0;
1195227825Stheraven    else if (__f.__f_ == (const __base*)&__f.__buf_)
1196227825Stheraven    {
1197227825Stheraven        __f_ = (__base*)&__buf_;
1198227825Stheraven        __f.__f_->__clone(__f_);
1199227825Stheraven    }
1200227825Stheraven    else
1201227825Stheraven        __f_ = __f.__f_->__clone();
1202227825Stheraven}
1203227825Stheraven
1204227825Stheraventemplate<class _R, class ..._ArgTypes>
1205227825Stheraventemplate <class _Alloc>
1206227825Stheravenfunction<_R(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
1207227825Stheraven                                     const function& __f)
1208227825Stheraven{
1209227825Stheraven    if (__f.__f_ == 0)
1210227825Stheraven        __f_ = 0;
1211227825Stheraven    else if (__f.__f_ == (const __base*)&__f.__buf_)
1212227825Stheraven    {
1213227825Stheraven        __f_ = (__base*)&__buf_;
1214227825Stheraven        __f.__f_->__clone(__f_);
1215227825Stheraven    }
1216227825Stheraven    else
1217227825Stheraven        __f_ = __f.__f_->__clone();
1218227825Stheraven}
1219227825Stheraven
1220227825Stheraventemplate<class _R, class ..._ArgTypes>
1221227825Stheravenfunction<_R(_ArgTypes...)>::function(function&& __f) _NOEXCEPT
1222227825Stheraven{
1223227825Stheraven    if (__f.__f_ == 0)
1224227825Stheraven        __f_ = 0;
1225227825Stheraven    else if (__f.__f_ == (__base*)&__f.__buf_)
1226227825Stheraven    {
1227227825Stheraven        __f_ = (__base*)&__buf_;
1228227825Stheraven        __f.__f_->__clone(__f_);
1229227825Stheraven    }
1230227825Stheraven    else
1231227825Stheraven    {
1232227825Stheraven        __f_ = __f.__f_;
1233227825Stheraven        __f.__f_ = 0;
1234227825Stheraven    }
1235227825Stheraven}
1236227825Stheraven
1237227825Stheraventemplate<class _R, class ..._ArgTypes>
1238227825Stheraventemplate <class _Alloc>
1239227825Stheravenfunction<_R(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
1240227825Stheraven                                     function&& __f)
1241227825Stheraven{
1242227825Stheraven    if (__f.__f_ == 0)
1243227825Stheraven        __f_ = 0;
1244227825Stheraven    else if (__f.__f_ == (__base*)&__f.__buf_)
1245227825Stheraven    {
1246227825Stheraven        __f_ = (__base*)&__buf_;
1247227825Stheraven        __f.__f_->__clone(__f_);
1248227825Stheraven    }
1249227825Stheraven    else
1250227825Stheraven    {
1251227825Stheraven        __f_ = __f.__f_;
1252227825Stheraven        __f.__f_ = 0;
1253227825Stheraven    }
1254227825Stheraven}
1255227825Stheraven
1256227825Stheraventemplate<class _R, class ..._ArgTypes>
1257227825Stheraventemplate <class _F>
1258227825Stheravenfunction<_R(_ArgTypes...)>::function(_F __f,
1259227825Stheraven                                     typename enable_if<__callable<_F>::value>::type*)
1260227825Stheraven    : __f_(0)
1261227825Stheraven{
1262227825Stheraven    if (__not_null(__f))
1263227825Stheraven    {
1264227825Stheraven        typedef __function::__func<_F, allocator<_F>, _R(_ArgTypes...)> _FF;
1265227825Stheraven        if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_F>::value)
1266227825Stheraven        {
1267227825Stheraven            __f_ = (__base*)&__buf_;
1268227825Stheraven            ::new (__f_) _FF(_VSTD::move(__f));
1269227825Stheraven        }
1270227825Stheraven        else
1271227825Stheraven        {
1272227825Stheraven            typedef allocator<_FF> _A;
1273227825Stheraven            _A __a;
1274227825Stheraven            typedef __allocator_destructor<_A> _D;
1275227825Stheraven            unique_ptr<__base, _D> __hold(__a.allocate(1), _D(__a, 1));
1276227825Stheraven            ::new (__hold.get()) _FF(_VSTD::move(__f), allocator<_F>(__a));
1277227825Stheraven            __f_ = __hold.release();
1278227825Stheraven        }
1279227825Stheraven    }
1280227825Stheraven}
1281227825Stheraven
1282227825Stheraventemplate<class _R, class ..._ArgTypes>
1283227825Stheraventemplate <class _F, class _Alloc>
1284227825Stheravenfunction<_R(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _F __f,
1285227825Stheraven                                     typename enable_if<__callable<_F>::value>::type*)
1286227825Stheraven    : __f_(0)
1287227825Stheraven{
1288227825Stheraven    typedef allocator_traits<_Alloc> __alloc_traits;
1289227825Stheraven    if (__not_null(__f))
1290227825Stheraven    {
1291227825Stheraven        typedef __function::__func<_F, _Alloc, _R(_ArgTypes...)> _FF;
1292227825Stheraven        if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_F>::value)
1293227825Stheraven        {
1294227825Stheraven            __f_ = (__base*)&__buf_;
1295227825Stheraven            ::new (__f_) _FF(_VSTD::move(__f));
1296227825Stheraven        }
1297227825Stheraven        else
1298227825Stheraven        {
1299227825Stheraven            typedef typename __alloc_traits::template
1300227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1301227825Stheraven                rebind_alloc<_FF>
1302227825Stheraven#else
1303227825Stheraven                rebind_alloc<_FF>::other
1304227825Stheraven#endif
1305227825Stheraven                                                         _A;
1306227825Stheraven            _A __a(__a0);
1307227825Stheraven            typedef __allocator_destructor<_A> _D;
1308227825Stheraven            unique_ptr<__base, _D> __hold(__a.allocate(1), _D(__a, 1));
1309227825Stheraven            ::new (__hold.get()) _FF(_VSTD::move(__f), _Alloc(__a));
1310227825Stheraven            __f_ = __hold.release();
1311227825Stheraven        }
1312227825Stheraven    }
1313227825Stheraven}
1314227825Stheraven
1315227825Stheraventemplate<class _R, class ..._ArgTypes>
1316227825Stheravenfunction<_R(_ArgTypes...)>&
1317227825Stheravenfunction<_R(_ArgTypes...)>::operator=(const function& __f)
1318227825Stheraven{
1319227825Stheraven    function(__f).swap(*this);
1320227825Stheraven    return *this;
1321227825Stheraven}
1322227825Stheraven
1323227825Stheraventemplate<class _R, class ..._ArgTypes>
1324227825Stheravenfunction<_R(_ArgTypes...)>&
1325227825Stheravenfunction<_R(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT
1326227825Stheraven{
1327227825Stheraven    if (__f_ == (__base*)&__buf_)
1328227825Stheraven        __f_->destroy();
1329227825Stheraven    else if (__f_)
1330227825Stheraven        __f_->destroy_deallocate();
1331227825Stheraven    __f_ = 0;
1332227825Stheraven    if (__f.__f_ == 0)
1333227825Stheraven        __f_ = 0;
1334227825Stheraven    else if (__f.__f_ == (__base*)&__f.__buf_)
1335227825Stheraven    {
1336227825Stheraven        __f_ = (__base*)&__buf_;
1337227825Stheraven        __f.__f_->__clone(__f_);
1338227825Stheraven    }
1339227825Stheraven    else
1340227825Stheraven    {
1341227825Stheraven        __f_ = __f.__f_;
1342227825Stheraven        __f.__f_ = 0;
1343227825Stheraven    }
1344227825Stheraven}
1345227825Stheraven
1346227825Stheraventemplate<class _R, class ..._ArgTypes>
1347227825Stheravenfunction<_R(_ArgTypes...)>&
1348227825Stheravenfunction<_R(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT
1349227825Stheraven{
1350227825Stheraven    if (__f_ == (__base*)&__buf_)
1351227825Stheraven        __f_->destroy();
1352227825Stheraven    else if (__f_)
1353227825Stheraven        __f_->destroy_deallocate();
1354227825Stheraven    __f_ = 0;
1355227825Stheraven}
1356227825Stheraven
1357227825Stheraventemplate<class _R, class ..._ArgTypes>
1358227825Stheraventemplate <class _F>
1359227825Stheraventypename enable_if
1360227825Stheraven<
1361227825Stheraven    function<_R(_ArgTypes...)>::template __callable<typename decay<_F>::type>::value,
1362227825Stheraven    function<_R(_ArgTypes...)>&
1363227825Stheraven>::type
1364227825Stheravenfunction<_R(_ArgTypes...)>::operator=(_F&& __f)
1365227825Stheraven{
1366227825Stheraven    function(_VSTD::forward<_F>(__f)).swap(*this);
1367227825Stheraven    return *this;
1368227825Stheraven}
1369227825Stheraven
1370227825Stheraventemplate<class _R, class ..._ArgTypes>
1371227825Stheravenfunction<_R(_ArgTypes...)>::~function()
1372227825Stheraven{
1373227825Stheraven    if (__f_ == (__base*)&__buf_)
1374227825Stheraven        __f_->destroy();
1375227825Stheraven    else if (__f_)
1376227825Stheraven        __f_->destroy_deallocate();
1377227825Stheraven}
1378227825Stheraven
1379227825Stheraventemplate<class _R, class ..._ArgTypes>
1380227825Stheravenvoid
1381227825Stheravenfunction<_R(_ArgTypes...)>::swap(function& __f) _NOEXCEPT
1382227825Stheraven{
1383227825Stheraven    if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_)
1384227825Stheraven    {
1385227825Stheraven        typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
1386227825Stheraven        __base* __t = (__base*)&__tempbuf;
1387227825Stheraven        __f_->__clone(__t);
1388227825Stheraven        __f_->destroy();
1389227825Stheraven        __f_ = 0;
1390227825Stheraven        __f.__f_->__clone((__base*)&__buf_);
1391227825Stheraven        __f.__f_->destroy();
1392227825Stheraven        __f.__f_ = 0;
1393227825Stheraven        __f_ = (__base*)&__buf_;
1394227825Stheraven        __t->__clone((__base*)&__f.__buf_);
1395227825Stheraven        __t->destroy();
1396227825Stheraven        __f.__f_ = (__base*)&__f.__buf_;
1397227825Stheraven    }
1398227825Stheraven    else if (__f_ == (__base*)&__buf_)
1399227825Stheraven    {
1400227825Stheraven        __f_->__clone((__base*)&__f.__buf_);
1401227825Stheraven        __f_->destroy();
1402227825Stheraven        __f_ = __f.__f_;
1403227825Stheraven        __f.__f_ = (__base*)&__f.__buf_;
1404227825Stheraven    }
1405227825Stheraven    else if (__f.__f_ == (__base*)&__f.__buf_)
1406227825Stheraven    {
1407227825Stheraven        __f.__f_->__clone((__base*)&__buf_);
1408227825Stheraven        __f.__f_->destroy();
1409227825Stheraven        __f.__f_ = __f_;
1410227825Stheraven        __f_ = (__base*)&__buf_;
1411227825Stheraven    }
1412227825Stheraven    else
1413227825Stheraven        _VSTD::swap(__f_, __f.__f_);
1414227825Stheraven}
1415227825Stheraven
1416227825Stheraventemplate<class _R, class ..._ArgTypes>
1417227825Stheraven_R
1418227825Stheravenfunction<_R(_ArgTypes...)>::operator()(_ArgTypes... __arg) const
1419227825Stheraven{
1420227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
1421227825Stheraven    if (__f_ == 0)
1422227825Stheraven        throw bad_function_call();
1423227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
1424227825Stheraven    return (*__f_)(_VSTD::forward<_ArgTypes>(__arg)...);
1425227825Stheraven}
1426227825Stheraven
1427227825Stheraven#ifndef _LIBCPP_NO_RTTI
1428227825Stheraven
1429227825Stheraventemplate<class _R, class ..._ArgTypes>
1430227825Stheravenconst std::type_info&
1431227825Stheravenfunction<_R(_ArgTypes...)>::target_type() const _NOEXCEPT
1432227825Stheraven{
1433227825Stheraven    if (__f_ == 0)
1434227825Stheraven        return typeid(void);
1435227825Stheraven    return __f_->target_type();
1436227825Stheraven}
1437227825Stheraven
1438227825Stheraventemplate<class _R, class ..._ArgTypes>
1439227825Stheraventemplate <typename _T>
1440227825Stheraven_T*
1441227825Stheravenfunction<_R(_ArgTypes...)>::target() _NOEXCEPT
1442227825Stheraven{
1443227825Stheraven    if (__f_ == 0)
1444227825Stheraven        return (_T*)0;
1445227825Stheraven    return (_T*)__f_->target(typeid(_T));
1446227825Stheraven}
1447227825Stheraven
1448227825Stheraventemplate<class _R, class ..._ArgTypes>
1449227825Stheraventemplate <typename _T>
1450227825Stheravenconst _T*
1451227825Stheravenfunction<_R(_ArgTypes...)>::target() const _NOEXCEPT
1452227825Stheraven{
1453227825Stheraven    if (__f_ == 0)
1454227825Stheraven        return (const _T*)0;
1455227825Stheraven    return (const _T*)__f_->target(typeid(_T));
1456227825Stheraven}
1457227825Stheraven
1458227825Stheraven#endif  // _LIBCPP_NO_RTTI
1459227825Stheraven
1460227825Stheraventemplate <class _R, class... _ArgTypes>
1461227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1462227825Stheravenbool
1463227825Stheravenoperator==(const function<_R(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;}
1464227825Stheraven
1465227825Stheraventemplate <class _R, class... _ArgTypes>
1466227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1467227825Stheravenbool
1468227825Stheravenoperator==(nullptr_t, const function<_R(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;}
1469227825Stheraven
1470227825Stheraventemplate <class _R, class... _ArgTypes>
1471227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1472227825Stheravenbool
1473227825Stheravenoperator!=(const function<_R(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;}
1474227825Stheraven
1475227825Stheraventemplate <class _R, class... _ArgTypes>
1476227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1477227825Stheravenbool
1478227825Stheravenoperator!=(nullptr_t, const function<_R(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;}
1479227825Stheraven
1480227825Stheraventemplate <class _R, class... _ArgTypes>
1481227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1482227825Stheravenvoid
1483227825Stheravenswap(function<_R(_ArgTypes...)>& __x, function<_R(_ArgTypes...)>& __y) _NOEXCEPT
1484227825Stheraven{return __x.swap(__y);}
1485227825Stheraven
1486227825Stheraventemplate<class _Tp> struct __is_bind_expression : public false_type {};
1487227825Stheraventemplate<class _Tp> struct _LIBCPP_VISIBLE is_bind_expression
1488227825Stheraven    : public __is_bind_expression<typename remove_cv<_Tp>::type> {};
1489227825Stheraven
1490227825Stheraventemplate<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {};
1491227825Stheraventemplate<class _Tp> struct _LIBCPP_VISIBLE is_placeholder
1492227825Stheraven    : public __is_placeholder<typename remove_cv<_Tp>::type> {};
1493227825Stheraven
1494227825Stheravennamespace placeholders
1495227825Stheraven{
1496227825Stheraven
1497227825Stheraventemplate <int _N> struct __ph {};
1498227825Stheraven
1499227825Stheravenextern __ph<1>   _1;
1500227825Stheravenextern __ph<2>   _2;
1501227825Stheravenextern __ph<3>   _3;
1502227825Stheravenextern __ph<4>   _4;
1503227825Stheravenextern __ph<5>   _5;
1504227825Stheravenextern __ph<6>   _6;
1505227825Stheravenextern __ph<7>   _7;
1506227825Stheravenextern __ph<8>   _8;
1507227825Stheravenextern __ph<9>   _9;
1508227825Stheravenextern __ph<10> _10;
1509227825Stheraven
1510227825Stheraven}  // placeholders
1511227825Stheraven
1512227825Stheraventemplate<int _N>
1513227825Stheravenstruct __is_placeholder<placeholders::__ph<_N> >
1514227825Stheraven    : public integral_constant<int, _N> {};
1515227825Stheraven
1516227825Stheraventemplate <class _Tp, class _Uj>
1517227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1518227825Stheraven_Tp&
1519227825Stheraven__mu(reference_wrapper<_Tp> __t, _Uj&)
1520227825Stheraven{
1521227825Stheraven    return __t.get();
1522227825Stheraven}
1523227825Stheraven
1524227825Stheraventemplate <class _Ti, class ..._Uj, size_t ..._Indx>
1525227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1526227825Stheraventypename __invoke_of<_Ti&, _Uj...>::type
1527227825Stheraven__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>)
1528227825Stheraven{
1529227825Stheraven    return __ti(_VSTD::forward<_Uj>(get<_Indx>(__uj))...);
1530227825Stheraven}
1531227825Stheraven
1532227825Stheraventemplate <class _Ti, class ..._Uj>
1533227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1534227825Stheraventypename enable_if
1535227825Stheraven<
1536227825Stheraven    is_bind_expression<_Ti>::value,
1537227825Stheraven    typename __invoke_of<_Ti&, _Uj...>::type
1538227825Stheraven>::type
1539227825Stheraven__mu(_Ti& __ti, tuple<_Uj...>& __uj)
1540227825Stheraven{
1541227825Stheraven    typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices;
1542227825Stheraven    return  __mu_expand(__ti, __uj, __indices());
1543227825Stheraven}
1544227825Stheraven
1545227825Stheraventemplate <bool IsPh, class _Ti, class _Uj>
1546227825Stheravenstruct __mu_return2 {};
1547227825Stheraven
1548227825Stheraventemplate <class _Ti, class _Uj>
1549227825Stheravenstruct __mu_return2<true, _Ti, _Uj>
1550227825Stheraven{
1551227825Stheraven    typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type;
1552227825Stheraven};
1553227825Stheraven
1554227825Stheraventemplate <class _Ti, class _Uj>
1555227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1556227825Stheraventypename enable_if
1557227825Stheraven<
1558227825Stheraven    0 < is_placeholder<_Ti>::value,
1559227825Stheraven    typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type
1560227825Stheraven>::type
1561227825Stheraven__mu(_Ti&, _Uj& __uj)
1562227825Stheraven{
1563227825Stheraven    const size_t _Indx = is_placeholder<_Ti>::value - 1;
1564227825Stheraven    return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(get<_Indx>(__uj));
1565227825Stheraven}
1566227825Stheraven
1567227825Stheraventemplate <class _Ti, class _Uj>
1568227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1569227825Stheraventypename enable_if
1570227825Stheraven<
1571227825Stheraven    !is_bind_expression<_Ti>::value &&
1572227825Stheraven    is_placeholder<_Ti>::value == 0 &&
1573227825Stheraven    !__is_reference_wrapper<_Ti>::value,
1574227825Stheraven    _Ti&
1575227825Stheraven>::type
1576227825Stheraven__mu(_Ti& __ti, _Uj& __uj)
1577227825Stheraven{
1578227825Stheraven    return __ti;
1579227825Stheraven}
1580227825Stheraven
1581227825Stheraventemplate <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh,
1582227825Stheraven          class _TupleUj>
1583227825Stheravenstruct ____mu_return;
1584227825Stheraven
1585227825Stheraventemplate <class _Ti, class ..._Uj>
1586227825Stheravenstruct ____mu_return<_Ti, false, true, false, tuple<_Uj...> >
1587227825Stheraven{
1588227825Stheraven    typedef typename __invoke_of<_Ti&, _Uj...>::type type;
1589227825Stheraven};
1590227825Stheraven
1591227825Stheraventemplate <class _Ti, class _TupleUj>
1592227825Stheravenstruct ____mu_return<_Ti, false, false, true, _TupleUj>
1593227825Stheraven{
1594227825Stheraven    typedef typename tuple_element<is_placeholder<_Ti>::value - 1,
1595227825Stheraven                                   _TupleUj>::type&& type;
1596227825Stheraven};
1597227825Stheraven
1598227825Stheraventemplate <class _Ti, class _TupleUj>
1599227825Stheravenstruct ____mu_return<_Ti, true, false, false, _TupleUj>
1600227825Stheraven{
1601227825Stheraven    typedef typename _Ti::type& type;
1602227825Stheraven};
1603227825Stheraven
1604227825Stheraventemplate <class _Ti, class _TupleUj>
1605227825Stheravenstruct ____mu_return<_Ti, false, false, false, _TupleUj>
1606227825Stheraven{
1607227825Stheraven    typedef _Ti& type;
1608227825Stheraven};
1609227825Stheraven
1610227825Stheraventemplate <class _Ti, class _TupleUj>
1611227825Stheravenstruct __mu_return
1612227825Stheraven    : public ____mu_return<_Ti,
1613227825Stheraven                           __is_reference_wrapper<_Ti>::value,
1614227825Stheraven                           is_bind_expression<_Ti>::value,
1615227825Stheraven                           0 < is_placeholder<_Ti>::value,
1616227825Stheraven                           _TupleUj>
1617227825Stheraven{
1618227825Stheraven};
1619227825Stheraven
1620227825Stheraventemplate <class _F, class _BoundArgs, class _TupleUj>
1621227825Stheravenstruct __bind_return;
1622227825Stheraven
1623227825Stheraventemplate <class _F, class ..._BoundArgs, class _TupleUj>
1624227825Stheravenstruct __bind_return<_F, tuple<_BoundArgs...>, _TupleUj>
1625227825Stheraven{
1626227825Stheraven    typedef typename __invoke_of
1627227825Stheraven    <
1628227825Stheraven        _F&,
1629227825Stheraven        typename __mu_return
1630227825Stheraven        <
1631227825Stheraven            _BoundArgs,
1632227825Stheraven            _TupleUj
1633227825Stheraven        >::type...
1634227825Stheraven    >::type type;
1635227825Stheraven};
1636227825Stheraven
1637227825Stheraventemplate <class _F, class ..._BoundArgs, class _TupleUj>
1638227825Stheravenstruct __bind_return<_F, const tuple<_BoundArgs...>, _TupleUj>
1639227825Stheraven{
1640227825Stheraven    typedef typename __invoke_of
1641227825Stheraven    <
1642227825Stheraven        _F&,
1643227825Stheraven        typename __mu_return
1644227825Stheraven        <
1645227825Stheraven            const _BoundArgs,
1646227825Stheraven            _TupleUj
1647227825Stheraven        >::type...
1648227825Stheraven    >::type type;
1649227825Stheraven};
1650227825Stheraven
1651227825Stheraventemplate <class _F, class _BoundArgs, size_t ..._Indx, class _Args>
1652227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1653227825Stheraventypename __bind_return<_F, _BoundArgs, _Args>::type
1654227825Stheraven__apply_functor(_F& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
1655227825Stheraven                _Args&& __args)
1656227825Stheraven{
1657227825Stheraven    return __invoke(__f, __mu(get<_Indx>(__bound_args), __args)...);
1658227825Stheraven}
1659227825Stheraven
1660227825Stheraventemplate<class _F, class ..._BoundArgs>
1661227825Stheravenclass __bind
1662227825Stheraven    : public __weak_result_type<typename decay<_F>::type>
1663227825Stheraven{
1664227825Stheraven    typedef typename decay<_F>::type _Fd;
1665227825Stheraven    typedef tuple<typename decay<_BoundArgs>::type...> _Td;
1666227825Stheraven    _Fd __f_;
1667227825Stheraven    _Td __bound_args_;
1668227825Stheraven
1669227825Stheraven    typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices;
1670227825Stheravenpublic:
1671227825Stheraven#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
1672227825Stheraven
1673227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1674227825Stheraven    __bind(const __bind& __b)
1675227825Stheraven        : __f_(__b.__f_),
1676227825Stheraven          __bound_args_(__b.__bound_args_) {}
1677227825Stheraven
1678227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1679227825Stheraven    __bind& operator=(const __bind& __b)
1680227825Stheraven    {
1681227825Stheraven        __f_ = __b.__f_;
1682227825Stheraven        __bound_args_ = __b.__bound_args_;
1683227825Stheraven        return *this;
1684227825Stheraven    }
1685227825Stheraven
1686227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1687227825Stheraven    __bind(__bind&& __b)
1688227825Stheraven        : __f_(_VSTD::move(__b.__f_)),
1689227825Stheraven          __bound_args_(_VSTD::move(__b.__bound_args_)) {}
1690227825Stheraven
1691227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1692227825Stheraven    __bind& operator=(__bind&& __b)
1693227825Stheraven    {
1694227825Stheraven        __f_ = _VSTD::move(__b.__f_);
1695227825Stheraven        __bound_args_ = _VSTD::move(__b.__bound_args_);
1696227825Stheraven        return *this;
1697227825Stheraven    }
1698227825Stheraven
1699227825Stheraven#endif  // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
1700227825Stheraven
1701227825Stheraven    template <class _G, class ..._BA>
1702227825Stheraven      _LIBCPP_INLINE_VISIBILITY
1703227825Stheraven      explicit __bind(_G&& __f, _BA&& ...__bound_args)
1704227825Stheraven        : __f_(_VSTD::forward<_G>(__f)),
1705227825Stheraven          __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {}
1706227825Stheraven
1707227825Stheraven    template <class ..._Args>
1708227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1709227825Stheraven        typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type
1710227825Stheraven        operator()(_Args&& ...__args)
1711227825Stheraven        {
1712227825Stheraven            return __apply_functor(__f_, __bound_args_, __indices(),
1713227825Stheraven                                  tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
1714227825Stheraven        }
1715227825Stheraven
1716227825Stheraven    template <class ..._Args>
1717227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1718227825Stheraven        typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type
1719227825Stheraven        operator()(_Args&& ...__args) const
1720227825Stheraven        {
1721227825Stheraven            return __apply_functor(__f_, __bound_args_, __indices(),
1722227825Stheraven                                   tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
1723227825Stheraven        }
1724227825Stheraven};
1725227825Stheraven
1726227825Stheraventemplate<class _F, class ..._BoundArgs>
1727227825Stheravenstruct __is_bind_expression<__bind<_F, _BoundArgs...> > : public true_type {};
1728227825Stheraven
1729227825Stheraventemplate<class _R, class _F, class ..._BoundArgs>
1730227825Stheravenclass __bind_r
1731227825Stheraven    : public __bind<_F, _BoundArgs...>
1732227825Stheraven{
1733227825Stheraven    typedef __bind<_F, _BoundArgs...> base;
1734227825Stheravenpublic:
1735227825Stheraven    typedef _R result_type;
1736227825Stheraven
1737227825Stheraven#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
1738227825Stheraven
1739227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1740227825Stheraven    __bind_r(const __bind_r& __b)
1741227825Stheraven        : base(_VSTD::forward<const base&>(__b)) {}
1742227825Stheraven
1743227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1744227825Stheraven    __bind_r& operator=(const __bind_r& __b)
1745227825Stheraven    {
1746227825Stheraven        base::operator=(_VSTD::forward<const base&>(__b));
1747227825Stheraven        return *this;
1748227825Stheraven    }
1749227825Stheraven
1750227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1751227825Stheraven    __bind_r(__bind_r&& __b)
1752227825Stheraven        : base(_VSTD::forward<base>(__b)) {}
1753227825Stheraven
1754227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1755227825Stheraven    __bind_r& operator=(__bind_r&& __b)
1756227825Stheraven    {
1757227825Stheraven        base::operator=(_VSTD::forward<base>(__b));
1758227825Stheraven        return *this;
1759227825Stheraven    }
1760227825Stheraven
1761227825Stheraven#endif  // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
1762227825Stheraven
1763227825Stheraven    template <class _G, class ..._BA>
1764227825Stheraven      _LIBCPP_INLINE_VISIBILITY
1765227825Stheraven      explicit __bind_r(_G&& __f, _BA&& ...__bound_args)
1766227825Stheraven        : base(_VSTD::forward<_G>(__f),
1767227825Stheraven               _VSTD::forward<_BA>(__bound_args)...) {}
1768227825Stheraven
1769227825Stheraven    template <class ..._Args>
1770227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1771227825Stheraven        result_type
1772227825Stheraven        operator()(_Args&& ...__args)
1773227825Stheraven        {
1774227825Stheraven            return base::operator()(_VSTD::forward<_Args>(__args)...);
1775227825Stheraven        }
1776227825Stheraven
1777227825Stheraven    template <class ..._Args>
1778227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1779227825Stheraven        result_type
1780227825Stheraven        operator()(_Args&& ...__args) const
1781227825Stheraven        {
1782227825Stheraven            return base::operator()(_VSTD::forward<_Args>(__args)...);
1783227825Stheraven        }
1784227825Stheraven};
1785227825Stheraven
1786227825Stheraventemplate<class _R, class _F, class ..._BoundArgs>
1787227825Stheravenstruct __is_bind_expression<__bind_r<_R, _F, _BoundArgs...> > : public true_type {};
1788227825Stheraven
1789227825Stheraventemplate<class _F, class ..._BoundArgs>
1790227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1791227825Stheraven__bind<_F, _BoundArgs...>
1792227825Stheravenbind(_F&& __f, _BoundArgs&&... __bound_args)
1793227825Stheraven{
1794227825Stheraven    typedef __bind<_F, _BoundArgs...> type;
1795227825Stheraven    return type(_VSTD::forward<_F>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
1796227825Stheraven}
1797227825Stheraven
1798227825Stheraventemplate<class _R, class _F, class ..._BoundArgs>
1799227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1800227825Stheraven__bind_r<_R, _F, _BoundArgs...>
1801227825Stheravenbind(_F&& __f, _BoundArgs&&... __bound_args)
1802227825Stheraven{
1803227825Stheraven    typedef __bind_r<_R, _F, _BoundArgs...> type;
1804227825Stheraven    return type(_VSTD::forward<_F>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
1805227825Stheraven}
1806227825Stheraven
1807227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
1808227825Stheraven
1809227825Stheraventemplate <>
1810227825Stheravenstruct _LIBCPP_VISIBLE hash<bool>
1811227825Stheraven    : public unary_function<bool, size_t>
1812227825Stheraven{
1813227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1814227825Stheraven    size_t operator()(bool __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1815227825Stheraven};
1816227825Stheraven
1817227825Stheraventemplate <>
1818227825Stheravenstruct _LIBCPP_VISIBLE hash<char>
1819227825Stheraven    : public unary_function<char, size_t>
1820227825Stheraven{
1821227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1822227825Stheraven    size_t operator()(char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1823227825Stheraven};
1824227825Stheraven
1825227825Stheraventemplate <>
1826227825Stheravenstruct _LIBCPP_VISIBLE hash<signed char>
1827227825Stheraven    : public unary_function<signed char, size_t>
1828227825Stheraven{
1829227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1830227825Stheraven    size_t operator()(signed char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1831227825Stheraven};
1832227825Stheraven
1833227825Stheraventemplate <>
1834227825Stheravenstruct _LIBCPP_VISIBLE hash<unsigned char>
1835227825Stheraven    : public unary_function<unsigned char, size_t>
1836227825Stheraven{
1837227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1838227825Stheraven    size_t operator()(unsigned char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1839227825Stheraven};
1840227825Stheraven
1841227825Stheraven#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
1842227825Stheraven
1843227825Stheraventemplate <>
1844227825Stheravenstruct _LIBCPP_VISIBLE hash<char16_t>
1845227825Stheraven    : public unary_function<char16_t, size_t>
1846227825Stheraven{
1847227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1848227825Stheraven    size_t operator()(char16_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1849227825Stheraven};
1850227825Stheraven
1851227825Stheraventemplate <>
1852227825Stheravenstruct _LIBCPP_VISIBLE hash<char32_t>
1853227825Stheraven    : public unary_function<char32_t, size_t>
1854227825Stheraven{
1855227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1856227825Stheraven    size_t operator()(char32_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1857227825Stheraven};
1858227825Stheraven
1859227825Stheraven#endif  // _LIBCPP_HAS_NO_UNICODE_CHARS
1860227825Stheraven
1861227825Stheraventemplate <>
1862227825Stheravenstruct _LIBCPP_VISIBLE hash<wchar_t>
1863227825Stheraven    : public unary_function<wchar_t, size_t>
1864227825Stheraven{
1865227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1866227825Stheraven    size_t operator()(wchar_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1867227825Stheraven};
1868227825Stheraven
1869227825Stheraventemplate <>
1870227825Stheravenstruct _LIBCPP_VISIBLE hash<short>
1871227825Stheraven    : public unary_function<short, size_t>
1872227825Stheraven{
1873227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1874227825Stheraven    size_t operator()(short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1875227825Stheraven};
1876227825Stheraven
1877227825Stheraventemplate <>
1878227825Stheravenstruct _LIBCPP_VISIBLE hash<unsigned short>
1879227825Stheraven    : public unary_function<unsigned short, size_t>
1880227825Stheraven{
1881227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1882227825Stheraven    size_t operator()(unsigned short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1883227825Stheraven};
1884227825Stheraven
1885227825Stheraventemplate <>
1886227825Stheravenstruct _LIBCPP_VISIBLE hash<int>
1887227825Stheraven    : public unary_function<int, size_t>
1888227825Stheraven{
1889227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1890227825Stheraven    size_t operator()(int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1891227825Stheraven};
1892227825Stheraven
1893227825Stheraventemplate <>
1894227825Stheravenstruct _LIBCPP_VISIBLE hash<unsigned int>
1895227825Stheraven    : public unary_function<unsigned int, size_t>
1896227825Stheraven{
1897227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1898227825Stheraven    size_t operator()(unsigned int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1899227825Stheraven};
1900227825Stheraven
1901227825Stheraventemplate <>
1902227825Stheravenstruct _LIBCPP_VISIBLE hash<long>
1903227825Stheraven    : public unary_function<long, size_t>
1904227825Stheraven{
1905227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1906227825Stheraven    size_t operator()(long __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1907227825Stheraven};
1908227825Stheraven
1909227825Stheraventemplate <>
1910227825Stheravenstruct _LIBCPP_VISIBLE hash<unsigned long>
1911227825Stheraven    : public unary_function<unsigned long, size_t>
1912227825Stheraven{
1913227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1914227825Stheraven    size_t operator()(unsigned long __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
1915227825Stheraven};
1916227825Stheraven
1917227825Stheraventemplate <>
1918227825Stheravenstruct _LIBCPP_VISIBLE hash<long long>
1919227825Stheraven    : public unary_function<long long, size_t>
1920227825Stheraven{
1921227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1922227825Stheraven    size_t operator()(long long __v) const _NOEXCEPT
1923227825Stheraven    {
1924227825Stheraven        size_t __r = 0;
1925227825Stheraven        const size_t* const __p = reinterpret_cast<const size_t*>(&__v);
1926227825Stheraven        for (unsigned __i = 0; __i < sizeof(argument_type)/sizeof(size_t); ++__i)
1927227825Stheraven            __r ^= __p[__i];
1928227825Stheraven        return __r;
1929227825Stheraven    }
1930227825Stheraven};
1931227825Stheraven
1932227825Stheraventemplate <>
1933227825Stheravenstruct _LIBCPP_VISIBLE hash<unsigned long long>
1934227825Stheraven    : public unary_function<unsigned long long, size_t>
1935227825Stheraven{
1936227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1937227825Stheraven    size_t operator()(unsigned long long __v) const _NOEXCEPT
1938227825Stheraven    {
1939227825Stheraven        size_t __r = 0;
1940227825Stheraven        const size_t* const __p = reinterpret_cast<const size_t*>(&__v);
1941227825Stheraven        for (unsigned __i = 0; __i < sizeof(argument_type)/sizeof(size_t); ++__i)
1942227825Stheraven            __r ^= __p[__i];
1943227825Stheraven        return __r;
1944227825Stheraven    }
1945227825Stheraven};
1946227825Stheraven
1947227825Stheraventemplate <>
1948227825Stheravenstruct _LIBCPP_VISIBLE hash<float>
1949227825Stheraven    : public unary_function<float, size_t>
1950227825Stheraven{
1951227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1952227825Stheraven    size_t operator()(float __v) const _NOEXCEPT
1953227825Stheraven    {
1954227825Stheraven        if (__v == 0)
1955227825Stheraven            return 0;
1956227825Stheraven        const size_t* const __p = reinterpret_cast<const size_t*>(&__v);
1957227825Stheraven        return *__p;
1958227825Stheraven    }
1959227825Stheraven};
1960227825Stheraven
1961227825Stheraventemplate <>
1962227825Stheravenstruct _LIBCPP_VISIBLE hash<double>
1963227825Stheraven    : public unary_function<double, size_t>
1964227825Stheraven{
1965227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1966227825Stheraven    size_t operator()(double __v) const _NOEXCEPT
1967227825Stheraven    {
1968227825Stheraven        if (__v == 0)
1969227825Stheraven            return 0;
1970227825Stheraven        size_t __r = 0;
1971227825Stheraven        const size_t* const __p = reinterpret_cast<const size_t*>(&__v);
1972227825Stheraven        for (unsigned __i = 0; __i < sizeof(argument_type)/sizeof(size_t); ++__i)
1973227825Stheraven            __r ^= __p[__i];
1974227825Stheraven        return __r;
1975227825Stheraven    }
1976227825Stheraven};
1977227825Stheraven
1978227825Stheraventemplate <>
1979227825Stheravenstruct _LIBCPP_VISIBLE hash<long double>
1980227825Stheraven    : public unary_function<long double, size_t>
1981227825Stheraven{
1982227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1983227825Stheraven    size_t operator()(long double __v) const _NOEXCEPT
1984227825Stheraven    {
1985227825Stheraven        if (__v == 0)
1986227825Stheraven            return 0;
1987227825Stheraven        size_t __r = 0;
1988227825Stheraven        const size_t* const __p = reinterpret_cast<const size_t*>(&__v);
1989227825Stheraven        for (unsigned __i = 0; __i < sizeof(argument_type)/sizeof(size_t); ++__i)
1990227825Stheraven            __r ^= __p[__i];
1991227825Stheraven        return __r;
1992227825Stheraven    }
1993227825Stheraven};
1994227825Stheraven
1995227825Stheraven// struct hash<T*> in <memory>
1996227825Stheraven
1997227825Stheraven_LIBCPP_END_NAMESPACE_STD
1998227825Stheraven
1999227825Stheraven#endif  // _LIBCPP_FUNCTIONAL
2000