functional revision 276792
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>
59261272Sdim      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
71261272Sdimtemplate <class T> // <class T=void> in C++14
72227825Stheravenstruct plus : binary_function<T, T, T>
73227825Stheraven{
74227825Stheraven    T operator()(const T& x, const T& y) const;
75227825Stheraven};
76227825Stheraven
77261272Sdimtemplate <class T> // <class T=void> in C++14
78227825Stheravenstruct minus : binary_function<T, T, T>
79227825Stheraven{
80227825Stheraven    T operator()(const T& x, const T& y) const;
81227825Stheraven};
82227825Stheraven
83261272Sdimtemplate <class T> // <class T=void> in C++14
84227825Stheravenstruct multiplies : binary_function<T, T, T>
85227825Stheraven{
86227825Stheraven    T operator()(const T& x, const T& y) const;
87227825Stheraven};
88227825Stheraven
89261272Sdimtemplate <class T> // <class T=void> in C++14
90227825Stheravenstruct divides : binary_function<T, T, T>
91227825Stheraven{
92227825Stheraven    T operator()(const T& x, const T& y) const;
93227825Stheraven};
94227825Stheraven
95261272Sdimtemplate <class T> // <class T=void> in C++14
96227825Stheravenstruct modulus : binary_function<T, T, T>
97227825Stheraven{
98227825Stheraven    T operator()(const T& x, const T& y) const;
99227825Stheraven};
100227825Stheraven
101261272Sdimtemplate <class T> // <class T=void> in C++14
102227825Stheravenstruct negate : unary_function<T, T>
103227825Stheraven{
104227825Stheraven    T operator()(const T& x) const;
105227825Stheraven};
106227825Stheraven
107261272Sdimtemplate <class T> // <class T=void> in C++14
108227825Stheravenstruct equal_to : binary_function<T, T, bool>
109227825Stheraven{
110227825Stheraven    bool operator()(const T& x, const T& y) const;
111227825Stheraven};
112227825Stheraven
113261272Sdimtemplate <class T> // <class T=void> in C++14
114227825Stheravenstruct not_equal_to : binary_function<T, T, bool>
115227825Stheraven{
116227825Stheraven    bool operator()(const T& x, const T& y) const;
117227825Stheraven};
118227825Stheraven
119261272Sdimtemplate <class T> // <class T=void> in C++14
120227825Stheravenstruct greater : binary_function<T, T, bool>
121227825Stheraven{
122227825Stheraven    bool operator()(const T& x, const T& y) const;
123227825Stheraven};
124227825Stheraven
125261272Sdimtemplate <class T> // <class T=void> in C++14
126227825Stheravenstruct less : binary_function<T, T, bool>
127227825Stheraven{
128227825Stheraven    bool operator()(const T& x, const T& y) const;
129227825Stheraven};
130227825Stheraven
131261272Sdimtemplate <class T> // <class T=void> in C++14
132227825Stheravenstruct greater_equal : binary_function<T, T, bool>
133227825Stheraven{
134227825Stheraven    bool operator()(const T& x, const T& y) const;
135227825Stheraven};
136227825Stheraven
137261272Sdimtemplate <class T> // <class T=void> in C++14
138227825Stheravenstruct less_equal : binary_function<T, T, bool>
139227825Stheraven{
140227825Stheraven    bool operator()(const T& x, const T& y) const;
141227825Stheraven};
142227825Stheraven
143261272Sdimtemplate <class T> // <class T=void> in C++14
144227825Stheravenstruct logical_and : binary_function<T, T, bool>
145227825Stheraven{
146227825Stheraven    bool operator()(const T& x, const T& y) const;
147227825Stheraven};
148227825Stheraven
149261272Sdimtemplate <class T> // <class T=void> in C++14
150227825Stheravenstruct logical_or : binary_function<T, T, bool>
151227825Stheraven{
152227825Stheraven    bool operator()(const T& x, const T& y) const;
153227825Stheraven};
154227825Stheraven
155261272Sdimtemplate <class T> // <class T=void> in C++14
156227825Stheravenstruct logical_not : unary_function<T, bool>
157227825Stheraven{
158227825Stheraven    bool operator()(const T& x) const;
159227825Stheraven};
160227825Stheraven
161261272Sdimtemplate <class T> // <class T=void> in C++14
162261272Sdimstruct bit_and : unary_function<T, bool>
163261272Sdim{
164261272Sdim    bool operator()(const T& x, const T& y) const;
165261272Sdim};
166261272Sdim
167261272Sdimtemplate <class T> // <class T=void> in C++14
168261272Sdimstruct bit_or : unary_function<T, bool>
169261272Sdim{
170261272Sdim    bool operator()(const T& x, const T& y) const;
171261272Sdim};
172261272Sdim
173261272Sdimtemplate <class T> // <class T=void> in C++14
174261272Sdimstruct bit_xor : unary_function<T, bool>
175261272Sdim{
176261272Sdim    bool operator()(const T& x, const T& y) const;
177261272Sdim};
178261272Sdim
179261272Sdimtemplate <class T=void> // C++14
180261272Sdimstruct bit_xor : unary_function<T, bool>
181261272Sdim{
182261272Sdim    bool operator()(const T& x) const;
183261272Sdim};
184261272Sdim
185227825Stheraventemplate <class Predicate>
186227825Stheravenclass unary_negate
187227825Stheraven    : public unary_function<typename Predicate::argument_type, bool>
188227825Stheraven{
189227825Stheravenpublic:
190227825Stheraven    explicit unary_negate(const Predicate& pred);
191227825Stheraven    bool operator()(const typename Predicate::argument_type& x) const;
192227825Stheraven};
193227825Stheraven
194227825Stheraventemplate <class Predicate> unary_negate<Predicate> not1(const Predicate& pred);
195227825Stheraven
196227825Stheraventemplate <class Predicate>
197227825Stheravenclass binary_negate
198227825Stheraven    : public binary_function<typename Predicate::first_argument_type,
199227825Stheraven                             typename Predicate::second_argument_type,
200227825Stheraven                             bool>
201227825Stheraven{
202227825Stheravenpublic:
203227825Stheraven    explicit binary_negate(const Predicate& pred);
204227825Stheraven    bool operator()(const typename Predicate::first_argument_type& x,
205227825Stheraven                    const typename Predicate::second_argument_type& y) const;
206227825Stheraven};
207227825Stheraven
208227825Stheraventemplate <class Predicate> binary_negate<Predicate> not2(const Predicate& pred);
209227825Stheraven
210227825Stheraventemplate<class T> struct is_bind_expression;
211227825Stheraventemplate<class T> struct is_placeholder;
212227825Stheraven
213227825Stheraventemplate<class Fn, class... BoundArgs>
214227825Stheraven  unspecified bind(Fn&&, BoundArgs&&...);
215227825Stheraventemplate<class R, class Fn, class... BoundArgs>
216227825Stheraven  unspecified bind(Fn&&, BoundArgs&&...);
217227825Stheraven
218227825Stheravennamespace placeholders {
219227825Stheraven  // M is the implementation-defined number of placeholders
220227825Stheraven  extern unspecified _1;
221227825Stheraven  extern unspecified _2;
222227825Stheraven  .
223227825Stheraven  .
224227825Stheraven  .
225232924Stheraven  extern unspecified _Mp;
226227825Stheraven}
227227825Stheraven
228227825Stheraventemplate <class Operation>
229227825Stheravenclass binder1st
230227825Stheraven    : public unary_function<typename Operation::second_argument_type,
231227825Stheraven                            typename Operation::result_type>
232227825Stheraven{
233227825Stheravenprotected:
234227825Stheraven    Operation                               op;
235227825Stheraven    typename Operation::first_argument_type value;
236227825Stheravenpublic:
237227825Stheraven    binder1st(const Operation& x, const typename Operation::first_argument_type y);
238227825Stheraven    typename Operation::result_type operator()(      typename Operation::second_argument_type& x) const;
239227825Stheraven    typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const;
240227825Stheraven};
241227825Stheraven
242227825Stheraventemplate <class Operation, class T>
243227825Stheravenbinder1st<Operation> bind1st(const Operation& op, const T& x);
244227825Stheraven
245227825Stheraventemplate <class Operation>
246227825Stheravenclass binder2nd
247227825Stheraven    : public unary_function<typename Operation::first_argument_type,
248227825Stheraven                            typename Operation::result_type>
249227825Stheraven{
250227825Stheravenprotected:
251227825Stheraven    Operation                                op;
252227825Stheraven    typename Operation::second_argument_type value;
253227825Stheravenpublic:
254227825Stheraven    binder2nd(const Operation& x, const typename Operation::second_argument_type y);
255227825Stheraven    typename Operation::result_type operator()(      typename Operation::first_argument_type& x) const;
256227825Stheraven    typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const;
257227825Stheraven};
258227825Stheraven
259227825Stheraventemplate <class Operation, class T>
260227825Stheravenbinder2nd<Operation> bind2nd(const Operation& op, const T& x);
261227825Stheraven
262227825Stheraventemplate <class Arg, class Result>
263227825Stheravenclass pointer_to_unary_function : public unary_function<Arg, Result>
264227825Stheraven{
265227825Stheravenpublic:
266227825Stheraven    explicit pointer_to_unary_function(Result (*f)(Arg));
267227825Stheraven    Result operator()(Arg x) const;
268227825Stheraven};
269227825Stheraven
270227825Stheraventemplate <class Arg, class Result>
271227825Stheravenpointer_to_unary_function<Arg,Result> ptr_fun(Result (*f)(Arg));
272227825Stheraven
273227825Stheraventemplate <class Arg1, class Arg2, class Result>
274227825Stheravenclass pointer_to_binary_function : public binary_function<Arg1, Arg2, Result>
275227825Stheraven{
276227825Stheravenpublic:
277227825Stheraven    explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2));
278227825Stheraven    Result operator()(Arg1 x, Arg2 y) const;
279227825Stheraven};
280227825Stheraven
281227825Stheraventemplate <class Arg1, class Arg2, class Result>
282227825Stheravenpointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1,Arg2));
283227825Stheraven
284227825Stheraventemplate<class S, class T>
285227825Stheravenclass mem_fun_t : public unary_function<T*, S>
286227825Stheraven{
287227825Stheravenpublic:
288227825Stheraven    explicit mem_fun_t(S (T::*p)());
289227825Stheraven    S operator()(T* p) const;
290227825Stheraven};
291227825Stheraven
292227825Stheraventemplate<class S, class T, class A>
293227825Stheravenclass mem_fun1_t : public binary_function<T*, A, S>
294227825Stheraven{
295227825Stheravenpublic:
296227825Stheraven    explicit mem_fun1_t(S (T::*p)(A));
297227825Stheraven    S operator()(T* p, A x) const;
298227825Stheraven};
299227825Stheraven
300227825Stheraventemplate<class S, class T>          mem_fun_t<S,T>    mem_fun(S (T::*f)());
301227825Stheraventemplate<class S, class T, class A> mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A));
302227825Stheraven
303227825Stheraventemplate<class S, class T>
304227825Stheravenclass mem_fun_ref_t : public unary_function<T, S>
305227825Stheraven{
306227825Stheravenpublic:
307227825Stheraven    explicit mem_fun_ref_t(S (T::*p)());
308227825Stheraven    S operator()(T& p) const;
309227825Stheraven};
310227825Stheraven
311227825Stheraventemplate<class S, class T, class A>
312227825Stheravenclass mem_fun1_ref_t : public binary_function<T, A, S>
313227825Stheraven{
314227825Stheravenpublic:
315227825Stheraven    explicit mem_fun1_ref_t(S (T::*p)(A));
316227825Stheraven    S operator()(T& p, A x) const;
317227825Stheraven};
318227825Stheraven
319227825Stheraventemplate<class S, class T>          mem_fun_ref_t<S,T>    mem_fun_ref(S (T::*f)());
320227825Stheraventemplate<class S, class T, class A> mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A));
321227825Stheraven
322227825Stheraventemplate <class S, class T>
323227825Stheravenclass const_mem_fun_t : public unary_function<const T*, S>
324227825Stheraven{
325227825Stheravenpublic:
326227825Stheraven    explicit const_mem_fun_t(S (T::*p)() const);
327227825Stheraven    S operator()(const T* p) const;
328227825Stheraven};
329227825Stheraven
330227825Stheraventemplate <class S, class T, class A>
331227825Stheravenclass const_mem_fun1_t : public binary_function<const T*, A, S>
332227825Stheraven{
333227825Stheravenpublic:
334227825Stheraven    explicit const_mem_fun1_t(S (T::*p)(A) const);
335227825Stheraven    S operator()(const T* p, A x) const;
336227825Stheraven};
337227825Stheraven
338227825Stheraventemplate <class S, class T>          const_mem_fun_t<S,T>    mem_fun(S (T::*f)() const);
339227825Stheraventemplate <class S, class T, class A> const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const);
340227825Stheraven
341227825Stheraventemplate <class S, class T>
342227825Stheravenclass const_mem_fun_ref_t : public unary_function<T, S>
343227825Stheraven{
344227825Stheravenpublic:
345227825Stheraven    explicit const_mem_fun_ref_t(S (T::*p)() const);
346227825Stheraven    S operator()(const T& p) const;
347227825Stheraven};
348227825Stheraven
349227825Stheraventemplate <class S, class T, class A>
350227825Stheravenclass const_mem_fun1_ref_t : public binary_function<T, A, S>
351227825Stheraven{
352227825Stheravenpublic:
353227825Stheraven    explicit const_mem_fun1_ref_t(S (T::*p)(A) const);
354227825Stheraven    S operator()(const T& p, A x) const;
355227825Stheraven};
356227825Stheraven
357227825Stheraventemplate <class S, class T>          const_mem_fun_ref_t<S,T>    mem_fun_ref(S (T::*f)() const);
358227825Stheraventemplate <class S, class T, class A> const_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const);
359227825Stheraven
360227825Stheraventemplate<class R, class T> unspecified mem_fn(R T::*);
361227825Stheraven
362227825Stheravenclass bad_function_call
363227825Stheraven    : public exception
364227825Stheraven{
365227825Stheraven};
366227825Stheraven
367227825Stheraventemplate<class> class function; // undefined
368227825Stheraven
369227825Stheraventemplate<class R, class... ArgTypes>
370227825Stheravenclass function<R(ArgTypes...)>
371227825Stheraven  : public unary_function<T1, R>      // iff sizeof...(ArgTypes) == 1 and
372227825Stheraven                                      // ArgTypes contains T1
373227825Stheraven  : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and
374227825Stheraven                                      // ArgTypes contains T1 and T2
375227825Stheraven{
376227825Stheravenpublic:
377227825Stheraven    typedef R result_type;
378227825Stheraven
379227825Stheraven    // construct/copy/destroy:
380227825Stheraven    function() noexcept;
381227825Stheraven    function(nullptr_t) noexcept;
382227825Stheraven    function(const function&);
383227825Stheraven    function(function&&) noexcept;
384227825Stheraven    template<class F>
385227825Stheraven      function(F);
386227825Stheraven    template<Allocator Alloc>
387227825Stheraven      function(allocator_arg_t, const Alloc&) noexcept;
388227825Stheraven    template<Allocator Alloc>
389227825Stheraven      function(allocator_arg_t, const Alloc&, nullptr_t) noexcept;
390227825Stheraven    template<Allocator Alloc>
391227825Stheraven      function(allocator_arg_t, const Alloc&, const function&);
392227825Stheraven    template<Allocator Alloc>
393227825Stheraven      function(allocator_arg_t, const Alloc&, function&&);
394227825Stheraven    template<class F, Allocator Alloc>
395227825Stheraven      function(allocator_arg_t, const Alloc&, F);
396227825Stheraven
397227825Stheraven    function& operator=(const function&);
398227825Stheraven    function& operator=(function&&) noexcept;
399227825Stheraven    function& operator=(nullptr_t) noexcept;
400227825Stheraven    template<class F>
401227825Stheraven      function& operator=(F&&);
402227825Stheraven    template<class F>
403227825Stheraven      function& operator=(reference_wrapper<F>) noexcept;
404227825Stheraven
405227825Stheraven    ~function();
406227825Stheraven
407227825Stheraven    // function modifiers:
408227825Stheraven    void swap(function&) noexcept;
409227825Stheraven    template<class F, class Alloc>
410227825Stheraven      void assign(F&&, const Alloc&);
411227825Stheraven
412227825Stheraven    // function capacity:
413227825Stheraven    explicit operator bool() const noexcept;
414227825Stheraven
415227825Stheraven    // function invocation:
416227825Stheraven    R operator()(ArgTypes...) const;
417227825Stheraven
418227825Stheraven    // function target access:
419227825Stheraven    const std::type_info& target_type() const noexcept;
420227825Stheraven    template <typename T>       T* target() noexcept;
421227825Stheraven    template <typename T> const T* target() const noexcept;
422227825Stheraven};
423227825Stheraven
424227825Stheraven// Null pointer comparisons:
425227825Stheraventemplate <class R, class ... ArgTypes>
426227825Stheraven  bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
427227825Stheraven
428227825Stheraventemplate <class R, class ... ArgTypes>
429227825Stheraven  bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
430227825Stheraven
431227825Stheraventemplate <class R, class ... ArgTypes>
432227825Stheraven  bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
433227825Stheraven
434227825Stheraventemplate <class  R, class ... ArgTypes>
435227825Stheraven  bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
436227825Stheraven
437227825Stheraven// specialized algorithms:
438227825Stheraventemplate <class  R, class ... ArgTypes>
439227825Stheraven  void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
440227825Stheraven
441227825Stheraventemplate <class T> struct hash;
442227825Stheraven
443227825Stheraventemplate <> struct hash<bool>;
444227825Stheraventemplate <> struct hash<char>;
445227825Stheraventemplate <> struct hash<signed char>;
446227825Stheraventemplate <> struct hash<unsigned char>;
447227825Stheraventemplate <> struct hash<char16_t>;
448227825Stheraventemplate <> struct hash<char32_t>;
449227825Stheraventemplate <> struct hash<wchar_t>;
450227825Stheraventemplate <> struct hash<short>;
451227825Stheraventemplate <> struct hash<unsigned short>;
452227825Stheraventemplate <> struct hash<int>;
453227825Stheraventemplate <> struct hash<unsigned int>;
454227825Stheraventemplate <> struct hash<long>;
455227825Stheraventemplate <> struct hash<long long>;
456227825Stheraventemplate <> struct hash<unsigned long>;
457227825Stheraventemplate <> struct hash<unsigned long long>;
458227825Stheraven
459227825Stheraventemplate <> struct hash<float>;
460227825Stheraventemplate <> struct hash<double>;
461227825Stheraventemplate <> struct hash<long double>;
462227825Stheraven
463227825Stheraventemplate<class T> struct hash<T*>;
464227825Stheraven
465227825Stheraven}  // std
466227825Stheraven
467227825StheravenPOLICY:  For non-variadic implementations, the number of arguments is limited
468227825Stheraven         to 3.  It is hoped that the need for non-variadic implementations
469227825Stheraven         will be minimal.
470227825Stheraven
471227825Stheraven*/
472227825Stheraven
473227825Stheraven#include <__config>
474227825Stheraven#include <type_traits>
475227825Stheraven#include <typeinfo>
476227825Stheraven#include <exception>
477227825Stheraven#include <memory>
478227825Stheraven#include <tuple>
479227825Stheraven
480227825Stheraven#include <__functional_base>
481227825Stheraven
482227825Stheraven#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
483227825Stheraven#pragma GCC system_header
484227825Stheraven#endif
485227825Stheraven
486227825Stheraven_LIBCPP_BEGIN_NAMESPACE_STD
487227825Stheraven
488261272Sdim#if _LIBCPP_STD_VER > 11
489261272Sdimtemplate <class _Tp = void>
490261272Sdim#else
491227825Stheraventemplate <class _Tp>
492261272Sdim#endif
493261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY plus : binary_function<_Tp, _Tp, _Tp>
494227825Stheraven{
495261272Sdim    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
496261272Sdim    _Tp operator()(const _Tp& __x, const _Tp& __y) const
497227825Stheraven        {return __x + __y;}
498227825Stheraven};
499227825Stheraven
500261272Sdim#if _LIBCPP_STD_VER > 11
501261272Sdimtemplate <>
502261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY plus<void>
503261272Sdim{
504261272Sdim    template <class _T1, class _T2>
505261272Sdim    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
506261272Sdim    auto operator()(_T1&& __t, _T2&& __u) const
507261272Sdim        { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
508261272Sdim    typedef void is_transparent;
509261272Sdim};
510261272Sdim#endif
511261272Sdim
512261272Sdim
513261272Sdim#if _LIBCPP_STD_VER > 11
514261272Sdimtemplate <class _Tp = void>
515261272Sdim#else
516227825Stheraventemplate <class _Tp>
517261272Sdim#endif
518261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY minus : binary_function<_Tp, _Tp, _Tp>
519227825Stheraven{
520261272Sdim    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
521261272Sdim    _Tp operator()(const _Tp& __x, const _Tp& __y) const
522227825Stheraven        {return __x - __y;}
523227825Stheraven};
524227825Stheraven
525261272Sdim#if _LIBCPP_STD_VER > 11
526261272Sdimtemplate <>
527261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY minus<void>
528261272Sdim{
529261272Sdim    template <class _T1, class _T2>
530261272Sdim    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
531261272Sdim    auto operator()(_T1&& __t, _T2&& __u) const
532261272Sdim        { return _VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u); }
533261272Sdim    typedef void is_transparent;
534261272Sdim};
535261272Sdim#endif
536261272Sdim
537261272Sdim
538261272Sdim#if _LIBCPP_STD_VER > 11
539261272Sdimtemplate <class _Tp = void>
540261272Sdim#else
541227825Stheraventemplate <class _Tp>
542261272Sdim#endif
543261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY multiplies : binary_function<_Tp, _Tp, _Tp>
544227825Stheraven{
545261272Sdim    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
546261272Sdim    _Tp operator()(const _Tp& __x, const _Tp& __y) const
547227825Stheraven        {return __x * __y;}
548227825Stheraven};
549227825Stheraven
550261272Sdim#if _LIBCPP_STD_VER > 11
551261272Sdimtemplate <>
552261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY multiplies<void>
553261272Sdim{
554261272Sdim    template <class _T1, class _T2>
555261272Sdim    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
556261272Sdim    auto operator()(_T1&& __t, _T2&& __u) const
557261272Sdim        { return _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u); }
558261272Sdim    typedef void is_transparent;
559261272Sdim};
560261272Sdim#endif
561261272Sdim
562261272Sdim
563261272Sdim#if _LIBCPP_STD_VER > 11
564261272Sdimtemplate <class _Tp = void>
565261272Sdim#else
566227825Stheraventemplate <class _Tp>
567261272Sdim#endif
568261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY divides : binary_function<_Tp, _Tp, _Tp>
569227825Stheraven{
570261272Sdim    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
571261272Sdim    _Tp operator()(const _Tp& __x, const _Tp& __y) const
572227825Stheraven        {return __x / __y;}
573227825Stheraven};
574227825Stheraven
575261272Sdim#if _LIBCPP_STD_VER > 11
576261272Sdimtemplate <>
577261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY divides<void>
578261272Sdim{
579261272Sdim    template <class _T1, class _T2>
580261272Sdim    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
581261272Sdim    auto operator()(_T1&& __t, _T2&& __u) const
582261272Sdim        { return _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u); }
583261272Sdim    typedef void is_transparent;
584261272Sdim};
585261272Sdim#endif
586261272Sdim
587261272Sdim
588261272Sdim#if _LIBCPP_STD_VER > 11
589261272Sdimtemplate <class _Tp = void>
590261272Sdim#else
591227825Stheraventemplate <class _Tp>
592261272Sdim#endif
593261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY modulus : binary_function<_Tp, _Tp, _Tp>
594227825Stheraven{
595261272Sdim    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
596261272Sdim    _Tp operator()(const _Tp& __x, const _Tp& __y) const
597227825Stheraven        {return __x % __y;}
598227825Stheraven};
599227825Stheraven
600261272Sdim#if _LIBCPP_STD_VER > 11
601261272Sdimtemplate <>
602261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY modulus<void>
603261272Sdim{
604261272Sdim    template <class _T1, class _T2>
605261272Sdim    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
606261272Sdim    auto operator()(_T1&& __t, _T2&& __u) const
607261272Sdim        { return _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u); }
608261272Sdim    typedef void is_transparent;
609261272Sdim};
610261272Sdim#endif
611261272Sdim
612261272Sdim
613261272Sdim#if _LIBCPP_STD_VER > 11
614261272Sdimtemplate <class _Tp = void>
615261272Sdim#else
616227825Stheraventemplate <class _Tp>
617261272Sdim#endif
618261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY negate : unary_function<_Tp, _Tp>
619227825Stheraven{
620261272Sdim    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
621261272Sdim    _Tp operator()(const _Tp& __x) const
622227825Stheraven        {return -__x;}
623227825Stheraven};
624227825Stheraven
625261272Sdim#if _LIBCPP_STD_VER > 11
626261272Sdimtemplate <>
627261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY negate<void>
628261272Sdim{
629261272Sdim    template <class _Tp>
630261272Sdim    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
631261272Sdim    auto operator()(_Tp&& __x) const
632261272Sdim        { return -_VSTD::forward<_Tp>(__x); }
633261272Sdim    typedef void is_transparent;
634261272Sdim};
635261272Sdim#endif
636261272Sdim
637261272Sdim
638261272Sdim#if _LIBCPP_STD_VER > 11
639261272Sdimtemplate <class _Tp = void>
640261272Sdim#else
641227825Stheraventemplate <class _Tp>
642261272Sdim#endif
643261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY equal_to : binary_function<_Tp, _Tp, bool>
644227825Stheraven{
645261272Sdim    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
646261272Sdim    bool operator()(const _Tp& __x, const _Tp& __y) const
647227825Stheraven        {return __x == __y;}
648227825Stheraven};
649227825Stheraven
650261272Sdim#if _LIBCPP_STD_VER > 11
651261272Sdimtemplate <>
652261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY equal_to<void>
653261272Sdim{
654261272Sdim    template <class _T1, class _T2>
655261272Sdim    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
656261272Sdim    auto operator()(_T1&& __t, _T2&& __u) const
657261272Sdim        { return _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u); }
658261272Sdim    typedef void is_transparent;
659261272Sdim};
660261272Sdim#endif
661261272Sdim
662261272Sdim
663261272Sdim#if _LIBCPP_STD_VER > 11
664261272Sdimtemplate <class _Tp = void>
665261272Sdim#else
666227825Stheraventemplate <class _Tp>
667261272Sdim#endif
668261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY not_equal_to : binary_function<_Tp, _Tp, bool>
669227825Stheraven{
670261272Sdim    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
671261272Sdim    bool operator()(const _Tp& __x, const _Tp& __y) const
672227825Stheraven        {return __x != __y;}
673227825Stheraven};
674227825Stheraven
675261272Sdim#if _LIBCPP_STD_VER > 11
676261272Sdimtemplate <>
677261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY not_equal_to<void>
678261272Sdim{
679261272Sdim    template <class _T1, class _T2>
680261272Sdim    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
681261272Sdim    auto operator()(_T1&& __t, _T2&& __u) const
682261272Sdim        { return _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u); }
683261272Sdim    typedef void is_transparent;
684261272Sdim};
685261272Sdim#endif
686261272Sdim
687261272Sdim
688261272Sdim#if _LIBCPP_STD_VER > 11
689261272Sdimtemplate <class _Tp = void>
690261272Sdim#else
691227825Stheraventemplate <class _Tp>
692261272Sdim#endif
693261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY greater : binary_function<_Tp, _Tp, bool>
694227825Stheraven{
695261272Sdim    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
696261272Sdim    bool operator()(const _Tp& __x, const _Tp& __y) const
697227825Stheraven        {return __x > __y;}
698227825Stheraven};
699227825Stheraven
700261272Sdim#if _LIBCPP_STD_VER > 11
701261272Sdimtemplate <>
702261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY greater<void>
703261272Sdim{
704261272Sdim    template <class _T1, class _T2>
705261272Sdim    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
706261272Sdim    auto operator()(_T1&& __t, _T2&& __u) const
707261272Sdim        { return _VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u); }
708261272Sdim    typedef void is_transparent;
709261272Sdim};
710261272Sdim#endif
711261272Sdim
712261272Sdim
713232924Stheraven// less in <__functional_base>
714227825Stheraven
715261272Sdim#if _LIBCPP_STD_VER > 11
716261272Sdimtemplate <class _Tp = void>
717261272Sdim#else
718227825Stheraventemplate <class _Tp>
719261272Sdim#endif
720261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY greater_equal : binary_function<_Tp, _Tp, bool>
721227825Stheraven{
722261272Sdim    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
723261272Sdim    bool operator()(const _Tp& __x, const _Tp& __y) const
724227825Stheraven        {return __x >= __y;}
725227825Stheraven};
726227825Stheraven
727261272Sdim#if _LIBCPP_STD_VER > 11
728261272Sdimtemplate <>
729261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY greater_equal<void>
730261272Sdim{
731261272Sdim    template <class _T1, class _T2>
732261272Sdim    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
733261272Sdim    auto operator()(_T1&& __t, _T2&& __u) const
734261272Sdim        { return _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u); }
735261272Sdim    typedef void is_transparent;
736261272Sdim};
737261272Sdim#endif
738261272Sdim
739261272Sdim
740261272Sdim#if _LIBCPP_STD_VER > 11
741261272Sdimtemplate <class _Tp = void>
742261272Sdim#else
743227825Stheraventemplate <class _Tp>
744261272Sdim#endif
745261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY less_equal : binary_function<_Tp, _Tp, bool>
746227825Stheraven{
747261272Sdim    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
748261272Sdim    bool operator()(const _Tp& __x, const _Tp& __y) const
749227825Stheraven        {return __x <= __y;}
750227825Stheraven};
751227825Stheraven
752261272Sdim#if _LIBCPP_STD_VER > 11
753261272Sdimtemplate <>
754261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY less_equal<void>
755261272Sdim{
756261272Sdim    template <class _T1, class _T2>
757261272Sdim    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
758261272Sdim    auto operator()(_T1&& __t, _T2&& __u) const
759261272Sdim        { return _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u); }
760261272Sdim    typedef void is_transparent;
761261272Sdim};
762261272Sdim#endif
763261272Sdim
764261272Sdim
765261272Sdim#if _LIBCPP_STD_VER > 11
766261272Sdimtemplate <class _Tp = void>
767261272Sdim#else
768227825Stheraventemplate <class _Tp>
769261272Sdim#endif
770261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY logical_and : binary_function<_Tp, _Tp, bool>
771227825Stheraven{
772261272Sdim    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
773261272Sdim    bool operator()(const _Tp& __x, const _Tp& __y) const
774227825Stheraven        {return __x && __y;}
775227825Stheraven};
776227825Stheraven
777261272Sdim#if _LIBCPP_STD_VER > 11
778261272Sdimtemplate <>
779261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY logical_and<void>
780261272Sdim{
781261272Sdim    template <class _T1, class _T2>
782261272Sdim    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
783261272Sdim    auto operator()(_T1&& __t, _T2&& __u) const
784261272Sdim        { return _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u); }
785261272Sdim    typedef void is_transparent;
786261272Sdim};
787261272Sdim#endif
788261272Sdim
789261272Sdim
790261272Sdim#if _LIBCPP_STD_VER > 11
791261272Sdimtemplate <class _Tp = void>
792261272Sdim#else
793227825Stheraventemplate <class _Tp>
794261272Sdim#endif
795261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY logical_or : binary_function<_Tp, _Tp, bool>
796227825Stheraven{
797261272Sdim    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
798261272Sdim    bool operator()(const _Tp& __x, const _Tp& __y) const
799227825Stheraven        {return __x || __y;}
800227825Stheraven};
801227825Stheraven
802261272Sdim#if _LIBCPP_STD_VER > 11
803261272Sdimtemplate <>
804261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY logical_or<void>
805261272Sdim{
806261272Sdim    template <class _T1, class _T2>
807261272Sdim    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
808261272Sdim    auto operator()(_T1&& __t, _T2&& __u) const
809261272Sdim        { return _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u); }
810261272Sdim    typedef void is_transparent;
811261272Sdim};
812261272Sdim#endif
813261272Sdim
814261272Sdim
815261272Sdim#if _LIBCPP_STD_VER > 11
816261272Sdimtemplate <class _Tp = void>
817261272Sdim#else
818227825Stheraventemplate <class _Tp>
819261272Sdim#endif
820261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY logical_not : unary_function<_Tp, bool>
821227825Stheraven{
822261272Sdim    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
823261272Sdim    bool operator()(const _Tp& __x) const
824227825Stheraven        {return !__x;}
825227825Stheraven};
826227825Stheraven
827261272Sdim#if _LIBCPP_STD_VER > 11
828261272Sdimtemplate <>
829261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY logical_not<void>
830261272Sdim{
831261272Sdim    template <class _Tp>
832261272Sdim    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
833261272Sdim    auto operator()(_Tp&& __x) const
834261272Sdim        { return !_VSTD::forward<_Tp>(__x); }
835261272Sdim    typedef void is_transparent;
836261272Sdim};
837261272Sdim#endif
838261272Sdim
839261272Sdim
840261272Sdim#if _LIBCPP_STD_VER > 11
841261272Sdimtemplate <class _Tp = void>
842261272Sdim#else
843227825Stheraventemplate <class _Tp>
844261272Sdim#endif
845261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY bit_and : binary_function<_Tp, _Tp, _Tp>
846227825Stheraven{
847261272Sdim    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
848261272Sdim    _Tp operator()(const _Tp& __x, const _Tp& __y) const
849227825Stheraven        {return __x & __y;}
850227825Stheraven};
851227825Stheraven
852261272Sdim#if _LIBCPP_STD_VER > 11
853261272Sdimtemplate <>
854261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY bit_and<void>
855261272Sdim{
856261272Sdim    template <class _T1, class _T2>
857261272Sdim    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
858261272Sdim    auto operator()(_T1&& __t, _T2&& __u) const
859261272Sdim        { return _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u); }
860261272Sdim    typedef void is_transparent;
861261272Sdim};
862261272Sdim#endif
863261272Sdim
864261272Sdim
865261272Sdim#if _LIBCPP_STD_VER > 11
866261272Sdimtemplate <class _Tp = void>
867261272Sdim#else
868227825Stheraventemplate <class _Tp>
869261272Sdim#endif
870261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY bit_or : binary_function<_Tp, _Tp, _Tp>
871227825Stheraven{
872261272Sdim    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
873261272Sdim    _Tp operator()(const _Tp& __x, const _Tp& __y) const
874227825Stheraven        {return __x | __y;}
875227825Stheraven};
876227825Stheraven
877261272Sdim#if _LIBCPP_STD_VER > 11
878261272Sdimtemplate <>
879261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY bit_or<void>
880261272Sdim{
881261272Sdim    template <class _T1, class _T2>
882261272Sdim    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
883261272Sdim    auto operator()(_T1&& __t, _T2&& __u) const
884261272Sdim        { return _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u); }
885261272Sdim    typedef void is_transparent;
886261272Sdim};
887261272Sdim#endif
888261272Sdim
889261272Sdim
890261272Sdim#if _LIBCPP_STD_VER > 11
891261272Sdimtemplate <class _Tp = void>
892261272Sdim#else
893227825Stheraventemplate <class _Tp>
894261272Sdim#endif
895261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY bit_xor : binary_function<_Tp, _Tp, _Tp>
896227825Stheraven{
897261272Sdim    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
898261272Sdim    _Tp operator()(const _Tp& __x, const _Tp& __y) const
899227825Stheraven        {return __x ^ __y;}
900227825Stheraven};
901227825Stheraven
902261272Sdim#if _LIBCPP_STD_VER > 11
903261272Sdimtemplate <>
904261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY bit_xor<void>
905261272Sdim{
906261272Sdim    template <class _T1, class _T2>
907261272Sdim    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
908261272Sdim    auto operator()(_T1&& __t, _T2&& __u) const
909261272Sdim        { return _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u); }
910261272Sdim    typedef void is_transparent;
911261272Sdim};
912261272Sdim#endif
913261272Sdim
914261272Sdim
915261272Sdim#if _LIBCPP_STD_VER > 11
916261272Sdimtemplate <class _Tp = void>
917261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY bit_not : unary_function<_Tp, _Tp>
918261272Sdim{
919261272Sdim    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
920261272Sdim    _Tp operator()(const _Tp& __x) const
921261272Sdim        {return ~__x;}
922261272Sdim};
923261272Sdim
924261272Sdimtemplate <>
925261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY bit_not<void>
926261272Sdim{
927261272Sdim    template <class _Tp>
928261272Sdim    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
929261272Sdim    auto operator()(_Tp&& __x) const
930261272Sdim        { return ~_VSTD::forward<_Tp>(__x); }
931261272Sdim    typedef void is_transparent;
932261272Sdim};
933261272Sdim#endif
934261272Sdim
935227825Stheraventemplate <class _Predicate>
936261272Sdimclass _LIBCPP_TYPE_VIS_ONLY unary_negate
937227825Stheraven    : public unary_function<typename _Predicate::argument_type, bool>
938227825Stheraven{
939227825Stheraven    _Predicate __pred_;
940227825Stheravenpublic:
941261272Sdim    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
942261272Sdim    explicit unary_negate(const _Predicate& __pred)
943227825Stheraven        : __pred_(__pred) {}
944261272Sdim    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
945261272Sdim    bool operator()(const typename _Predicate::argument_type& __x) const
946227825Stheraven        {return !__pred_(__x);}
947227825Stheraven};
948227825Stheraven
949227825Stheraventemplate <class _Predicate>
950261272Sdiminline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
951227825Stheravenunary_negate<_Predicate>
952227825Stheravennot1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);}
953227825Stheraven
954227825Stheraventemplate <class _Predicate>
955261272Sdimclass _LIBCPP_TYPE_VIS_ONLY binary_negate
956227825Stheraven    : public binary_function<typename _Predicate::first_argument_type,
957227825Stheraven                             typename _Predicate::second_argument_type,
958227825Stheraven                             bool>
959227825Stheraven{
960227825Stheraven    _Predicate __pred_;
961227825Stheravenpublic:
962261272Sdim    _LIBCPP_INLINE_VISIBILITY explicit _LIBCPP_CONSTEXPR_AFTER_CXX11 
963261272Sdim    binary_negate(const _Predicate& __pred) : __pred_(__pred) {}
964261272Sdim
965261272Sdim    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
966261272Sdim    bool operator()(const typename _Predicate::first_argument_type& __x,
967227825Stheraven                    const typename _Predicate::second_argument_type& __y) const
968227825Stheraven        {return !__pred_(__x, __y);}
969227825Stheraven};
970227825Stheraven
971227825Stheraventemplate <class _Predicate>
972261272Sdiminline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
973227825Stheravenbinary_negate<_Predicate>
974227825Stheravennot2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);}
975227825Stheraven
976227825Stheraventemplate <class __Operation>
977261272Sdimclass _LIBCPP_TYPE_VIS_ONLY binder1st
978227825Stheraven    : public unary_function<typename __Operation::second_argument_type,
979227825Stheraven                            typename __Operation::result_type>
980227825Stheraven{
981227825Stheravenprotected:
982227825Stheraven    __Operation                               op;
983227825Stheraven    typename __Operation::first_argument_type value;
984227825Stheravenpublic:
985227825Stheraven    _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x,
986227825Stheraven                               const typename __Operation::first_argument_type __y)
987227825Stheraven        : op(__x), value(__y) {}
988227825Stheraven    _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
989227825Stheraven        (typename __Operation::second_argument_type& __x) const
990227825Stheraven            {return op(value, __x);}
991227825Stheraven    _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
992227825Stheraven        (const typename __Operation::second_argument_type& __x) const
993227825Stheraven            {return op(value, __x);}
994227825Stheraven};
995227825Stheraven
996227825Stheraventemplate <class __Operation, class _Tp>
997227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
998227825Stheravenbinder1st<__Operation>
999227825Stheravenbind1st(const __Operation& __op, const _Tp& __x)
1000227825Stheraven    {return binder1st<__Operation>(__op, __x);}
1001227825Stheraven
1002227825Stheraventemplate <class __Operation>
1003261272Sdimclass _LIBCPP_TYPE_VIS_ONLY binder2nd
1004227825Stheraven    : public unary_function<typename __Operation::first_argument_type,
1005227825Stheraven                            typename __Operation::result_type>
1006227825Stheraven{
1007227825Stheravenprotected:
1008227825Stheraven    __Operation                                op;
1009227825Stheraven    typename __Operation::second_argument_type value;
1010227825Stheravenpublic:
1011227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1012227825Stheraven    binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y)
1013227825Stheraven        : op(__x), value(__y) {}
1014227825Stheraven    _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1015227825Stheraven        (      typename __Operation::first_argument_type& __x) const
1016227825Stheraven            {return op(__x, value);}
1017227825Stheraven    _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1018227825Stheraven        (const typename __Operation::first_argument_type& __x) const
1019227825Stheraven            {return op(__x, value);}
1020227825Stheraven};
1021227825Stheraven
1022227825Stheraventemplate <class __Operation, class _Tp>
1023227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1024227825Stheravenbinder2nd<__Operation>
1025227825Stheravenbind2nd(const __Operation& __op, const _Tp& __x)
1026227825Stheraven    {return binder2nd<__Operation>(__op, __x);}
1027227825Stheraven
1028227825Stheraventemplate <class _Arg, class _Result>
1029261272Sdimclass _LIBCPP_TYPE_VIS_ONLY pointer_to_unary_function
1030227825Stheraven    : public unary_function<_Arg, _Result>
1031227825Stheraven{
1032227825Stheraven    _Result (*__f_)(_Arg);
1033227825Stheravenpublic:
1034227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg))
1035227825Stheraven        : __f_(__f) {}
1036227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const
1037227825Stheraven        {return __f_(__x);}
1038227825Stheraven};
1039227825Stheraven
1040227825Stheraventemplate <class _Arg, class _Result>
1041227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1042227825Stheravenpointer_to_unary_function<_Arg,_Result>
1043227825Stheravenptr_fun(_Result (*__f)(_Arg))
1044227825Stheraven    {return pointer_to_unary_function<_Arg,_Result>(__f);}
1045227825Stheraven
1046227825Stheraventemplate <class _Arg1, class _Arg2, class _Result>
1047261272Sdimclass _LIBCPP_TYPE_VIS_ONLY pointer_to_binary_function
1048227825Stheraven    : public binary_function<_Arg1, _Arg2, _Result>
1049227825Stheraven{
1050227825Stheraven    _Result (*__f_)(_Arg1, _Arg2);
1051227825Stheravenpublic:
1052227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2))
1053227825Stheraven        : __f_(__f) {}
1054227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const
1055227825Stheraven        {return __f_(__x, __y);}
1056227825Stheraven};
1057227825Stheraven
1058227825Stheraventemplate <class _Arg1, class _Arg2, class _Result>
1059227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1060227825Stheravenpointer_to_binary_function<_Arg1,_Arg2,_Result>
1061227825Stheravenptr_fun(_Result (*__f)(_Arg1,_Arg2))
1062227825Stheraven    {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);}
1063227825Stheraven
1064227825Stheraventemplate<class _Sp, class _Tp>
1065261272Sdimclass _LIBCPP_TYPE_VIS_ONLY mem_fun_t : public unary_function<_Tp*, _Sp>
1066227825Stheraven{
1067227825Stheraven    _Sp (_Tp::*__p_)();
1068227825Stheravenpublic:
1069227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)())
1070227825Stheraven        : __p_(__p) {}
1071227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const
1072227825Stheraven        {return (__p->*__p_)();}
1073227825Stheraven};
1074227825Stheraven
1075227825Stheraventemplate<class _Sp, class _Tp, class _Ap>
1076261272Sdimclass _LIBCPP_TYPE_VIS_ONLY mem_fun1_t : public binary_function<_Tp*, _Ap, _Sp>
1077227825Stheraven{
1078227825Stheraven    _Sp (_Tp::*__p_)(_Ap);
1079227825Stheravenpublic:
1080227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap))
1081227825Stheraven        : __p_(__p) {}
1082227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const
1083227825Stheraven        {return (__p->*__p_)(__x);}
1084227825Stheraven};
1085227825Stheraven
1086227825Stheraventemplate<class _Sp, class _Tp>
1087227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1088227825Stheravenmem_fun_t<_Sp,_Tp>
1089227825Stheravenmem_fun(_Sp (_Tp::*__f)())
1090227825Stheraven    {return mem_fun_t<_Sp,_Tp>(__f);}
1091227825Stheraven
1092227825Stheraventemplate<class _Sp, class _Tp, class _Ap>
1093227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1094227825Stheravenmem_fun1_t<_Sp,_Tp,_Ap>
1095227825Stheravenmem_fun(_Sp (_Tp::*__f)(_Ap))
1096227825Stheraven    {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1097227825Stheraven
1098227825Stheraventemplate<class _Sp, class _Tp>
1099261272Sdimclass _LIBCPP_TYPE_VIS_ONLY mem_fun_ref_t : public unary_function<_Tp, _Sp>
1100227825Stheraven{
1101227825Stheraven    _Sp (_Tp::*__p_)();
1102227825Stheravenpublic:
1103227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)())
1104227825Stheraven        : __p_(__p) {}
1105227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const
1106227825Stheraven        {return (__p.*__p_)();}
1107227825Stheraven};
1108227825Stheraven
1109227825Stheraventemplate<class _Sp, class _Tp, class _Ap>
1110261272Sdimclass _LIBCPP_TYPE_VIS_ONLY mem_fun1_ref_t : public binary_function<_Tp, _Ap, _Sp>
1111227825Stheraven{
1112227825Stheraven    _Sp (_Tp::*__p_)(_Ap);
1113227825Stheravenpublic:
1114227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap))
1115227825Stheraven        : __p_(__p) {}
1116227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const
1117227825Stheraven        {return (__p.*__p_)(__x);}
1118227825Stheraven};
1119227825Stheraven
1120227825Stheraventemplate<class _Sp, class _Tp>
1121227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1122227825Stheravenmem_fun_ref_t<_Sp,_Tp>
1123227825Stheravenmem_fun_ref(_Sp (_Tp::*__f)())
1124227825Stheraven    {return mem_fun_ref_t<_Sp,_Tp>(__f);}
1125227825Stheraven
1126227825Stheraventemplate<class _Sp, class _Tp, class _Ap>
1127227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1128227825Stheravenmem_fun1_ref_t<_Sp,_Tp,_Ap>
1129227825Stheravenmem_fun_ref(_Sp (_Tp::*__f)(_Ap))
1130227825Stheraven    {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
1131227825Stheraven
1132227825Stheraventemplate <class _Sp, class _Tp>
1133261272Sdimclass _LIBCPP_TYPE_VIS_ONLY const_mem_fun_t : public unary_function<const _Tp*, _Sp>
1134227825Stheraven{
1135227825Stheraven    _Sp (_Tp::*__p_)() const;
1136227825Stheravenpublic:
1137227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const)
1138227825Stheraven        : __p_(__p) {}
1139227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const
1140227825Stheraven        {return (__p->*__p_)();}
1141227825Stheraven};
1142227825Stheraven
1143227825Stheraventemplate <class _Sp, class _Tp, class _Ap>
1144261272Sdimclass _LIBCPP_TYPE_VIS_ONLY const_mem_fun1_t : public binary_function<const _Tp*, _Ap, _Sp>
1145227825Stheraven{
1146227825Stheraven    _Sp (_Tp::*__p_)(_Ap) const;
1147227825Stheravenpublic:
1148227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const)
1149227825Stheraven        : __p_(__p) {}
1150227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const
1151227825Stheraven        {return (__p->*__p_)(__x);}
1152227825Stheraven};
1153227825Stheraven
1154227825Stheraventemplate <class _Sp, class _Tp>
1155227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1156227825Stheravenconst_mem_fun_t<_Sp,_Tp>
1157227825Stheravenmem_fun(_Sp (_Tp::*__f)() const)
1158227825Stheraven    {return const_mem_fun_t<_Sp,_Tp>(__f);}
1159227825Stheraven
1160227825Stheraventemplate <class _Sp, class _Tp, class _Ap>
1161227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1162227825Stheravenconst_mem_fun1_t<_Sp,_Tp,_Ap>
1163227825Stheravenmem_fun(_Sp (_Tp::*__f)(_Ap) const)
1164227825Stheraven    {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1165227825Stheraven
1166227825Stheraventemplate <class _Sp, class _Tp>
1167261272Sdimclass _LIBCPP_TYPE_VIS_ONLY const_mem_fun_ref_t : public unary_function<_Tp, _Sp>
1168227825Stheraven{
1169227825Stheraven    _Sp (_Tp::*__p_)() const;
1170227825Stheravenpublic:
1171227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const)
1172227825Stheraven        : __p_(__p) {}
1173227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const
1174227825Stheraven        {return (__p.*__p_)();}
1175227825Stheraven};
1176227825Stheraven
1177227825Stheraventemplate <class _Sp, class _Tp, class _Ap>
1178261272Sdimclass _LIBCPP_TYPE_VIS_ONLY const_mem_fun1_ref_t
1179227825Stheraven    : public binary_function<_Tp, _Ap, _Sp>
1180227825Stheraven{
1181227825Stheraven    _Sp (_Tp::*__p_)(_Ap) const;
1182227825Stheravenpublic:
1183227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const)
1184227825Stheraven        : __p_(__p) {}
1185227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const
1186227825Stheraven        {return (__p.*__p_)(__x);}
1187227825Stheraven};
1188227825Stheraven
1189227825Stheraventemplate <class _Sp, class _Tp>
1190227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1191227825Stheravenconst_mem_fun_ref_t<_Sp,_Tp>
1192227825Stheravenmem_fun_ref(_Sp (_Tp::*__f)() const)
1193227825Stheraven    {return const_mem_fun_ref_t<_Sp,_Tp>(__f);}
1194227825Stheraven
1195227825Stheraventemplate <class _Sp, class _Tp, class _Ap>
1196227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1197227825Stheravenconst_mem_fun1_ref_t<_Sp,_Tp,_Ap>
1198227825Stheravenmem_fun_ref(_Sp (_Tp::*__f)(_Ap) const)
1199227825Stheraven    {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
1200227825Stheraven
1201227825Stheraven#ifdef _LIBCPP_HAS_NO_VARIADICS
1202227825Stheraven
1203227825Stheraven#include <__functional_03>
1204227825Stheraven
1205227825Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
1206227825Stheraven
1207227825Stheraventemplate <class _Tp>
1208227825Stheravenclass __mem_fn
1209227825Stheraven    : public __weak_result_type<_Tp>
1210227825Stheraven{
1211227825Stheravenpublic:
1212227825Stheraven    // types
1213227825Stheraven    typedef _Tp type;
1214227825Stheravenprivate:
1215227825Stheraven    type __f_;
1216227825Stheraven
1217227825Stheravenpublic:
1218227825Stheraven    _LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) : __f_(__f) {}
1219227825Stheraven
1220227825Stheraven    // invoke
1221227825Stheraven    template <class... _ArgTypes>
1222227825Stheraven       _LIBCPP_INLINE_VISIBILITY
1223227825Stheraven       typename __invoke_return<type, _ArgTypes...>::type
1224276792Sdim          operator() (_ArgTypes&&... __args) const
1225227825Stheraven          {
1226227825Stheraven              return __invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...);
1227227825Stheraven          }
1228227825Stheraven};
1229227825Stheraven
1230232924Stheraventemplate<class _Rp, class _Tp>
1231227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1232232924Stheraven__mem_fn<_Rp _Tp::*>
1233232924Stheravenmem_fn(_Rp _Tp::* __pm)
1234227825Stheraven{
1235232924Stheraven    return __mem_fn<_Rp _Tp::*>(__pm);
1236227825Stheraven}
1237227825Stheraven
1238227825Stheraven// bad_function_call
1239227825Stheraven
1240227825Stheravenclass _LIBCPP_EXCEPTION_ABI bad_function_call
1241227825Stheraven    : public exception
1242227825Stheraven{
1243227825Stheraven};
1244227825Stheraven
1245261272Sdimtemplate<class _Fp> class _LIBCPP_TYPE_VIS_ONLY function; // undefined
1246227825Stheraven
1247227825Stheravennamespace __function
1248227825Stheraven{
1249227825Stheraven
1250232924Stheraventemplate<class _Rp, class ..._ArgTypes>
1251227825Stheravenstruct __maybe_derive_from_unary_function
1252227825Stheraven{
1253227825Stheraven};
1254227825Stheraven
1255232924Stheraventemplate<class _Rp, class _A1>
1256232924Stheravenstruct __maybe_derive_from_unary_function<_Rp(_A1)>
1257232924Stheraven    : public unary_function<_A1, _Rp>
1258227825Stheraven{
1259227825Stheraven};
1260227825Stheraven
1261232924Stheraventemplate<class _Rp, class ..._ArgTypes>
1262227825Stheravenstruct __maybe_derive_from_binary_function
1263227825Stheraven{
1264227825Stheraven};
1265227825Stheraven
1266232924Stheraventemplate<class _Rp, class _A1, class _A2>
1267232924Stheravenstruct __maybe_derive_from_binary_function<_Rp(_A1, _A2)>
1268232924Stheraven    : public binary_function<_A1, _A2, _Rp>
1269227825Stheraven{
1270227825Stheraven};
1271227825Stheraven
1272227825Stheraventemplate<class _Fp> class __base;
1273227825Stheraven
1274232924Stheraventemplate<class _Rp, class ..._ArgTypes>
1275232924Stheravenclass __base<_Rp(_ArgTypes...)>
1276227825Stheraven{
1277227825Stheraven    __base(const __base&);
1278227825Stheraven    __base& operator=(const __base&);
1279227825Stheravenpublic:
1280227825Stheraven    _LIBCPP_INLINE_VISIBILITY __base() {}
1281227825Stheraven    _LIBCPP_INLINE_VISIBILITY virtual ~__base() {}
1282227825Stheraven    virtual __base* __clone() const = 0;
1283227825Stheraven    virtual void __clone(__base*) const = 0;
1284227825Stheraven    virtual void destroy() _NOEXCEPT = 0;
1285227825Stheraven    virtual void destroy_deallocate() _NOEXCEPT = 0;
1286232924Stheraven    virtual _Rp operator()(_ArgTypes&& ...) = 0;
1287227825Stheraven#ifndef _LIBCPP_NO_RTTI
1288227825Stheraven    virtual const void* target(const type_info&) const _NOEXCEPT = 0;
1289227825Stheraven    virtual const std::type_info& target_type() const _NOEXCEPT = 0;
1290227825Stheraven#endif  // _LIBCPP_NO_RTTI
1291227825Stheraven};
1292227825Stheraven
1293227825Stheraventemplate<class _FD, class _Alloc, class _FB> class __func;
1294227825Stheraven
1295232924Stheraventemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1296232924Stheravenclass __func<_Fp, _Alloc, _Rp(_ArgTypes...)>
1297232924Stheraven    : public  __base<_Rp(_ArgTypes...)>
1298227825Stheraven{
1299232924Stheraven    __compressed_pair<_Fp, _Alloc> __f_;
1300227825Stheravenpublic:
1301227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1302232924Stheraven    explicit __func(_Fp&& __f)
1303232924Stheraven        : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1304232924Stheraven                                    _VSTD::forward_as_tuple()) {}
1305227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1306232924Stheraven    explicit __func(const _Fp& __f, const _Alloc& __a)
1307232924Stheraven        : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1308232924Stheraven                                    _VSTD::forward_as_tuple(__a)) {}
1309232924Stheraven
1310232924Stheraven    _LIBCPP_INLINE_VISIBILITY
1311232924Stheraven    explicit __func(const _Fp& __f, _Alloc&& __a)
1312232924Stheraven        : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1313232924Stheraven                                    _VSTD::forward_as_tuple(_VSTD::move(__a))) {}
1314232924Stheraven
1315232924Stheraven    _LIBCPP_INLINE_VISIBILITY
1316232924Stheraven    explicit __func(_Fp&& __f, _Alloc&& __a)
1317232924Stheraven        : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1318232924Stheraven                                    _VSTD::forward_as_tuple(_VSTD::move(__a))) {}
1319232924Stheraven    virtual __base<_Rp(_ArgTypes...)>* __clone() const;
1320232924Stheraven    virtual void __clone(__base<_Rp(_ArgTypes...)>*) const;
1321227825Stheraven    virtual void destroy() _NOEXCEPT;
1322227825Stheraven    virtual void destroy_deallocate() _NOEXCEPT;
1323232924Stheraven    virtual _Rp operator()(_ArgTypes&& ... __arg);
1324227825Stheraven#ifndef _LIBCPP_NO_RTTI
1325227825Stheraven    virtual const void* target(const type_info&) const _NOEXCEPT;
1326227825Stheraven    virtual const std::type_info& target_type() const _NOEXCEPT;
1327227825Stheraven#endif  // _LIBCPP_NO_RTTI
1328227825Stheraven};
1329227825Stheraven
1330232924Stheraventemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1331232924Stheraven__base<_Rp(_ArgTypes...)>*
1332232924Stheraven__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const
1333227825Stheraven{
1334232924Stheraven    typedef typename _Alloc::template rebind<__func>::other _Ap;
1335232924Stheraven    _Ap __a(__f_.second());
1336232924Stheraven    typedef __allocator_destructor<_Ap> _Dp;
1337232924Stheraven    unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1338227825Stheraven    ::new (__hold.get()) __func(__f_.first(), _Alloc(__a));
1339227825Stheraven    return __hold.release();
1340227825Stheraven}
1341227825Stheraven
1342232924Stheraventemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1343227825Stheravenvoid
1344232924Stheraven__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const
1345227825Stheraven{
1346227825Stheraven    ::new (__p) __func(__f_.first(), __f_.second());
1347227825Stheraven}
1348227825Stheraven
1349232924Stheraventemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1350227825Stheravenvoid
1351232924Stheraven__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPT
1352227825Stheraven{
1353232924Stheraven    __f_.~__compressed_pair<_Fp, _Alloc>();
1354227825Stheraven}
1355227825Stheraven
1356232924Stheraventemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1357227825Stheravenvoid
1358232924Stheraven__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT
1359227825Stheraven{
1360232924Stheraven    typedef typename _Alloc::template rebind<__func>::other _Ap;
1361232924Stheraven    _Ap __a(__f_.second());
1362232924Stheraven    __f_.~__compressed_pair<_Fp, _Alloc>();
1363227825Stheraven    __a.deallocate(this, 1);
1364227825Stheraven}
1365227825Stheraven
1366232924Stheraventemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1367232924Stheraven_Rp
1368232924Stheraven__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg)
1369227825Stheraven{
1370227825Stheraven    return __invoke(__f_.first(), _VSTD::forward<_ArgTypes>(__arg)...);
1371227825Stheraven}
1372227825Stheraven
1373227825Stheraven#ifndef _LIBCPP_NO_RTTI
1374227825Stheraven
1375232924Stheraventemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1376227825Stheravenconst void*
1377232924Stheraven__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT
1378227825Stheraven{
1379232924Stheraven    if (__ti == typeid(_Fp))
1380227825Stheraven        return &__f_.first();
1381227825Stheraven    return (const void*)0;
1382227825Stheraven}
1383227825Stheraven
1384232924Stheraventemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1385227825Stheravenconst std::type_info&
1386232924Stheraven__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
1387227825Stheraven{
1388232924Stheraven    return typeid(_Fp);
1389227825Stheraven}
1390227825Stheraven
1391227825Stheraven#endif  // _LIBCPP_NO_RTTI
1392227825Stheraven
1393227825Stheraven}  // __function
1394227825Stheraven
1395232924Stheraventemplate<class _Rp, class ..._ArgTypes>
1396261272Sdimclass _LIBCPP_TYPE_VIS_ONLY function<_Rp(_ArgTypes...)>
1397232924Stheraven    : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>,
1398232924Stheraven      public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)>
1399227825Stheraven{
1400232924Stheraven    typedef __function::__base<_Rp(_ArgTypes...)> __base;
1401246468Stheraven    typename aligned_storage<3*sizeof(void*)>::type __buf_;
1402227825Stheraven    __base* __f_;
1403227825Stheraven
1404232924Stheraven    template <class _Fp>
1405227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1406232924Stheraven        static bool __not_null(const _Fp&) {return true;}
1407232924Stheraven    template <class _R2, class ..._Ap>
1408227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1409232924Stheraven        static bool __not_null(_R2 (*__p)(_Ap...)) {return __p;}
1410232924Stheraven    template <class _R2, class _Cp, class ..._Ap>
1411227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1412232924Stheraven        static bool __not_null(_R2 (_Cp::*__p)(_Ap...)) {return __p;}
1413232924Stheraven    template <class _R2, class _Cp, class ..._Ap>
1414227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1415232924Stheraven        static bool __not_null(_R2 (_Cp::*__p)(_Ap...) const) {return __p;}
1416232924Stheraven    template <class _R2, class _Cp, class ..._Ap>
1417227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1418232924Stheraven        static bool __not_null(_R2 (_Cp::*__p)(_Ap...) volatile) {return __p;}
1419232924Stheraven    template <class _R2, class _Cp, class ..._Ap>
1420227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1421232924Stheraven        static bool __not_null(_R2 (_Cp::*__p)(_Ap...) const volatile) {return __p;}
1422232924Stheraven    template <class _R2, class ..._Ap>
1423227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1424276792Sdim        static bool __not_null(const function<_R2(_Ap...)>& __p) {return !!__p;}
1425227825Stheraven
1426241900Sdim    template <class _Fp, bool = !is_same<_Fp, function>::value &&
1427241900Sdim                                __invokable<_Fp&, _ArgTypes...>::value>
1428227825Stheraven        struct __callable;
1429232924Stheraven    template <class _Fp>
1430232924Stheraven        struct __callable<_Fp, true>
1431227825Stheraven        {
1432227825Stheraven            static const bool value =
1433232924Stheraven                is_convertible<typename __invoke_of<_Fp&, _ArgTypes...>::type,
1434232924Stheraven                               _Rp>::value;
1435227825Stheraven        };
1436232924Stheraven    template <class _Fp>
1437232924Stheraven        struct __callable<_Fp, false>
1438227825Stheraven        {
1439227825Stheraven            static const bool value = false;
1440227825Stheraven        };
1441227825Stheravenpublic:
1442232924Stheraven    typedef _Rp result_type;
1443227825Stheraven
1444227825Stheraven    // construct/copy/destroy:
1445227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1446227825Stheraven    function() _NOEXCEPT : __f_(0) {}
1447227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1448227825Stheraven    function(nullptr_t) _NOEXCEPT : __f_(0) {}
1449227825Stheraven    function(const function&);
1450227825Stheraven    function(function&&) _NOEXCEPT;
1451232924Stheraven    template<class _Fp>
1452253146Stheraven      function(_Fp, typename enable_if
1453253146Stheraven                                     <
1454253146Stheraven                                        __callable<_Fp>::value &&
1455253146Stheraven                                        !is_same<_Fp, function>::value
1456253146Stheraven                                      >::type* = 0);
1457227825Stheraven
1458227825Stheraven    template<class _Alloc>
1459227825Stheraven      _LIBCPP_INLINE_VISIBILITY
1460227825Stheraven      function(allocator_arg_t, const _Alloc&) _NOEXCEPT : __f_(0) {}
1461227825Stheraven    template<class _Alloc>
1462227825Stheraven      _LIBCPP_INLINE_VISIBILITY
1463227825Stheraven      function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT : __f_(0) {}
1464227825Stheraven    template<class _Alloc>
1465227825Stheraven      function(allocator_arg_t, const _Alloc&, const function&);
1466227825Stheraven    template<class _Alloc>
1467227825Stheraven      function(allocator_arg_t, const _Alloc&, function&&);
1468232924Stheraven    template<class _Fp, class _Alloc>
1469232924Stheraven      function(allocator_arg_t, const _Alloc& __a, _Fp __f,
1470232924Stheraven               typename enable_if<__callable<_Fp>::value>::type* = 0);
1471227825Stheraven
1472227825Stheraven    function& operator=(const function&);
1473227825Stheraven    function& operator=(function&&) _NOEXCEPT;
1474227825Stheraven    function& operator=(nullptr_t) _NOEXCEPT;
1475232924Stheraven    template<class _Fp>
1476227825Stheraven      typename enable_if
1477227825Stheraven      <
1478253146Stheraven        __callable<typename decay<_Fp>::type>::value &&
1479253146Stheraven        !is_same<typename remove_reference<_Fp>::type, function>::value,
1480227825Stheraven        function&
1481227825Stheraven      >::type
1482232924Stheraven      operator=(_Fp&&);
1483227825Stheraven
1484227825Stheraven    ~function();
1485227825Stheraven
1486227825Stheraven    // function modifiers:
1487227825Stheraven    void swap(function&) _NOEXCEPT;
1488232924Stheraven    template<class _Fp, class _Alloc>
1489227825Stheraven      _LIBCPP_INLINE_VISIBILITY
1490232924Stheraven      void assign(_Fp&& __f, const _Alloc& __a)
1491232924Stheraven        {function(allocator_arg, __a, _VSTD::forward<_Fp>(__f)).swap(*this);}
1492227825Stheraven
1493227825Stheraven    // function capacity:
1494227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1495232924Stheraven        _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return __f_;}
1496227825Stheraven
1497227825Stheraven    // deleted overloads close possible hole in the type system
1498227825Stheraven    template<class _R2, class... _ArgTypes2>
1499227825Stheraven      bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete;
1500227825Stheraven    template<class _R2, class... _ArgTypes2>
1501227825Stheraven      bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete;
1502227825Stheravenpublic:
1503227825Stheraven    // function invocation:
1504232924Stheraven    _Rp operator()(_ArgTypes...) const;
1505227825Stheraven
1506227825Stheraven#ifndef _LIBCPP_NO_RTTI
1507227825Stheraven    // function target access:
1508227825Stheraven    const std::type_info& target_type() const _NOEXCEPT;
1509232924Stheraven    template <typename _Tp> _Tp* target() _NOEXCEPT;
1510232924Stheraven    template <typename _Tp> const _Tp* target() const _NOEXCEPT;
1511227825Stheraven#endif  // _LIBCPP_NO_RTTI
1512227825Stheraven};
1513227825Stheraven
1514232924Stheraventemplate<class _Rp, class ..._ArgTypes>
1515232924Stheravenfunction<_Rp(_ArgTypes...)>::function(const function& __f)
1516227825Stheraven{
1517227825Stheraven    if (__f.__f_ == 0)
1518227825Stheraven        __f_ = 0;
1519227825Stheraven    else if (__f.__f_ == (const __base*)&__f.__buf_)
1520227825Stheraven    {
1521227825Stheraven        __f_ = (__base*)&__buf_;
1522227825Stheraven        __f.__f_->__clone(__f_);
1523227825Stheraven    }
1524227825Stheraven    else
1525227825Stheraven        __f_ = __f.__f_->__clone();
1526227825Stheraven}
1527227825Stheraven
1528232924Stheraventemplate<class _Rp, class ..._ArgTypes>
1529227825Stheraventemplate <class _Alloc>
1530232924Stheravenfunction<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
1531227825Stheraven                                     const function& __f)
1532227825Stheraven{
1533227825Stheraven    if (__f.__f_ == 0)
1534227825Stheraven        __f_ = 0;
1535227825Stheraven    else if (__f.__f_ == (const __base*)&__f.__buf_)
1536227825Stheraven    {
1537227825Stheraven        __f_ = (__base*)&__buf_;
1538227825Stheraven        __f.__f_->__clone(__f_);
1539227825Stheraven    }
1540227825Stheraven    else
1541227825Stheraven        __f_ = __f.__f_->__clone();
1542227825Stheraven}
1543227825Stheraven
1544232924Stheraventemplate<class _Rp, class ..._ArgTypes>
1545232924Stheravenfunction<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT
1546227825Stheraven{
1547227825Stheraven    if (__f.__f_ == 0)
1548227825Stheraven        __f_ = 0;
1549227825Stheraven    else if (__f.__f_ == (__base*)&__f.__buf_)
1550227825Stheraven    {
1551227825Stheraven        __f_ = (__base*)&__buf_;
1552227825Stheraven        __f.__f_->__clone(__f_);
1553227825Stheraven    }
1554227825Stheraven    else
1555227825Stheraven    {
1556227825Stheraven        __f_ = __f.__f_;
1557227825Stheraven        __f.__f_ = 0;
1558227825Stheraven    }
1559227825Stheraven}
1560227825Stheraven
1561232924Stheraventemplate<class _Rp, class ..._ArgTypes>
1562227825Stheraventemplate <class _Alloc>
1563232924Stheravenfunction<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
1564227825Stheraven                                     function&& __f)
1565227825Stheraven{
1566227825Stheraven    if (__f.__f_ == 0)
1567227825Stheraven        __f_ = 0;
1568227825Stheraven    else if (__f.__f_ == (__base*)&__f.__buf_)
1569227825Stheraven    {
1570227825Stheraven        __f_ = (__base*)&__buf_;
1571227825Stheraven        __f.__f_->__clone(__f_);
1572227825Stheraven    }
1573227825Stheraven    else
1574227825Stheraven    {
1575227825Stheraven        __f_ = __f.__f_;
1576227825Stheraven        __f.__f_ = 0;
1577227825Stheraven    }
1578227825Stheraven}
1579227825Stheraven
1580232924Stheraventemplate<class _Rp, class ..._ArgTypes>
1581232924Stheraventemplate <class _Fp>
1582232924Stheravenfunction<_Rp(_ArgTypes...)>::function(_Fp __f,
1583253146Stheraven                                     typename enable_if
1584253146Stheraven                                     <
1585253146Stheraven                                        __callable<_Fp>::value &&
1586253146Stheraven                                        !is_same<_Fp, function>::value
1587253146Stheraven                                     >::type*)
1588227825Stheraven    : __f_(0)
1589227825Stheraven{
1590227825Stheraven    if (__not_null(__f))
1591227825Stheraven    {
1592232924Stheraven        typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_ArgTypes...)> _FF;
1593232924Stheraven        if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value)
1594227825Stheraven        {
1595227825Stheraven            __f_ = (__base*)&__buf_;
1596227825Stheraven            ::new (__f_) _FF(_VSTD::move(__f));
1597227825Stheraven        }
1598227825Stheraven        else
1599227825Stheraven        {
1600232924Stheraven            typedef allocator<_FF> _Ap;
1601232924Stheraven            _Ap __a;
1602232924Stheraven            typedef __allocator_destructor<_Ap> _Dp;
1603232924Stheraven            unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1604232924Stheraven            ::new (__hold.get()) _FF(_VSTD::move(__f), allocator<_Fp>(__a));
1605227825Stheraven            __f_ = __hold.release();
1606227825Stheraven        }
1607227825Stheraven    }
1608227825Stheraven}
1609227825Stheraven
1610232924Stheraventemplate<class _Rp, class ..._ArgTypes>
1611232924Stheraventemplate <class _Fp, class _Alloc>
1612232924Stheravenfunction<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f,
1613232924Stheraven                                     typename enable_if<__callable<_Fp>::value>::type*)
1614227825Stheraven    : __f_(0)
1615227825Stheraven{
1616227825Stheraven    typedef allocator_traits<_Alloc> __alloc_traits;
1617227825Stheraven    if (__not_null(__f))
1618227825Stheraven    {
1619232924Stheraven        typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _FF;
1620276792Sdim        typedef typename __alloc_traits::template
1621276792Sdim#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1622276792Sdim            rebind_alloc<_FF>
1623276792Sdim#else
1624276792Sdim            rebind_alloc<_FF>::other
1625276792Sdim#endif
1626276792Sdim            _Ap;
1627276792Sdim        _Ap __a(__a0);
1628276792Sdim        if (sizeof(_FF) <= sizeof(__buf_) && 
1629276792Sdim            is_nothrow_copy_constructible<_Fp>::value && is_nothrow_copy_constructible<_Ap>::value)
1630227825Stheraven        {
1631227825Stheraven            __f_ = (__base*)&__buf_;
1632276792Sdim            ::new (__f_) _FF(_VSTD::move(__f), _Alloc(__a));
1633227825Stheraven        }
1634227825Stheraven        else
1635227825Stheraven        {
1636232924Stheraven            typedef __allocator_destructor<_Ap> _Dp;
1637232924Stheraven            unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1638227825Stheraven            ::new (__hold.get()) _FF(_VSTD::move(__f), _Alloc(__a));
1639227825Stheraven            __f_ = __hold.release();
1640227825Stheraven        }
1641227825Stheraven    }
1642227825Stheraven}
1643227825Stheraven
1644232924Stheraventemplate<class _Rp, class ..._ArgTypes>
1645232924Stheravenfunction<_Rp(_ArgTypes...)>&
1646232924Stheravenfunction<_Rp(_ArgTypes...)>::operator=(const function& __f)
1647227825Stheraven{
1648227825Stheraven    function(__f).swap(*this);
1649227825Stheraven    return *this;
1650227825Stheraven}
1651227825Stheraven
1652232924Stheraventemplate<class _Rp, class ..._ArgTypes>
1653232924Stheravenfunction<_Rp(_ArgTypes...)>&
1654232924Stheravenfunction<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT
1655227825Stheraven{
1656227825Stheraven    if (__f_ == (__base*)&__buf_)
1657227825Stheraven        __f_->destroy();
1658227825Stheraven    else if (__f_)
1659227825Stheraven        __f_->destroy_deallocate();
1660227825Stheraven    __f_ = 0;
1661227825Stheraven    if (__f.__f_ == 0)
1662227825Stheraven        __f_ = 0;
1663227825Stheraven    else if (__f.__f_ == (__base*)&__f.__buf_)
1664227825Stheraven    {
1665227825Stheraven        __f_ = (__base*)&__buf_;
1666227825Stheraven        __f.__f_->__clone(__f_);
1667227825Stheraven    }
1668227825Stheraven    else
1669227825Stheraven    {
1670227825Stheraven        __f_ = __f.__f_;
1671227825Stheraven        __f.__f_ = 0;
1672227825Stheraven    }
1673241900Sdim    return *this;
1674227825Stheraven}
1675227825Stheraven
1676232924Stheraventemplate<class _Rp, class ..._ArgTypes>
1677232924Stheravenfunction<_Rp(_ArgTypes...)>&
1678232924Stheravenfunction<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT
1679227825Stheraven{
1680227825Stheraven    if (__f_ == (__base*)&__buf_)
1681227825Stheraven        __f_->destroy();
1682227825Stheraven    else if (__f_)
1683227825Stheraven        __f_->destroy_deallocate();
1684227825Stheraven    __f_ = 0;
1685241900Sdim    return *this;
1686227825Stheraven}
1687227825Stheraven
1688232924Stheraventemplate<class _Rp, class ..._ArgTypes>
1689232924Stheraventemplate <class _Fp>
1690227825Stheraventypename enable_if
1691227825Stheraven<
1692253146Stheraven    function<_Rp(_ArgTypes...)>::template __callable<typename decay<_Fp>::type>::value &&
1693253146Stheraven    !is_same<typename remove_reference<_Fp>::type, function<_Rp(_ArgTypes...)>>::value,
1694232924Stheraven    function<_Rp(_ArgTypes...)>&
1695227825Stheraven>::type
1696232924Stheravenfunction<_Rp(_ArgTypes...)>::operator=(_Fp&& __f)
1697227825Stheraven{
1698232924Stheraven    function(_VSTD::forward<_Fp>(__f)).swap(*this);
1699227825Stheraven    return *this;
1700227825Stheraven}
1701227825Stheraven
1702232924Stheraventemplate<class _Rp, class ..._ArgTypes>
1703232924Stheravenfunction<_Rp(_ArgTypes...)>::~function()
1704227825Stheraven{
1705227825Stheraven    if (__f_ == (__base*)&__buf_)
1706227825Stheraven        __f_->destroy();
1707227825Stheraven    else if (__f_)
1708227825Stheraven        __f_->destroy_deallocate();
1709227825Stheraven}
1710227825Stheraven
1711232924Stheraventemplate<class _Rp, class ..._ArgTypes>
1712227825Stheravenvoid
1713232924Stheravenfunction<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT
1714227825Stheraven{
1715227825Stheraven    if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_)
1716227825Stheraven    {
1717227825Stheraven        typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
1718227825Stheraven        __base* __t = (__base*)&__tempbuf;
1719227825Stheraven        __f_->__clone(__t);
1720227825Stheraven        __f_->destroy();
1721227825Stheraven        __f_ = 0;
1722227825Stheraven        __f.__f_->__clone((__base*)&__buf_);
1723227825Stheraven        __f.__f_->destroy();
1724227825Stheraven        __f.__f_ = 0;
1725227825Stheraven        __f_ = (__base*)&__buf_;
1726227825Stheraven        __t->__clone((__base*)&__f.__buf_);
1727227825Stheraven        __t->destroy();
1728227825Stheraven        __f.__f_ = (__base*)&__f.__buf_;
1729227825Stheraven    }
1730227825Stheraven    else if (__f_ == (__base*)&__buf_)
1731227825Stheraven    {
1732227825Stheraven        __f_->__clone((__base*)&__f.__buf_);
1733227825Stheraven        __f_->destroy();
1734227825Stheraven        __f_ = __f.__f_;
1735227825Stheraven        __f.__f_ = (__base*)&__f.__buf_;
1736227825Stheraven    }
1737227825Stheraven    else if (__f.__f_ == (__base*)&__f.__buf_)
1738227825Stheraven    {
1739227825Stheraven        __f.__f_->__clone((__base*)&__buf_);
1740227825Stheraven        __f.__f_->destroy();
1741227825Stheraven        __f.__f_ = __f_;
1742227825Stheraven        __f_ = (__base*)&__buf_;
1743227825Stheraven    }
1744227825Stheraven    else
1745227825Stheraven        _VSTD::swap(__f_, __f.__f_);
1746227825Stheraven}
1747227825Stheraven
1748232924Stheraventemplate<class _Rp, class ..._ArgTypes>
1749232924Stheraven_Rp
1750232924Stheravenfunction<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const
1751227825Stheraven{
1752227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
1753227825Stheraven    if (__f_ == 0)
1754227825Stheraven        throw bad_function_call();
1755227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
1756227825Stheraven    return (*__f_)(_VSTD::forward<_ArgTypes>(__arg)...);
1757227825Stheraven}
1758227825Stheraven
1759227825Stheraven#ifndef _LIBCPP_NO_RTTI
1760227825Stheraven
1761232924Stheraventemplate<class _Rp, class ..._ArgTypes>
1762227825Stheravenconst std::type_info&
1763232924Stheravenfunction<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
1764227825Stheraven{
1765227825Stheraven    if (__f_ == 0)
1766227825Stheraven        return typeid(void);
1767227825Stheraven    return __f_->target_type();
1768227825Stheraven}
1769227825Stheraven
1770232924Stheraventemplate<class _Rp, class ..._ArgTypes>
1771232924Stheraventemplate <typename _Tp>
1772232924Stheraven_Tp*
1773232924Stheravenfunction<_Rp(_ArgTypes...)>::target() _NOEXCEPT
1774227825Stheraven{
1775227825Stheraven    if (__f_ == 0)
1776232924Stheraven        return (_Tp*)0;
1777232924Stheraven    return (_Tp*)__f_->target(typeid(_Tp));
1778227825Stheraven}
1779227825Stheraven
1780232924Stheraventemplate<class _Rp, class ..._ArgTypes>
1781232924Stheraventemplate <typename _Tp>
1782232924Stheravenconst _Tp*
1783232924Stheravenfunction<_Rp(_ArgTypes...)>::target() const _NOEXCEPT
1784227825Stheraven{
1785227825Stheraven    if (__f_ == 0)
1786232924Stheraven        return (const _Tp*)0;
1787232924Stheraven    return (const _Tp*)__f_->target(typeid(_Tp));
1788227825Stheraven}
1789227825Stheraven
1790227825Stheraven#endif  // _LIBCPP_NO_RTTI
1791227825Stheraven
1792232924Stheraventemplate <class _Rp, class... _ArgTypes>
1793227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1794227825Stheravenbool
1795232924Stheravenoperator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;}
1796227825Stheraven
1797232924Stheraventemplate <class _Rp, class... _ArgTypes>
1798227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1799227825Stheravenbool
1800232924Stheravenoperator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;}
1801227825Stheraven
1802232924Stheraventemplate <class _Rp, class... _ArgTypes>
1803227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1804227825Stheravenbool
1805232924Stheravenoperator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;}
1806227825Stheraven
1807232924Stheraventemplate <class _Rp, class... _ArgTypes>
1808227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1809227825Stheravenbool
1810232924Stheravenoperator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;}
1811227825Stheraven
1812232924Stheraventemplate <class _Rp, class... _ArgTypes>
1813227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1814227825Stheravenvoid
1815232924Stheravenswap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT
1816227825Stheraven{return __x.swap(__y);}
1817227825Stheraven
1818227825Stheraventemplate<class _Tp> struct __is_bind_expression : public false_type {};
1819261272Sdimtemplate<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_bind_expression
1820227825Stheraven    : public __is_bind_expression<typename remove_cv<_Tp>::type> {};
1821227825Stheraven
1822227825Stheraventemplate<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {};
1823261272Sdimtemplate<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_placeholder
1824227825Stheraven    : public __is_placeholder<typename remove_cv<_Tp>::type> {};
1825227825Stheraven
1826227825Stheravennamespace placeholders
1827227825Stheraven{
1828227825Stheraven
1829232924Stheraventemplate <int _Np> struct __ph {};
1830227825Stheraven
1831261272Sdim_LIBCPP_FUNC_VIS extern __ph<1>   _1;
1832261272Sdim_LIBCPP_FUNC_VIS extern __ph<2>   _2;
1833261272Sdim_LIBCPP_FUNC_VIS extern __ph<3>   _3;
1834261272Sdim_LIBCPP_FUNC_VIS extern __ph<4>   _4;
1835261272Sdim_LIBCPP_FUNC_VIS extern __ph<5>   _5;
1836261272Sdim_LIBCPP_FUNC_VIS extern __ph<6>   _6;
1837261272Sdim_LIBCPP_FUNC_VIS extern __ph<7>   _7;
1838261272Sdim_LIBCPP_FUNC_VIS extern __ph<8>   _8;
1839261272Sdim_LIBCPP_FUNC_VIS extern __ph<9>   _9;
1840261272Sdim_LIBCPP_FUNC_VIS extern __ph<10> _10;
1841227825Stheraven
1842227825Stheraven}  // placeholders
1843227825Stheraven
1844232924Stheraventemplate<int _Np>
1845232924Stheravenstruct __is_placeholder<placeholders::__ph<_Np> >
1846232924Stheraven    : public integral_constant<int, _Np> {};
1847227825Stheraven
1848227825Stheraventemplate <class _Tp, class _Uj>
1849227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1850227825Stheraven_Tp&
1851227825Stheraven__mu(reference_wrapper<_Tp> __t, _Uj&)
1852227825Stheraven{
1853227825Stheraven    return __t.get();
1854227825Stheraven}
1855227825Stheraven
1856227825Stheraventemplate <class _Ti, class ..._Uj, size_t ..._Indx>
1857227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1858227825Stheraventypename __invoke_of<_Ti&, _Uj...>::type
1859227825Stheraven__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>)
1860227825Stheraven{
1861276792Sdim    return __ti(_VSTD::forward<_Uj>(_VSTD::get<_Indx>(__uj))...);
1862227825Stheraven}
1863227825Stheraven
1864227825Stheraventemplate <class _Ti, class ..._Uj>
1865227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1866276792Sdimtypename __lazy_enable_if
1867227825Stheraven<
1868227825Stheraven    is_bind_expression<_Ti>::value,
1869276792Sdim    __invoke_of<_Ti&, _Uj...>
1870227825Stheraven>::type
1871227825Stheraven__mu(_Ti& __ti, tuple<_Uj...>& __uj)
1872227825Stheraven{
1873227825Stheraven    typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices;
1874227825Stheraven    return  __mu_expand(__ti, __uj, __indices());
1875227825Stheraven}
1876227825Stheraven
1877227825Stheraventemplate <bool IsPh, class _Ti, class _Uj>
1878227825Stheravenstruct __mu_return2 {};
1879227825Stheraven
1880227825Stheraventemplate <class _Ti, class _Uj>
1881227825Stheravenstruct __mu_return2<true, _Ti, _Uj>
1882227825Stheraven{
1883227825Stheraven    typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type;
1884227825Stheraven};
1885227825Stheraven
1886227825Stheraventemplate <class _Ti, class _Uj>
1887227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1888227825Stheraventypename enable_if
1889227825Stheraven<
1890227825Stheraven    0 < is_placeholder<_Ti>::value,
1891227825Stheraven    typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type
1892227825Stheraven>::type
1893227825Stheraven__mu(_Ti&, _Uj& __uj)
1894227825Stheraven{
1895227825Stheraven    const size_t _Indx = is_placeholder<_Ti>::value - 1;
1896276792Sdim    return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj));
1897227825Stheraven}
1898227825Stheraven
1899227825Stheraventemplate <class _Ti, class _Uj>
1900227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1901227825Stheraventypename enable_if
1902227825Stheraven<
1903227825Stheraven    !is_bind_expression<_Ti>::value &&
1904227825Stheraven    is_placeholder<_Ti>::value == 0 &&
1905227825Stheraven    !__is_reference_wrapper<_Ti>::value,
1906227825Stheraven    _Ti&
1907227825Stheraven>::type
1908232924Stheraven__mu(_Ti& __ti, _Uj&)
1909227825Stheraven{
1910227825Stheraven    return __ti;
1911227825Stheraven}
1912227825Stheraven
1913227825Stheraventemplate <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh,
1914227825Stheraven          class _TupleUj>
1915227825Stheravenstruct ____mu_return;
1916227825Stheraven
1917253146Stheraventemplate <bool _Invokable, class _Ti, class ..._Uj>
1918253146Stheravenstruct ____mu_return_invokable  // false
1919253146Stheraven{
1920253146Stheraven    typedef __nat type;
1921253146Stheraven};
1922253146Stheraven
1923227825Stheraventemplate <class _Ti, class ..._Uj>
1924253146Stheravenstruct ____mu_return_invokable<true, _Ti, _Uj...>
1925227825Stheraven{
1926227825Stheraven    typedef typename __invoke_of<_Ti&, _Uj...>::type type;
1927227825Stheraven};
1928227825Stheraven
1929253146Stheraventemplate <class _Ti, class ..._Uj>
1930253146Stheravenstruct ____mu_return<_Ti, false, true, false, tuple<_Uj...> >
1931253146Stheraven    : public ____mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...>
1932253146Stheraven{
1933253146Stheraven};
1934253146Stheraven
1935227825Stheraventemplate <class _Ti, class _TupleUj>
1936227825Stheravenstruct ____mu_return<_Ti, false, false, true, _TupleUj>
1937227825Stheraven{
1938227825Stheraven    typedef typename tuple_element<is_placeholder<_Ti>::value - 1,
1939227825Stheraven                                   _TupleUj>::type&& type;
1940227825Stheraven};
1941227825Stheraven
1942227825Stheraventemplate <class _Ti, class _TupleUj>
1943227825Stheravenstruct ____mu_return<_Ti, true, false, false, _TupleUj>
1944227825Stheraven{
1945227825Stheraven    typedef typename _Ti::type& type;
1946227825Stheraven};
1947227825Stheraven
1948227825Stheraventemplate <class _Ti, class _TupleUj>
1949227825Stheravenstruct ____mu_return<_Ti, false, false, false, _TupleUj>
1950227825Stheraven{
1951227825Stheraven    typedef _Ti& type;
1952227825Stheraven};
1953227825Stheraven
1954227825Stheraventemplate <class _Ti, class _TupleUj>
1955227825Stheravenstruct __mu_return
1956227825Stheraven    : public ____mu_return<_Ti,
1957227825Stheraven                           __is_reference_wrapper<_Ti>::value,
1958227825Stheraven                           is_bind_expression<_Ti>::value,
1959249989Sdim                           0 < is_placeholder<_Ti>::value &&
1960249989Sdim                           is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value,
1961227825Stheraven                           _TupleUj>
1962227825Stheraven{
1963227825Stheraven};
1964227825Stheraven
1965232924Stheraventemplate <class _Fp, class _BoundArgs, class _TupleUj>
1966249989Sdimstruct _is_valid_bind_return
1967249989Sdim{
1968249989Sdim    static const bool value = false;
1969249989Sdim};
1970249989Sdim
1971249989Sdimtemplate <class _Fp, class ..._BoundArgs, class _TupleUj>
1972249989Sdimstruct _is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj>
1973249989Sdim{
1974249989Sdim    static const bool value = __invokable<_Fp,
1975249989Sdim                    typename __mu_return<_BoundArgs, _TupleUj>::type...>::value;
1976249989Sdim};
1977249989Sdim
1978249989Sdimtemplate <class _Fp, class ..._BoundArgs, class _TupleUj>
1979249989Sdimstruct _is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj>
1980249989Sdim{
1981249989Sdim    static const bool value = __invokable<_Fp,
1982249989Sdim                    typename __mu_return<const _BoundArgs, _TupleUj>::type...>::value;
1983249989Sdim};
1984249989Sdim
1985249989Sdimtemplate <class _Fp, class _BoundArgs, class _TupleUj,
1986249989Sdim          bool = _is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value>
1987227825Stheravenstruct __bind_return;
1988227825Stheraven
1989232924Stheraventemplate <class _Fp, class ..._BoundArgs, class _TupleUj>
1990249989Sdimstruct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true>
1991227825Stheraven{
1992227825Stheraven    typedef typename __invoke_of
1993227825Stheraven    <
1994232924Stheraven        _Fp&,
1995227825Stheraven        typename __mu_return
1996227825Stheraven        <
1997227825Stheraven            _BoundArgs,
1998227825Stheraven            _TupleUj
1999227825Stheraven        >::type...
2000227825Stheraven    >::type type;
2001227825Stheraven};
2002227825Stheraven
2003232924Stheraventemplate <class _Fp, class ..._BoundArgs, class _TupleUj>
2004249989Sdimstruct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true>
2005227825Stheraven{
2006227825Stheraven    typedef typename __invoke_of
2007227825Stheraven    <
2008232924Stheraven        _Fp&,
2009227825Stheraven        typename __mu_return
2010227825Stheraven        <
2011227825Stheraven            const _BoundArgs,
2012227825Stheraven            _TupleUj
2013227825Stheraven        >::type...
2014227825Stheraven    >::type type;
2015227825Stheraven};
2016227825Stheraven
2017232924Stheraventemplate <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args>
2018227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
2019232924Stheraventypename __bind_return<_Fp, _BoundArgs, _Args>::type
2020232924Stheraven__apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
2021227825Stheraven                _Args&& __args)
2022227825Stheraven{
2023276792Sdim    return __invoke(__f, __mu(_VSTD::get<_Indx>(__bound_args), __args)...);
2024227825Stheraven}
2025227825Stheraven
2026232924Stheraventemplate<class _Fp, class ..._BoundArgs>
2027227825Stheravenclass __bind
2028232924Stheraven    : public __weak_result_type<typename decay<_Fp>::type>
2029227825Stheraven{
2030249989Sdimprotected:
2031232924Stheraven    typedef typename decay<_Fp>::type _Fd;
2032227825Stheraven    typedef tuple<typename decay<_BoundArgs>::type...> _Td;
2033249989Sdimprivate:
2034227825Stheraven    _Fd __f_;
2035227825Stheraven    _Td __bound_args_;
2036227825Stheraven
2037227825Stheraven    typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices;
2038227825Stheravenpublic:
2039227825Stheraven#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2040227825Stheraven
2041227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2042227825Stheraven    __bind(const __bind& __b)
2043227825Stheraven        : __f_(__b.__f_),
2044227825Stheraven          __bound_args_(__b.__bound_args_) {}
2045227825Stheraven
2046227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2047227825Stheraven    __bind& operator=(const __bind& __b)
2048227825Stheraven    {
2049227825Stheraven        __f_ = __b.__f_;
2050227825Stheraven        __bound_args_ = __b.__bound_args_;
2051227825Stheraven        return *this;
2052227825Stheraven    }
2053227825Stheraven
2054227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2055227825Stheraven    __bind(__bind&& __b)
2056227825Stheraven        : __f_(_VSTD::move(__b.__f_)),
2057227825Stheraven          __bound_args_(_VSTD::move(__b.__bound_args_)) {}
2058227825Stheraven
2059227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2060227825Stheraven    __bind& operator=(__bind&& __b)
2061227825Stheraven    {
2062227825Stheraven        __f_ = _VSTD::move(__b.__f_);
2063227825Stheraven        __bound_args_ = _VSTD::move(__b.__bound_args_);
2064227825Stheraven        return *this;
2065227825Stheraven    }
2066227825Stheraven
2067227825Stheraven#endif  // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2068227825Stheraven
2069241900Sdim    template <class _Gp, class ..._BA,
2070241900Sdim              class = typename enable_if
2071241900Sdim                               <
2072253146Stheraven                                  is_constructible<_Fd, _Gp>::value &&
2073253146Stheraven                                  !is_same<typename remove_reference<_Gp>::type,
2074253146Stheraven                                           __bind>::value
2075241900Sdim                               >::type>
2076227825Stheraven      _LIBCPP_INLINE_VISIBILITY
2077232924Stheraven      explicit __bind(_Gp&& __f, _BA&& ...__bound_args)
2078232924Stheraven        : __f_(_VSTD::forward<_Gp>(__f)),
2079227825Stheraven          __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {}
2080227825Stheraven
2081227825Stheraven    template <class ..._Args>
2082227825Stheraven        _LIBCPP_INLINE_VISIBILITY
2083227825Stheraven        typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type
2084227825Stheraven        operator()(_Args&& ...__args)
2085227825Stheraven        {
2086227825Stheraven            return __apply_functor(__f_, __bound_args_, __indices(),
2087227825Stheraven                                  tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
2088227825Stheraven        }
2089227825Stheraven
2090227825Stheraven    template <class ..._Args>
2091227825Stheraven        _LIBCPP_INLINE_VISIBILITY
2092249989Sdim        typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type
2093227825Stheraven        operator()(_Args&& ...__args) const
2094227825Stheraven        {
2095227825Stheraven            return __apply_functor(__f_, __bound_args_, __indices(),
2096227825Stheraven                                   tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
2097227825Stheraven        }
2098227825Stheraven};
2099227825Stheraven
2100232924Stheraventemplate<class _Fp, class ..._BoundArgs>
2101232924Stheravenstruct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {};
2102227825Stheraven
2103232924Stheraventemplate<class _Rp, class _Fp, class ..._BoundArgs>
2104227825Stheravenclass __bind_r
2105232924Stheraven    : public __bind<_Fp, _BoundArgs...>
2106227825Stheraven{
2107232924Stheraven    typedef __bind<_Fp, _BoundArgs...> base;
2108249989Sdim    typedef typename base::_Fd _Fd;
2109249989Sdim    typedef typename base::_Td _Td;
2110227825Stheravenpublic:
2111232924Stheraven    typedef _Rp result_type;
2112227825Stheraven
2113227825Stheraven#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2114227825Stheraven
2115227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2116227825Stheraven    __bind_r(const __bind_r& __b)
2117227825Stheraven        : base(_VSTD::forward<const base&>(__b)) {}
2118227825Stheraven
2119227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2120227825Stheraven    __bind_r& operator=(const __bind_r& __b)
2121227825Stheraven    {
2122227825Stheraven        base::operator=(_VSTD::forward<const base&>(__b));
2123227825Stheraven        return *this;
2124227825Stheraven    }
2125227825Stheraven
2126227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2127227825Stheraven    __bind_r(__bind_r&& __b)
2128227825Stheraven        : base(_VSTD::forward<base>(__b)) {}
2129227825Stheraven
2130227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2131227825Stheraven    __bind_r& operator=(__bind_r&& __b)
2132227825Stheraven    {
2133227825Stheraven        base::operator=(_VSTD::forward<base>(__b));
2134227825Stheraven        return *this;
2135227825Stheraven    }
2136227825Stheraven
2137227825Stheraven#endif  // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2138227825Stheraven
2139253146Stheraven    template <class _Gp, class ..._BA,
2140253146Stheraven              class = typename enable_if
2141253146Stheraven                               <
2142253146Stheraven                                  is_constructible<_Fd, _Gp>::value &&
2143253146Stheraven                                  !is_same<typename remove_reference<_Gp>::type,
2144253146Stheraven                                           __bind_r>::value
2145253146Stheraven                               >::type>
2146227825Stheraven      _LIBCPP_INLINE_VISIBILITY
2147232924Stheraven      explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args)
2148232924Stheraven        : base(_VSTD::forward<_Gp>(__f),
2149227825Stheraven               _VSTD::forward<_BA>(__bound_args)...) {}
2150227825Stheraven
2151227825Stheraven    template <class ..._Args>
2152227825Stheraven        _LIBCPP_INLINE_VISIBILITY
2153249989Sdim        typename enable_if
2154249989Sdim        <
2155249989Sdim            is_convertible<typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type,
2156249989Sdim                           result_type>::value,
2157249989Sdim            result_type
2158249989Sdim        >::type
2159227825Stheraven        operator()(_Args&& ...__args)
2160227825Stheraven        {
2161227825Stheraven            return base::operator()(_VSTD::forward<_Args>(__args)...);
2162227825Stheraven        }
2163227825Stheraven
2164227825Stheraven    template <class ..._Args>
2165227825Stheraven        _LIBCPP_INLINE_VISIBILITY
2166249989Sdim        typename enable_if
2167249989Sdim        <
2168249989Sdim            is_convertible<typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type,
2169249989Sdim                           result_type>::value,
2170249989Sdim            result_type
2171249989Sdim        >::type
2172227825Stheraven        operator()(_Args&& ...__args) const
2173227825Stheraven        {
2174227825Stheraven            return base::operator()(_VSTD::forward<_Args>(__args)...);
2175227825Stheraven        }
2176227825Stheraven};
2177227825Stheraven
2178232924Stheraventemplate<class _Rp, class _Fp, class ..._BoundArgs>
2179232924Stheravenstruct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {};
2180227825Stheraven
2181232924Stheraventemplate<class _Fp, class ..._BoundArgs>
2182227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
2183232924Stheraven__bind<_Fp, _BoundArgs...>
2184232924Stheravenbind(_Fp&& __f, _BoundArgs&&... __bound_args)
2185227825Stheraven{
2186232924Stheraven    typedef __bind<_Fp, _BoundArgs...> type;
2187232924Stheraven    return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
2188227825Stheraven}
2189227825Stheraven
2190232924Stheraventemplate<class _Rp, class _Fp, class ..._BoundArgs>
2191227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
2192232924Stheraven__bind_r<_Rp, _Fp, _BoundArgs...>
2193232924Stheravenbind(_Fp&& __f, _BoundArgs&&... __bound_args)
2194227825Stheraven{
2195232924Stheraven    typedef __bind_r<_Rp, _Fp, _BoundArgs...> type;
2196232924Stheraven    return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
2197227825Stheraven}
2198227825Stheraven
2199227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
2200227825Stheraven
2201227825Stheraventemplate <>
2202261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY hash<bool>
2203227825Stheraven    : public unary_function<bool, size_t>
2204227825Stheraven{
2205227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2206227825Stheraven    size_t operator()(bool __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
2207227825Stheraven};
2208227825Stheraven
2209227825Stheraventemplate <>
2210261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY hash<char>
2211227825Stheraven    : public unary_function<char, size_t>
2212227825Stheraven{
2213227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2214227825Stheraven    size_t operator()(char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
2215227825Stheraven};
2216227825Stheraven
2217227825Stheraventemplate <>
2218261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY hash<signed char>
2219227825Stheraven    : public unary_function<signed char, size_t>
2220227825Stheraven{
2221227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2222227825Stheraven    size_t operator()(signed char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
2223227825Stheraven};
2224227825Stheraven
2225227825Stheraventemplate <>
2226261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY hash<unsigned char>
2227227825Stheraven    : public unary_function<unsigned char, size_t>
2228227825Stheraven{
2229227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2230227825Stheraven    size_t operator()(unsigned char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
2231227825Stheraven};
2232227825Stheraven
2233227825Stheraven#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
2234227825Stheraven
2235227825Stheraventemplate <>
2236261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY hash<char16_t>
2237227825Stheraven    : public unary_function<char16_t, size_t>
2238227825Stheraven{
2239227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2240227825Stheraven    size_t operator()(char16_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
2241227825Stheraven};
2242227825Stheraven
2243227825Stheraventemplate <>
2244261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY hash<char32_t>
2245227825Stheraven    : public unary_function<char32_t, size_t>
2246227825Stheraven{
2247227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2248227825Stheraven    size_t operator()(char32_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
2249227825Stheraven};
2250227825Stheraven
2251227825Stheraven#endif  // _LIBCPP_HAS_NO_UNICODE_CHARS
2252227825Stheraven
2253227825Stheraventemplate <>
2254261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY hash<wchar_t>
2255227825Stheraven    : public unary_function<wchar_t, size_t>
2256227825Stheraven{
2257227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2258227825Stheraven    size_t operator()(wchar_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
2259227825Stheraven};
2260227825Stheraven
2261227825Stheraventemplate <>
2262261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY hash<short>
2263227825Stheraven    : public unary_function<short, size_t>
2264227825Stheraven{
2265227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2266227825Stheraven    size_t operator()(short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
2267227825Stheraven};
2268227825Stheraven
2269227825Stheraventemplate <>
2270261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY hash<unsigned short>
2271227825Stheraven    : public unary_function<unsigned short, size_t>
2272227825Stheraven{
2273227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2274227825Stheraven    size_t operator()(unsigned short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
2275227825Stheraven};
2276227825Stheraven
2277227825Stheraventemplate <>
2278261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY hash<int>
2279227825Stheraven    : public unary_function<int, size_t>
2280227825Stheraven{
2281227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2282227825Stheraven    size_t operator()(int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
2283227825Stheraven};
2284227825Stheraven
2285227825Stheraventemplate <>
2286261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY hash<unsigned int>
2287227825Stheraven    : public unary_function<unsigned int, size_t>
2288227825Stheraven{
2289227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2290227825Stheraven    size_t operator()(unsigned int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
2291227825Stheraven};
2292227825Stheraven
2293227825Stheraventemplate <>
2294261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY hash<long>
2295227825Stheraven    : public unary_function<long, size_t>
2296227825Stheraven{
2297227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2298227825Stheraven    size_t operator()(long __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
2299227825Stheraven};
2300227825Stheraven
2301227825Stheraventemplate <>
2302261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY hash<unsigned long>
2303227825Stheraven    : public unary_function<unsigned long, size_t>
2304227825Stheraven{
2305227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2306227825Stheraven    size_t operator()(unsigned long __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
2307227825Stheraven};
2308227825Stheraven
2309227825Stheraventemplate <>
2310261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY hash<long long>
2311232924Stheraven    : public __scalar_hash<long long>
2312227825Stheraven{
2313227825Stheraven};
2314227825Stheraven
2315227825Stheraventemplate <>
2316261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY hash<unsigned long long>
2317232924Stheraven    : public __scalar_hash<unsigned long long>
2318227825Stheraven{
2319227825Stheraven};
2320227825Stheraven
2321227825Stheraventemplate <>
2322261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY hash<float>
2323232924Stheraven    : public __scalar_hash<float>
2324227825Stheraven{
2325227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2326227825Stheraven    size_t operator()(float __v) const _NOEXCEPT
2327227825Stheraven    {
2328232924Stheraven        // -0.0 and 0.0 should return same hash
2329232924Stheraven       if (__v == 0)
2330232924Stheraven           return 0;
2331232924Stheraven        return __scalar_hash<float>::operator()(__v);
2332227825Stheraven    }
2333227825Stheraven};
2334227825Stheraven
2335227825Stheraventemplate <>
2336261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY hash<double>
2337232924Stheraven    : public __scalar_hash<double>
2338227825Stheraven{
2339227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2340227825Stheraven    size_t operator()(double __v) const _NOEXCEPT
2341227825Stheraven    {
2342232924Stheraven        // -0.0 and 0.0 should return same hash
2343232924Stheraven       if (__v == 0)
2344232924Stheraven           return 0;
2345232924Stheraven        return __scalar_hash<double>::operator()(__v);
2346227825Stheraven    }
2347227825Stheraven};
2348227825Stheraven
2349227825Stheraventemplate <>
2350261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY hash<long double>
2351232924Stheraven    : public __scalar_hash<long double>
2352227825Stheraven{
2353227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2354227825Stheraven    size_t operator()(long double __v) const _NOEXCEPT
2355227825Stheraven    {
2356232924Stheraven        // -0.0 and 0.0 should return same hash
2357227825Stheraven        if (__v == 0)
2358227825Stheraven            return 0;
2359232924Stheraven#if defined(__i386__)
2360232924Stheraven        // Zero out padding bits
2361232924Stheraven        union
2362232924Stheraven        {
2363232924Stheraven            long double __t;
2364232924Stheraven            struct
2365232924Stheraven            {
2366232924Stheraven                size_t __a;
2367232924Stheraven                size_t __b;
2368232924Stheraven                size_t __c;
2369232924Stheraven                size_t __d;
2370232924Stheraven            };
2371232924Stheraven        } __u;
2372232924Stheraven        __u.__a = 0;
2373232924Stheraven        __u.__b = 0;
2374232924Stheraven        __u.__c = 0;
2375232924Stheraven        __u.__d = 0;
2376232924Stheraven        __u.__t = __v;
2377232924Stheraven        return __u.__a ^ __u.__b ^ __u.__c ^ __u.__d;
2378232924Stheraven#elif defined(__x86_64__)
2379232924Stheraven        // Zero out padding bits
2380232924Stheraven        union
2381232924Stheraven        {
2382232924Stheraven            long double __t;
2383232924Stheraven            struct
2384232924Stheraven            {
2385232924Stheraven                size_t __a;
2386232924Stheraven                size_t __b;
2387232924Stheraven            };
2388232924Stheraven        } __u;
2389232924Stheraven        __u.__a = 0;
2390232924Stheraven        __u.__b = 0;
2391232924Stheraven        __u.__t = __v;
2392232924Stheraven        return __u.__a ^ __u.__b;
2393232924Stheraven#else
2394232924Stheraven        return __scalar_hash<long double>::operator()(__v);
2395232924Stheraven#endif
2396227825Stheraven    }
2397227825Stheraven};
2398227825Stheraven
2399261272Sdim#if _LIBCPP_STD_VER > 11
2400261272Sdimtemplate <class _Tp>
2401261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY hash
2402261272Sdim    : public unary_function<_Tp, size_t>
2403261272Sdim{
2404261272Sdim    static_assert(is_enum<_Tp>::value, "This hash only works for enumeration types");
2405261272Sdim
2406261272Sdim    _LIBCPP_INLINE_VISIBILITY
2407261272Sdim    size_t operator()(_Tp __v) const _NOEXCEPT
2408261272Sdim    {
2409261272Sdim        typedef typename underlying_type<_Tp>::type type;
2410261272Sdim        return hash<type>{}(static_cast<type>(__v));
2411261272Sdim    }
2412261272Sdim};
2413261272Sdim#endif
2414261272Sdim
2415227825Stheraven// struct hash<T*> in <memory>
2416227825Stheraven
2417227825Stheraven_LIBCPP_END_NAMESPACE_STD
2418227825Stheraven
2419227825Stheraven#endif  // _LIBCPP_FUNCTIONAL
2420