xref: /netbsd-src/external/apache2/llvm/dist/libcxx/include/functional (revision 4d6fc14bc9b0c5bf3e30be318c143ee82cadd108)
1*4d6fc14bSjoerg// -*- C++ -*-
2*4d6fc14bSjoerg//===------------------------ functional ----------------------------------===//
3*4d6fc14bSjoerg//
4*4d6fc14bSjoerg// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5*4d6fc14bSjoerg// See https://llvm.org/LICENSE.txt for license information.
6*4d6fc14bSjoerg// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7*4d6fc14bSjoerg//
8*4d6fc14bSjoerg//===----------------------------------------------------------------------===//
9*4d6fc14bSjoerg
10*4d6fc14bSjoerg#ifndef _LIBCPP_FUNCTIONAL
11*4d6fc14bSjoerg#define _LIBCPP_FUNCTIONAL
12*4d6fc14bSjoerg
13*4d6fc14bSjoerg/*
14*4d6fc14bSjoerg    functional synopsis
15*4d6fc14bSjoerg
16*4d6fc14bSjoergnamespace std
17*4d6fc14bSjoerg{
18*4d6fc14bSjoerg
19*4d6fc14bSjoergtemplate <class Arg, class Result>
20*4d6fc14bSjoergstruct unary_function
21*4d6fc14bSjoerg{
22*4d6fc14bSjoerg    typedef Arg    argument_type;
23*4d6fc14bSjoerg    typedef Result result_type;
24*4d6fc14bSjoerg};
25*4d6fc14bSjoerg
26*4d6fc14bSjoergtemplate <class Arg1, class Arg2, class Result>
27*4d6fc14bSjoergstruct binary_function
28*4d6fc14bSjoerg{
29*4d6fc14bSjoerg    typedef Arg1   first_argument_type;
30*4d6fc14bSjoerg    typedef Arg2   second_argument_type;
31*4d6fc14bSjoerg    typedef Result result_type;
32*4d6fc14bSjoerg};
33*4d6fc14bSjoerg
34*4d6fc14bSjoergtemplate <class T>
35*4d6fc14bSjoergclass reference_wrapper
36*4d6fc14bSjoerg    : public unary_function<T1, R> // if wrapping a unary functor
37*4d6fc14bSjoerg    : public binary_function<T1, T2, R> // if wraping a binary functor
38*4d6fc14bSjoerg{
39*4d6fc14bSjoergpublic:
40*4d6fc14bSjoerg    // types
41*4d6fc14bSjoerg    typedef T type;
42*4d6fc14bSjoerg    typedef see below result_type; // Not always defined
43*4d6fc14bSjoerg
44*4d6fc14bSjoerg    // construct/copy/destroy
45*4d6fc14bSjoerg    template<class U>
46*4d6fc14bSjoerg      reference_wrapper(U&&);
47*4d6fc14bSjoerg    reference_wrapper(const reference_wrapper<T>& x) noexcept;
48*4d6fc14bSjoerg
49*4d6fc14bSjoerg    // assignment
50*4d6fc14bSjoerg    reference_wrapper& operator=(const reference_wrapper<T>& x) noexcept;
51*4d6fc14bSjoerg
52*4d6fc14bSjoerg    // access
53*4d6fc14bSjoerg    operator T& () const noexcept;
54*4d6fc14bSjoerg    T& get() const noexcept;
55*4d6fc14bSjoerg
56*4d6fc14bSjoerg    // invoke
57*4d6fc14bSjoerg    template <class... ArgTypes>
58*4d6fc14bSjoerg      typename result_of<T&(ArgTypes&&...)>::type
59*4d6fc14bSjoerg          operator() (ArgTypes&&...) const;
60*4d6fc14bSjoerg};
61*4d6fc14bSjoerg
62*4d6fc14bSjoergtemplate <class T>
63*4d6fc14bSjoerg  reference_wrapper(T&) -> reference_wrapper<T>;
64*4d6fc14bSjoerg
65*4d6fc14bSjoergtemplate <class T> reference_wrapper<T> ref(T& t) noexcept;
66*4d6fc14bSjoergtemplate <class T> void ref(const T&& t) = delete;
67*4d6fc14bSjoergtemplate <class T> reference_wrapper<T> ref(reference_wrapper<T>t) noexcept;
68*4d6fc14bSjoerg
69*4d6fc14bSjoergtemplate <class T> reference_wrapper<const T> cref(const T& t) noexcept;
70*4d6fc14bSjoergtemplate <class T> void cref(const T&& t) = delete;
71*4d6fc14bSjoergtemplate <class T> reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept;
72*4d6fc14bSjoerg
73*4d6fc14bSjoergtemplate <class T> struct unwrap_reference;                                       // since C++20
74*4d6fc14bSjoergtemplate <class T> struct unwrap_ref_decay : unwrap_reference<decay_t<T>> { };    // since C++20
75*4d6fc14bSjoergtemplate <class T> using unwrap_reference_t = typename unwrap_reference<T>::type; // since C++20
76*4d6fc14bSjoergtemplate <class T> using unwrap_ref_decay_t = typename unwrap_ref_decay<T>::type; // since C++20
77*4d6fc14bSjoerg
78*4d6fc14bSjoergtemplate <class T> // <class T=void> in C++14
79*4d6fc14bSjoergstruct plus : binary_function<T, T, T>
80*4d6fc14bSjoerg{
81*4d6fc14bSjoerg    T operator()(const T& x, const T& y) const;
82*4d6fc14bSjoerg};
83*4d6fc14bSjoerg
84*4d6fc14bSjoergtemplate <class T> // <class T=void> in C++14
85*4d6fc14bSjoergstruct minus : binary_function<T, T, T>
86*4d6fc14bSjoerg{
87*4d6fc14bSjoerg    T operator()(const T& x, const T& y) const;
88*4d6fc14bSjoerg};
89*4d6fc14bSjoerg
90*4d6fc14bSjoergtemplate <class T> // <class T=void> in C++14
91*4d6fc14bSjoergstruct multiplies : binary_function<T, T, T>
92*4d6fc14bSjoerg{
93*4d6fc14bSjoerg    T operator()(const T& x, const T& y) const;
94*4d6fc14bSjoerg};
95*4d6fc14bSjoerg
96*4d6fc14bSjoergtemplate <class T> // <class T=void> in C++14
97*4d6fc14bSjoergstruct divides : binary_function<T, T, T>
98*4d6fc14bSjoerg{
99*4d6fc14bSjoerg    T operator()(const T& x, const T& y) const;
100*4d6fc14bSjoerg};
101*4d6fc14bSjoerg
102*4d6fc14bSjoergtemplate <class T> // <class T=void> in C++14
103*4d6fc14bSjoergstruct modulus : binary_function<T, T, T>
104*4d6fc14bSjoerg{
105*4d6fc14bSjoerg    T operator()(const T& x, const T& y) const;
106*4d6fc14bSjoerg};
107*4d6fc14bSjoerg
108*4d6fc14bSjoergtemplate <class T> // <class T=void> in C++14
109*4d6fc14bSjoergstruct negate : unary_function<T, T>
110*4d6fc14bSjoerg{
111*4d6fc14bSjoerg    T operator()(const T& x) const;
112*4d6fc14bSjoerg};
113*4d6fc14bSjoerg
114*4d6fc14bSjoergtemplate <class T> // <class T=void> in C++14
115*4d6fc14bSjoergstruct equal_to : binary_function<T, T, bool>
116*4d6fc14bSjoerg{
117*4d6fc14bSjoerg    bool operator()(const T& x, const T& y) const;
118*4d6fc14bSjoerg};
119*4d6fc14bSjoerg
120*4d6fc14bSjoergtemplate <class T> // <class T=void> in C++14
121*4d6fc14bSjoergstruct not_equal_to : binary_function<T, T, bool>
122*4d6fc14bSjoerg{
123*4d6fc14bSjoerg    bool operator()(const T& x, const T& y) const;
124*4d6fc14bSjoerg};
125*4d6fc14bSjoerg
126*4d6fc14bSjoergtemplate <class T> // <class T=void> in C++14
127*4d6fc14bSjoergstruct greater : binary_function<T, T, bool>
128*4d6fc14bSjoerg{
129*4d6fc14bSjoerg    bool operator()(const T& x, const T& y) const;
130*4d6fc14bSjoerg};
131*4d6fc14bSjoerg
132*4d6fc14bSjoergtemplate <class T> // <class T=void> in C++14
133*4d6fc14bSjoergstruct less : binary_function<T, T, bool>
134*4d6fc14bSjoerg{
135*4d6fc14bSjoerg    bool operator()(const T& x, const T& y) const;
136*4d6fc14bSjoerg};
137*4d6fc14bSjoerg
138*4d6fc14bSjoergtemplate <class T> // <class T=void> in C++14
139*4d6fc14bSjoergstruct greater_equal : binary_function<T, T, bool>
140*4d6fc14bSjoerg{
141*4d6fc14bSjoerg    bool operator()(const T& x, const T& y) const;
142*4d6fc14bSjoerg};
143*4d6fc14bSjoerg
144*4d6fc14bSjoergtemplate <class T> // <class T=void> in C++14
145*4d6fc14bSjoergstruct less_equal : binary_function<T, T, bool>
146*4d6fc14bSjoerg{
147*4d6fc14bSjoerg    bool operator()(const T& x, const T& y) const;
148*4d6fc14bSjoerg};
149*4d6fc14bSjoerg
150*4d6fc14bSjoergtemplate <class T> // <class T=void> in C++14
151*4d6fc14bSjoergstruct logical_and : binary_function<T, T, bool>
152*4d6fc14bSjoerg{
153*4d6fc14bSjoerg    bool operator()(const T& x, const T& y) const;
154*4d6fc14bSjoerg};
155*4d6fc14bSjoerg
156*4d6fc14bSjoergtemplate <class T> // <class T=void> in C++14
157*4d6fc14bSjoergstruct logical_or : binary_function<T, T, bool>
158*4d6fc14bSjoerg{
159*4d6fc14bSjoerg    bool operator()(const T& x, const T& y) const;
160*4d6fc14bSjoerg};
161*4d6fc14bSjoerg
162*4d6fc14bSjoergtemplate <class T> // <class T=void> in C++14
163*4d6fc14bSjoergstruct logical_not : unary_function<T, bool>
164*4d6fc14bSjoerg{
165*4d6fc14bSjoerg    bool operator()(const T& x) const;
166*4d6fc14bSjoerg};
167*4d6fc14bSjoerg
168*4d6fc14bSjoergtemplate <class T> // <class T=void> in C++14
169*4d6fc14bSjoergstruct bit_and : binary_function<T, T, T>
170*4d6fc14bSjoerg{
171*4d6fc14bSjoerg    T operator()(const T& x, const T& y) const;
172*4d6fc14bSjoerg};
173*4d6fc14bSjoerg
174*4d6fc14bSjoergtemplate <class T> // <class T=void> in C++14
175*4d6fc14bSjoergstruct bit_or : binary_function<T, T, T>
176*4d6fc14bSjoerg{
177*4d6fc14bSjoerg    T operator()(const T& x, const T& y) const;
178*4d6fc14bSjoerg};
179*4d6fc14bSjoerg
180*4d6fc14bSjoergtemplate <class T> // <class T=void> in C++14
181*4d6fc14bSjoergstruct bit_xor : binary_function<T, T, T>
182*4d6fc14bSjoerg{
183*4d6fc14bSjoerg    T operator()(const T& x, const T& y) const;
184*4d6fc14bSjoerg};
185*4d6fc14bSjoerg
186*4d6fc14bSjoergtemplate <class T=void> // C++14
187*4d6fc14bSjoergstruct bit_not : unary_function<T, T>
188*4d6fc14bSjoerg{
189*4d6fc14bSjoerg    T operator()(const T& x) const;
190*4d6fc14bSjoerg};
191*4d6fc14bSjoerg
192*4d6fc14bSjoergstruct identity; // C++20
193*4d6fc14bSjoerg
194*4d6fc14bSjoergtemplate <class Predicate>
195*4d6fc14bSjoergclass unary_negate // deprecated in C++17
196*4d6fc14bSjoerg    : public unary_function<typename Predicate::argument_type, bool>
197*4d6fc14bSjoerg{
198*4d6fc14bSjoergpublic:
199*4d6fc14bSjoerg    explicit unary_negate(const Predicate& pred);
200*4d6fc14bSjoerg    bool operator()(const typename Predicate::argument_type& x) const;
201*4d6fc14bSjoerg};
202*4d6fc14bSjoerg
203*4d6fc14bSjoergtemplate <class Predicate> // deprecated in C++17
204*4d6fc14bSjoergunary_negate<Predicate> not1(const Predicate& pred);
205*4d6fc14bSjoerg
206*4d6fc14bSjoergtemplate <class Predicate>
207*4d6fc14bSjoergclass binary_negate // deprecated in C++17
208*4d6fc14bSjoerg    : public binary_function<typename Predicate::first_argument_type,
209*4d6fc14bSjoerg                             typename Predicate::second_argument_type,
210*4d6fc14bSjoerg                             bool>
211*4d6fc14bSjoerg{
212*4d6fc14bSjoergpublic:
213*4d6fc14bSjoerg    explicit binary_negate(const Predicate& pred);
214*4d6fc14bSjoerg    bool operator()(const typename Predicate::first_argument_type& x,
215*4d6fc14bSjoerg                    const typename Predicate::second_argument_type& y) const;
216*4d6fc14bSjoerg};
217*4d6fc14bSjoerg
218*4d6fc14bSjoergtemplate <class Predicate> // deprecated in C++17
219*4d6fc14bSjoergbinary_negate<Predicate> not2(const Predicate& pred);
220*4d6fc14bSjoerg
221*4d6fc14bSjoergtemplate <class F>
222*4d6fc14bSjoergconstexpr unspecified not_fn(F&& f); // C++17, constexpr in C++20
223*4d6fc14bSjoerg
224*4d6fc14bSjoergtemplate<class T> struct is_bind_expression;
225*4d6fc14bSjoergtemplate<class T> struct is_placeholder;
226*4d6fc14bSjoerg
227*4d6fc14bSjoerg    // See C++14 20.9.9, Function object binders
228*4d6fc14bSjoergtemplate <class T> inline constexpr bool is_bind_expression_v
229*4d6fc14bSjoerg  = is_bind_expression<T>::value; // C++17
230*4d6fc14bSjoergtemplate <class T> inline constexpr int is_placeholder_v
231*4d6fc14bSjoerg  = is_placeholder<T>::value; // C++17
232*4d6fc14bSjoerg
233*4d6fc14bSjoerg
234*4d6fc14bSjoergtemplate<class Fn, class... BoundArgs>
235*4d6fc14bSjoerg  constexpr unspecified bind(Fn&&, BoundArgs&&...);  // constexpr in C++20
236*4d6fc14bSjoergtemplate<class R, class Fn, class... BoundArgs>
237*4d6fc14bSjoerg  constexpr unspecified bind(Fn&&, BoundArgs&&...);  // constexpr in C++20
238*4d6fc14bSjoerg
239*4d6fc14bSjoergtemplate<class F, class... Args>
240*4d6fc14bSjoerg constexpr // constexpr in C++20
241*4d6fc14bSjoerg invoke_result_t<F, Args...> invoke(F&& f, Args&&... args) // C++17
242*4d6fc14bSjoerg    noexcept(is_nothrow_invocable_v<F, Args...>);
243*4d6fc14bSjoerg
244*4d6fc14bSjoergnamespace placeholders {
245*4d6fc14bSjoerg  // M is the implementation-defined number of placeholders
246*4d6fc14bSjoerg  extern unspecified _1;
247*4d6fc14bSjoerg  extern unspecified _2;
248*4d6fc14bSjoerg  .
249*4d6fc14bSjoerg  .
250*4d6fc14bSjoerg  .
251*4d6fc14bSjoerg  extern unspecified _Mp;
252*4d6fc14bSjoerg}
253*4d6fc14bSjoerg
254*4d6fc14bSjoergtemplate <class Operation>
255*4d6fc14bSjoergclass binder1st     // deprecated in C++11, removed in C++17
256*4d6fc14bSjoerg    : public unary_function<typename Operation::second_argument_type,
257*4d6fc14bSjoerg                            typename Operation::result_type>
258*4d6fc14bSjoerg{
259*4d6fc14bSjoergprotected:
260*4d6fc14bSjoerg    Operation                               op;
261*4d6fc14bSjoerg    typename Operation::first_argument_type value;
262*4d6fc14bSjoergpublic:
263*4d6fc14bSjoerg    binder1st(const Operation& x, const typename Operation::first_argument_type y);
264*4d6fc14bSjoerg    typename Operation::result_type operator()(      typename Operation::second_argument_type& x) const;
265*4d6fc14bSjoerg    typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const;
266*4d6fc14bSjoerg};
267*4d6fc14bSjoerg
268*4d6fc14bSjoergtemplate <class Operation, class T>
269*4d6fc14bSjoergbinder1st<Operation> bind1st(const Operation& op, const T& x);  // deprecated in C++11, removed in C++17
270*4d6fc14bSjoerg
271*4d6fc14bSjoergtemplate <class Operation>
272*4d6fc14bSjoergclass binder2nd     // deprecated in C++11, removed in C++17
273*4d6fc14bSjoerg    : public unary_function<typename Operation::first_argument_type,
274*4d6fc14bSjoerg                            typename Operation::result_type>
275*4d6fc14bSjoerg{
276*4d6fc14bSjoergprotected:
277*4d6fc14bSjoerg    Operation                                op;
278*4d6fc14bSjoerg    typename Operation::second_argument_type value;
279*4d6fc14bSjoergpublic:
280*4d6fc14bSjoerg    binder2nd(const Operation& x, const typename Operation::second_argument_type y);
281*4d6fc14bSjoerg    typename Operation::result_type operator()(      typename Operation::first_argument_type& x) const;
282*4d6fc14bSjoerg    typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const;
283*4d6fc14bSjoerg};
284*4d6fc14bSjoerg
285*4d6fc14bSjoergtemplate <class Operation, class T>
286*4d6fc14bSjoergbinder2nd<Operation> bind2nd(const Operation& op, const T& x);  // deprecated in C++11, removed in C++17
287*4d6fc14bSjoerg
288*4d6fc14bSjoergtemplate <class Arg, class Result>      // deprecated in C++11, removed in C++17
289*4d6fc14bSjoergclass pointer_to_unary_function : public unary_function<Arg, Result>
290*4d6fc14bSjoerg{
291*4d6fc14bSjoergpublic:
292*4d6fc14bSjoerg    explicit pointer_to_unary_function(Result (*f)(Arg));
293*4d6fc14bSjoerg    Result operator()(Arg x) const;
294*4d6fc14bSjoerg};
295*4d6fc14bSjoerg
296*4d6fc14bSjoergtemplate <class Arg, class Result>
297*4d6fc14bSjoergpointer_to_unary_function<Arg,Result> ptr_fun(Result (*f)(Arg));      // deprecated in C++11, removed in C++17
298*4d6fc14bSjoerg
299*4d6fc14bSjoergtemplate <class Arg1, class Arg2, class Result>      // deprecated in C++11, removed in C++17
300*4d6fc14bSjoergclass pointer_to_binary_function : public binary_function<Arg1, Arg2, Result>
301*4d6fc14bSjoerg{
302*4d6fc14bSjoergpublic:
303*4d6fc14bSjoerg    explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2));
304*4d6fc14bSjoerg    Result operator()(Arg1 x, Arg2 y) const;
305*4d6fc14bSjoerg};
306*4d6fc14bSjoerg
307*4d6fc14bSjoergtemplate <class Arg1, class Arg2, class Result>
308*4d6fc14bSjoergpointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1,Arg2));      // deprecated in C++11, removed in C++17
309*4d6fc14bSjoerg
310*4d6fc14bSjoergtemplate<class S, class T>      // deprecated in C++11, removed in C++17
311*4d6fc14bSjoergclass mem_fun_t : public unary_function<T*, S>
312*4d6fc14bSjoerg{
313*4d6fc14bSjoergpublic:
314*4d6fc14bSjoerg    explicit mem_fun_t(S (T::*p)());
315*4d6fc14bSjoerg    S operator()(T* p) const;
316*4d6fc14bSjoerg};
317*4d6fc14bSjoerg
318*4d6fc14bSjoergtemplate<class S, class T, class A>
319*4d6fc14bSjoergclass mem_fun1_t : public binary_function<T*, A, S>      // deprecated in C++11, removed in C++17
320*4d6fc14bSjoerg{
321*4d6fc14bSjoergpublic:
322*4d6fc14bSjoerg    explicit mem_fun1_t(S (T::*p)(A));
323*4d6fc14bSjoerg    S operator()(T* p, A x) const;
324*4d6fc14bSjoerg};
325*4d6fc14bSjoerg
326*4d6fc14bSjoergtemplate<class S, class T>          mem_fun_t<S,T>    mem_fun(S (T::*f)());      // deprecated in C++11, removed in C++17
327*4d6fc14bSjoergtemplate<class S, class T, class A> mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A));     // deprecated in C++11, removed in C++17
328*4d6fc14bSjoerg
329*4d6fc14bSjoergtemplate<class S, class T>
330*4d6fc14bSjoergclass mem_fun_ref_t : public unary_function<T, S>      // deprecated in C++11, removed in C++17
331*4d6fc14bSjoerg{
332*4d6fc14bSjoergpublic:
333*4d6fc14bSjoerg    explicit mem_fun_ref_t(S (T::*p)());
334*4d6fc14bSjoerg    S operator()(T& p) const;
335*4d6fc14bSjoerg};
336*4d6fc14bSjoerg
337*4d6fc14bSjoergtemplate<class S, class T, class A>
338*4d6fc14bSjoergclass mem_fun1_ref_t : public binary_function<T, A, S>      // deprecated in C++11, removed in C++17
339*4d6fc14bSjoerg{
340*4d6fc14bSjoergpublic:
341*4d6fc14bSjoerg    explicit mem_fun1_ref_t(S (T::*p)(A));
342*4d6fc14bSjoerg    S operator()(T& p, A x) const;
343*4d6fc14bSjoerg};
344*4d6fc14bSjoerg
345*4d6fc14bSjoergtemplate<class S, class T>          mem_fun_ref_t<S,T>    mem_fun_ref(S (T::*f)());      // deprecated in C++11, removed in C++17
346*4d6fc14bSjoergtemplate<class S, class T, class A> mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A));     // deprecated in C++11, removed in C++17
347*4d6fc14bSjoerg
348*4d6fc14bSjoergtemplate <class S, class T>
349*4d6fc14bSjoergclass const_mem_fun_t : public unary_function<const T*, S>      // deprecated in C++11, removed in C++17
350*4d6fc14bSjoerg{
351*4d6fc14bSjoergpublic:
352*4d6fc14bSjoerg    explicit const_mem_fun_t(S (T::*p)() const);
353*4d6fc14bSjoerg    S operator()(const T* p) const;
354*4d6fc14bSjoerg};
355*4d6fc14bSjoerg
356*4d6fc14bSjoergtemplate <class S, class T, class A>
357*4d6fc14bSjoergclass const_mem_fun1_t : public binary_function<const T*, A, S>      // deprecated in C++11, removed in C++17
358*4d6fc14bSjoerg{
359*4d6fc14bSjoergpublic:
360*4d6fc14bSjoerg    explicit const_mem_fun1_t(S (T::*p)(A) const);
361*4d6fc14bSjoerg    S operator()(const T* p, A x) const;
362*4d6fc14bSjoerg};
363*4d6fc14bSjoerg
364*4d6fc14bSjoergtemplate <class S, class T>          const_mem_fun_t<S,T>    mem_fun(S (T::*f)() const);      // deprecated in C++11, removed in C++17
365*4d6fc14bSjoergtemplate <class S, class T, class A> const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const);     // deprecated in C++11, removed in C++17
366*4d6fc14bSjoerg
367*4d6fc14bSjoergtemplate <class S, class T>
368*4d6fc14bSjoergclass const_mem_fun_ref_t : public unary_function<T, S>      // deprecated in C++11, removed in C++17
369*4d6fc14bSjoerg{
370*4d6fc14bSjoergpublic:
371*4d6fc14bSjoerg    explicit const_mem_fun_ref_t(S (T::*p)() const);
372*4d6fc14bSjoerg    S operator()(const T& p) const;
373*4d6fc14bSjoerg};
374*4d6fc14bSjoerg
375*4d6fc14bSjoergtemplate <class S, class T, class A>
376*4d6fc14bSjoergclass const_mem_fun1_ref_t : public binary_function<T, A, S>      // deprecated in C++11, removed in C++17
377*4d6fc14bSjoerg{
378*4d6fc14bSjoergpublic:
379*4d6fc14bSjoerg    explicit const_mem_fun1_ref_t(S (T::*p)(A) const);
380*4d6fc14bSjoerg    S operator()(const T& p, A x) const;
381*4d6fc14bSjoerg};
382*4d6fc14bSjoerg
383*4d6fc14bSjoergtemplate <class S, class T>          const_mem_fun_ref_t<S,T>    mem_fun_ref(S (T::*f)() const);   // deprecated in C++11, removed in C++17
384*4d6fc14bSjoergtemplate <class S, class T, class A> const_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const);  // deprecated in C++11, removed in C++17
385*4d6fc14bSjoerg
386*4d6fc14bSjoergtemplate<class R, class T>
387*4d6fc14bSjoergconstexpr unspecified mem_fn(R T::*); // constexpr in C++20
388*4d6fc14bSjoerg
389*4d6fc14bSjoergclass bad_function_call
390*4d6fc14bSjoerg    : public exception
391*4d6fc14bSjoerg{
392*4d6fc14bSjoerg};
393*4d6fc14bSjoerg
394*4d6fc14bSjoergtemplate<class> class function; // undefined
395*4d6fc14bSjoerg
396*4d6fc14bSjoergtemplate<class R, class... ArgTypes>
397*4d6fc14bSjoergclass function<R(ArgTypes...)>
398*4d6fc14bSjoerg  : public unary_function<T1, R>      // iff sizeof...(ArgTypes) == 1 and
399*4d6fc14bSjoerg                                      // ArgTypes contains T1
400*4d6fc14bSjoerg  : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and
401*4d6fc14bSjoerg                                      // ArgTypes contains T1 and T2
402*4d6fc14bSjoerg{
403*4d6fc14bSjoergpublic:
404*4d6fc14bSjoerg    typedef R result_type;
405*4d6fc14bSjoerg
406*4d6fc14bSjoerg    // construct/copy/destroy:
407*4d6fc14bSjoerg    function() noexcept;
408*4d6fc14bSjoerg    function(nullptr_t) noexcept;
409*4d6fc14bSjoerg    function(const function&);
410*4d6fc14bSjoerg    function(function&&) noexcept;
411*4d6fc14bSjoerg    template<class F>
412*4d6fc14bSjoerg      function(F);
413*4d6fc14bSjoerg    template<Allocator Alloc>
414*4d6fc14bSjoerg      function(allocator_arg_t, const Alloc&) noexcept;            // removed in C++17
415*4d6fc14bSjoerg    template<Allocator Alloc>
416*4d6fc14bSjoerg      function(allocator_arg_t, const Alloc&, nullptr_t) noexcept; // removed in C++17
417*4d6fc14bSjoerg    template<Allocator Alloc>
418*4d6fc14bSjoerg      function(allocator_arg_t, const Alloc&, const function&);    // removed in C++17
419*4d6fc14bSjoerg    template<Allocator Alloc>
420*4d6fc14bSjoerg      function(allocator_arg_t, const Alloc&, function&&);         // removed in C++17
421*4d6fc14bSjoerg    template<class F, Allocator Alloc>
422*4d6fc14bSjoerg      function(allocator_arg_t, const Alloc&, F);                  // removed in C++17
423*4d6fc14bSjoerg
424*4d6fc14bSjoerg    function& operator=(const function&);
425*4d6fc14bSjoerg    function& operator=(function&&) noexcept;
426*4d6fc14bSjoerg    function& operator=(nullptr_t) noexcept;
427*4d6fc14bSjoerg    template<class F>
428*4d6fc14bSjoerg      function& operator=(F&&);
429*4d6fc14bSjoerg    template<class F>
430*4d6fc14bSjoerg      function& operator=(reference_wrapper<F>) noexcept;
431*4d6fc14bSjoerg
432*4d6fc14bSjoerg    ~function();
433*4d6fc14bSjoerg
434*4d6fc14bSjoerg    // function modifiers:
435*4d6fc14bSjoerg    void swap(function&) noexcept;
436*4d6fc14bSjoerg    template<class F, class Alloc>
437*4d6fc14bSjoerg      void assign(F&&, const Alloc&);                 // Removed in C++17
438*4d6fc14bSjoerg
439*4d6fc14bSjoerg    // function capacity:
440*4d6fc14bSjoerg    explicit operator bool() const noexcept;
441*4d6fc14bSjoerg
442*4d6fc14bSjoerg    // function invocation:
443*4d6fc14bSjoerg    R operator()(ArgTypes...) const;
444*4d6fc14bSjoerg
445*4d6fc14bSjoerg    // function target access:
446*4d6fc14bSjoerg    const std::type_info& target_type() const noexcept;
447*4d6fc14bSjoerg    template <typename T>       T* target() noexcept;
448*4d6fc14bSjoerg    template <typename T> const T* target() const noexcept;
449*4d6fc14bSjoerg};
450*4d6fc14bSjoerg
451*4d6fc14bSjoerg// Deduction guides
452*4d6fc14bSjoergtemplate<class R, class ...Args>
453*4d6fc14bSjoergfunction(R(*)(Args...)) -> function<R(Args...)>; // since C++17
454*4d6fc14bSjoerg
455*4d6fc14bSjoergtemplate<class F>
456*4d6fc14bSjoergfunction(F) -> function<see-below>; // since C++17
457*4d6fc14bSjoerg
458*4d6fc14bSjoerg// Null pointer comparisons:
459*4d6fc14bSjoergtemplate <class R, class ... ArgTypes>
460*4d6fc14bSjoerg  bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
461*4d6fc14bSjoerg
462*4d6fc14bSjoergtemplate <class R, class ... ArgTypes>
463*4d6fc14bSjoerg  bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
464*4d6fc14bSjoerg
465*4d6fc14bSjoergtemplate <class R, class ... ArgTypes>
466*4d6fc14bSjoerg  bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
467*4d6fc14bSjoerg
468*4d6fc14bSjoergtemplate <class  R, class ... ArgTypes>
469*4d6fc14bSjoerg  bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
470*4d6fc14bSjoerg
471*4d6fc14bSjoerg// specialized algorithms:
472*4d6fc14bSjoergtemplate <class  R, class ... ArgTypes>
473*4d6fc14bSjoerg  void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
474*4d6fc14bSjoerg
475*4d6fc14bSjoergtemplate <class T> struct hash;
476*4d6fc14bSjoerg
477*4d6fc14bSjoergtemplate <> struct hash<bool>;
478*4d6fc14bSjoergtemplate <> struct hash<char>;
479*4d6fc14bSjoergtemplate <> struct hash<signed char>;
480*4d6fc14bSjoergtemplate <> struct hash<unsigned char>;
481*4d6fc14bSjoergtemplate <> struct hash<char8_t>; // since C++20
482*4d6fc14bSjoergtemplate <> struct hash<char16_t>;
483*4d6fc14bSjoergtemplate <> struct hash<char32_t>;
484*4d6fc14bSjoergtemplate <> struct hash<wchar_t>;
485*4d6fc14bSjoergtemplate <> struct hash<short>;
486*4d6fc14bSjoergtemplate <> struct hash<unsigned short>;
487*4d6fc14bSjoergtemplate <> struct hash<int>;
488*4d6fc14bSjoergtemplate <> struct hash<unsigned int>;
489*4d6fc14bSjoergtemplate <> struct hash<long>;
490*4d6fc14bSjoergtemplate <> struct hash<long long>;
491*4d6fc14bSjoergtemplate <> struct hash<unsigned long>;
492*4d6fc14bSjoergtemplate <> struct hash<unsigned long long>;
493*4d6fc14bSjoerg
494*4d6fc14bSjoergtemplate <> struct hash<float>;
495*4d6fc14bSjoergtemplate <> struct hash<double>;
496*4d6fc14bSjoergtemplate <> struct hash<long double>;
497*4d6fc14bSjoerg
498*4d6fc14bSjoergtemplate<class T> struct hash<T*>;
499*4d6fc14bSjoergtemplate <> struct hash<nullptr_t>;  // C++17
500*4d6fc14bSjoerg
501*4d6fc14bSjoerg}  // std
502*4d6fc14bSjoerg
503*4d6fc14bSjoergPOLICY:  For non-variadic implementations, the number of arguments is limited
504*4d6fc14bSjoerg         to 3.  It is hoped that the need for non-variadic implementations
505*4d6fc14bSjoerg         will be minimal.
506*4d6fc14bSjoerg
507*4d6fc14bSjoerg*/
508*4d6fc14bSjoerg
509*4d6fc14bSjoerg#include <__config>
510*4d6fc14bSjoerg#include <__debug>
511*4d6fc14bSjoerg#include <concepts>
512*4d6fc14bSjoerg#include <type_traits>
513*4d6fc14bSjoerg#include <typeinfo>
514*4d6fc14bSjoerg#include <exception>
515*4d6fc14bSjoerg#include <memory>
516*4d6fc14bSjoerg#include <tuple>
517*4d6fc14bSjoerg#include <utility>
518*4d6fc14bSjoerg#include <version>
519*4d6fc14bSjoerg
520*4d6fc14bSjoerg#include <__functional_base>
521*4d6fc14bSjoerg
522*4d6fc14bSjoerg#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
523*4d6fc14bSjoerg#pragma GCC system_header
524*4d6fc14bSjoerg#endif
525*4d6fc14bSjoerg
526*4d6fc14bSjoerg_LIBCPP_BEGIN_NAMESPACE_STD
527*4d6fc14bSjoerg
528*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 11
529*4d6fc14bSjoergtemplate <class _Tp = void>
530*4d6fc14bSjoerg#else
531*4d6fc14bSjoergtemplate <class _Tp>
532*4d6fc14bSjoerg#endif
533*4d6fc14bSjoergstruct _LIBCPP_TEMPLATE_VIS plus : binary_function<_Tp, _Tp, _Tp>
534*4d6fc14bSjoerg{
535*4d6fc14bSjoerg    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
536*4d6fc14bSjoerg    _Tp operator()(const _Tp& __x, const _Tp& __y) const
537*4d6fc14bSjoerg        {return __x + __y;}
538*4d6fc14bSjoerg};
539*4d6fc14bSjoerg
540*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 11
541*4d6fc14bSjoergtemplate <>
542*4d6fc14bSjoergstruct _LIBCPP_TEMPLATE_VIS plus<void>
543*4d6fc14bSjoerg{
544*4d6fc14bSjoerg    template <class _T1, class _T2>
545*4d6fc14bSjoerg    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
546*4d6fc14bSjoerg    auto operator()(_T1&& __t, _T2&& __u) const
547*4d6fc14bSjoerg    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
548*4d6fc14bSjoerg    -> decltype        (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
549*4d6fc14bSjoerg        { return        _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
550*4d6fc14bSjoerg    typedef void is_transparent;
551*4d6fc14bSjoerg};
552*4d6fc14bSjoerg#endif
553*4d6fc14bSjoerg
554*4d6fc14bSjoerg
555*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 11
556*4d6fc14bSjoergtemplate <class _Tp = void>
557*4d6fc14bSjoerg#else
558*4d6fc14bSjoergtemplate <class _Tp>
559*4d6fc14bSjoerg#endif
560*4d6fc14bSjoergstruct _LIBCPP_TEMPLATE_VIS minus : binary_function<_Tp, _Tp, _Tp>
561*4d6fc14bSjoerg{
562*4d6fc14bSjoerg    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
563*4d6fc14bSjoerg    _Tp operator()(const _Tp& __x, const _Tp& __y) const
564*4d6fc14bSjoerg        {return __x - __y;}
565*4d6fc14bSjoerg};
566*4d6fc14bSjoerg
567*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 11
568*4d6fc14bSjoergtemplate <>
569*4d6fc14bSjoergstruct _LIBCPP_TEMPLATE_VIS minus<void>
570*4d6fc14bSjoerg{
571*4d6fc14bSjoerg    template <class _T1, class _T2>
572*4d6fc14bSjoerg    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
573*4d6fc14bSjoerg    auto operator()(_T1&& __t, _T2&& __u) const
574*4d6fc14bSjoerg    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u)))
575*4d6fc14bSjoerg    -> decltype        (_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u))
576*4d6fc14bSjoerg        { return        _VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u); }
577*4d6fc14bSjoerg    typedef void is_transparent;
578*4d6fc14bSjoerg};
579*4d6fc14bSjoerg#endif
580*4d6fc14bSjoerg
581*4d6fc14bSjoerg
582*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 11
583*4d6fc14bSjoergtemplate <class _Tp = void>
584*4d6fc14bSjoerg#else
585*4d6fc14bSjoergtemplate <class _Tp>
586*4d6fc14bSjoerg#endif
587*4d6fc14bSjoergstruct _LIBCPP_TEMPLATE_VIS multiplies : binary_function<_Tp, _Tp, _Tp>
588*4d6fc14bSjoerg{
589*4d6fc14bSjoerg    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
590*4d6fc14bSjoerg    _Tp operator()(const _Tp& __x, const _Tp& __y) const
591*4d6fc14bSjoerg        {return __x * __y;}
592*4d6fc14bSjoerg};
593*4d6fc14bSjoerg
594*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 11
595*4d6fc14bSjoergtemplate <>
596*4d6fc14bSjoergstruct _LIBCPP_TEMPLATE_VIS multiplies<void>
597*4d6fc14bSjoerg{
598*4d6fc14bSjoerg    template <class _T1, class _T2>
599*4d6fc14bSjoerg    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
600*4d6fc14bSjoerg    auto operator()(_T1&& __t, _T2&& __u) const
601*4d6fc14bSjoerg    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u)))
602*4d6fc14bSjoerg    -> decltype        (_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u))
603*4d6fc14bSjoerg        { return        _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u); }
604*4d6fc14bSjoerg    typedef void is_transparent;
605*4d6fc14bSjoerg};
606*4d6fc14bSjoerg#endif
607*4d6fc14bSjoerg
608*4d6fc14bSjoerg
609*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 11
610*4d6fc14bSjoergtemplate <class _Tp = void>
611*4d6fc14bSjoerg#else
612*4d6fc14bSjoergtemplate <class _Tp>
613*4d6fc14bSjoerg#endif
614*4d6fc14bSjoergstruct _LIBCPP_TEMPLATE_VIS divides : binary_function<_Tp, _Tp, _Tp>
615*4d6fc14bSjoerg{
616*4d6fc14bSjoerg    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
617*4d6fc14bSjoerg    _Tp operator()(const _Tp& __x, const _Tp& __y) const
618*4d6fc14bSjoerg        {return __x / __y;}
619*4d6fc14bSjoerg};
620*4d6fc14bSjoerg
621*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 11
622*4d6fc14bSjoergtemplate <>
623*4d6fc14bSjoergstruct _LIBCPP_TEMPLATE_VIS divides<void>
624*4d6fc14bSjoerg{
625*4d6fc14bSjoerg    template <class _T1, class _T2>
626*4d6fc14bSjoerg    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
627*4d6fc14bSjoerg    auto operator()(_T1&& __t, _T2&& __u) const
628*4d6fc14bSjoerg    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u)))
629*4d6fc14bSjoerg    -> decltype        (_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u))
630*4d6fc14bSjoerg        { return        _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u); }
631*4d6fc14bSjoerg    typedef void is_transparent;
632*4d6fc14bSjoerg};
633*4d6fc14bSjoerg#endif
634*4d6fc14bSjoerg
635*4d6fc14bSjoerg
636*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 11
637*4d6fc14bSjoergtemplate <class _Tp = void>
638*4d6fc14bSjoerg#else
639*4d6fc14bSjoergtemplate <class _Tp>
640*4d6fc14bSjoerg#endif
641*4d6fc14bSjoergstruct _LIBCPP_TEMPLATE_VIS modulus : binary_function<_Tp, _Tp, _Tp>
642*4d6fc14bSjoerg{
643*4d6fc14bSjoerg    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
644*4d6fc14bSjoerg    _Tp operator()(const _Tp& __x, const _Tp& __y) const
645*4d6fc14bSjoerg        {return __x % __y;}
646*4d6fc14bSjoerg};
647*4d6fc14bSjoerg
648*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 11
649*4d6fc14bSjoergtemplate <>
650*4d6fc14bSjoergstruct _LIBCPP_TEMPLATE_VIS modulus<void>
651*4d6fc14bSjoerg{
652*4d6fc14bSjoerg    template <class _T1, class _T2>
653*4d6fc14bSjoerg    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
654*4d6fc14bSjoerg    auto operator()(_T1&& __t, _T2&& __u) const
655*4d6fc14bSjoerg    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u)))
656*4d6fc14bSjoerg    -> decltype        (_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u))
657*4d6fc14bSjoerg        { return        _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u); }
658*4d6fc14bSjoerg    typedef void is_transparent;
659*4d6fc14bSjoerg};
660*4d6fc14bSjoerg#endif
661*4d6fc14bSjoerg
662*4d6fc14bSjoerg
663*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 11
664*4d6fc14bSjoergtemplate <class _Tp = void>
665*4d6fc14bSjoerg#else
666*4d6fc14bSjoergtemplate <class _Tp>
667*4d6fc14bSjoerg#endif
668*4d6fc14bSjoergstruct _LIBCPP_TEMPLATE_VIS negate : unary_function<_Tp, _Tp>
669*4d6fc14bSjoerg{
670*4d6fc14bSjoerg    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
671*4d6fc14bSjoerg    _Tp operator()(const _Tp& __x) const
672*4d6fc14bSjoerg        {return -__x;}
673*4d6fc14bSjoerg};
674*4d6fc14bSjoerg
675*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 11
676*4d6fc14bSjoergtemplate <>
677*4d6fc14bSjoergstruct _LIBCPP_TEMPLATE_VIS negate<void>
678*4d6fc14bSjoerg{
679*4d6fc14bSjoerg    template <class _Tp>
680*4d6fc14bSjoerg    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
681*4d6fc14bSjoerg    auto operator()(_Tp&& __x) const
682*4d6fc14bSjoerg    _NOEXCEPT_(noexcept(- _VSTD::forward<_Tp>(__x)))
683*4d6fc14bSjoerg    -> decltype        (- _VSTD::forward<_Tp>(__x))
684*4d6fc14bSjoerg        { return        - _VSTD::forward<_Tp>(__x); }
685*4d6fc14bSjoerg    typedef void is_transparent;
686*4d6fc14bSjoerg};
687*4d6fc14bSjoerg#endif
688*4d6fc14bSjoerg
689*4d6fc14bSjoerg
690*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 11
691*4d6fc14bSjoergtemplate <class _Tp = void>
692*4d6fc14bSjoerg#else
693*4d6fc14bSjoergtemplate <class _Tp>
694*4d6fc14bSjoerg#endif
695*4d6fc14bSjoergstruct _LIBCPP_TEMPLATE_VIS equal_to : binary_function<_Tp, _Tp, bool>
696*4d6fc14bSjoerg{
697*4d6fc14bSjoerg    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
698*4d6fc14bSjoerg    bool operator()(const _Tp& __x, const _Tp& __y) const
699*4d6fc14bSjoerg        {return __x == __y;}
700*4d6fc14bSjoerg};
701*4d6fc14bSjoerg
702*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 11
703*4d6fc14bSjoergtemplate <>
704*4d6fc14bSjoergstruct _LIBCPP_TEMPLATE_VIS equal_to<void>
705*4d6fc14bSjoerg{
706*4d6fc14bSjoerg    template <class _T1, class _T2>
707*4d6fc14bSjoerg    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
708*4d6fc14bSjoerg    auto operator()(_T1&& __t, _T2&& __u) const
709*4d6fc14bSjoerg    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u)))
710*4d6fc14bSjoerg    -> decltype        (_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u))
711*4d6fc14bSjoerg        { return        _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u); }
712*4d6fc14bSjoerg    typedef void is_transparent;
713*4d6fc14bSjoerg};
714*4d6fc14bSjoerg#endif
715*4d6fc14bSjoerg
716*4d6fc14bSjoerg
717*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 11
718*4d6fc14bSjoergtemplate <class _Tp = void>
719*4d6fc14bSjoerg#else
720*4d6fc14bSjoergtemplate <class _Tp>
721*4d6fc14bSjoerg#endif
722*4d6fc14bSjoergstruct _LIBCPP_TEMPLATE_VIS not_equal_to : binary_function<_Tp, _Tp, bool>
723*4d6fc14bSjoerg{
724*4d6fc14bSjoerg    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
725*4d6fc14bSjoerg    bool operator()(const _Tp& __x, const _Tp& __y) const
726*4d6fc14bSjoerg        {return __x != __y;}
727*4d6fc14bSjoerg};
728*4d6fc14bSjoerg
729*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 11
730*4d6fc14bSjoergtemplate <>
731*4d6fc14bSjoergstruct _LIBCPP_TEMPLATE_VIS not_equal_to<void>
732*4d6fc14bSjoerg{
733*4d6fc14bSjoerg    template <class _T1, class _T2>
734*4d6fc14bSjoerg    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
735*4d6fc14bSjoerg    auto operator()(_T1&& __t, _T2&& __u) const
736*4d6fc14bSjoerg    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u)))
737*4d6fc14bSjoerg    -> decltype        (_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u))
738*4d6fc14bSjoerg        { return        _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u); }
739*4d6fc14bSjoerg    typedef void is_transparent;
740*4d6fc14bSjoerg};
741*4d6fc14bSjoerg#endif
742*4d6fc14bSjoerg
743*4d6fc14bSjoerg
744*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 11
745*4d6fc14bSjoergtemplate <class _Tp = void>
746*4d6fc14bSjoerg#else
747*4d6fc14bSjoergtemplate <class _Tp>
748*4d6fc14bSjoerg#endif
749*4d6fc14bSjoergstruct _LIBCPP_TEMPLATE_VIS greater : binary_function<_Tp, _Tp, bool>
750*4d6fc14bSjoerg{
751*4d6fc14bSjoerg    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
752*4d6fc14bSjoerg    bool operator()(const _Tp& __x, const _Tp& __y) const
753*4d6fc14bSjoerg        {return __x > __y;}
754*4d6fc14bSjoerg};
755*4d6fc14bSjoerg
756*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 11
757*4d6fc14bSjoergtemplate <>
758*4d6fc14bSjoergstruct _LIBCPP_TEMPLATE_VIS greater<void>
759*4d6fc14bSjoerg{
760*4d6fc14bSjoerg    template <class _T1, class _T2>
761*4d6fc14bSjoerg    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
762*4d6fc14bSjoerg    auto operator()(_T1&& __t, _T2&& __u) const
763*4d6fc14bSjoerg    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u)))
764*4d6fc14bSjoerg    -> decltype        (_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u))
765*4d6fc14bSjoerg        { return        _VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u); }
766*4d6fc14bSjoerg    typedef void is_transparent;
767*4d6fc14bSjoerg};
768*4d6fc14bSjoerg#endif
769*4d6fc14bSjoerg
770*4d6fc14bSjoerg
771*4d6fc14bSjoerg// less in <__functional_base>
772*4d6fc14bSjoerg
773*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 11
774*4d6fc14bSjoergtemplate <class _Tp = void>
775*4d6fc14bSjoerg#else
776*4d6fc14bSjoergtemplate <class _Tp>
777*4d6fc14bSjoerg#endif
778*4d6fc14bSjoergstruct _LIBCPP_TEMPLATE_VIS greater_equal : binary_function<_Tp, _Tp, bool>
779*4d6fc14bSjoerg{
780*4d6fc14bSjoerg    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
781*4d6fc14bSjoerg    bool operator()(const _Tp& __x, const _Tp& __y) const
782*4d6fc14bSjoerg        {return __x >= __y;}
783*4d6fc14bSjoerg};
784*4d6fc14bSjoerg
785*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 11
786*4d6fc14bSjoergtemplate <>
787*4d6fc14bSjoergstruct _LIBCPP_TEMPLATE_VIS greater_equal<void>
788*4d6fc14bSjoerg{
789*4d6fc14bSjoerg    template <class _T1, class _T2>
790*4d6fc14bSjoerg    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
791*4d6fc14bSjoerg    auto operator()(_T1&& __t, _T2&& __u) const
792*4d6fc14bSjoerg    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u)))
793*4d6fc14bSjoerg    -> decltype        (_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u))
794*4d6fc14bSjoerg        { return        _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u); }
795*4d6fc14bSjoerg    typedef void is_transparent;
796*4d6fc14bSjoerg};
797*4d6fc14bSjoerg#endif
798*4d6fc14bSjoerg
799*4d6fc14bSjoerg
800*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 11
801*4d6fc14bSjoergtemplate <class _Tp = void>
802*4d6fc14bSjoerg#else
803*4d6fc14bSjoergtemplate <class _Tp>
804*4d6fc14bSjoerg#endif
805*4d6fc14bSjoergstruct _LIBCPP_TEMPLATE_VIS less_equal : binary_function<_Tp, _Tp, bool>
806*4d6fc14bSjoerg{
807*4d6fc14bSjoerg    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
808*4d6fc14bSjoerg    bool operator()(const _Tp& __x, const _Tp& __y) const
809*4d6fc14bSjoerg        {return __x <= __y;}
810*4d6fc14bSjoerg};
811*4d6fc14bSjoerg
812*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 11
813*4d6fc14bSjoergtemplate <>
814*4d6fc14bSjoergstruct _LIBCPP_TEMPLATE_VIS less_equal<void>
815*4d6fc14bSjoerg{
816*4d6fc14bSjoerg    template <class _T1, class _T2>
817*4d6fc14bSjoerg    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
818*4d6fc14bSjoerg    auto operator()(_T1&& __t, _T2&& __u) const
819*4d6fc14bSjoerg    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u)))
820*4d6fc14bSjoerg    -> decltype        (_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u))
821*4d6fc14bSjoerg        { return        _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u); }
822*4d6fc14bSjoerg    typedef void is_transparent;
823*4d6fc14bSjoerg};
824*4d6fc14bSjoerg#endif
825*4d6fc14bSjoerg
826*4d6fc14bSjoerg
827*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 11
828*4d6fc14bSjoergtemplate <class _Tp = void>
829*4d6fc14bSjoerg#else
830*4d6fc14bSjoergtemplate <class _Tp>
831*4d6fc14bSjoerg#endif
832*4d6fc14bSjoergstruct _LIBCPP_TEMPLATE_VIS logical_and : binary_function<_Tp, _Tp, bool>
833*4d6fc14bSjoerg{
834*4d6fc14bSjoerg    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
835*4d6fc14bSjoerg    bool operator()(const _Tp& __x, const _Tp& __y) const
836*4d6fc14bSjoerg        {return __x && __y;}
837*4d6fc14bSjoerg};
838*4d6fc14bSjoerg
839*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 11
840*4d6fc14bSjoergtemplate <>
841*4d6fc14bSjoergstruct _LIBCPP_TEMPLATE_VIS logical_and<void>
842*4d6fc14bSjoerg{
843*4d6fc14bSjoerg    template <class _T1, class _T2>
844*4d6fc14bSjoerg    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
845*4d6fc14bSjoerg    auto operator()(_T1&& __t, _T2&& __u) const
846*4d6fc14bSjoerg    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u)))
847*4d6fc14bSjoerg    -> decltype        (_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u))
848*4d6fc14bSjoerg        { return        _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u); }
849*4d6fc14bSjoerg    typedef void is_transparent;
850*4d6fc14bSjoerg};
851*4d6fc14bSjoerg#endif
852*4d6fc14bSjoerg
853*4d6fc14bSjoerg
854*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 11
855*4d6fc14bSjoergtemplate <class _Tp = void>
856*4d6fc14bSjoerg#else
857*4d6fc14bSjoergtemplate <class _Tp>
858*4d6fc14bSjoerg#endif
859*4d6fc14bSjoergstruct _LIBCPP_TEMPLATE_VIS logical_or : binary_function<_Tp, _Tp, bool>
860*4d6fc14bSjoerg{
861*4d6fc14bSjoerg    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
862*4d6fc14bSjoerg    bool operator()(const _Tp& __x, const _Tp& __y) const
863*4d6fc14bSjoerg        {return __x || __y;}
864*4d6fc14bSjoerg};
865*4d6fc14bSjoerg
866*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 11
867*4d6fc14bSjoergtemplate <>
868*4d6fc14bSjoergstruct _LIBCPP_TEMPLATE_VIS logical_or<void>
869*4d6fc14bSjoerg{
870*4d6fc14bSjoerg    template <class _T1, class _T2>
871*4d6fc14bSjoerg    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
872*4d6fc14bSjoerg    auto operator()(_T1&& __t, _T2&& __u) const
873*4d6fc14bSjoerg    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u)))
874*4d6fc14bSjoerg    -> decltype        (_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u))
875*4d6fc14bSjoerg        { return        _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u); }
876*4d6fc14bSjoerg    typedef void is_transparent;
877*4d6fc14bSjoerg};
878*4d6fc14bSjoerg#endif
879*4d6fc14bSjoerg
880*4d6fc14bSjoerg
881*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 11
882*4d6fc14bSjoergtemplate <class _Tp = void>
883*4d6fc14bSjoerg#else
884*4d6fc14bSjoergtemplate <class _Tp>
885*4d6fc14bSjoerg#endif
886*4d6fc14bSjoergstruct _LIBCPP_TEMPLATE_VIS logical_not : unary_function<_Tp, bool>
887*4d6fc14bSjoerg{
888*4d6fc14bSjoerg    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
889*4d6fc14bSjoerg    bool operator()(const _Tp& __x) const
890*4d6fc14bSjoerg        {return !__x;}
891*4d6fc14bSjoerg};
892*4d6fc14bSjoerg
893*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 11
894*4d6fc14bSjoergtemplate <>
895*4d6fc14bSjoergstruct _LIBCPP_TEMPLATE_VIS logical_not<void>
896*4d6fc14bSjoerg{
897*4d6fc14bSjoerg    template <class _Tp>
898*4d6fc14bSjoerg    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
899*4d6fc14bSjoerg    auto operator()(_Tp&& __x) const
900*4d6fc14bSjoerg    _NOEXCEPT_(noexcept(!_VSTD::forward<_Tp>(__x)))
901*4d6fc14bSjoerg    -> decltype        (!_VSTD::forward<_Tp>(__x))
902*4d6fc14bSjoerg        { return        !_VSTD::forward<_Tp>(__x); }
903*4d6fc14bSjoerg    typedef void is_transparent;
904*4d6fc14bSjoerg};
905*4d6fc14bSjoerg#endif
906*4d6fc14bSjoerg
907*4d6fc14bSjoerg
908*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 11
909*4d6fc14bSjoergtemplate <class _Tp = void>
910*4d6fc14bSjoerg#else
911*4d6fc14bSjoergtemplate <class _Tp>
912*4d6fc14bSjoerg#endif
913*4d6fc14bSjoergstruct _LIBCPP_TEMPLATE_VIS bit_and : binary_function<_Tp, _Tp, _Tp>
914*4d6fc14bSjoerg{
915*4d6fc14bSjoerg    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
916*4d6fc14bSjoerg    _Tp operator()(const _Tp& __x, const _Tp& __y) const
917*4d6fc14bSjoerg        {return __x & __y;}
918*4d6fc14bSjoerg};
919*4d6fc14bSjoerg
920*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 11
921*4d6fc14bSjoergtemplate <>
922*4d6fc14bSjoergstruct _LIBCPP_TEMPLATE_VIS bit_and<void>
923*4d6fc14bSjoerg{
924*4d6fc14bSjoerg    template <class _T1, class _T2>
925*4d6fc14bSjoerg    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
926*4d6fc14bSjoerg    auto operator()(_T1&& __t, _T2&& __u) const
927*4d6fc14bSjoerg    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u)))
928*4d6fc14bSjoerg    -> decltype        (_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u))
929*4d6fc14bSjoerg        { return        _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u); }
930*4d6fc14bSjoerg    typedef void is_transparent;
931*4d6fc14bSjoerg};
932*4d6fc14bSjoerg#endif
933*4d6fc14bSjoerg
934*4d6fc14bSjoerg
935*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 11
936*4d6fc14bSjoergtemplate <class _Tp = void>
937*4d6fc14bSjoerg#else
938*4d6fc14bSjoergtemplate <class _Tp>
939*4d6fc14bSjoerg#endif
940*4d6fc14bSjoergstruct _LIBCPP_TEMPLATE_VIS bit_or : binary_function<_Tp, _Tp, _Tp>
941*4d6fc14bSjoerg{
942*4d6fc14bSjoerg    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
943*4d6fc14bSjoerg    _Tp operator()(const _Tp& __x, const _Tp& __y) const
944*4d6fc14bSjoerg        {return __x | __y;}
945*4d6fc14bSjoerg};
946*4d6fc14bSjoerg
947*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 11
948*4d6fc14bSjoergtemplate <>
949*4d6fc14bSjoergstruct _LIBCPP_TEMPLATE_VIS bit_or<void>
950*4d6fc14bSjoerg{
951*4d6fc14bSjoerg    template <class _T1, class _T2>
952*4d6fc14bSjoerg    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
953*4d6fc14bSjoerg    auto operator()(_T1&& __t, _T2&& __u) const
954*4d6fc14bSjoerg    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u)))
955*4d6fc14bSjoerg    -> decltype        (_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u))
956*4d6fc14bSjoerg        { return        _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u); }
957*4d6fc14bSjoerg    typedef void is_transparent;
958*4d6fc14bSjoerg};
959*4d6fc14bSjoerg#endif
960*4d6fc14bSjoerg
961*4d6fc14bSjoerg
962*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 11
963*4d6fc14bSjoergtemplate <class _Tp = void>
964*4d6fc14bSjoerg#else
965*4d6fc14bSjoergtemplate <class _Tp>
966*4d6fc14bSjoerg#endif
967*4d6fc14bSjoergstruct _LIBCPP_TEMPLATE_VIS bit_xor : binary_function<_Tp, _Tp, _Tp>
968*4d6fc14bSjoerg{
969*4d6fc14bSjoerg    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
970*4d6fc14bSjoerg    _Tp operator()(const _Tp& __x, const _Tp& __y) const
971*4d6fc14bSjoerg        {return __x ^ __y;}
972*4d6fc14bSjoerg};
973*4d6fc14bSjoerg
974*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 11
975*4d6fc14bSjoergtemplate <>
976*4d6fc14bSjoergstruct _LIBCPP_TEMPLATE_VIS bit_xor<void>
977*4d6fc14bSjoerg{
978*4d6fc14bSjoerg    template <class _T1, class _T2>
979*4d6fc14bSjoerg    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
980*4d6fc14bSjoerg    auto operator()(_T1&& __t, _T2&& __u) const
981*4d6fc14bSjoerg    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u)))
982*4d6fc14bSjoerg    -> decltype        (_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u))
983*4d6fc14bSjoerg        { return        _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u); }
984*4d6fc14bSjoerg    typedef void is_transparent;
985*4d6fc14bSjoerg};
986*4d6fc14bSjoerg#endif
987*4d6fc14bSjoerg
988*4d6fc14bSjoerg
989*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 11
990*4d6fc14bSjoergtemplate <class _Tp = void>
991*4d6fc14bSjoergstruct _LIBCPP_TEMPLATE_VIS bit_not : unary_function<_Tp, _Tp>
992*4d6fc14bSjoerg{
993*4d6fc14bSjoerg    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
994*4d6fc14bSjoerg    _Tp operator()(const _Tp& __x) const
995*4d6fc14bSjoerg        {return ~__x;}
996*4d6fc14bSjoerg};
997*4d6fc14bSjoerg
998*4d6fc14bSjoergtemplate <>
999*4d6fc14bSjoergstruct _LIBCPP_TEMPLATE_VIS bit_not<void>
1000*4d6fc14bSjoerg{
1001*4d6fc14bSjoerg    template <class _Tp>
1002*4d6fc14bSjoerg    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1003*4d6fc14bSjoerg    auto operator()(_Tp&& __x) const
1004*4d6fc14bSjoerg    _NOEXCEPT_(noexcept(~_VSTD::forward<_Tp>(__x)))
1005*4d6fc14bSjoerg    -> decltype        (~_VSTD::forward<_Tp>(__x))
1006*4d6fc14bSjoerg        { return        ~_VSTD::forward<_Tp>(__x); }
1007*4d6fc14bSjoerg    typedef void is_transparent;
1008*4d6fc14bSjoerg};
1009*4d6fc14bSjoerg#endif
1010*4d6fc14bSjoerg
1011*4d6fc14bSjoergtemplate <class _Predicate>
1012*4d6fc14bSjoergclass _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 unary_negate
1013*4d6fc14bSjoerg    : public unary_function<typename _Predicate::argument_type, bool>
1014*4d6fc14bSjoerg{
1015*4d6fc14bSjoerg    _Predicate __pred_;
1016*4d6fc14bSjoergpublic:
1017*4d6fc14bSjoerg    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1018*4d6fc14bSjoerg    explicit unary_negate(const _Predicate& __pred)
1019*4d6fc14bSjoerg        : __pred_(__pred) {}
1020*4d6fc14bSjoerg    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1021*4d6fc14bSjoerg    bool operator()(const typename _Predicate::argument_type& __x) const
1022*4d6fc14bSjoerg        {return !__pred_(__x);}
1023*4d6fc14bSjoerg};
1024*4d6fc14bSjoerg
1025*4d6fc14bSjoergtemplate <class _Predicate>
1026*4d6fc14bSjoerg_LIBCPP_DEPRECATED_IN_CXX17 inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1027*4d6fc14bSjoergunary_negate<_Predicate>
1028*4d6fc14bSjoergnot1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);}
1029*4d6fc14bSjoerg
1030*4d6fc14bSjoergtemplate <class _Predicate>
1031*4d6fc14bSjoergclass _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 binary_negate
1032*4d6fc14bSjoerg    : public binary_function<typename _Predicate::first_argument_type,
1033*4d6fc14bSjoerg                             typename _Predicate::second_argument_type,
1034*4d6fc14bSjoerg                             bool>
1035*4d6fc14bSjoerg{
1036*4d6fc14bSjoerg    _Predicate __pred_;
1037*4d6fc14bSjoergpublic:
1038*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY explicit _LIBCPP_CONSTEXPR_AFTER_CXX11
1039*4d6fc14bSjoerg    binary_negate(const _Predicate& __pred) : __pred_(__pred) {}
1040*4d6fc14bSjoerg
1041*4d6fc14bSjoerg    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1042*4d6fc14bSjoerg    bool operator()(const typename _Predicate::first_argument_type& __x,
1043*4d6fc14bSjoerg                    const typename _Predicate::second_argument_type& __y) const
1044*4d6fc14bSjoerg        {return !__pred_(__x, __y);}
1045*4d6fc14bSjoerg};
1046*4d6fc14bSjoerg
1047*4d6fc14bSjoergtemplate <class _Predicate>
1048*4d6fc14bSjoerg_LIBCPP_DEPRECATED_IN_CXX17 inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1049*4d6fc14bSjoergbinary_negate<_Predicate>
1050*4d6fc14bSjoergnot2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);}
1051*4d6fc14bSjoerg
1052*4d6fc14bSjoerg#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS)
1053*4d6fc14bSjoergtemplate <class __Operation>
1054*4d6fc14bSjoergclass _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 binder1st
1055*4d6fc14bSjoerg    : public unary_function<typename __Operation::second_argument_type,
1056*4d6fc14bSjoerg                            typename __Operation::result_type>
1057*4d6fc14bSjoerg{
1058*4d6fc14bSjoergprotected:
1059*4d6fc14bSjoerg    __Operation                               op;
1060*4d6fc14bSjoerg    typename __Operation::first_argument_type value;
1061*4d6fc14bSjoergpublic:
1062*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x,
1063*4d6fc14bSjoerg                               const typename __Operation::first_argument_type __y)
1064*4d6fc14bSjoerg        : op(__x), value(__y) {}
1065*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1066*4d6fc14bSjoerg        (typename __Operation::second_argument_type& __x) const
1067*4d6fc14bSjoerg            {return op(value, __x);}
1068*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1069*4d6fc14bSjoerg        (const typename __Operation::second_argument_type& __x) const
1070*4d6fc14bSjoerg            {return op(value, __x);}
1071*4d6fc14bSjoerg};
1072*4d6fc14bSjoerg
1073*4d6fc14bSjoergtemplate <class __Operation, class _Tp>
1074*4d6fc14bSjoerg_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
1075*4d6fc14bSjoergbinder1st<__Operation>
1076*4d6fc14bSjoergbind1st(const __Operation& __op, const _Tp& __x)
1077*4d6fc14bSjoerg    {return binder1st<__Operation>(__op, __x);}
1078*4d6fc14bSjoerg
1079*4d6fc14bSjoergtemplate <class __Operation>
1080*4d6fc14bSjoergclass _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 binder2nd
1081*4d6fc14bSjoerg    : public unary_function<typename __Operation::first_argument_type,
1082*4d6fc14bSjoerg                            typename __Operation::result_type>
1083*4d6fc14bSjoerg{
1084*4d6fc14bSjoergprotected:
1085*4d6fc14bSjoerg    __Operation                                op;
1086*4d6fc14bSjoerg    typename __Operation::second_argument_type value;
1087*4d6fc14bSjoergpublic:
1088*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
1089*4d6fc14bSjoerg    binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y)
1090*4d6fc14bSjoerg        : op(__x), value(__y) {}
1091*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1092*4d6fc14bSjoerg        (      typename __Operation::first_argument_type& __x) const
1093*4d6fc14bSjoerg            {return op(__x, value);}
1094*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1095*4d6fc14bSjoerg        (const typename __Operation::first_argument_type& __x) const
1096*4d6fc14bSjoerg            {return op(__x, value);}
1097*4d6fc14bSjoerg};
1098*4d6fc14bSjoerg
1099*4d6fc14bSjoergtemplate <class __Operation, class _Tp>
1100*4d6fc14bSjoerg_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
1101*4d6fc14bSjoergbinder2nd<__Operation>
1102*4d6fc14bSjoergbind2nd(const __Operation& __op, const _Tp& __x)
1103*4d6fc14bSjoerg    {return binder2nd<__Operation>(__op, __x);}
1104*4d6fc14bSjoerg
1105*4d6fc14bSjoergtemplate <class _Arg, class _Result>
1106*4d6fc14bSjoergclass _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 pointer_to_unary_function
1107*4d6fc14bSjoerg    : public unary_function<_Arg, _Result>
1108*4d6fc14bSjoerg{
1109*4d6fc14bSjoerg    _Result (*__f_)(_Arg);
1110*4d6fc14bSjoergpublic:
1111*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg))
1112*4d6fc14bSjoerg        : __f_(__f) {}
1113*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const
1114*4d6fc14bSjoerg        {return __f_(__x);}
1115*4d6fc14bSjoerg};
1116*4d6fc14bSjoerg
1117*4d6fc14bSjoergtemplate <class _Arg, class _Result>
1118*4d6fc14bSjoerg_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
1119*4d6fc14bSjoergpointer_to_unary_function<_Arg,_Result>
1120*4d6fc14bSjoergptr_fun(_Result (*__f)(_Arg))
1121*4d6fc14bSjoerg    {return pointer_to_unary_function<_Arg,_Result>(__f);}
1122*4d6fc14bSjoerg
1123*4d6fc14bSjoergtemplate <class _Arg1, class _Arg2, class _Result>
1124*4d6fc14bSjoergclass _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 pointer_to_binary_function
1125*4d6fc14bSjoerg    : public binary_function<_Arg1, _Arg2, _Result>
1126*4d6fc14bSjoerg{
1127*4d6fc14bSjoerg    _Result (*__f_)(_Arg1, _Arg2);
1128*4d6fc14bSjoergpublic:
1129*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2))
1130*4d6fc14bSjoerg        : __f_(__f) {}
1131*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const
1132*4d6fc14bSjoerg        {return __f_(__x, __y);}
1133*4d6fc14bSjoerg};
1134*4d6fc14bSjoerg
1135*4d6fc14bSjoergtemplate <class _Arg1, class _Arg2, class _Result>
1136*4d6fc14bSjoerg_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
1137*4d6fc14bSjoergpointer_to_binary_function<_Arg1,_Arg2,_Result>
1138*4d6fc14bSjoergptr_fun(_Result (*__f)(_Arg1,_Arg2))
1139*4d6fc14bSjoerg    {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);}
1140*4d6fc14bSjoerg
1141*4d6fc14bSjoergtemplate<class _Sp, class _Tp>
1142*4d6fc14bSjoergclass _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun_t
1143*4d6fc14bSjoerg    : public unary_function<_Tp*, _Sp>
1144*4d6fc14bSjoerg{
1145*4d6fc14bSjoerg    _Sp (_Tp::*__p_)();
1146*4d6fc14bSjoergpublic:
1147*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)())
1148*4d6fc14bSjoerg        : __p_(__p) {}
1149*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const
1150*4d6fc14bSjoerg        {return (__p->*__p_)();}
1151*4d6fc14bSjoerg};
1152*4d6fc14bSjoerg
1153*4d6fc14bSjoergtemplate<class _Sp, class _Tp, class _Ap>
1154*4d6fc14bSjoergclass _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun1_t
1155*4d6fc14bSjoerg    : public binary_function<_Tp*, _Ap, _Sp>
1156*4d6fc14bSjoerg{
1157*4d6fc14bSjoerg    _Sp (_Tp::*__p_)(_Ap);
1158*4d6fc14bSjoergpublic:
1159*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap))
1160*4d6fc14bSjoerg        : __p_(__p) {}
1161*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const
1162*4d6fc14bSjoerg        {return (__p->*__p_)(__x);}
1163*4d6fc14bSjoerg};
1164*4d6fc14bSjoerg
1165*4d6fc14bSjoergtemplate<class _Sp, class _Tp>
1166*4d6fc14bSjoerg_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
1167*4d6fc14bSjoergmem_fun_t<_Sp,_Tp>
1168*4d6fc14bSjoergmem_fun(_Sp (_Tp::*__f)())
1169*4d6fc14bSjoerg    {return mem_fun_t<_Sp,_Tp>(__f);}
1170*4d6fc14bSjoerg
1171*4d6fc14bSjoergtemplate<class _Sp, class _Tp, class _Ap>
1172*4d6fc14bSjoerg_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
1173*4d6fc14bSjoergmem_fun1_t<_Sp,_Tp,_Ap>
1174*4d6fc14bSjoergmem_fun(_Sp (_Tp::*__f)(_Ap))
1175*4d6fc14bSjoerg    {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1176*4d6fc14bSjoerg
1177*4d6fc14bSjoergtemplate<class _Sp, class _Tp>
1178*4d6fc14bSjoergclass _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun_ref_t
1179*4d6fc14bSjoerg    : public unary_function<_Tp, _Sp>
1180*4d6fc14bSjoerg{
1181*4d6fc14bSjoerg    _Sp (_Tp::*__p_)();
1182*4d6fc14bSjoergpublic:
1183*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)())
1184*4d6fc14bSjoerg        : __p_(__p) {}
1185*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const
1186*4d6fc14bSjoerg        {return (__p.*__p_)();}
1187*4d6fc14bSjoerg};
1188*4d6fc14bSjoerg
1189*4d6fc14bSjoergtemplate<class _Sp, class _Tp, class _Ap>
1190*4d6fc14bSjoergclass _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun1_ref_t
1191*4d6fc14bSjoerg    : public binary_function<_Tp, _Ap, _Sp>
1192*4d6fc14bSjoerg{
1193*4d6fc14bSjoerg    _Sp (_Tp::*__p_)(_Ap);
1194*4d6fc14bSjoergpublic:
1195*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap))
1196*4d6fc14bSjoerg        : __p_(__p) {}
1197*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const
1198*4d6fc14bSjoerg        {return (__p.*__p_)(__x);}
1199*4d6fc14bSjoerg};
1200*4d6fc14bSjoerg
1201*4d6fc14bSjoergtemplate<class _Sp, class _Tp>
1202*4d6fc14bSjoerg_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
1203*4d6fc14bSjoergmem_fun_ref_t<_Sp,_Tp>
1204*4d6fc14bSjoergmem_fun_ref(_Sp (_Tp::*__f)())
1205*4d6fc14bSjoerg    {return mem_fun_ref_t<_Sp,_Tp>(__f);}
1206*4d6fc14bSjoerg
1207*4d6fc14bSjoergtemplate<class _Sp, class _Tp, class _Ap>
1208*4d6fc14bSjoerg_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
1209*4d6fc14bSjoergmem_fun1_ref_t<_Sp,_Tp,_Ap>
1210*4d6fc14bSjoergmem_fun_ref(_Sp (_Tp::*__f)(_Ap))
1211*4d6fc14bSjoerg    {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
1212*4d6fc14bSjoerg
1213*4d6fc14bSjoergtemplate <class _Sp, class _Tp>
1214*4d6fc14bSjoergclass _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun_t
1215*4d6fc14bSjoerg    : public unary_function<const _Tp*, _Sp>
1216*4d6fc14bSjoerg{
1217*4d6fc14bSjoerg    _Sp (_Tp::*__p_)() const;
1218*4d6fc14bSjoergpublic:
1219*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const)
1220*4d6fc14bSjoerg        : __p_(__p) {}
1221*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const
1222*4d6fc14bSjoerg        {return (__p->*__p_)();}
1223*4d6fc14bSjoerg};
1224*4d6fc14bSjoerg
1225*4d6fc14bSjoergtemplate <class _Sp, class _Tp, class _Ap>
1226*4d6fc14bSjoergclass _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun1_t
1227*4d6fc14bSjoerg    : public binary_function<const _Tp*, _Ap, _Sp>
1228*4d6fc14bSjoerg{
1229*4d6fc14bSjoerg    _Sp (_Tp::*__p_)(_Ap) const;
1230*4d6fc14bSjoergpublic:
1231*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const)
1232*4d6fc14bSjoerg        : __p_(__p) {}
1233*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const
1234*4d6fc14bSjoerg        {return (__p->*__p_)(__x);}
1235*4d6fc14bSjoerg};
1236*4d6fc14bSjoerg
1237*4d6fc14bSjoergtemplate <class _Sp, class _Tp>
1238*4d6fc14bSjoerg_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
1239*4d6fc14bSjoergconst_mem_fun_t<_Sp,_Tp>
1240*4d6fc14bSjoergmem_fun(_Sp (_Tp::*__f)() const)
1241*4d6fc14bSjoerg    {return const_mem_fun_t<_Sp,_Tp>(__f);}
1242*4d6fc14bSjoerg
1243*4d6fc14bSjoergtemplate <class _Sp, class _Tp, class _Ap>
1244*4d6fc14bSjoerg_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
1245*4d6fc14bSjoergconst_mem_fun1_t<_Sp,_Tp,_Ap>
1246*4d6fc14bSjoergmem_fun(_Sp (_Tp::*__f)(_Ap) const)
1247*4d6fc14bSjoerg    {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1248*4d6fc14bSjoerg
1249*4d6fc14bSjoergtemplate <class _Sp, class _Tp>
1250*4d6fc14bSjoergclass _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun_ref_t
1251*4d6fc14bSjoerg    : public unary_function<_Tp, _Sp>
1252*4d6fc14bSjoerg{
1253*4d6fc14bSjoerg    _Sp (_Tp::*__p_)() const;
1254*4d6fc14bSjoergpublic:
1255*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const)
1256*4d6fc14bSjoerg        : __p_(__p) {}
1257*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const
1258*4d6fc14bSjoerg        {return (__p.*__p_)();}
1259*4d6fc14bSjoerg};
1260*4d6fc14bSjoerg
1261*4d6fc14bSjoergtemplate <class _Sp, class _Tp, class _Ap>
1262*4d6fc14bSjoergclass _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun1_ref_t
1263*4d6fc14bSjoerg    : public binary_function<_Tp, _Ap, _Sp>
1264*4d6fc14bSjoerg{
1265*4d6fc14bSjoerg    _Sp (_Tp::*__p_)(_Ap) const;
1266*4d6fc14bSjoergpublic:
1267*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const)
1268*4d6fc14bSjoerg        : __p_(__p) {}
1269*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const
1270*4d6fc14bSjoerg        {return (__p.*__p_)(__x);}
1271*4d6fc14bSjoerg};
1272*4d6fc14bSjoerg
1273*4d6fc14bSjoergtemplate <class _Sp, class _Tp>
1274*4d6fc14bSjoerg_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
1275*4d6fc14bSjoergconst_mem_fun_ref_t<_Sp,_Tp>
1276*4d6fc14bSjoergmem_fun_ref(_Sp (_Tp::*__f)() const)
1277*4d6fc14bSjoerg    {return const_mem_fun_ref_t<_Sp,_Tp>(__f);}
1278*4d6fc14bSjoerg
1279*4d6fc14bSjoergtemplate <class _Sp, class _Tp, class _Ap>
1280*4d6fc14bSjoerg_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
1281*4d6fc14bSjoergconst_mem_fun1_ref_t<_Sp,_Tp,_Ap>
1282*4d6fc14bSjoergmem_fun_ref(_Sp (_Tp::*__f)(_Ap) const)
1283*4d6fc14bSjoerg    {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
1284*4d6fc14bSjoerg#endif
1285*4d6fc14bSjoerg
1286*4d6fc14bSjoerg////////////////////////////////////////////////////////////////////////////////
1287*4d6fc14bSjoerg//                                MEMFUN
1288*4d6fc14bSjoerg//==============================================================================
1289*4d6fc14bSjoerg
1290*4d6fc14bSjoergtemplate <class _Tp>
1291*4d6fc14bSjoergclass __mem_fn
1292*4d6fc14bSjoerg    : public __weak_result_type<_Tp>
1293*4d6fc14bSjoerg{
1294*4d6fc14bSjoergpublic:
1295*4d6fc14bSjoerg    // types
1296*4d6fc14bSjoerg    typedef _Tp type;
1297*4d6fc14bSjoergprivate:
1298*4d6fc14bSjoerg    type __f_;
1299*4d6fc14bSjoerg
1300*4d6fc14bSjoergpublic:
1301*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1302*4d6fc14bSjoerg    __mem_fn(type __f) _NOEXCEPT : __f_(__f) {}
1303*4d6fc14bSjoerg
1304*4d6fc14bSjoerg#ifndef _LIBCPP_CXX03_LANG
1305*4d6fc14bSjoerg    // invoke
1306*4d6fc14bSjoerg    template <class... _ArgTypes>
1307*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1308*4d6fc14bSjoerg    typename __invoke_return<type, _ArgTypes...>::type
1309*4d6fc14bSjoerg    operator() (_ArgTypes&&... __args) const {
1310*4d6fc14bSjoerg        return _VSTD::__invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...);
1311*4d6fc14bSjoerg    }
1312*4d6fc14bSjoerg#else
1313*4d6fc14bSjoerg
1314*4d6fc14bSjoerg    template <class _A0>
1315*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
1316*4d6fc14bSjoerg    typename __invoke_return0<type, _A0>::type
1317*4d6fc14bSjoerg    operator() (_A0& __a0) const {
1318*4d6fc14bSjoerg        return _VSTD::__invoke(__f_, __a0);
1319*4d6fc14bSjoerg    }
1320*4d6fc14bSjoerg
1321*4d6fc14bSjoerg    template <class _A0>
1322*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
1323*4d6fc14bSjoerg    typename __invoke_return0<type, _A0 const>::type
1324*4d6fc14bSjoerg    operator() (_A0 const& __a0) const {
1325*4d6fc14bSjoerg        return _VSTD::__invoke(__f_, __a0);
1326*4d6fc14bSjoerg    }
1327*4d6fc14bSjoerg
1328*4d6fc14bSjoerg    template <class _A0, class _A1>
1329*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
1330*4d6fc14bSjoerg    typename __invoke_return1<type, _A0, _A1>::type
1331*4d6fc14bSjoerg    operator() (_A0& __a0, _A1& __a1) const {
1332*4d6fc14bSjoerg        return _VSTD::__invoke(__f_, __a0, __a1);
1333*4d6fc14bSjoerg    }
1334*4d6fc14bSjoerg
1335*4d6fc14bSjoerg    template <class _A0, class _A1>
1336*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
1337*4d6fc14bSjoerg    typename __invoke_return1<type, _A0 const, _A1>::type
1338*4d6fc14bSjoerg    operator() (_A0 const& __a0, _A1& __a1) const {
1339*4d6fc14bSjoerg        return _VSTD::__invoke(__f_, __a0, __a1);
1340*4d6fc14bSjoerg    }
1341*4d6fc14bSjoerg
1342*4d6fc14bSjoerg    template <class _A0, class _A1>
1343*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
1344*4d6fc14bSjoerg    typename __invoke_return1<type, _A0, _A1 const>::type
1345*4d6fc14bSjoerg    operator() (_A0& __a0, _A1 const& __a1) const {
1346*4d6fc14bSjoerg        return _VSTD::__invoke(__f_, __a0, __a1);
1347*4d6fc14bSjoerg    }
1348*4d6fc14bSjoerg
1349*4d6fc14bSjoerg    template <class _A0, class _A1>
1350*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
1351*4d6fc14bSjoerg    typename __invoke_return1<type, _A0 const, _A1 const>::type
1352*4d6fc14bSjoerg    operator() (_A0 const& __a0, _A1 const& __a1) const {
1353*4d6fc14bSjoerg        return _VSTD::__invoke(__f_, __a0, __a1);
1354*4d6fc14bSjoerg    }
1355*4d6fc14bSjoerg
1356*4d6fc14bSjoerg    template <class _A0, class _A1, class _A2>
1357*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
1358*4d6fc14bSjoerg    typename __invoke_return2<type, _A0, _A1, _A2>::type
1359*4d6fc14bSjoerg    operator() (_A0& __a0, _A1& __a1, _A2& __a2) const {
1360*4d6fc14bSjoerg        return _VSTD::__invoke(__f_, __a0, __a1, __a2);
1361*4d6fc14bSjoerg    }
1362*4d6fc14bSjoerg
1363*4d6fc14bSjoerg    template <class _A0, class _A1, class _A2>
1364*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
1365*4d6fc14bSjoerg    typename __invoke_return2<type, _A0 const, _A1, _A2>::type
1366*4d6fc14bSjoerg    operator() (_A0 const& __a0, _A1& __a1, _A2& __a2) const {
1367*4d6fc14bSjoerg        return _VSTD::__invoke(__f_, __a0, __a1, __a2);
1368*4d6fc14bSjoerg    }
1369*4d6fc14bSjoerg
1370*4d6fc14bSjoerg    template <class _A0, class _A1, class _A2>
1371*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
1372*4d6fc14bSjoerg    typename __invoke_return2<type, _A0, _A1 const, _A2>::type
1373*4d6fc14bSjoerg    operator() (_A0& __a0, _A1 const& __a1, _A2& __a2) const {
1374*4d6fc14bSjoerg        return _VSTD::__invoke(__f_, __a0, __a1, __a2);
1375*4d6fc14bSjoerg    }
1376*4d6fc14bSjoerg
1377*4d6fc14bSjoerg    template <class _A0, class _A1, class _A2>
1378*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
1379*4d6fc14bSjoerg    typename __invoke_return2<type, _A0, _A1, _A2 const>::type
1380*4d6fc14bSjoerg    operator() (_A0& __a0, _A1& __a1, _A2 const& __a2) const {
1381*4d6fc14bSjoerg        return _VSTD::__invoke(__f_, __a0, __a1, __a2);
1382*4d6fc14bSjoerg    }
1383*4d6fc14bSjoerg
1384*4d6fc14bSjoerg    template <class _A0, class _A1, class _A2>
1385*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
1386*4d6fc14bSjoerg    typename __invoke_return2<type, _A0 const, _A1 const, _A2>::type
1387*4d6fc14bSjoerg    operator() (_A0 const& __a0, _A1 const& __a1, _A2& __a2) const {
1388*4d6fc14bSjoerg        return _VSTD::__invoke(__f_, __a0, __a1, __a2);
1389*4d6fc14bSjoerg    }
1390*4d6fc14bSjoerg
1391*4d6fc14bSjoerg    template <class _A0, class _A1, class _A2>
1392*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
1393*4d6fc14bSjoerg    typename __invoke_return2<type, _A0 const, _A1, _A2 const>::type
1394*4d6fc14bSjoerg    operator() (_A0 const& __a0, _A1& __a1, _A2 const& __a2) const {
1395*4d6fc14bSjoerg        return _VSTD::__invoke(__f_, __a0, __a1, __a2);
1396*4d6fc14bSjoerg    }
1397*4d6fc14bSjoerg
1398*4d6fc14bSjoerg    template <class _A0, class _A1, class _A2>
1399*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
1400*4d6fc14bSjoerg    typename __invoke_return2<type, _A0, _A1 const, _A2 const>::type
1401*4d6fc14bSjoerg    operator() (_A0& __a0, _A1 const& __a1, _A2 const& __a2) const {
1402*4d6fc14bSjoerg        return _VSTD::__invoke(__f_, __a0, __a1, __a2);
1403*4d6fc14bSjoerg    }
1404*4d6fc14bSjoerg
1405*4d6fc14bSjoerg    template <class _A0, class _A1, class _A2>
1406*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
1407*4d6fc14bSjoerg    typename __invoke_return2<type, _A0 const, _A1 const, _A2 const>::type
1408*4d6fc14bSjoerg    operator() (_A0 const& __a0, _A1 const& __a1, _A2 const& __a2) const {
1409*4d6fc14bSjoerg        return _VSTD::__invoke(__f_, __a0, __a1, __a2);
1410*4d6fc14bSjoerg    }
1411*4d6fc14bSjoerg#endif
1412*4d6fc14bSjoerg};
1413*4d6fc14bSjoerg
1414*4d6fc14bSjoergtemplate<class _Rp, class _Tp>
1415*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1416*4d6fc14bSjoerg__mem_fn<_Rp _Tp::*>
1417*4d6fc14bSjoergmem_fn(_Rp _Tp::* __pm) _NOEXCEPT
1418*4d6fc14bSjoerg{
1419*4d6fc14bSjoerg    return __mem_fn<_Rp _Tp::*>(__pm);
1420*4d6fc14bSjoerg}
1421*4d6fc14bSjoerg
1422*4d6fc14bSjoerg////////////////////////////////////////////////////////////////////////////////
1423*4d6fc14bSjoerg//                                FUNCTION
1424*4d6fc14bSjoerg//==============================================================================
1425*4d6fc14bSjoerg
1426*4d6fc14bSjoerg// bad_function_call
1427*4d6fc14bSjoerg
1428*4d6fc14bSjoergclass _LIBCPP_EXCEPTION_ABI bad_function_call
1429*4d6fc14bSjoerg    : public exception
1430*4d6fc14bSjoerg{
1431*4d6fc14bSjoerg#ifdef _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
1432*4d6fc14bSjoergpublic:
1433*4d6fc14bSjoerg    virtual ~bad_function_call() _NOEXCEPT;
1434*4d6fc14bSjoerg
1435*4d6fc14bSjoerg    virtual const char* what() const _NOEXCEPT;
1436*4d6fc14bSjoerg#endif
1437*4d6fc14bSjoerg};
1438*4d6fc14bSjoerg
1439*4d6fc14bSjoerg_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
1440*4d6fc14bSjoergvoid __throw_bad_function_call()
1441*4d6fc14bSjoerg{
1442*4d6fc14bSjoerg#ifndef _LIBCPP_NO_EXCEPTIONS
1443*4d6fc14bSjoerg    throw bad_function_call();
1444*4d6fc14bSjoerg#else
1445*4d6fc14bSjoerg    _VSTD::abort();
1446*4d6fc14bSjoerg#endif
1447*4d6fc14bSjoerg}
1448*4d6fc14bSjoerg
1449*4d6fc14bSjoerg#if defined(_LIBCPP_CXX03_LANG) && !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS) && __has_attribute(deprecated)
1450*4d6fc14bSjoerg#   define _LIBCPP_DEPRECATED_CXX03_FUNCTION \
1451*4d6fc14bSjoerg        __attribute__((deprecated("Using std::function in C++03 is not supported anymore. Please upgrade to C++11 or later, or use a different type")))
1452*4d6fc14bSjoerg#else
1453*4d6fc14bSjoerg#   define _LIBCPP_DEPRECATED_CXX03_FUNCTION /* nothing */
1454*4d6fc14bSjoerg#endif
1455*4d6fc14bSjoerg
1456*4d6fc14bSjoergtemplate<class _Fp> class _LIBCPP_DEPRECATED_CXX03_FUNCTION _LIBCPP_TEMPLATE_VIS function; // undefined
1457*4d6fc14bSjoerg
1458*4d6fc14bSjoergnamespace __function
1459*4d6fc14bSjoerg{
1460*4d6fc14bSjoerg
1461*4d6fc14bSjoergtemplate<class _Rp>
1462*4d6fc14bSjoergstruct __maybe_derive_from_unary_function
1463*4d6fc14bSjoerg{
1464*4d6fc14bSjoerg};
1465*4d6fc14bSjoerg
1466*4d6fc14bSjoergtemplate<class _Rp, class _A1>
1467*4d6fc14bSjoergstruct __maybe_derive_from_unary_function<_Rp(_A1)>
1468*4d6fc14bSjoerg    : public unary_function<_A1, _Rp>
1469*4d6fc14bSjoerg{
1470*4d6fc14bSjoerg};
1471*4d6fc14bSjoerg
1472*4d6fc14bSjoergtemplate<class _Rp>
1473*4d6fc14bSjoergstruct __maybe_derive_from_binary_function
1474*4d6fc14bSjoerg{
1475*4d6fc14bSjoerg};
1476*4d6fc14bSjoerg
1477*4d6fc14bSjoergtemplate<class _Rp, class _A1, class _A2>
1478*4d6fc14bSjoergstruct __maybe_derive_from_binary_function<_Rp(_A1, _A2)>
1479*4d6fc14bSjoerg    : public binary_function<_A1, _A2, _Rp>
1480*4d6fc14bSjoerg{
1481*4d6fc14bSjoerg};
1482*4d6fc14bSjoerg
1483*4d6fc14bSjoergtemplate <class _Fp>
1484*4d6fc14bSjoerg_LIBCPP_INLINE_VISIBILITY
1485*4d6fc14bSjoergbool __not_null(_Fp const&) { return true; }
1486*4d6fc14bSjoerg
1487*4d6fc14bSjoergtemplate <class _Fp>
1488*4d6fc14bSjoerg_LIBCPP_INLINE_VISIBILITY
1489*4d6fc14bSjoergbool __not_null(_Fp* __ptr) { return __ptr; }
1490*4d6fc14bSjoerg
1491*4d6fc14bSjoergtemplate <class _Ret, class _Class>
1492*4d6fc14bSjoerg_LIBCPP_INLINE_VISIBILITY
1493*4d6fc14bSjoergbool __not_null(_Ret _Class::*__ptr) { return __ptr; }
1494*4d6fc14bSjoerg
1495*4d6fc14bSjoergtemplate <class _Fp>
1496*4d6fc14bSjoerg_LIBCPP_INLINE_VISIBILITY
1497*4d6fc14bSjoergbool __not_null(function<_Fp> const& __f) { return !!__f; }
1498*4d6fc14bSjoerg
1499*4d6fc14bSjoerg#ifdef _LIBCPP_HAS_EXTENSION_BLOCKS
1500*4d6fc14bSjoergtemplate <class _Rp, class ..._Args>
1501*4d6fc14bSjoerg_LIBCPP_INLINE_VISIBILITY
1502*4d6fc14bSjoergbool __not_null(_Rp (^__p)(_Args...)) { return __p; }
1503*4d6fc14bSjoerg#endif
1504*4d6fc14bSjoerg
1505*4d6fc14bSjoerg} // namespace __function
1506*4d6fc14bSjoerg
1507*4d6fc14bSjoerg#ifndef _LIBCPP_CXX03_LANG
1508*4d6fc14bSjoerg
1509*4d6fc14bSjoergnamespace __function {
1510*4d6fc14bSjoerg
1511*4d6fc14bSjoerg// __alloc_func holds a functor and an allocator.
1512*4d6fc14bSjoerg
1513*4d6fc14bSjoergtemplate <class _Fp, class _Ap, class _FB> class __alloc_func;
1514*4d6fc14bSjoergtemplate <class _Fp, class _FB>
1515*4d6fc14bSjoergclass __default_alloc_func;
1516*4d6fc14bSjoerg
1517*4d6fc14bSjoergtemplate <class _Fp, class _Ap, class _Rp, class... _ArgTypes>
1518*4d6fc14bSjoergclass __alloc_func<_Fp, _Ap, _Rp(_ArgTypes...)>
1519*4d6fc14bSjoerg{
1520*4d6fc14bSjoerg    __compressed_pair<_Fp, _Ap> __f_;
1521*4d6fc14bSjoerg
1522*4d6fc14bSjoerg  public:
1523*4d6fc14bSjoerg    typedef _LIBCPP_NODEBUG_TYPE _Fp _Target;
1524*4d6fc14bSjoerg    typedef _LIBCPP_NODEBUG_TYPE _Ap _Alloc;
1525*4d6fc14bSjoerg
1526*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
1527*4d6fc14bSjoerg    const _Target& __target() const { return __f_.first(); }
1528*4d6fc14bSjoerg
1529*4d6fc14bSjoerg    // WIN32 APIs may define __allocator, so use __get_allocator instead.
1530*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
1531*4d6fc14bSjoerg    const _Alloc& __get_allocator() const { return __f_.second(); }
1532*4d6fc14bSjoerg
1533*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
1534*4d6fc14bSjoerg    explicit __alloc_func(_Target&& __f)
1535*4d6fc14bSjoerg        : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1536*4d6fc14bSjoerg               _VSTD::forward_as_tuple())
1537*4d6fc14bSjoerg    {
1538*4d6fc14bSjoerg    }
1539*4d6fc14bSjoerg
1540*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
1541*4d6fc14bSjoerg    explicit __alloc_func(const _Target& __f, const _Alloc& __a)
1542*4d6fc14bSjoerg        : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1543*4d6fc14bSjoerg               _VSTD::forward_as_tuple(__a))
1544*4d6fc14bSjoerg    {
1545*4d6fc14bSjoerg    }
1546*4d6fc14bSjoerg
1547*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
1548*4d6fc14bSjoerg    explicit __alloc_func(const _Target& __f, _Alloc&& __a)
1549*4d6fc14bSjoerg        : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1550*4d6fc14bSjoerg               _VSTD::forward_as_tuple(_VSTD::move(__a)))
1551*4d6fc14bSjoerg    {
1552*4d6fc14bSjoerg    }
1553*4d6fc14bSjoerg
1554*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
1555*4d6fc14bSjoerg    explicit __alloc_func(_Target&& __f, _Alloc&& __a)
1556*4d6fc14bSjoerg        : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1557*4d6fc14bSjoerg               _VSTD::forward_as_tuple(_VSTD::move(__a)))
1558*4d6fc14bSjoerg    {
1559*4d6fc14bSjoerg    }
1560*4d6fc14bSjoerg
1561*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
1562*4d6fc14bSjoerg    _Rp operator()(_ArgTypes&&... __arg)
1563*4d6fc14bSjoerg    {
1564*4d6fc14bSjoerg        typedef __invoke_void_return_wrapper<_Rp> _Invoker;
1565*4d6fc14bSjoerg        return _Invoker::__call(__f_.first(),
1566*4d6fc14bSjoerg                                _VSTD::forward<_ArgTypes>(__arg)...);
1567*4d6fc14bSjoerg    }
1568*4d6fc14bSjoerg
1569*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
1570*4d6fc14bSjoerg    __alloc_func* __clone() const
1571*4d6fc14bSjoerg    {
1572*4d6fc14bSjoerg        typedef allocator_traits<_Alloc> __alloc_traits;
1573*4d6fc14bSjoerg        typedef
1574*4d6fc14bSjoerg            typename __rebind_alloc_helper<__alloc_traits, __alloc_func>::type
1575*4d6fc14bSjoerg                _AA;
1576*4d6fc14bSjoerg        _AA __a(__f_.second());
1577*4d6fc14bSjoerg        typedef __allocator_destructor<_AA> _Dp;
1578*4d6fc14bSjoerg        unique_ptr<__alloc_func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1579*4d6fc14bSjoerg        ::new ((void*)__hold.get()) __alloc_func(__f_.first(), _Alloc(__a));
1580*4d6fc14bSjoerg        return __hold.release();
1581*4d6fc14bSjoerg    }
1582*4d6fc14bSjoerg
1583*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
1584*4d6fc14bSjoerg    void destroy() _NOEXCEPT { __f_.~__compressed_pair<_Target, _Alloc>(); }
1585*4d6fc14bSjoerg
1586*4d6fc14bSjoerg    static void __destroy_and_delete(__alloc_func* __f) {
1587*4d6fc14bSjoerg      typedef allocator_traits<_Alloc> __alloc_traits;
1588*4d6fc14bSjoerg      typedef typename __rebind_alloc_helper<__alloc_traits, __alloc_func>::type
1589*4d6fc14bSjoerg          _FunAlloc;
1590*4d6fc14bSjoerg      _FunAlloc __a(__f->__get_allocator());
1591*4d6fc14bSjoerg      __f->destroy();
1592*4d6fc14bSjoerg      __a.deallocate(__f, 1);
1593*4d6fc14bSjoerg    }
1594*4d6fc14bSjoerg};
1595*4d6fc14bSjoerg
1596*4d6fc14bSjoergtemplate <class _Fp, class _Rp, class... _ArgTypes>
1597*4d6fc14bSjoergclass __default_alloc_func<_Fp, _Rp(_ArgTypes...)> {
1598*4d6fc14bSjoerg  _Fp __f_;
1599*4d6fc14bSjoerg
1600*4d6fc14bSjoergpublic:
1601*4d6fc14bSjoerg  typedef _LIBCPP_NODEBUG_TYPE _Fp _Target;
1602*4d6fc14bSjoerg
1603*4d6fc14bSjoerg  _LIBCPP_INLINE_VISIBILITY
1604*4d6fc14bSjoerg  const _Target& __target() const { return __f_; }
1605*4d6fc14bSjoerg
1606*4d6fc14bSjoerg  _LIBCPP_INLINE_VISIBILITY
1607*4d6fc14bSjoerg  explicit __default_alloc_func(_Target&& __f) : __f_(_VSTD::move(__f)) {}
1608*4d6fc14bSjoerg
1609*4d6fc14bSjoerg  _LIBCPP_INLINE_VISIBILITY
1610*4d6fc14bSjoerg  explicit __default_alloc_func(const _Target& __f) : __f_(__f) {}
1611*4d6fc14bSjoerg
1612*4d6fc14bSjoerg  _LIBCPP_INLINE_VISIBILITY
1613*4d6fc14bSjoerg  _Rp operator()(_ArgTypes&&... __arg) {
1614*4d6fc14bSjoerg    typedef __invoke_void_return_wrapper<_Rp> _Invoker;
1615*4d6fc14bSjoerg    return _Invoker::__call(__f_, _VSTD::forward<_ArgTypes>(__arg)...);
1616*4d6fc14bSjoerg  }
1617*4d6fc14bSjoerg
1618*4d6fc14bSjoerg  _LIBCPP_INLINE_VISIBILITY
1619*4d6fc14bSjoerg  __default_alloc_func* __clone() const {
1620*4d6fc14bSjoerg      __builtin_new_allocator::__holder_t __hold =
1621*4d6fc14bSjoerg        __builtin_new_allocator::__allocate_type<__default_alloc_func>(1);
1622*4d6fc14bSjoerg    __default_alloc_func* __res =
1623*4d6fc14bSjoerg        ::new ((void*)__hold.get()) __default_alloc_func(__f_);
1624*4d6fc14bSjoerg    (void)__hold.release();
1625*4d6fc14bSjoerg    return __res;
1626*4d6fc14bSjoerg  }
1627*4d6fc14bSjoerg
1628*4d6fc14bSjoerg  _LIBCPP_INLINE_VISIBILITY
1629*4d6fc14bSjoerg  void destroy() _NOEXCEPT { __f_.~_Target(); }
1630*4d6fc14bSjoerg
1631*4d6fc14bSjoerg  static void __destroy_and_delete(__default_alloc_func* __f) {
1632*4d6fc14bSjoerg    __f->destroy();
1633*4d6fc14bSjoerg      __builtin_new_allocator::__deallocate_type<__default_alloc_func>(__f, 1);
1634*4d6fc14bSjoerg  }
1635*4d6fc14bSjoerg};
1636*4d6fc14bSjoerg
1637*4d6fc14bSjoerg// __base provides an abstract interface for copyable functors.
1638*4d6fc14bSjoerg
1639*4d6fc14bSjoergtemplate<class _Fp> class _LIBCPP_TEMPLATE_VIS __base;
1640*4d6fc14bSjoerg
1641*4d6fc14bSjoergtemplate<class _Rp, class ..._ArgTypes>
1642*4d6fc14bSjoergclass __base<_Rp(_ArgTypes...)>
1643*4d6fc14bSjoerg{
1644*4d6fc14bSjoerg    __base(const __base&);
1645*4d6fc14bSjoerg    __base& operator=(const __base&);
1646*4d6fc14bSjoergpublic:
1647*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY __base() {}
1648*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY virtual ~__base() {}
1649*4d6fc14bSjoerg    virtual __base* __clone() const = 0;
1650*4d6fc14bSjoerg    virtual void __clone(__base*) const = 0;
1651*4d6fc14bSjoerg    virtual void destroy() _NOEXCEPT = 0;
1652*4d6fc14bSjoerg    virtual void destroy_deallocate() _NOEXCEPT = 0;
1653*4d6fc14bSjoerg    virtual _Rp operator()(_ArgTypes&& ...) = 0;
1654*4d6fc14bSjoerg#ifndef _LIBCPP_NO_RTTI
1655*4d6fc14bSjoerg    virtual const void* target(const type_info&) const _NOEXCEPT = 0;
1656*4d6fc14bSjoerg    virtual const std::type_info& target_type() const _NOEXCEPT = 0;
1657*4d6fc14bSjoerg#endif // _LIBCPP_NO_RTTI
1658*4d6fc14bSjoerg};
1659*4d6fc14bSjoerg
1660*4d6fc14bSjoerg// __func implements __base for a given functor type.
1661*4d6fc14bSjoerg
1662*4d6fc14bSjoergtemplate<class _FD, class _Alloc, class _FB> class __func;
1663*4d6fc14bSjoerg
1664*4d6fc14bSjoergtemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1665*4d6fc14bSjoergclass __func<_Fp, _Alloc, _Rp(_ArgTypes...)>
1666*4d6fc14bSjoerg    : public  __base<_Rp(_ArgTypes...)>
1667*4d6fc14bSjoerg{
1668*4d6fc14bSjoerg    __alloc_func<_Fp, _Alloc, _Rp(_ArgTypes...)> __f_;
1669*4d6fc14bSjoergpublic:
1670*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
1671*4d6fc14bSjoerg    explicit __func(_Fp&& __f)
1672*4d6fc14bSjoerg        : __f_(_VSTD::move(__f)) {}
1673*4d6fc14bSjoerg
1674*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
1675*4d6fc14bSjoerg    explicit __func(const _Fp& __f, const _Alloc& __a)
1676*4d6fc14bSjoerg        : __f_(__f, __a) {}
1677*4d6fc14bSjoerg
1678*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
1679*4d6fc14bSjoerg    explicit __func(const _Fp& __f, _Alloc&& __a)
1680*4d6fc14bSjoerg        : __f_(__f, _VSTD::move(__a)) {}
1681*4d6fc14bSjoerg
1682*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
1683*4d6fc14bSjoerg    explicit __func(_Fp&& __f, _Alloc&& __a)
1684*4d6fc14bSjoerg        : __f_(_VSTD::move(__f), _VSTD::move(__a)) {}
1685*4d6fc14bSjoerg
1686*4d6fc14bSjoerg    virtual __base<_Rp(_ArgTypes...)>* __clone() const;
1687*4d6fc14bSjoerg    virtual void __clone(__base<_Rp(_ArgTypes...)>*) const;
1688*4d6fc14bSjoerg    virtual void destroy() _NOEXCEPT;
1689*4d6fc14bSjoerg    virtual void destroy_deallocate() _NOEXCEPT;
1690*4d6fc14bSjoerg    virtual _Rp operator()(_ArgTypes&&... __arg);
1691*4d6fc14bSjoerg#ifndef _LIBCPP_NO_RTTI
1692*4d6fc14bSjoerg    virtual const void* target(const type_info&) const _NOEXCEPT;
1693*4d6fc14bSjoerg    virtual const std::type_info& target_type() const _NOEXCEPT;
1694*4d6fc14bSjoerg#endif // _LIBCPP_NO_RTTI
1695*4d6fc14bSjoerg};
1696*4d6fc14bSjoerg
1697*4d6fc14bSjoergtemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1698*4d6fc14bSjoerg__base<_Rp(_ArgTypes...)>*
1699*4d6fc14bSjoerg__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const
1700*4d6fc14bSjoerg{
1701*4d6fc14bSjoerg    typedef allocator_traits<_Alloc> __alloc_traits;
1702*4d6fc14bSjoerg    typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
1703*4d6fc14bSjoerg    _Ap __a(__f_.__get_allocator());
1704*4d6fc14bSjoerg    typedef __allocator_destructor<_Ap> _Dp;
1705*4d6fc14bSjoerg    unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1706*4d6fc14bSjoerg    ::new ((void*)__hold.get()) __func(__f_.__target(), _Alloc(__a));
1707*4d6fc14bSjoerg    return __hold.release();
1708*4d6fc14bSjoerg}
1709*4d6fc14bSjoerg
1710*4d6fc14bSjoergtemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1711*4d6fc14bSjoergvoid
1712*4d6fc14bSjoerg__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const
1713*4d6fc14bSjoerg{
1714*4d6fc14bSjoerg    ::new ((void*)__p) __func(__f_.__target(), __f_.__get_allocator());
1715*4d6fc14bSjoerg}
1716*4d6fc14bSjoerg
1717*4d6fc14bSjoergtemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1718*4d6fc14bSjoergvoid
1719*4d6fc14bSjoerg__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPT
1720*4d6fc14bSjoerg{
1721*4d6fc14bSjoerg    __f_.destroy();
1722*4d6fc14bSjoerg}
1723*4d6fc14bSjoerg
1724*4d6fc14bSjoergtemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1725*4d6fc14bSjoergvoid
1726*4d6fc14bSjoerg__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT
1727*4d6fc14bSjoerg{
1728*4d6fc14bSjoerg    typedef allocator_traits<_Alloc> __alloc_traits;
1729*4d6fc14bSjoerg    typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
1730*4d6fc14bSjoerg    _Ap __a(__f_.__get_allocator());
1731*4d6fc14bSjoerg    __f_.destroy();
1732*4d6fc14bSjoerg    __a.deallocate(this, 1);
1733*4d6fc14bSjoerg}
1734*4d6fc14bSjoerg
1735*4d6fc14bSjoergtemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1736*4d6fc14bSjoerg_Rp
1737*4d6fc14bSjoerg__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg)
1738*4d6fc14bSjoerg{
1739*4d6fc14bSjoerg    return __f_(_VSTD::forward<_ArgTypes>(__arg)...);
1740*4d6fc14bSjoerg}
1741*4d6fc14bSjoerg
1742*4d6fc14bSjoerg#ifndef _LIBCPP_NO_RTTI
1743*4d6fc14bSjoerg
1744*4d6fc14bSjoergtemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1745*4d6fc14bSjoergconst void*
1746*4d6fc14bSjoerg__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT
1747*4d6fc14bSjoerg{
1748*4d6fc14bSjoerg    if (__ti == typeid(_Fp))
1749*4d6fc14bSjoerg        return &__f_.__target();
1750*4d6fc14bSjoerg    return nullptr;
1751*4d6fc14bSjoerg}
1752*4d6fc14bSjoerg
1753*4d6fc14bSjoergtemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1754*4d6fc14bSjoergconst std::type_info&
1755*4d6fc14bSjoerg__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
1756*4d6fc14bSjoerg{
1757*4d6fc14bSjoerg    return typeid(_Fp);
1758*4d6fc14bSjoerg}
1759*4d6fc14bSjoerg
1760*4d6fc14bSjoerg#endif // _LIBCPP_NO_RTTI
1761*4d6fc14bSjoerg
1762*4d6fc14bSjoerg// __value_func creates a value-type from a __func.
1763*4d6fc14bSjoerg
1764*4d6fc14bSjoergtemplate <class _Fp> class __value_func;
1765*4d6fc14bSjoerg
1766*4d6fc14bSjoergtemplate <class _Rp, class... _ArgTypes> class __value_func<_Rp(_ArgTypes...)>
1767*4d6fc14bSjoerg{
1768*4d6fc14bSjoerg    typename aligned_storage<3 * sizeof(void*)>::type __buf_;
1769*4d6fc14bSjoerg
1770*4d6fc14bSjoerg    typedef __base<_Rp(_ArgTypes...)> __func;
1771*4d6fc14bSjoerg    __func* __f_;
1772*4d6fc14bSjoerg
1773*4d6fc14bSjoerg    _LIBCPP_NO_CFI static __func* __as_base(void* p)
1774*4d6fc14bSjoerg    {
1775*4d6fc14bSjoerg        return reinterpret_cast<__func*>(p);
1776*4d6fc14bSjoerg    }
1777*4d6fc14bSjoerg
1778*4d6fc14bSjoerg  public:
1779*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
1780*4d6fc14bSjoerg    __value_func() _NOEXCEPT : __f_(nullptr) {}
1781*4d6fc14bSjoerg
1782*4d6fc14bSjoerg    template <class _Fp, class _Alloc>
1783*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY __value_func(_Fp&& __f, const _Alloc& __a)
1784*4d6fc14bSjoerg        : __f_(nullptr)
1785*4d6fc14bSjoerg    {
1786*4d6fc14bSjoerg        typedef allocator_traits<_Alloc> __alloc_traits;
1787*4d6fc14bSjoerg        typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _Fun;
1788*4d6fc14bSjoerg        typedef typename __rebind_alloc_helper<__alloc_traits, _Fun>::type
1789*4d6fc14bSjoerg            _FunAlloc;
1790*4d6fc14bSjoerg
1791*4d6fc14bSjoerg        if (__function::__not_null(__f))
1792*4d6fc14bSjoerg        {
1793*4d6fc14bSjoerg            _FunAlloc __af(__a);
1794*4d6fc14bSjoerg            if (sizeof(_Fun) <= sizeof(__buf_) &&
1795*4d6fc14bSjoerg                is_nothrow_copy_constructible<_Fp>::value &&
1796*4d6fc14bSjoerg                is_nothrow_copy_constructible<_FunAlloc>::value)
1797*4d6fc14bSjoerg            {
1798*4d6fc14bSjoerg                __f_ =
1799*4d6fc14bSjoerg                    ::new ((void*)&__buf_) _Fun(_VSTD::move(__f), _Alloc(__af));
1800*4d6fc14bSjoerg            }
1801*4d6fc14bSjoerg            else
1802*4d6fc14bSjoerg            {
1803*4d6fc14bSjoerg                typedef __allocator_destructor<_FunAlloc> _Dp;
1804*4d6fc14bSjoerg                unique_ptr<__func, _Dp> __hold(__af.allocate(1), _Dp(__af, 1));
1805*4d6fc14bSjoerg                ::new ((void*)__hold.get()) _Fun(_VSTD::move(__f), _Alloc(__a));
1806*4d6fc14bSjoerg                __f_ = __hold.release();
1807*4d6fc14bSjoerg            }
1808*4d6fc14bSjoerg        }
1809*4d6fc14bSjoerg    }
1810*4d6fc14bSjoerg
1811*4d6fc14bSjoerg    template <class _Fp,
1812*4d6fc14bSjoerg        class = typename enable_if<!is_same<typename decay<_Fp>::type, __value_func>::value>::type>
1813*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY explicit __value_func(_Fp&& __f)
1814*4d6fc14bSjoerg        : __value_func(_VSTD::forward<_Fp>(__f), allocator<_Fp>()) {}
1815*4d6fc14bSjoerg
1816*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
1817*4d6fc14bSjoerg    __value_func(const __value_func& __f)
1818*4d6fc14bSjoerg    {
1819*4d6fc14bSjoerg        if (__f.__f_ == nullptr)
1820*4d6fc14bSjoerg            __f_ = nullptr;
1821*4d6fc14bSjoerg        else if ((void*)__f.__f_ == &__f.__buf_)
1822*4d6fc14bSjoerg        {
1823*4d6fc14bSjoerg            __f_ = __as_base(&__buf_);
1824*4d6fc14bSjoerg            __f.__f_->__clone(__f_);
1825*4d6fc14bSjoerg        }
1826*4d6fc14bSjoerg        else
1827*4d6fc14bSjoerg            __f_ = __f.__f_->__clone();
1828*4d6fc14bSjoerg    }
1829*4d6fc14bSjoerg
1830*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
1831*4d6fc14bSjoerg    __value_func(__value_func&& __f) _NOEXCEPT
1832*4d6fc14bSjoerg    {
1833*4d6fc14bSjoerg        if (__f.__f_ == nullptr)
1834*4d6fc14bSjoerg            __f_ = nullptr;
1835*4d6fc14bSjoerg        else if ((void*)__f.__f_ == &__f.__buf_)
1836*4d6fc14bSjoerg        {
1837*4d6fc14bSjoerg            __f_ = __as_base(&__buf_);
1838*4d6fc14bSjoerg            __f.__f_->__clone(__f_);
1839*4d6fc14bSjoerg        }
1840*4d6fc14bSjoerg        else
1841*4d6fc14bSjoerg        {
1842*4d6fc14bSjoerg            __f_ = __f.__f_;
1843*4d6fc14bSjoerg            __f.__f_ = nullptr;
1844*4d6fc14bSjoerg        }
1845*4d6fc14bSjoerg    }
1846*4d6fc14bSjoerg
1847*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
1848*4d6fc14bSjoerg    ~__value_func()
1849*4d6fc14bSjoerg    {
1850*4d6fc14bSjoerg        if ((void*)__f_ == &__buf_)
1851*4d6fc14bSjoerg            __f_->destroy();
1852*4d6fc14bSjoerg        else if (__f_)
1853*4d6fc14bSjoerg            __f_->destroy_deallocate();
1854*4d6fc14bSjoerg    }
1855*4d6fc14bSjoerg
1856*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
1857*4d6fc14bSjoerg    __value_func& operator=(__value_func&& __f)
1858*4d6fc14bSjoerg    {
1859*4d6fc14bSjoerg        *this = nullptr;
1860*4d6fc14bSjoerg        if (__f.__f_ == nullptr)
1861*4d6fc14bSjoerg            __f_ = nullptr;
1862*4d6fc14bSjoerg        else if ((void*)__f.__f_ == &__f.__buf_)
1863*4d6fc14bSjoerg        {
1864*4d6fc14bSjoerg            __f_ = __as_base(&__buf_);
1865*4d6fc14bSjoerg            __f.__f_->__clone(__f_);
1866*4d6fc14bSjoerg        }
1867*4d6fc14bSjoerg        else
1868*4d6fc14bSjoerg        {
1869*4d6fc14bSjoerg            __f_ = __f.__f_;
1870*4d6fc14bSjoerg            __f.__f_ = nullptr;
1871*4d6fc14bSjoerg        }
1872*4d6fc14bSjoerg        return *this;
1873*4d6fc14bSjoerg    }
1874*4d6fc14bSjoerg
1875*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
1876*4d6fc14bSjoerg    __value_func& operator=(nullptr_t)
1877*4d6fc14bSjoerg    {
1878*4d6fc14bSjoerg        __func* __f = __f_;
1879*4d6fc14bSjoerg        __f_ = nullptr;
1880*4d6fc14bSjoerg        if ((void*)__f == &__buf_)
1881*4d6fc14bSjoerg            __f->destroy();
1882*4d6fc14bSjoerg        else if (__f)
1883*4d6fc14bSjoerg            __f->destroy_deallocate();
1884*4d6fc14bSjoerg        return *this;
1885*4d6fc14bSjoerg    }
1886*4d6fc14bSjoerg
1887*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
1888*4d6fc14bSjoerg    _Rp operator()(_ArgTypes&&... __args) const
1889*4d6fc14bSjoerg    {
1890*4d6fc14bSjoerg        if (__f_ == nullptr)
1891*4d6fc14bSjoerg            __throw_bad_function_call();
1892*4d6fc14bSjoerg        return (*__f_)(_VSTD::forward<_ArgTypes>(__args)...);
1893*4d6fc14bSjoerg    }
1894*4d6fc14bSjoerg
1895*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
1896*4d6fc14bSjoerg    void swap(__value_func& __f) _NOEXCEPT
1897*4d6fc14bSjoerg    {
1898*4d6fc14bSjoerg        if (&__f == this)
1899*4d6fc14bSjoerg            return;
1900*4d6fc14bSjoerg        if ((void*)__f_ == &__buf_ && (void*)__f.__f_ == &__f.__buf_)
1901*4d6fc14bSjoerg        {
1902*4d6fc14bSjoerg            typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
1903*4d6fc14bSjoerg            __func* __t = __as_base(&__tempbuf);
1904*4d6fc14bSjoerg            __f_->__clone(__t);
1905*4d6fc14bSjoerg            __f_->destroy();
1906*4d6fc14bSjoerg            __f_ = nullptr;
1907*4d6fc14bSjoerg            __f.__f_->__clone(__as_base(&__buf_));
1908*4d6fc14bSjoerg            __f.__f_->destroy();
1909*4d6fc14bSjoerg            __f.__f_ = nullptr;
1910*4d6fc14bSjoerg            __f_ = __as_base(&__buf_);
1911*4d6fc14bSjoerg            __t->__clone(__as_base(&__f.__buf_));
1912*4d6fc14bSjoerg            __t->destroy();
1913*4d6fc14bSjoerg            __f.__f_ = __as_base(&__f.__buf_);
1914*4d6fc14bSjoerg        }
1915*4d6fc14bSjoerg        else if ((void*)__f_ == &__buf_)
1916*4d6fc14bSjoerg        {
1917*4d6fc14bSjoerg            __f_->__clone(__as_base(&__f.__buf_));
1918*4d6fc14bSjoerg            __f_->destroy();
1919*4d6fc14bSjoerg            __f_ = __f.__f_;
1920*4d6fc14bSjoerg            __f.__f_ = __as_base(&__f.__buf_);
1921*4d6fc14bSjoerg        }
1922*4d6fc14bSjoerg        else if ((void*)__f.__f_ == &__f.__buf_)
1923*4d6fc14bSjoerg        {
1924*4d6fc14bSjoerg            __f.__f_->__clone(__as_base(&__buf_));
1925*4d6fc14bSjoerg            __f.__f_->destroy();
1926*4d6fc14bSjoerg            __f.__f_ = __f_;
1927*4d6fc14bSjoerg            __f_ = __as_base(&__buf_);
1928*4d6fc14bSjoerg        }
1929*4d6fc14bSjoerg        else
1930*4d6fc14bSjoerg            _VSTD::swap(__f_, __f.__f_);
1931*4d6fc14bSjoerg    }
1932*4d6fc14bSjoerg
1933*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
1934*4d6fc14bSjoerg    _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT { return __f_ != nullptr; }
1935*4d6fc14bSjoerg
1936*4d6fc14bSjoerg#ifndef _LIBCPP_NO_RTTI
1937*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
1938*4d6fc14bSjoerg    const std::type_info& target_type() const _NOEXCEPT
1939*4d6fc14bSjoerg    {
1940*4d6fc14bSjoerg        if (__f_ == nullptr)
1941*4d6fc14bSjoerg            return typeid(void);
1942*4d6fc14bSjoerg        return __f_->target_type();
1943*4d6fc14bSjoerg    }
1944*4d6fc14bSjoerg
1945*4d6fc14bSjoerg    template <typename _Tp>
1946*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY const _Tp* target() const _NOEXCEPT
1947*4d6fc14bSjoerg    {
1948*4d6fc14bSjoerg        if (__f_ == nullptr)
1949*4d6fc14bSjoerg            return nullptr;
1950*4d6fc14bSjoerg        return (const _Tp*)__f_->target(typeid(_Tp));
1951*4d6fc14bSjoerg    }
1952*4d6fc14bSjoerg#endif // _LIBCPP_NO_RTTI
1953*4d6fc14bSjoerg};
1954*4d6fc14bSjoerg
1955*4d6fc14bSjoerg// Storage for a functor object, to be used with __policy to manage copy and
1956*4d6fc14bSjoerg// destruction.
1957*4d6fc14bSjoergunion __policy_storage
1958*4d6fc14bSjoerg{
1959*4d6fc14bSjoerg    mutable char __small[sizeof(void*) * 2];
1960*4d6fc14bSjoerg    void* __large;
1961*4d6fc14bSjoerg};
1962*4d6fc14bSjoerg
1963*4d6fc14bSjoerg// True if _Fun can safely be held in __policy_storage.__small.
1964*4d6fc14bSjoergtemplate <typename _Fun>
1965*4d6fc14bSjoergstruct __use_small_storage
1966*4d6fc14bSjoerg    : public integral_constant<
1967*4d6fc14bSjoerg          bool, sizeof(_Fun) <= sizeof(__policy_storage) &&
1968*4d6fc14bSjoerg                    _LIBCPP_ALIGNOF(_Fun) <= _LIBCPP_ALIGNOF(__policy_storage) &&
1969*4d6fc14bSjoerg                    is_trivially_copy_constructible<_Fun>::value &&
1970*4d6fc14bSjoerg                    is_trivially_destructible<_Fun>::value> {};
1971*4d6fc14bSjoerg
1972*4d6fc14bSjoerg// Policy contains information about how to copy, destroy, and move the
1973*4d6fc14bSjoerg// underlying functor. You can think of it as a vtable of sorts.
1974*4d6fc14bSjoergstruct __policy
1975*4d6fc14bSjoerg{
1976*4d6fc14bSjoerg    // Used to copy or destroy __large values. null for trivial objects.
1977*4d6fc14bSjoerg    void* (*const __clone)(const void*);
1978*4d6fc14bSjoerg    void (*const __destroy)(void*);
1979*4d6fc14bSjoerg
1980*4d6fc14bSjoerg    // True if this is the null policy (no value).
1981*4d6fc14bSjoerg    const bool __is_null;
1982*4d6fc14bSjoerg
1983*4d6fc14bSjoerg    // The target type. May be null if RTTI is disabled.
1984*4d6fc14bSjoerg    const std::type_info* const __type_info;
1985*4d6fc14bSjoerg
1986*4d6fc14bSjoerg    // Returns a pointer to a static policy object suitable for the functor
1987*4d6fc14bSjoerg    // type.
1988*4d6fc14bSjoerg    template <typename _Fun>
1989*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY static const __policy* __create()
1990*4d6fc14bSjoerg    {
1991*4d6fc14bSjoerg        return __choose_policy<_Fun>(__use_small_storage<_Fun>());
1992*4d6fc14bSjoerg    }
1993*4d6fc14bSjoerg
1994*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
1995*4d6fc14bSjoerg    static const __policy* __create_empty()
1996*4d6fc14bSjoerg    {
1997*4d6fc14bSjoerg        static const _LIBCPP_CONSTEXPR __policy __policy_ = {nullptr, nullptr,
1998*4d6fc14bSjoerg                                                             true,
1999*4d6fc14bSjoerg#ifndef _LIBCPP_NO_RTTI
2000*4d6fc14bSjoerg                                                             &typeid(void)
2001*4d6fc14bSjoerg#else
2002*4d6fc14bSjoerg                                                             nullptr
2003*4d6fc14bSjoerg#endif
2004*4d6fc14bSjoerg        };
2005*4d6fc14bSjoerg        return &__policy_;
2006*4d6fc14bSjoerg    }
2007*4d6fc14bSjoerg
2008*4d6fc14bSjoerg  private:
2009*4d6fc14bSjoerg    template <typename _Fun> static void* __large_clone(const void* __s)
2010*4d6fc14bSjoerg    {
2011*4d6fc14bSjoerg        const _Fun* __f = static_cast<const _Fun*>(__s);
2012*4d6fc14bSjoerg        return __f->__clone();
2013*4d6fc14bSjoerg    }
2014*4d6fc14bSjoerg
2015*4d6fc14bSjoerg    template <typename _Fun>
2016*4d6fc14bSjoerg    static void __large_destroy(void* __s) {
2017*4d6fc14bSjoerg      _Fun::__destroy_and_delete(static_cast<_Fun*>(__s));
2018*4d6fc14bSjoerg    }
2019*4d6fc14bSjoerg
2020*4d6fc14bSjoerg    template <typename _Fun>
2021*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY static const __policy*
2022*4d6fc14bSjoerg    __choose_policy(/* is_small = */ false_type) {
2023*4d6fc14bSjoerg      static const _LIBCPP_CONSTEXPR __policy __policy_ = {
2024*4d6fc14bSjoerg          &__large_clone<_Fun>, &__large_destroy<_Fun>, false,
2025*4d6fc14bSjoerg#ifndef _LIBCPP_NO_RTTI
2026*4d6fc14bSjoerg          &typeid(typename _Fun::_Target)
2027*4d6fc14bSjoerg#else
2028*4d6fc14bSjoerg          nullptr
2029*4d6fc14bSjoerg#endif
2030*4d6fc14bSjoerg      };
2031*4d6fc14bSjoerg        return &__policy_;
2032*4d6fc14bSjoerg    }
2033*4d6fc14bSjoerg
2034*4d6fc14bSjoerg    template <typename _Fun>
2035*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY static const __policy*
2036*4d6fc14bSjoerg        __choose_policy(/* is_small = */ true_type)
2037*4d6fc14bSjoerg    {
2038*4d6fc14bSjoerg        static const _LIBCPP_CONSTEXPR __policy __policy_ = {
2039*4d6fc14bSjoerg            nullptr, nullptr, false,
2040*4d6fc14bSjoerg#ifndef _LIBCPP_NO_RTTI
2041*4d6fc14bSjoerg            &typeid(typename _Fun::_Target)
2042*4d6fc14bSjoerg#else
2043*4d6fc14bSjoerg            nullptr
2044*4d6fc14bSjoerg#endif
2045*4d6fc14bSjoerg        };
2046*4d6fc14bSjoerg        return &__policy_;
2047*4d6fc14bSjoerg    }
2048*4d6fc14bSjoerg};
2049*4d6fc14bSjoerg
2050*4d6fc14bSjoerg// Used to choose between perfect forwarding or pass-by-value. Pass-by-value is
2051*4d6fc14bSjoerg// faster for types that can be passed in registers.
2052*4d6fc14bSjoergtemplate <typename _Tp>
2053*4d6fc14bSjoergusing __fast_forward =
2054*4d6fc14bSjoerg    typename conditional<is_scalar<_Tp>::value, _Tp, _Tp&&>::type;
2055*4d6fc14bSjoerg
2056*4d6fc14bSjoerg// __policy_invoker calls an instance of __alloc_func held in __policy_storage.
2057*4d6fc14bSjoerg
2058*4d6fc14bSjoergtemplate <class _Fp> struct __policy_invoker;
2059*4d6fc14bSjoerg
2060*4d6fc14bSjoergtemplate <class _Rp, class... _ArgTypes>
2061*4d6fc14bSjoergstruct __policy_invoker<_Rp(_ArgTypes...)>
2062*4d6fc14bSjoerg{
2063*4d6fc14bSjoerg    typedef _Rp (*__Call)(const __policy_storage*,
2064*4d6fc14bSjoerg                          __fast_forward<_ArgTypes>...);
2065*4d6fc14bSjoerg
2066*4d6fc14bSjoerg    __Call __call_;
2067*4d6fc14bSjoerg
2068*4d6fc14bSjoerg    // Creates an invoker that throws bad_function_call.
2069*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
2070*4d6fc14bSjoerg    __policy_invoker() : __call_(&__call_empty) {}
2071*4d6fc14bSjoerg
2072*4d6fc14bSjoerg    // Creates an invoker that calls the given instance of __func.
2073*4d6fc14bSjoerg    template <typename _Fun>
2074*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY static __policy_invoker __create()
2075*4d6fc14bSjoerg    {
2076*4d6fc14bSjoerg        return __policy_invoker(&__call_impl<_Fun>);
2077*4d6fc14bSjoerg    }
2078*4d6fc14bSjoerg
2079*4d6fc14bSjoerg  private:
2080*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
2081*4d6fc14bSjoerg    explicit __policy_invoker(__Call __c) : __call_(__c) {}
2082*4d6fc14bSjoerg
2083*4d6fc14bSjoerg    static _Rp __call_empty(const __policy_storage*,
2084*4d6fc14bSjoerg                            __fast_forward<_ArgTypes>...)
2085*4d6fc14bSjoerg    {
2086*4d6fc14bSjoerg        __throw_bad_function_call();
2087*4d6fc14bSjoerg    }
2088*4d6fc14bSjoerg
2089*4d6fc14bSjoerg    template <typename _Fun>
2090*4d6fc14bSjoerg    static _Rp __call_impl(const __policy_storage* __buf,
2091*4d6fc14bSjoerg                           __fast_forward<_ArgTypes>... __args)
2092*4d6fc14bSjoerg    {
2093*4d6fc14bSjoerg        _Fun* __f = reinterpret_cast<_Fun*>(__use_small_storage<_Fun>::value
2094*4d6fc14bSjoerg                                                ? &__buf->__small
2095*4d6fc14bSjoerg                                                : __buf->__large);
2096*4d6fc14bSjoerg        return (*__f)(_VSTD::forward<_ArgTypes>(__args)...);
2097*4d6fc14bSjoerg    }
2098*4d6fc14bSjoerg};
2099*4d6fc14bSjoerg
2100*4d6fc14bSjoerg// __policy_func uses a __policy and __policy_invoker to create a type-erased,
2101*4d6fc14bSjoerg// copyable functor.
2102*4d6fc14bSjoerg
2103*4d6fc14bSjoergtemplate <class _Fp> class __policy_func;
2104*4d6fc14bSjoerg
2105*4d6fc14bSjoergtemplate <class _Rp, class... _ArgTypes> class __policy_func<_Rp(_ArgTypes...)>
2106*4d6fc14bSjoerg{
2107*4d6fc14bSjoerg    // Inline storage for small objects.
2108*4d6fc14bSjoerg    __policy_storage __buf_;
2109*4d6fc14bSjoerg
2110*4d6fc14bSjoerg    // Calls the value stored in __buf_. This could technically be part of
2111*4d6fc14bSjoerg    // policy, but storing it here eliminates a level of indirection inside
2112*4d6fc14bSjoerg    // operator().
2113*4d6fc14bSjoerg    typedef __function::__policy_invoker<_Rp(_ArgTypes...)> __invoker;
2114*4d6fc14bSjoerg    __invoker __invoker_;
2115*4d6fc14bSjoerg
2116*4d6fc14bSjoerg    // The policy that describes how to move / copy / destroy __buf_. Never
2117*4d6fc14bSjoerg    // null, even if the function is empty.
2118*4d6fc14bSjoerg    const __policy* __policy_;
2119*4d6fc14bSjoerg
2120*4d6fc14bSjoerg  public:
2121*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
2122*4d6fc14bSjoerg    __policy_func() : __policy_(__policy::__create_empty()) {}
2123*4d6fc14bSjoerg
2124*4d6fc14bSjoerg    template <class _Fp, class _Alloc>
2125*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY __policy_func(_Fp&& __f, const _Alloc& __a)
2126*4d6fc14bSjoerg        : __policy_(__policy::__create_empty())
2127*4d6fc14bSjoerg    {
2128*4d6fc14bSjoerg        typedef __alloc_func<_Fp, _Alloc, _Rp(_ArgTypes...)> _Fun;
2129*4d6fc14bSjoerg        typedef allocator_traits<_Alloc> __alloc_traits;
2130*4d6fc14bSjoerg        typedef typename __rebind_alloc_helper<__alloc_traits, _Fun>::type
2131*4d6fc14bSjoerg            _FunAlloc;
2132*4d6fc14bSjoerg
2133*4d6fc14bSjoerg        if (__function::__not_null(__f))
2134*4d6fc14bSjoerg        {
2135*4d6fc14bSjoerg            __invoker_ = __invoker::template __create<_Fun>();
2136*4d6fc14bSjoerg            __policy_ = __policy::__create<_Fun>();
2137*4d6fc14bSjoerg
2138*4d6fc14bSjoerg            _FunAlloc __af(__a);
2139*4d6fc14bSjoerg            if (__use_small_storage<_Fun>())
2140*4d6fc14bSjoerg            {
2141*4d6fc14bSjoerg                ::new ((void*)&__buf_.__small)
2142*4d6fc14bSjoerg                    _Fun(_VSTD::move(__f), _Alloc(__af));
2143*4d6fc14bSjoerg            }
2144*4d6fc14bSjoerg            else
2145*4d6fc14bSjoerg            {
2146*4d6fc14bSjoerg                typedef __allocator_destructor<_FunAlloc> _Dp;
2147*4d6fc14bSjoerg                unique_ptr<_Fun, _Dp> __hold(__af.allocate(1), _Dp(__af, 1));
2148*4d6fc14bSjoerg                ::new ((void*)__hold.get())
2149*4d6fc14bSjoerg                    _Fun(_VSTD::move(__f), _Alloc(__af));
2150*4d6fc14bSjoerg                __buf_.__large = __hold.release();
2151*4d6fc14bSjoerg            }
2152*4d6fc14bSjoerg        }
2153*4d6fc14bSjoerg    }
2154*4d6fc14bSjoerg
2155*4d6fc14bSjoerg    template <class _Fp, class = typename enable_if<!is_same<typename decay<_Fp>::type, __policy_func>::value>::type>
2156*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY explicit __policy_func(_Fp&& __f)
2157*4d6fc14bSjoerg        : __policy_(__policy::__create_empty()) {
2158*4d6fc14bSjoerg      typedef __default_alloc_func<_Fp, _Rp(_ArgTypes...)> _Fun;
2159*4d6fc14bSjoerg
2160*4d6fc14bSjoerg      if (__function::__not_null(__f)) {
2161*4d6fc14bSjoerg        __invoker_ = __invoker::template __create<_Fun>();
2162*4d6fc14bSjoerg        __policy_ = __policy::__create<_Fun>();
2163*4d6fc14bSjoerg        if (__use_small_storage<_Fun>()) {
2164*4d6fc14bSjoerg          ::new ((void*)&__buf_.__small) _Fun(_VSTD::move(__f));
2165*4d6fc14bSjoerg        } else {
2166*4d6fc14bSjoerg          __builtin_new_allocator::__holder_t __hold =
2167*4d6fc14bSjoerg              __builtin_new_allocator::__allocate_type<_Fun>(1);
2168*4d6fc14bSjoerg          __buf_.__large = ::new ((void*)__hold.get()) _Fun(_VSTD::move(__f));
2169*4d6fc14bSjoerg          (void)__hold.release();
2170*4d6fc14bSjoerg        }
2171*4d6fc14bSjoerg      }
2172*4d6fc14bSjoerg    }
2173*4d6fc14bSjoerg
2174*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
2175*4d6fc14bSjoerg    __policy_func(const __policy_func& __f)
2176*4d6fc14bSjoerg        : __buf_(__f.__buf_), __invoker_(__f.__invoker_),
2177*4d6fc14bSjoerg          __policy_(__f.__policy_)
2178*4d6fc14bSjoerg    {
2179*4d6fc14bSjoerg        if (__policy_->__clone)
2180*4d6fc14bSjoerg            __buf_.__large = __policy_->__clone(__f.__buf_.__large);
2181*4d6fc14bSjoerg    }
2182*4d6fc14bSjoerg
2183*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
2184*4d6fc14bSjoerg    __policy_func(__policy_func&& __f)
2185*4d6fc14bSjoerg        : __buf_(__f.__buf_), __invoker_(__f.__invoker_),
2186*4d6fc14bSjoerg          __policy_(__f.__policy_)
2187*4d6fc14bSjoerg    {
2188*4d6fc14bSjoerg        if (__policy_->__destroy)
2189*4d6fc14bSjoerg        {
2190*4d6fc14bSjoerg            __f.__policy_ = __policy::__create_empty();
2191*4d6fc14bSjoerg            __f.__invoker_ = __invoker();
2192*4d6fc14bSjoerg        }
2193*4d6fc14bSjoerg    }
2194*4d6fc14bSjoerg
2195*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
2196*4d6fc14bSjoerg    ~__policy_func()
2197*4d6fc14bSjoerg    {
2198*4d6fc14bSjoerg        if (__policy_->__destroy)
2199*4d6fc14bSjoerg            __policy_->__destroy(__buf_.__large);
2200*4d6fc14bSjoerg    }
2201*4d6fc14bSjoerg
2202*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
2203*4d6fc14bSjoerg    __policy_func& operator=(__policy_func&& __f)
2204*4d6fc14bSjoerg    {
2205*4d6fc14bSjoerg        *this = nullptr;
2206*4d6fc14bSjoerg        __buf_ = __f.__buf_;
2207*4d6fc14bSjoerg        __invoker_ = __f.__invoker_;
2208*4d6fc14bSjoerg        __policy_ = __f.__policy_;
2209*4d6fc14bSjoerg        __f.__policy_ = __policy::__create_empty();
2210*4d6fc14bSjoerg        __f.__invoker_ = __invoker();
2211*4d6fc14bSjoerg        return *this;
2212*4d6fc14bSjoerg    }
2213*4d6fc14bSjoerg
2214*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
2215*4d6fc14bSjoerg    __policy_func& operator=(nullptr_t)
2216*4d6fc14bSjoerg    {
2217*4d6fc14bSjoerg        const __policy* __p = __policy_;
2218*4d6fc14bSjoerg        __policy_ = __policy::__create_empty();
2219*4d6fc14bSjoerg        __invoker_ = __invoker();
2220*4d6fc14bSjoerg        if (__p->__destroy)
2221*4d6fc14bSjoerg            __p->__destroy(__buf_.__large);
2222*4d6fc14bSjoerg        return *this;
2223*4d6fc14bSjoerg    }
2224*4d6fc14bSjoerg
2225*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
2226*4d6fc14bSjoerg    _Rp operator()(_ArgTypes&&... __args) const
2227*4d6fc14bSjoerg    {
2228*4d6fc14bSjoerg        return __invoker_.__call_(_VSTD::addressof(__buf_),
2229*4d6fc14bSjoerg                                  _VSTD::forward<_ArgTypes>(__args)...);
2230*4d6fc14bSjoerg    }
2231*4d6fc14bSjoerg
2232*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
2233*4d6fc14bSjoerg    void swap(__policy_func& __f)
2234*4d6fc14bSjoerg    {
2235*4d6fc14bSjoerg        _VSTD::swap(__invoker_, __f.__invoker_);
2236*4d6fc14bSjoerg        _VSTD::swap(__policy_, __f.__policy_);
2237*4d6fc14bSjoerg        _VSTD::swap(__buf_, __f.__buf_);
2238*4d6fc14bSjoerg    }
2239*4d6fc14bSjoerg
2240*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
2241*4d6fc14bSjoerg    explicit operator bool() const _NOEXCEPT
2242*4d6fc14bSjoerg    {
2243*4d6fc14bSjoerg        return !__policy_->__is_null;
2244*4d6fc14bSjoerg    }
2245*4d6fc14bSjoerg
2246*4d6fc14bSjoerg#ifndef _LIBCPP_NO_RTTI
2247*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
2248*4d6fc14bSjoerg    const std::type_info& target_type() const _NOEXCEPT
2249*4d6fc14bSjoerg    {
2250*4d6fc14bSjoerg        return *__policy_->__type_info;
2251*4d6fc14bSjoerg    }
2252*4d6fc14bSjoerg
2253*4d6fc14bSjoerg    template <typename _Tp>
2254*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY const _Tp* target() const _NOEXCEPT
2255*4d6fc14bSjoerg    {
2256*4d6fc14bSjoerg        if (__policy_->__is_null || typeid(_Tp) != *__policy_->__type_info)
2257*4d6fc14bSjoerg            return nullptr;
2258*4d6fc14bSjoerg        if (__policy_->__clone) // Out of line storage.
2259*4d6fc14bSjoerg            return reinterpret_cast<const _Tp*>(__buf_.__large);
2260*4d6fc14bSjoerg        else
2261*4d6fc14bSjoerg            return reinterpret_cast<const _Tp*>(&__buf_.__small);
2262*4d6fc14bSjoerg    }
2263*4d6fc14bSjoerg#endif // _LIBCPP_NO_RTTI
2264*4d6fc14bSjoerg};
2265*4d6fc14bSjoerg
2266*4d6fc14bSjoerg#if defined(_LIBCPP_HAS_BLOCKS_RUNTIME) && !defined(_LIBCPP_HAS_OBJC_ARC)
2267*4d6fc14bSjoerg
2268*4d6fc14bSjoergextern "C" void *_Block_copy(const void *);
2269*4d6fc14bSjoergextern "C" void _Block_release(const void *);
2270*4d6fc14bSjoerg
2271*4d6fc14bSjoergtemplate<class _Rp1, class ..._ArgTypes1, class _Alloc, class _Rp, class ..._ArgTypes>
2272*4d6fc14bSjoergclass __func<_Rp1(^)(_ArgTypes1...), _Alloc, _Rp(_ArgTypes...)>
2273*4d6fc14bSjoerg    : public  __base<_Rp(_ArgTypes...)>
2274*4d6fc14bSjoerg{
2275*4d6fc14bSjoerg    typedef _Rp1(^__block_type)(_ArgTypes1...);
2276*4d6fc14bSjoerg    __block_type __f_;
2277*4d6fc14bSjoerg
2278*4d6fc14bSjoergpublic:
2279*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
2280*4d6fc14bSjoerg    explicit __func(__block_type const& __f)
2281*4d6fc14bSjoerg        : __f_(reinterpret_cast<__block_type>(__f ? _Block_copy(__f) : nullptr))
2282*4d6fc14bSjoerg    { }
2283*4d6fc14bSjoerg
2284*4d6fc14bSjoerg    // [TODO] add && to save on a retain
2285*4d6fc14bSjoerg
2286*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
2287*4d6fc14bSjoerg    explicit __func(__block_type __f, const _Alloc& /* unused */)
2288*4d6fc14bSjoerg        : __f_(reinterpret_cast<__block_type>(__f ? _Block_copy(__f) : nullptr))
2289*4d6fc14bSjoerg    { }
2290*4d6fc14bSjoerg
2291*4d6fc14bSjoerg    virtual __base<_Rp(_ArgTypes...)>* __clone() const {
2292*4d6fc14bSjoerg        _LIBCPP_ASSERT(false,
2293*4d6fc14bSjoerg            "Block pointers are just pointers, so they should always fit into "
2294*4d6fc14bSjoerg            "std::function's small buffer optimization. This function should "
2295*4d6fc14bSjoerg            "never be invoked.");
2296*4d6fc14bSjoerg        return nullptr;
2297*4d6fc14bSjoerg    }
2298*4d6fc14bSjoerg
2299*4d6fc14bSjoerg    virtual void __clone(__base<_Rp(_ArgTypes...)>* __p) const {
2300*4d6fc14bSjoerg        ::new ((void*)__p) __func(__f_);
2301*4d6fc14bSjoerg    }
2302*4d6fc14bSjoerg
2303*4d6fc14bSjoerg    virtual void destroy() _NOEXCEPT {
2304*4d6fc14bSjoerg        if (__f_)
2305*4d6fc14bSjoerg            _Block_release(__f_);
2306*4d6fc14bSjoerg        __f_ = 0;
2307*4d6fc14bSjoerg    }
2308*4d6fc14bSjoerg
2309*4d6fc14bSjoerg    virtual void destroy_deallocate() _NOEXCEPT {
2310*4d6fc14bSjoerg        _LIBCPP_ASSERT(false,
2311*4d6fc14bSjoerg            "Block pointers are just pointers, so they should always fit into "
2312*4d6fc14bSjoerg            "std::function's small buffer optimization. This function should "
2313*4d6fc14bSjoerg            "never be invoked.");
2314*4d6fc14bSjoerg    }
2315*4d6fc14bSjoerg
2316*4d6fc14bSjoerg    virtual _Rp operator()(_ArgTypes&& ... __arg) {
2317*4d6fc14bSjoerg        return _VSTD::__invoke(__f_, _VSTD::forward<_ArgTypes>(__arg)...);
2318*4d6fc14bSjoerg    }
2319*4d6fc14bSjoerg
2320*4d6fc14bSjoerg#ifndef _LIBCPP_NO_RTTI
2321*4d6fc14bSjoerg    virtual const void* target(type_info const& __ti) const _NOEXCEPT {
2322*4d6fc14bSjoerg        if (__ti == typeid(__func::__block_type))
2323*4d6fc14bSjoerg            return &__f_;
2324*4d6fc14bSjoerg        return (const void*)nullptr;
2325*4d6fc14bSjoerg    }
2326*4d6fc14bSjoerg
2327*4d6fc14bSjoerg    virtual const std::type_info& target_type() const _NOEXCEPT {
2328*4d6fc14bSjoerg        return typeid(__func::__block_type);
2329*4d6fc14bSjoerg    }
2330*4d6fc14bSjoerg#endif // _LIBCPP_NO_RTTI
2331*4d6fc14bSjoerg};
2332*4d6fc14bSjoerg
2333*4d6fc14bSjoerg#endif // _LIBCPP_HAS_EXTENSION_BLOCKS && !_LIBCPP_HAS_OBJC_ARC
2334*4d6fc14bSjoerg
2335*4d6fc14bSjoerg}  // __function
2336*4d6fc14bSjoerg
2337*4d6fc14bSjoergtemplate<class _Rp, class ..._ArgTypes>
2338*4d6fc14bSjoergclass _LIBCPP_TEMPLATE_VIS function<_Rp(_ArgTypes...)>
2339*4d6fc14bSjoerg    : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>,
2340*4d6fc14bSjoerg      public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)>
2341*4d6fc14bSjoerg{
2342*4d6fc14bSjoerg#ifndef _LIBCPP_ABI_OPTIMIZED_FUNCTION
2343*4d6fc14bSjoerg    typedef __function::__value_func<_Rp(_ArgTypes...)> __func;
2344*4d6fc14bSjoerg#else
2345*4d6fc14bSjoerg    typedef __function::__policy_func<_Rp(_ArgTypes...)> __func;
2346*4d6fc14bSjoerg#endif
2347*4d6fc14bSjoerg
2348*4d6fc14bSjoerg    __func __f_;
2349*4d6fc14bSjoerg
2350*4d6fc14bSjoerg    template <class _Fp, bool = _And<
2351*4d6fc14bSjoerg        _IsNotSame<__uncvref_t<_Fp>, function>,
2352*4d6fc14bSjoerg        __invokable<_Fp, _ArgTypes...>
2353*4d6fc14bSjoerg    >::value>
2354*4d6fc14bSjoerg    struct __callable;
2355*4d6fc14bSjoerg    template <class _Fp>
2356*4d6fc14bSjoerg        struct __callable<_Fp, true>
2357*4d6fc14bSjoerg        {
2358*4d6fc14bSjoerg            static const bool value = is_void<_Rp>::value ||
2359*4d6fc14bSjoerg                __is_core_convertible<typename __invoke_of<_Fp, _ArgTypes...>::type,
2360*4d6fc14bSjoerg                                      _Rp>::value;
2361*4d6fc14bSjoerg        };
2362*4d6fc14bSjoerg    template <class _Fp>
2363*4d6fc14bSjoerg        struct __callable<_Fp, false>
2364*4d6fc14bSjoerg        {
2365*4d6fc14bSjoerg            static const bool value = false;
2366*4d6fc14bSjoerg        };
2367*4d6fc14bSjoerg
2368*4d6fc14bSjoerg  template <class _Fp>
2369*4d6fc14bSjoerg  using _EnableIfLValueCallable = typename enable_if<__callable<_Fp&>::value>::type;
2370*4d6fc14bSjoergpublic:
2371*4d6fc14bSjoerg    typedef _Rp result_type;
2372*4d6fc14bSjoerg
2373*4d6fc14bSjoerg    // construct/copy/destroy:
2374*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
2375*4d6fc14bSjoerg    function() _NOEXCEPT { }
2376*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
2377*4d6fc14bSjoerg    function(nullptr_t) _NOEXCEPT {}
2378*4d6fc14bSjoerg    function(const function&);
2379*4d6fc14bSjoerg    function(function&&) _NOEXCEPT;
2380*4d6fc14bSjoerg    template<class _Fp, class = _EnableIfLValueCallable<_Fp>>
2381*4d6fc14bSjoerg    function(_Fp);
2382*4d6fc14bSjoerg
2383*4d6fc14bSjoerg#if _LIBCPP_STD_VER <= 14
2384*4d6fc14bSjoerg    template<class _Alloc>
2385*4d6fc14bSjoerg      _LIBCPP_INLINE_VISIBILITY
2386*4d6fc14bSjoerg      function(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
2387*4d6fc14bSjoerg    template<class _Alloc>
2388*4d6fc14bSjoerg      _LIBCPP_INLINE_VISIBILITY
2389*4d6fc14bSjoerg      function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT {}
2390*4d6fc14bSjoerg    template<class _Alloc>
2391*4d6fc14bSjoerg      function(allocator_arg_t, const _Alloc&, const function&);
2392*4d6fc14bSjoerg    template<class _Alloc>
2393*4d6fc14bSjoerg      function(allocator_arg_t, const _Alloc&, function&&);
2394*4d6fc14bSjoerg    template<class _Fp, class _Alloc, class = _EnableIfLValueCallable<_Fp>>
2395*4d6fc14bSjoerg      function(allocator_arg_t, const _Alloc& __a, _Fp __f);
2396*4d6fc14bSjoerg#endif
2397*4d6fc14bSjoerg
2398*4d6fc14bSjoerg    function& operator=(const function&);
2399*4d6fc14bSjoerg    function& operator=(function&&) _NOEXCEPT;
2400*4d6fc14bSjoerg    function& operator=(nullptr_t) _NOEXCEPT;
2401*4d6fc14bSjoerg    template<class _Fp, class = _EnableIfLValueCallable<typename decay<_Fp>::type>>
2402*4d6fc14bSjoerg    function& operator=(_Fp&&);
2403*4d6fc14bSjoerg
2404*4d6fc14bSjoerg    ~function();
2405*4d6fc14bSjoerg
2406*4d6fc14bSjoerg    // function modifiers:
2407*4d6fc14bSjoerg    void swap(function&) _NOEXCEPT;
2408*4d6fc14bSjoerg
2409*4d6fc14bSjoerg#if _LIBCPP_STD_VER <= 14
2410*4d6fc14bSjoerg    template<class _Fp, class _Alloc>
2411*4d6fc14bSjoerg      _LIBCPP_INLINE_VISIBILITY
2412*4d6fc14bSjoerg      void assign(_Fp&& __f, const _Alloc& __a)
2413*4d6fc14bSjoerg        {function(allocator_arg, __a, _VSTD::forward<_Fp>(__f)).swap(*this);}
2414*4d6fc14bSjoerg#endif
2415*4d6fc14bSjoerg
2416*4d6fc14bSjoerg    // function capacity:
2417*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY
2418*4d6fc14bSjoerg    _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {
2419*4d6fc14bSjoerg      return static_cast<bool>(__f_);
2420*4d6fc14bSjoerg    }
2421*4d6fc14bSjoerg
2422*4d6fc14bSjoerg    // deleted overloads close possible hole in the type system
2423*4d6fc14bSjoerg    template<class _R2, class... _ArgTypes2>
2424*4d6fc14bSjoerg      bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete;
2425*4d6fc14bSjoerg    template<class _R2, class... _ArgTypes2>
2426*4d6fc14bSjoerg      bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete;
2427*4d6fc14bSjoergpublic:
2428*4d6fc14bSjoerg    // function invocation:
2429*4d6fc14bSjoerg    _Rp operator()(_ArgTypes...) const;
2430*4d6fc14bSjoerg
2431*4d6fc14bSjoerg#ifndef _LIBCPP_NO_RTTI
2432*4d6fc14bSjoerg    // function target access:
2433*4d6fc14bSjoerg    const std::type_info& target_type() const _NOEXCEPT;
2434*4d6fc14bSjoerg    template <typename _Tp> _Tp* target() _NOEXCEPT;
2435*4d6fc14bSjoerg    template <typename _Tp> const _Tp* target() const _NOEXCEPT;
2436*4d6fc14bSjoerg#endif // _LIBCPP_NO_RTTI
2437*4d6fc14bSjoerg};
2438*4d6fc14bSjoerg
2439*4d6fc14bSjoerg#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
2440*4d6fc14bSjoergtemplate<class _Rp, class ..._Ap>
2441*4d6fc14bSjoergfunction(_Rp(*)(_Ap...)) -> function<_Rp(_Ap...)>;
2442*4d6fc14bSjoerg
2443*4d6fc14bSjoergtemplate<class _Fp>
2444*4d6fc14bSjoergstruct __strip_signature;
2445*4d6fc14bSjoerg
2446*4d6fc14bSjoergtemplate<class _Rp, class _Gp, class ..._Ap>
2447*4d6fc14bSjoergstruct __strip_signature<_Rp (_Gp::*) (_Ap...)> { using type = _Rp(_Ap...); };
2448*4d6fc14bSjoergtemplate<class _Rp, class _Gp, class ..._Ap>
2449*4d6fc14bSjoergstruct __strip_signature<_Rp (_Gp::*) (_Ap...) const> { using type = _Rp(_Ap...); };
2450*4d6fc14bSjoergtemplate<class _Rp, class _Gp, class ..._Ap>
2451*4d6fc14bSjoergstruct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile> { using type = _Rp(_Ap...); };
2452*4d6fc14bSjoergtemplate<class _Rp, class _Gp, class ..._Ap>
2453*4d6fc14bSjoergstruct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile> { using type = _Rp(_Ap...); };
2454*4d6fc14bSjoerg
2455*4d6fc14bSjoergtemplate<class _Rp, class _Gp, class ..._Ap>
2456*4d6fc14bSjoergstruct __strip_signature<_Rp (_Gp::*) (_Ap...) &> { using type = _Rp(_Ap...); };
2457*4d6fc14bSjoergtemplate<class _Rp, class _Gp, class ..._Ap>
2458*4d6fc14bSjoergstruct __strip_signature<_Rp (_Gp::*) (_Ap...) const &> { using type = _Rp(_Ap...); };
2459*4d6fc14bSjoergtemplate<class _Rp, class _Gp, class ..._Ap>
2460*4d6fc14bSjoergstruct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile &> { using type = _Rp(_Ap...); };
2461*4d6fc14bSjoergtemplate<class _Rp, class _Gp, class ..._Ap>
2462*4d6fc14bSjoergstruct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile &> { using type = _Rp(_Ap...); };
2463*4d6fc14bSjoerg
2464*4d6fc14bSjoergtemplate<class _Rp, class _Gp, class ..._Ap>
2465*4d6fc14bSjoergstruct __strip_signature<_Rp (_Gp::*) (_Ap...) noexcept> { using type = _Rp(_Ap...); };
2466*4d6fc14bSjoergtemplate<class _Rp, class _Gp, class ..._Ap>
2467*4d6fc14bSjoergstruct __strip_signature<_Rp (_Gp::*) (_Ap...) const noexcept> { using type = _Rp(_Ap...); };
2468*4d6fc14bSjoergtemplate<class _Rp, class _Gp, class ..._Ap>
2469*4d6fc14bSjoergstruct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile noexcept> { using type = _Rp(_Ap...); };
2470*4d6fc14bSjoergtemplate<class _Rp, class _Gp, class ..._Ap>
2471*4d6fc14bSjoergstruct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile noexcept> { using type = _Rp(_Ap...); };
2472*4d6fc14bSjoerg
2473*4d6fc14bSjoergtemplate<class _Rp, class _Gp, class ..._Ap>
2474*4d6fc14bSjoergstruct __strip_signature<_Rp (_Gp::*) (_Ap...) & noexcept> { using type = _Rp(_Ap...); };
2475*4d6fc14bSjoergtemplate<class _Rp, class _Gp, class ..._Ap>
2476*4d6fc14bSjoergstruct __strip_signature<_Rp (_Gp::*) (_Ap...) const & noexcept> { using type = _Rp(_Ap...); };
2477*4d6fc14bSjoergtemplate<class _Rp, class _Gp, class ..._Ap>
2478*4d6fc14bSjoergstruct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile & noexcept> { using type = _Rp(_Ap...); };
2479*4d6fc14bSjoergtemplate<class _Rp, class _Gp, class ..._Ap>
2480*4d6fc14bSjoergstruct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile & noexcept> { using type = _Rp(_Ap...); };
2481*4d6fc14bSjoerg
2482*4d6fc14bSjoergtemplate<class _Fp, class _Stripped = typename __strip_signature<decltype(&_Fp::operator())>::type>
2483*4d6fc14bSjoergfunction(_Fp) -> function<_Stripped>;
2484*4d6fc14bSjoerg#endif // !_LIBCPP_HAS_NO_DEDUCTION_GUIDES
2485*4d6fc14bSjoerg
2486*4d6fc14bSjoergtemplate<class _Rp, class ..._ArgTypes>
2487*4d6fc14bSjoergfunction<_Rp(_ArgTypes...)>::function(const function& __f) : __f_(__f.__f_) {}
2488*4d6fc14bSjoerg
2489*4d6fc14bSjoerg#if _LIBCPP_STD_VER <= 14
2490*4d6fc14bSjoergtemplate<class _Rp, class ..._ArgTypes>
2491*4d6fc14bSjoergtemplate <class _Alloc>
2492*4d6fc14bSjoergfunction<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
2493*4d6fc14bSjoerg                                     const function& __f) : __f_(__f.__f_) {}
2494*4d6fc14bSjoerg#endif
2495*4d6fc14bSjoerg
2496*4d6fc14bSjoergtemplate <class _Rp, class... _ArgTypes>
2497*4d6fc14bSjoergfunction<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT
2498*4d6fc14bSjoerg    : __f_(_VSTD::move(__f.__f_)) {}
2499*4d6fc14bSjoerg
2500*4d6fc14bSjoerg#if _LIBCPP_STD_VER <= 14
2501*4d6fc14bSjoergtemplate<class _Rp, class ..._ArgTypes>
2502*4d6fc14bSjoergtemplate <class _Alloc>
2503*4d6fc14bSjoergfunction<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
2504*4d6fc14bSjoerg                                      function&& __f)
2505*4d6fc14bSjoerg    : __f_(_VSTD::move(__f.__f_)) {}
2506*4d6fc14bSjoerg#endif
2507*4d6fc14bSjoerg
2508*4d6fc14bSjoergtemplate <class _Rp, class... _ArgTypes>
2509*4d6fc14bSjoergtemplate <class _Fp, class>
2510*4d6fc14bSjoergfunction<_Rp(_ArgTypes...)>::function(_Fp __f) : __f_(_VSTD::move(__f)) {}
2511*4d6fc14bSjoerg
2512*4d6fc14bSjoerg#if _LIBCPP_STD_VER <= 14
2513*4d6fc14bSjoergtemplate <class _Rp, class... _ArgTypes>
2514*4d6fc14bSjoergtemplate <class _Fp, class _Alloc, class>
2515*4d6fc14bSjoergfunction<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a,
2516*4d6fc14bSjoerg                                      _Fp __f)
2517*4d6fc14bSjoerg    : __f_(_VSTD::move(__f), __a) {}
2518*4d6fc14bSjoerg#endif
2519*4d6fc14bSjoerg
2520*4d6fc14bSjoergtemplate<class _Rp, class ..._ArgTypes>
2521*4d6fc14bSjoergfunction<_Rp(_ArgTypes...)>&
2522*4d6fc14bSjoergfunction<_Rp(_ArgTypes...)>::operator=(const function& __f)
2523*4d6fc14bSjoerg{
2524*4d6fc14bSjoerg    function(__f).swap(*this);
2525*4d6fc14bSjoerg    return *this;
2526*4d6fc14bSjoerg}
2527*4d6fc14bSjoerg
2528*4d6fc14bSjoergtemplate<class _Rp, class ..._ArgTypes>
2529*4d6fc14bSjoergfunction<_Rp(_ArgTypes...)>&
2530*4d6fc14bSjoergfunction<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT
2531*4d6fc14bSjoerg{
2532*4d6fc14bSjoerg    __f_ = _VSTD::move(__f.__f_);
2533*4d6fc14bSjoerg    return *this;
2534*4d6fc14bSjoerg}
2535*4d6fc14bSjoerg
2536*4d6fc14bSjoergtemplate<class _Rp, class ..._ArgTypes>
2537*4d6fc14bSjoergfunction<_Rp(_ArgTypes...)>&
2538*4d6fc14bSjoergfunction<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT
2539*4d6fc14bSjoerg{
2540*4d6fc14bSjoerg    __f_ = nullptr;
2541*4d6fc14bSjoerg    return *this;
2542*4d6fc14bSjoerg}
2543*4d6fc14bSjoerg
2544*4d6fc14bSjoergtemplate<class _Rp, class ..._ArgTypes>
2545*4d6fc14bSjoergtemplate <class _Fp, class>
2546*4d6fc14bSjoergfunction<_Rp(_ArgTypes...)>&
2547*4d6fc14bSjoergfunction<_Rp(_ArgTypes...)>::operator=(_Fp&& __f)
2548*4d6fc14bSjoerg{
2549*4d6fc14bSjoerg    function(_VSTD::forward<_Fp>(__f)).swap(*this);
2550*4d6fc14bSjoerg    return *this;
2551*4d6fc14bSjoerg}
2552*4d6fc14bSjoerg
2553*4d6fc14bSjoergtemplate<class _Rp, class ..._ArgTypes>
2554*4d6fc14bSjoergfunction<_Rp(_ArgTypes...)>::~function() {}
2555*4d6fc14bSjoerg
2556*4d6fc14bSjoergtemplate<class _Rp, class ..._ArgTypes>
2557*4d6fc14bSjoergvoid
2558*4d6fc14bSjoergfunction<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT
2559*4d6fc14bSjoerg{
2560*4d6fc14bSjoerg    __f_.swap(__f.__f_);
2561*4d6fc14bSjoerg}
2562*4d6fc14bSjoerg
2563*4d6fc14bSjoergtemplate<class _Rp, class ..._ArgTypes>
2564*4d6fc14bSjoerg_Rp
2565*4d6fc14bSjoergfunction<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const
2566*4d6fc14bSjoerg{
2567*4d6fc14bSjoerg    return __f_(_VSTD::forward<_ArgTypes>(__arg)...);
2568*4d6fc14bSjoerg}
2569*4d6fc14bSjoerg
2570*4d6fc14bSjoerg#ifndef _LIBCPP_NO_RTTI
2571*4d6fc14bSjoerg
2572*4d6fc14bSjoergtemplate<class _Rp, class ..._ArgTypes>
2573*4d6fc14bSjoergconst std::type_info&
2574*4d6fc14bSjoergfunction<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
2575*4d6fc14bSjoerg{
2576*4d6fc14bSjoerg    return __f_.target_type();
2577*4d6fc14bSjoerg}
2578*4d6fc14bSjoerg
2579*4d6fc14bSjoergtemplate<class _Rp, class ..._ArgTypes>
2580*4d6fc14bSjoergtemplate <typename _Tp>
2581*4d6fc14bSjoerg_Tp*
2582*4d6fc14bSjoergfunction<_Rp(_ArgTypes...)>::target() _NOEXCEPT
2583*4d6fc14bSjoerg{
2584*4d6fc14bSjoerg    return (_Tp*)(__f_.template target<_Tp>());
2585*4d6fc14bSjoerg}
2586*4d6fc14bSjoerg
2587*4d6fc14bSjoergtemplate<class _Rp, class ..._ArgTypes>
2588*4d6fc14bSjoergtemplate <typename _Tp>
2589*4d6fc14bSjoergconst _Tp*
2590*4d6fc14bSjoergfunction<_Rp(_ArgTypes...)>::target() const _NOEXCEPT
2591*4d6fc14bSjoerg{
2592*4d6fc14bSjoerg    return __f_.template target<_Tp>();
2593*4d6fc14bSjoerg}
2594*4d6fc14bSjoerg
2595*4d6fc14bSjoerg#endif // _LIBCPP_NO_RTTI
2596*4d6fc14bSjoerg
2597*4d6fc14bSjoergtemplate <class _Rp, class... _ArgTypes>
2598*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY
2599*4d6fc14bSjoergbool
2600*4d6fc14bSjoergoperator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;}
2601*4d6fc14bSjoerg
2602*4d6fc14bSjoergtemplate <class _Rp, class... _ArgTypes>
2603*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY
2604*4d6fc14bSjoergbool
2605*4d6fc14bSjoergoperator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;}
2606*4d6fc14bSjoerg
2607*4d6fc14bSjoergtemplate <class _Rp, class... _ArgTypes>
2608*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY
2609*4d6fc14bSjoergbool
2610*4d6fc14bSjoergoperator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;}
2611*4d6fc14bSjoerg
2612*4d6fc14bSjoergtemplate <class _Rp, class... _ArgTypes>
2613*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY
2614*4d6fc14bSjoergbool
2615*4d6fc14bSjoergoperator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;}
2616*4d6fc14bSjoerg
2617*4d6fc14bSjoergtemplate <class _Rp, class... _ArgTypes>
2618*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY
2619*4d6fc14bSjoergvoid
2620*4d6fc14bSjoergswap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT
2621*4d6fc14bSjoerg{return __x.swap(__y);}
2622*4d6fc14bSjoerg
2623*4d6fc14bSjoerg#else // _LIBCPP_CXX03_LANG
2624*4d6fc14bSjoerg
2625*4d6fc14bSjoerg#include <__functional_03>
2626*4d6fc14bSjoerg
2627*4d6fc14bSjoerg#endif
2628*4d6fc14bSjoerg
2629*4d6fc14bSjoerg////////////////////////////////////////////////////////////////////////////////
2630*4d6fc14bSjoerg//                                  BIND
2631*4d6fc14bSjoerg//==============================================================================
2632*4d6fc14bSjoerg
2633*4d6fc14bSjoergtemplate<class _Tp> struct __is_bind_expression : public false_type {};
2634*4d6fc14bSjoergtemplate<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_bind_expression
2635*4d6fc14bSjoerg    : public __is_bind_expression<typename remove_cv<_Tp>::type> {};
2636*4d6fc14bSjoerg
2637*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 14
2638*4d6fc14bSjoergtemplate <class _Tp>
2639*4d6fc14bSjoerg_LIBCPP_INLINE_VAR constexpr size_t is_bind_expression_v = is_bind_expression<_Tp>::value;
2640*4d6fc14bSjoerg#endif
2641*4d6fc14bSjoerg
2642*4d6fc14bSjoergtemplate<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {};
2643*4d6fc14bSjoergtemplate<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_placeholder
2644*4d6fc14bSjoerg    : public __is_placeholder<typename remove_cv<_Tp>::type> {};
2645*4d6fc14bSjoerg
2646*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 14
2647*4d6fc14bSjoergtemplate <class _Tp>
2648*4d6fc14bSjoerg_LIBCPP_INLINE_VAR constexpr size_t is_placeholder_v = is_placeholder<_Tp>::value;
2649*4d6fc14bSjoerg#endif
2650*4d6fc14bSjoerg
2651*4d6fc14bSjoergnamespace placeholders
2652*4d6fc14bSjoerg{
2653*4d6fc14bSjoerg
2654*4d6fc14bSjoergtemplate <int _Np> struct __ph {};
2655*4d6fc14bSjoerg
2656*4d6fc14bSjoerg#if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY)
2657*4d6fc14bSjoerg_LIBCPP_FUNC_VIS extern const __ph<1>   _1;
2658*4d6fc14bSjoerg_LIBCPP_FUNC_VIS extern const __ph<2>   _2;
2659*4d6fc14bSjoerg_LIBCPP_FUNC_VIS extern const __ph<3>   _3;
2660*4d6fc14bSjoerg_LIBCPP_FUNC_VIS extern const __ph<4>   _4;
2661*4d6fc14bSjoerg_LIBCPP_FUNC_VIS extern const __ph<5>   _5;
2662*4d6fc14bSjoerg_LIBCPP_FUNC_VIS extern const __ph<6>   _6;
2663*4d6fc14bSjoerg_LIBCPP_FUNC_VIS extern const __ph<7>   _7;
2664*4d6fc14bSjoerg_LIBCPP_FUNC_VIS extern const __ph<8>   _8;
2665*4d6fc14bSjoerg_LIBCPP_FUNC_VIS extern const __ph<9>   _9;
2666*4d6fc14bSjoerg_LIBCPP_FUNC_VIS extern const __ph<10> _10;
2667*4d6fc14bSjoerg#else
2668*4d6fc14bSjoerg/* _LIBCPP_INLINE_VAR */ constexpr __ph<1>   _1{};
2669*4d6fc14bSjoerg/* _LIBCPP_INLINE_VAR */ constexpr __ph<2>   _2{};
2670*4d6fc14bSjoerg/* _LIBCPP_INLINE_VAR */ constexpr __ph<3>   _3{};
2671*4d6fc14bSjoerg/* _LIBCPP_INLINE_VAR */ constexpr __ph<4>   _4{};
2672*4d6fc14bSjoerg/* _LIBCPP_INLINE_VAR */ constexpr __ph<5>   _5{};
2673*4d6fc14bSjoerg/* _LIBCPP_INLINE_VAR */ constexpr __ph<6>   _6{};
2674*4d6fc14bSjoerg/* _LIBCPP_INLINE_VAR */ constexpr __ph<7>   _7{};
2675*4d6fc14bSjoerg/* _LIBCPP_INLINE_VAR */ constexpr __ph<8>   _8{};
2676*4d6fc14bSjoerg/* _LIBCPP_INLINE_VAR */ constexpr __ph<9>   _9{};
2677*4d6fc14bSjoerg/* _LIBCPP_INLINE_VAR */ constexpr __ph<10> _10{};
2678*4d6fc14bSjoerg#endif // defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY)
2679*4d6fc14bSjoerg
2680*4d6fc14bSjoerg}  // placeholders
2681*4d6fc14bSjoerg
2682*4d6fc14bSjoergtemplate<int _Np>
2683*4d6fc14bSjoergstruct __is_placeholder<placeholders::__ph<_Np> >
2684*4d6fc14bSjoerg    : public integral_constant<int, _Np> {};
2685*4d6fc14bSjoerg
2686*4d6fc14bSjoerg
2687*4d6fc14bSjoerg#ifndef _LIBCPP_CXX03_LANG
2688*4d6fc14bSjoerg
2689*4d6fc14bSjoergtemplate <class _Tp, class _Uj>
2690*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY
2691*4d6fc14bSjoerg_Tp&
2692*4d6fc14bSjoerg__mu(reference_wrapper<_Tp> __t, _Uj&)
2693*4d6fc14bSjoerg{
2694*4d6fc14bSjoerg    return __t.get();
2695*4d6fc14bSjoerg}
2696*4d6fc14bSjoerg
2697*4d6fc14bSjoergtemplate <class _Ti, class ..._Uj, size_t ..._Indx>
2698*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY
2699*4d6fc14bSjoergtypename __invoke_of<_Ti&, _Uj...>::type
2700*4d6fc14bSjoerg__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>)
2701*4d6fc14bSjoerg{
2702*4d6fc14bSjoerg    return __ti(_VSTD::forward<_Uj>(_VSTD::get<_Indx>(__uj))...);
2703*4d6fc14bSjoerg}
2704*4d6fc14bSjoerg
2705*4d6fc14bSjoergtemplate <class _Ti, class ..._Uj>
2706*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY
2707*4d6fc14bSjoergtypename _EnableIf
2708*4d6fc14bSjoerg<
2709*4d6fc14bSjoerg    is_bind_expression<_Ti>::value,
2710*4d6fc14bSjoerg    __invoke_of<_Ti&, _Uj...>
2711*4d6fc14bSjoerg>::type
2712*4d6fc14bSjoerg__mu(_Ti& __ti, tuple<_Uj...>& __uj)
2713*4d6fc14bSjoerg{
2714*4d6fc14bSjoerg    typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices;
2715*4d6fc14bSjoerg    return _VSTD::__mu_expand(__ti, __uj, __indices());
2716*4d6fc14bSjoerg}
2717*4d6fc14bSjoerg
2718*4d6fc14bSjoergtemplate <bool IsPh, class _Ti, class _Uj>
2719*4d6fc14bSjoergstruct __mu_return2 {};
2720*4d6fc14bSjoerg
2721*4d6fc14bSjoergtemplate <class _Ti, class _Uj>
2722*4d6fc14bSjoergstruct __mu_return2<true, _Ti, _Uj>
2723*4d6fc14bSjoerg{
2724*4d6fc14bSjoerg    typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type;
2725*4d6fc14bSjoerg};
2726*4d6fc14bSjoerg
2727*4d6fc14bSjoergtemplate <class _Ti, class _Uj>
2728*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY
2729*4d6fc14bSjoergtypename enable_if
2730*4d6fc14bSjoerg<
2731*4d6fc14bSjoerg    0 < is_placeholder<_Ti>::value,
2732*4d6fc14bSjoerg    typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type
2733*4d6fc14bSjoerg>::type
2734*4d6fc14bSjoerg__mu(_Ti&, _Uj& __uj)
2735*4d6fc14bSjoerg{
2736*4d6fc14bSjoerg    const size_t _Indx = is_placeholder<_Ti>::value - 1;
2737*4d6fc14bSjoerg    return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj));
2738*4d6fc14bSjoerg}
2739*4d6fc14bSjoerg
2740*4d6fc14bSjoergtemplate <class _Ti, class _Uj>
2741*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY
2742*4d6fc14bSjoergtypename enable_if
2743*4d6fc14bSjoerg<
2744*4d6fc14bSjoerg    !is_bind_expression<_Ti>::value &&
2745*4d6fc14bSjoerg    is_placeholder<_Ti>::value == 0 &&
2746*4d6fc14bSjoerg    !__is_reference_wrapper<_Ti>::value,
2747*4d6fc14bSjoerg    _Ti&
2748*4d6fc14bSjoerg>::type
2749*4d6fc14bSjoerg__mu(_Ti& __ti, _Uj&)
2750*4d6fc14bSjoerg{
2751*4d6fc14bSjoerg    return __ti;
2752*4d6fc14bSjoerg}
2753*4d6fc14bSjoerg
2754*4d6fc14bSjoergtemplate <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh,
2755*4d6fc14bSjoerg          class _TupleUj>
2756*4d6fc14bSjoergstruct __mu_return_impl;
2757*4d6fc14bSjoerg
2758*4d6fc14bSjoergtemplate <bool _Invokable, class _Ti, class ..._Uj>
2759*4d6fc14bSjoergstruct __mu_return_invokable  // false
2760*4d6fc14bSjoerg{
2761*4d6fc14bSjoerg    typedef __nat type;
2762*4d6fc14bSjoerg};
2763*4d6fc14bSjoerg
2764*4d6fc14bSjoergtemplate <class _Ti, class ..._Uj>
2765*4d6fc14bSjoergstruct __mu_return_invokable<true, _Ti, _Uj...>
2766*4d6fc14bSjoerg{
2767*4d6fc14bSjoerg    typedef typename __invoke_of<_Ti&, _Uj...>::type type;
2768*4d6fc14bSjoerg};
2769*4d6fc14bSjoerg
2770*4d6fc14bSjoergtemplate <class _Ti, class ..._Uj>
2771*4d6fc14bSjoergstruct __mu_return_impl<_Ti, false, true, false, tuple<_Uj...> >
2772*4d6fc14bSjoerg    : public __mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...>
2773*4d6fc14bSjoerg{
2774*4d6fc14bSjoerg};
2775*4d6fc14bSjoerg
2776*4d6fc14bSjoergtemplate <class _Ti, class _TupleUj>
2777*4d6fc14bSjoergstruct __mu_return_impl<_Ti, false, false, true, _TupleUj>
2778*4d6fc14bSjoerg{
2779*4d6fc14bSjoerg    typedef typename tuple_element<is_placeholder<_Ti>::value - 1,
2780*4d6fc14bSjoerg                                   _TupleUj>::type&& type;
2781*4d6fc14bSjoerg};
2782*4d6fc14bSjoerg
2783*4d6fc14bSjoergtemplate <class _Ti, class _TupleUj>
2784*4d6fc14bSjoergstruct __mu_return_impl<_Ti, true, false, false, _TupleUj>
2785*4d6fc14bSjoerg{
2786*4d6fc14bSjoerg    typedef typename _Ti::type& type;
2787*4d6fc14bSjoerg};
2788*4d6fc14bSjoerg
2789*4d6fc14bSjoergtemplate <class _Ti, class _TupleUj>
2790*4d6fc14bSjoergstruct __mu_return_impl<_Ti, false, false, false, _TupleUj>
2791*4d6fc14bSjoerg{
2792*4d6fc14bSjoerg    typedef _Ti& type;
2793*4d6fc14bSjoerg};
2794*4d6fc14bSjoerg
2795*4d6fc14bSjoergtemplate <class _Ti, class _TupleUj>
2796*4d6fc14bSjoergstruct __mu_return
2797*4d6fc14bSjoerg    : public __mu_return_impl<_Ti,
2798*4d6fc14bSjoerg                              __is_reference_wrapper<_Ti>::value,
2799*4d6fc14bSjoerg                              is_bind_expression<_Ti>::value,
2800*4d6fc14bSjoerg                              0 < is_placeholder<_Ti>::value &&
2801*4d6fc14bSjoerg                              is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value,
2802*4d6fc14bSjoerg                              _TupleUj>
2803*4d6fc14bSjoerg{
2804*4d6fc14bSjoerg};
2805*4d6fc14bSjoerg
2806*4d6fc14bSjoergtemplate <class _Fp, class _BoundArgs, class _TupleUj>
2807*4d6fc14bSjoergstruct __is_valid_bind_return
2808*4d6fc14bSjoerg{
2809*4d6fc14bSjoerg    static const bool value = false;
2810*4d6fc14bSjoerg};
2811*4d6fc14bSjoerg
2812*4d6fc14bSjoergtemplate <class _Fp, class ..._BoundArgs, class _TupleUj>
2813*4d6fc14bSjoergstruct __is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj>
2814*4d6fc14bSjoerg{
2815*4d6fc14bSjoerg    static const bool value = __invokable<_Fp,
2816*4d6fc14bSjoerg                    typename __mu_return<_BoundArgs, _TupleUj>::type...>::value;
2817*4d6fc14bSjoerg};
2818*4d6fc14bSjoerg
2819*4d6fc14bSjoergtemplate <class _Fp, class ..._BoundArgs, class _TupleUj>
2820*4d6fc14bSjoergstruct __is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj>
2821*4d6fc14bSjoerg{
2822*4d6fc14bSjoerg    static const bool value = __invokable<_Fp,
2823*4d6fc14bSjoerg                    typename __mu_return<const _BoundArgs, _TupleUj>::type...>::value;
2824*4d6fc14bSjoerg};
2825*4d6fc14bSjoerg
2826*4d6fc14bSjoergtemplate <class _Fp, class _BoundArgs, class _TupleUj,
2827*4d6fc14bSjoerg          bool = __is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value>
2828*4d6fc14bSjoergstruct __bind_return;
2829*4d6fc14bSjoerg
2830*4d6fc14bSjoergtemplate <class _Fp, class ..._BoundArgs, class _TupleUj>
2831*4d6fc14bSjoergstruct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true>
2832*4d6fc14bSjoerg{
2833*4d6fc14bSjoerg    typedef typename __invoke_of
2834*4d6fc14bSjoerg    <
2835*4d6fc14bSjoerg        _Fp&,
2836*4d6fc14bSjoerg        typename __mu_return
2837*4d6fc14bSjoerg        <
2838*4d6fc14bSjoerg            _BoundArgs,
2839*4d6fc14bSjoerg            _TupleUj
2840*4d6fc14bSjoerg        >::type...
2841*4d6fc14bSjoerg    >::type type;
2842*4d6fc14bSjoerg};
2843*4d6fc14bSjoerg
2844*4d6fc14bSjoergtemplate <class _Fp, class ..._BoundArgs, class _TupleUj>
2845*4d6fc14bSjoergstruct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true>
2846*4d6fc14bSjoerg{
2847*4d6fc14bSjoerg    typedef typename __invoke_of
2848*4d6fc14bSjoerg    <
2849*4d6fc14bSjoerg        _Fp&,
2850*4d6fc14bSjoerg        typename __mu_return
2851*4d6fc14bSjoerg        <
2852*4d6fc14bSjoerg            const _BoundArgs,
2853*4d6fc14bSjoerg            _TupleUj
2854*4d6fc14bSjoerg        >::type...
2855*4d6fc14bSjoerg    >::type type;
2856*4d6fc14bSjoerg};
2857*4d6fc14bSjoerg
2858*4d6fc14bSjoergtemplate <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args>
2859*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY
2860*4d6fc14bSjoergtypename __bind_return<_Fp, _BoundArgs, _Args>::type
2861*4d6fc14bSjoerg__apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
2862*4d6fc14bSjoerg                _Args&& __args)
2863*4d6fc14bSjoerg{
2864*4d6fc14bSjoerg    return _VSTD::__invoke(__f, _VSTD::__mu(_VSTD::get<_Indx>(__bound_args), __args)...);
2865*4d6fc14bSjoerg}
2866*4d6fc14bSjoerg
2867*4d6fc14bSjoergtemplate<class _Fp, class ..._BoundArgs>
2868*4d6fc14bSjoergclass __bind
2869*4d6fc14bSjoerg    : public __weak_result_type<typename decay<_Fp>::type>
2870*4d6fc14bSjoerg{
2871*4d6fc14bSjoergprotected:
2872*4d6fc14bSjoerg    typedef typename decay<_Fp>::type _Fd;
2873*4d6fc14bSjoerg    typedef tuple<typename decay<_BoundArgs>::type...> _Td;
2874*4d6fc14bSjoergprivate:
2875*4d6fc14bSjoerg    _Fd __f_;
2876*4d6fc14bSjoerg    _Td __bound_args_;
2877*4d6fc14bSjoerg
2878*4d6fc14bSjoerg    typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices;
2879*4d6fc14bSjoergpublic:
2880*4d6fc14bSjoerg    template <class _Gp, class ..._BA,
2881*4d6fc14bSjoerg              class = typename enable_if
2882*4d6fc14bSjoerg                               <
2883*4d6fc14bSjoerg                                  is_constructible<_Fd, _Gp>::value &&
2884*4d6fc14bSjoerg                                  !is_same<typename remove_reference<_Gp>::type,
2885*4d6fc14bSjoerg                                           __bind>::value
2886*4d6fc14bSjoerg                               >::type>
2887*4d6fc14bSjoerg      _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
2888*4d6fc14bSjoerg      explicit __bind(_Gp&& __f, _BA&& ...__bound_args)
2889*4d6fc14bSjoerg        : __f_(_VSTD::forward<_Gp>(__f)),
2890*4d6fc14bSjoerg          __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {}
2891*4d6fc14bSjoerg
2892*4d6fc14bSjoerg    template <class ..._Args>
2893*4d6fc14bSjoerg        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
2894*4d6fc14bSjoerg        typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type
2895*4d6fc14bSjoerg        operator()(_Args&& ...__args)
2896*4d6fc14bSjoerg        {
2897*4d6fc14bSjoerg            return _VSTD::__apply_functor(__f_, __bound_args_, __indices(),
2898*4d6fc14bSjoerg                                  tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
2899*4d6fc14bSjoerg        }
2900*4d6fc14bSjoerg
2901*4d6fc14bSjoerg    template <class ..._Args>
2902*4d6fc14bSjoerg        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
2903*4d6fc14bSjoerg        typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type
2904*4d6fc14bSjoerg        operator()(_Args&& ...__args) const
2905*4d6fc14bSjoerg        {
2906*4d6fc14bSjoerg            return _VSTD::__apply_functor(__f_, __bound_args_, __indices(),
2907*4d6fc14bSjoerg                                   tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
2908*4d6fc14bSjoerg        }
2909*4d6fc14bSjoerg};
2910*4d6fc14bSjoerg
2911*4d6fc14bSjoergtemplate<class _Fp, class ..._BoundArgs>
2912*4d6fc14bSjoergstruct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {};
2913*4d6fc14bSjoerg
2914*4d6fc14bSjoergtemplate<class _Rp, class _Fp, class ..._BoundArgs>
2915*4d6fc14bSjoergclass __bind_r
2916*4d6fc14bSjoerg    : public __bind<_Fp, _BoundArgs...>
2917*4d6fc14bSjoerg{
2918*4d6fc14bSjoerg    typedef __bind<_Fp, _BoundArgs...> base;
2919*4d6fc14bSjoerg    typedef typename base::_Fd _Fd;
2920*4d6fc14bSjoerg    typedef typename base::_Td _Td;
2921*4d6fc14bSjoergpublic:
2922*4d6fc14bSjoerg    typedef _Rp result_type;
2923*4d6fc14bSjoerg
2924*4d6fc14bSjoerg
2925*4d6fc14bSjoerg    template <class _Gp, class ..._BA,
2926*4d6fc14bSjoerg              class = typename enable_if
2927*4d6fc14bSjoerg                               <
2928*4d6fc14bSjoerg                                  is_constructible<_Fd, _Gp>::value &&
2929*4d6fc14bSjoerg                                  !is_same<typename remove_reference<_Gp>::type,
2930*4d6fc14bSjoerg                                           __bind_r>::value
2931*4d6fc14bSjoerg                               >::type>
2932*4d6fc14bSjoerg      _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
2933*4d6fc14bSjoerg      explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args)
2934*4d6fc14bSjoerg        : base(_VSTD::forward<_Gp>(__f),
2935*4d6fc14bSjoerg               _VSTD::forward<_BA>(__bound_args)...) {}
2936*4d6fc14bSjoerg
2937*4d6fc14bSjoerg    template <class ..._Args>
2938*4d6fc14bSjoerg        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
2939*4d6fc14bSjoerg        typename enable_if
2940*4d6fc14bSjoerg        <
2941*4d6fc14bSjoerg            is_convertible<typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type,
2942*4d6fc14bSjoerg                           result_type>::value || is_void<_Rp>::value,
2943*4d6fc14bSjoerg            result_type
2944*4d6fc14bSjoerg        >::type
2945*4d6fc14bSjoerg        operator()(_Args&& ...__args)
2946*4d6fc14bSjoerg        {
2947*4d6fc14bSjoerg            typedef __invoke_void_return_wrapper<_Rp> _Invoker;
2948*4d6fc14bSjoerg            return _Invoker::__call(static_cast<base&>(*this), _VSTD::forward<_Args>(__args)...);
2949*4d6fc14bSjoerg        }
2950*4d6fc14bSjoerg
2951*4d6fc14bSjoerg    template <class ..._Args>
2952*4d6fc14bSjoerg        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
2953*4d6fc14bSjoerg        typename enable_if
2954*4d6fc14bSjoerg        <
2955*4d6fc14bSjoerg            is_convertible<typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type,
2956*4d6fc14bSjoerg                           result_type>::value || is_void<_Rp>::value,
2957*4d6fc14bSjoerg            result_type
2958*4d6fc14bSjoerg        >::type
2959*4d6fc14bSjoerg        operator()(_Args&& ...__args) const
2960*4d6fc14bSjoerg        {
2961*4d6fc14bSjoerg            typedef __invoke_void_return_wrapper<_Rp> _Invoker;
2962*4d6fc14bSjoerg            return _Invoker::__call(static_cast<base const&>(*this), _VSTD::forward<_Args>(__args)...);
2963*4d6fc14bSjoerg        }
2964*4d6fc14bSjoerg};
2965*4d6fc14bSjoerg
2966*4d6fc14bSjoergtemplate<class _Rp, class _Fp, class ..._BoundArgs>
2967*4d6fc14bSjoergstruct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {};
2968*4d6fc14bSjoerg
2969*4d6fc14bSjoergtemplate<class _Fp, class ..._BoundArgs>
2970*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
2971*4d6fc14bSjoerg__bind<_Fp, _BoundArgs...>
2972*4d6fc14bSjoergbind(_Fp&& __f, _BoundArgs&&... __bound_args)
2973*4d6fc14bSjoerg{
2974*4d6fc14bSjoerg    typedef __bind<_Fp, _BoundArgs...> type;
2975*4d6fc14bSjoerg    return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
2976*4d6fc14bSjoerg}
2977*4d6fc14bSjoerg
2978*4d6fc14bSjoergtemplate<class _Rp, class _Fp, class ..._BoundArgs>
2979*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
2980*4d6fc14bSjoerg__bind_r<_Rp, _Fp, _BoundArgs...>
2981*4d6fc14bSjoergbind(_Fp&& __f, _BoundArgs&&... __bound_args)
2982*4d6fc14bSjoerg{
2983*4d6fc14bSjoerg    typedef __bind_r<_Rp, _Fp, _BoundArgs...> type;
2984*4d6fc14bSjoerg    return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
2985*4d6fc14bSjoerg}
2986*4d6fc14bSjoerg
2987*4d6fc14bSjoerg#endif // _LIBCPP_CXX03_LANG
2988*4d6fc14bSjoerg
2989*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 14
2990*4d6fc14bSjoerg
2991*4d6fc14bSjoergtemplate<class _Op, class _Tuple,
2992*4d6fc14bSjoerg         class _Idxs = typename __make_tuple_indices<tuple_size<_Tuple>::value>::type>
2993*4d6fc14bSjoergstruct __perfect_forward_impl;
2994*4d6fc14bSjoerg
2995*4d6fc14bSjoergtemplate<class _Op, class... _Bound, size_t... _Idxs>
2996*4d6fc14bSjoergstruct __perfect_forward_impl<_Op, __tuple_types<_Bound...>, __tuple_indices<_Idxs...>>
2997*4d6fc14bSjoerg{
2998*4d6fc14bSjoerg    tuple<_Bound...> __bound_;
2999*4d6fc14bSjoerg
3000*4d6fc14bSjoerg    template<class... _Args>
3001*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) &
3002*4d6fc14bSjoerg    noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...)))
3003*4d6fc14bSjoerg    -> decltype(      _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...))
3004*4d6fc14bSjoerg    {return           _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...);}
3005*4d6fc14bSjoerg
3006*4d6fc14bSjoerg    template<class... _Args>
3007*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) const&
3008*4d6fc14bSjoerg    noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...)))
3009*4d6fc14bSjoerg    -> decltype(      _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...))
3010*4d6fc14bSjoerg    {return           _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...);}
3011*4d6fc14bSjoerg
3012*4d6fc14bSjoerg    template<class... _Args>
3013*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) &&
3014*4d6fc14bSjoerg    noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3015*4d6fc14bSjoerg                                  _VSTD::forward<_Args>(__args)...)))
3016*4d6fc14bSjoerg    -> decltype(      _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3017*4d6fc14bSjoerg                                  _VSTD::forward<_Args>(__args)...))
3018*4d6fc14bSjoerg    {return           _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3019*4d6fc14bSjoerg                                  _VSTD::forward<_Args>(__args)...);}
3020*4d6fc14bSjoerg
3021*4d6fc14bSjoerg    template<class... _Args>
3022*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) const&&
3023*4d6fc14bSjoerg    noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3024*4d6fc14bSjoerg                                  _VSTD::forward<_Args>(__args)...)))
3025*4d6fc14bSjoerg    -> decltype(      _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3026*4d6fc14bSjoerg                                  _VSTD::forward<_Args>(__args)...))
3027*4d6fc14bSjoerg    {return           _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3028*4d6fc14bSjoerg                                  _VSTD::forward<_Args>(__args)...);}
3029*4d6fc14bSjoerg
3030*4d6fc14bSjoerg    template<class _Fn = typename tuple_element<0, tuple<_Bound...>>::type,
3031*4d6fc14bSjoerg             class = _EnableIf<is_copy_constructible_v<_Fn>>>
3032*4d6fc14bSjoerg    constexpr __perfect_forward_impl(__perfect_forward_impl const& __other)
3033*4d6fc14bSjoerg        : __bound_(__other.__bound_) {}
3034*4d6fc14bSjoerg
3035*4d6fc14bSjoerg    template<class _Fn = typename tuple_element<0, tuple<_Bound...>>::type,
3036*4d6fc14bSjoerg             class = _EnableIf<is_move_constructible_v<_Fn>>>
3037*4d6fc14bSjoerg    constexpr __perfect_forward_impl(__perfect_forward_impl && __other)
3038*4d6fc14bSjoerg        : __bound_(_VSTD::move(__other.__bound_)) {}
3039*4d6fc14bSjoerg
3040*4d6fc14bSjoerg    template<class... _BoundArgs>
3041*4d6fc14bSjoerg    explicit constexpr __perfect_forward_impl(_BoundArgs&&... __bound) :
3042*4d6fc14bSjoerg        __bound_(_VSTD::forward<_BoundArgs>(__bound)...) { }
3043*4d6fc14bSjoerg};
3044*4d6fc14bSjoerg
3045*4d6fc14bSjoergtemplate<class _Op, class... _Args>
3046*4d6fc14bSjoergusing __perfect_forward =
3047*4d6fc14bSjoerg    __perfect_forward_impl<_Op, __tuple_types<decay_t<_Args>...>>;
3048*4d6fc14bSjoerg
3049*4d6fc14bSjoergstruct __not_fn_op
3050*4d6fc14bSjoerg{
3051*4d6fc14bSjoerg    template<class... _Args>
3052*4d6fc14bSjoerg    static _LIBCPP_CONSTEXPR_AFTER_CXX17 auto __call(_Args&&... __args)
3053*4d6fc14bSjoerg    noexcept(noexcept(!_VSTD::invoke(_VSTD::forward<_Args>(__args)...)))
3054*4d6fc14bSjoerg    -> decltype(      !_VSTD::invoke(_VSTD::forward<_Args>(__args)...))
3055*4d6fc14bSjoerg    { return          !_VSTD::invoke(_VSTD::forward<_Args>(__args)...); }
3056*4d6fc14bSjoerg};
3057*4d6fc14bSjoerg
3058*4d6fc14bSjoergtemplate<class _Fn,
3059*4d6fc14bSjoerg         class = _EnableIf<is_constructible_v<decay_t<_Fn>, _Fn> &&
3060*4d6fc14bSjoerg                           is_move_constructible_v<_Fn>>>
3061*4d6fc14bSjoerg_LIBCPP_CONSTEXPR_AFTER_CXX17 auto not_fn(_Fn&& __f)
3062*4d6fc14bSjoerg{
3063*4d6fc14bSjoerg    return __perfect_forward<__not_fn_op, _Fn>(_VSTD::forward<_Fn>(__f));
3064*4d6fc14bSjoerg}
3065*4d6fc14bSjoerg
3066*4d6fc14bSjoerg#endif // _LIBCPP_STD_VER > 14
3067*4d6fc14bSjoerg
3068*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 17
3069*4d6fc14bSjoerg
3070*4d6fc14bSjoergstruct __bind_front_op
3071*4d6fc14bSjoerg{
3072*4d6fc14bSjoerg    template<class... _Args>
3073*4d6fc14bSjoerg    constexpr static auto __call(_Args&&... __args)
3074*4d6fc14bSjoerg    noexcept(noexcept(_VSTD::invoke(_VSTD::forward<_Args>(__args)...)))
3075*4d6fc14bSjoerg    -> decltype(      _VSTD::invoke(_VSTD::forward<_Args>(__args)...))
3076*4d6fc14bSjoerg    { return          _VSTD::invoke(_VSTD::forward<_Args>(__args)...); }
3077*4d6fc14bSjoerg};
3078*4d6fc14bSjoerg
3079*4d6fc14bSjoergtemplate<class _Fn, class... _Args,
3080*4d6fc14bSjoerg         class = _EnableIf<conjunction<is_constructible<decay_t<_Fn>, _Fn>,
3081*4d6fc14bSjoerg                                       is_move_constructible<decay_t<_Fn>>,
3082*4d6fc14bSjoerg                                       is_constructible<decay_t<_Args>, _Args>...,
3083*4d6fc14bSjoerg                                       is_move_constructible<decay_t<_Args>>...
3084*4d6fc14bSjoerg                                       >::value>>
3085*4d6fc14bSjoergconstexpr auto bind_front(_Fn&& __f, _Args&&... __args)
3086*4d6fc14bSjoerg{
3087*4d6fc14bSjoerg    return __perfect_forward<__bind_front_op, _Fn, _Args...>(_VSTD::forward<_Fn>(__f),
3088*4d6fc14bSjoerg                                                             _VSTD::forward<_Args>(__args)...);
3089*4d6fc14bSjoerg}
3090*4d6fc14bSjoerg
3091*4d6fc14bSjoerg#endif // _LIBCPP_STD_VER > 17
3092*4d6fc14bSjoerg
3093*4d6fc14bSjoerg// struct hash<T*> in <memory>
3094*4d6fc14bSjoerg
3095*4d6fc14bSjoergtemplate <class _BinaryPredicate, class _ForwardIterator1, class _ForwardIterator2>
3096*4d6fc14bSjoergpair<_ForwardIterator1, _ForwardIterator1> _LIBCPP_CONSTEXPR_AFTER_CXX11
3097*4d6fc14bSjoerg__search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
3098*4d6fc14bSjoerg         _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred,
3099*4d6fc14bSjoerg         forward_iterator_tag, forward_iterator_tag)
3100*4d6fc14bSjoerg{
3101*4d6fc14bSjoerg    if (__first2 == __last2)
3102*4d6fc14bSjoerg        return _VSTD::make_pair(__first1, __first1);  // Everything matches an empty sequence
3103*4d6fc14bSjoerg    while (true)
3104*4d6fc14bSjoerg    {
3105*4d6fc14bSjoerg        // Find first element in sequence 1 that matchs *__first2, with a mininum of loop checks
3106*4d6fc14bSjoerg        while (true)
3107*4d6fc14bSjoerg        {
3108*4d6fc14bSjoerg            if (__first1 == __last1)  // return __last1 if no element matches *__first2
3109*4d6fc14bSjoerg                return _VSTD::make_pair(__last1, __last1);
3110*4d6fc14bSjoerg            if (__pred(*__first1, *__first2))
3111*4d6fc14bSjoerg                break;
3112*4d6fc14bSjoerg            ++__first1;
3113*4d6fc14bSjoerg        }
3114*4d6fc14bSjoerg        // *__first1 matches *__first2, now match elements after here
3115*4d6fc14bSjoerg        _ForwardIterator1 __m1 = __first1;
3116*4d6fc14bSjoerg        _ForwardIterator2 __m2 = __first2;
3117*4d6fc14bSjoerg        while (true)
3118*4d6fc14bSjoerg        {
3119*4d6fc14bSjoerg            if (++__m2 == __last2)  // If pattern exhausted, __first1 is the answer (works for 1 element pattern)
3120*4d6fc14bSjoerg                return _VSTD::make_pair(__first1, __m1);
3121*4d6fc14bSjoerg            if (++__m1 == __last1)  // Otherwise if source exhaused, pattern not found
3122*4d6fc14bSjoerg                return _VSTD::make_pair(__last1, __last1);
3123*4d6fc14bSjoerg            if (!__pred(*__m1, *__m2))  // if there is a mismatch, restart with a new __first1
3124*4d6fc14bSjoerg            {
3125*4d6fc14bSjoerg                ++__first1;
3126*4d6fc14bSjoerg                break;
3127*4d6fc14bSjoerg            }  // else there is a match, check next elements
3128*4d6fc14bSjoerg        }
3129*4d6fc14bSjoerg    }
3130*4d6fc14bSjoerg}
3131*4d6fc14bSjoerg
3132*4d6fc14bSjoergtemplate <class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2>
3133*4d6fc14bSjoerg_LIBCPP_CONSTEXPR_AFTER_CXX11
3134*4d6fc14bSjoergpair<_RandomAccessIterator1, _RandomAccessIterator1>
3135*4d6fc14bSjoerg__search(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1,
3136*4d6fc14bSjoerg         _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __pred,
3137*4d6fc14bSjoerg           random_access_iterator_tag, random_access_iterator_tag)
3138*4d6fc14bSjoerg{
3139*4d6fc14bSjoerg    typedef typename iterator_traits<_RandomAccessIterator1>::difference_type _D1;
3140*4d6fc14bSjoerg    typedef typename iterator_traits<_RandomAccessIterator2>::difference_type _D2;
3141*4d6fc14bSjoerg    // Take advantage of knowing source and pattern lengths.  Stop short when source is smaller than pattern
3142*4d6fc14bSjoerg    const _D2 __len2 = __last2 - __first2;
3143*4d6fc14bSjoerg    if (__len2 == 0)
3144*4d6fc14bSjoerg        return _VSTD::make_pair(__first1, __first1);
3145*4d6fc14bSjoerg    const _D1 __len1 = __last1 - __first1;
3146*4d6fc14bSjoerg    if (__len1 < __len2)
3147*4d6fc14bSjoerg        return _VSTD::make_pair(__last1, __last1);
3148*4d6fc14bSjoerg    const _RandomAccessIterator1 __s = __last1 - (__len2 - 1);  // Start of pattern match can't go beyond here
3149*4d6fc14bSjoerg
3150*4d6fc14bSjoerg    while (true)
3151*4d6fc14bSjoerg    {
3152*4d6fc14bSjoerg        while (true)
3153*4d6fc14bSjoerg        {
3154*4d6fc14bSjoerg            if (__first1 == __s)
3155*4d6fc14bSjoerg                return _VSTD::make_pair(__last1, __last1);
3156*4d6fc14bSjoerg            if (__pred(*__first1, *__first2))
3157*4d6fc14bSjoerg                break;
3158*4d6fc14bSjoerg            ++__first1;
3159*4d6fc14bSjoerg        }
3160*4d6fc14bSjoerg
3161*4d6fc14bSjoerg        _RandomAccessIterator1 __m1 = __first1;
3162*4d6fc14bSjoerg        _RandomAccessIterator2 __m2 = __first2;
3163*4d6fc14bSjoerg         while (true)
3164*4d6fc14bSjoerg         {
3165*4d6fc14bSjoerg             if (++__m2 == __last2)
3166*4d6fc14bSjoerg                 return _VSTD::make_pair(__first1, __first1 + __len2);
3167*4d6fc14bSjoerg             ++__m1;          // no need to check range on __m1 because __s guarantees we have enough source
3168*4d6fc14bSjoerg             if (!__pred(*__m1, *__m2))
3169*4d6fc14bSjoerg             {
3170*4d6fc14bSjoerg                 ++__first1;
3171*4d6fc14bSjoerg                 break;
3172*4d6fc14bSjoerg             }
3173*4d6fc14bSjoerg         }
3174*4d6fc14bSjoerg    }
3175*4d6fc14bSjoerg}
3176*4d6fc14bSjoerg
3177*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 14
3178*4d6fc14bSjoerg
3179*4d6fc14bSjoerg// default searcher
3180*4d6fc14bSjoergtemplate<class _ForwardIterator, class _BinaryPredicate = equal_to<>>
3181*4d6fc14bSjoergclass _LIBCPP_TEMPLATE_VIS default_searcher {
3182*4d6fc14bSjoergpublic:
3183*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
3184*4d6fc14bSjoerg    default_searcher(_ForwardIterator __f, _ForwardIterator __l,
3185*4d6fc14bSjoerg                       _BinaryPredicate __p = _BinaryPredicate())
3186*4d6fc14bSjoerg        : __first_(__f), __last_(__l), __pred_(__p) {}
3187*4d6fc14bSjoerg
3188*4d6fc14bSjoerg    template <typename _ForwardIterator2>
3189*4d6fc14bSjoerg    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
3190*4d6fc14bSjoerg    pair<_ForwardIterator2, _ForwardIterator2>
3191*4d6fc14bSjoerg    operator () (_ForwardIterator2 __f, _ForwardIterator2 __l) const
3192*4d6fc14bSjoerg    {
3193*4d6fc14bSjoerg        return _VSTD::__search(__f, __l, __first_, __last_, __pred_,
3194*4d6fc14bSjoerg            typename iterator_traits<_ForwardIterator>::iterator_category(),
3195*4d6fc14bSjoerg            typename iterator_traits<_ForwardIterator2>::iterator_category());
3196*4d6fc14bSjoerg    }
3197*4d6fc14bSjoerg
3198*4d6fc14bSjoergprivate:
3199*4d6fc14bSjoerg    _ForwardIterator __first_;
3200*4d6fc14bSjoerg    _ForwardIterator __last_;
3201*4d6fc14bSjoerg    _BinaryPredicate __pred_;
3202*4d6fc14bSjoerg    };
3203*4d6fc14bSjoerg
3204*4d6fc14bSjoerg#endif // _LIBCPP_STD_VER > 14
3205*4d6fc14bSjoerg
3206*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 17
3207*4d6fc14bSjoergtemplate <class _Tp>
3208*4d6fc14bSjoergusing unwrap_reference_t = typename unwrap_reference<_Tp>::type;
3209*4d6fc14bSjoerg
3210*4d6fc14bSjoergtemplate <class _Tp>
3211*4d6fc14bSjoergusing unwrap_ref_decay_t = typename unwrap_ref_decay<_Tp>::type;
3212*4d6fc14bSjoerg#endif // > C++17
3213*4d6fc14bSjoerg
3214*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 17
3215*4d6fc14bSjoerg// [func.identity]
3216*4d6fc14bSjoergstruct identity {
3217*4d6fc14bSjoerg    template<class _Tp>
3218*4d6fc14bSjoerg    _LIBCPP_NODISCARD_EXT constexpr _Tp&& operator()(_Tp&& __t) const noexcept
3219*4d6fc14bSjoerg    {
3220*4d6fc14bSjoerg        return _VSTD::forward<_Tp>(__t);
3221*4d6fc14bSjoerg    }
3222*4d6fc14bSjoerg
3223*4d6fc14bSjoerg    using is_transparent = void;
3224*4d6fc14bSjoerg};
3225*4d6fc14bSjoerg#endif // _LIBCPP_STD_VER > 17
3226*4d6fc14bSjoerg
3227*4d6fc14bSjoerg#if !defined(_LIBCPP_HAS_NO_RANGES)
3228*4d6fc14bSjoerg
3229*4d6fc14bSjoergnamespace ranges {
3230*4d6fc14bSjoerg
3231*4d6fc14bSjoergstruct equal_to {
3232*4d6fc14bSjoerg  template <class _Tp, class _Up>
3233*4d6fc14bSjoerg  requires equality_comparable_with<_Tp, _Up>
3234*4d6fc14bSjoerg  [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3235*4d6fc14bSjoerg      noexcept(noexcept(bool(_VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u)))) {
3236*4d6fc14bSjoerg    return _VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u);
3237*4d6fc14bSjoerg  }
3238*4d6fc14bSjoerg
3239*4d6fc14bSjoerg  using is_transparent = void;
3240*4d6fc14bSjoerg};
3241*4d6fc14bSjoerg
3242*4d6fc14bSjoergstruct not_equal_to {
3243*4d6fc14bSjoerg  template <class _Tp, class _Up>
3244*4d6fc14bSjoerg  requires equality_comparable_with<_Tp, _Up>
3245*4d6fc14bSjoerg  [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3246*4d6fc14bSjoerg      noexcept(noexcept(bool(!(_VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u))))) {
3247*4d6fc14bSjoerg    return !(_VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u));
3248*4d6fc14bSjoerg  }
3249*4d6fc14bSjoerg
3250*4d6fc14bSjoerg  using is_transparent = void;
3251*4d6fc14bSjoerg};
3252*4d6fc14bSjoerg
3253*4d6fc14bSjoergstruct greater {
3254*4d6fc14bSjoerg  template <class _Tp, class _Up>
3255*4d6fc14bSjoerg  requires totally_ordered_with<_Tp, _Up>
3256*4d6fc14bSjoerg  [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3257*4d6fc14bSjoerg      noexcept(noexcept(bool(_VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t)))) {
3258*4d6fc14bSjoerg    return _VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t);
3259*4d6fc14bSjoerg  }
3260*4d6fc14bSjoerg
3261*4d6fc14bSjoerg  using is_transparent = void;
3262*4d6fc14bSjoerg};
3263*4d6fc14bSjoerg
3264*4d6fc14bSjoergstruct less {
3265*4d6fc14bSjoerg  template <class _Tp, class _Up>
3266*4d6fc14bSjoerg  requires totally_ordered_with<_Tp, _Up>
3267*4d6fc14bSjoerg  [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3268*4d6fc14bSjoerg      noexcept(noexcept(bool(_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u)))) {
3269*4d6fc14bSjoerg    return _VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u);
3270*4d6fc14bSjoerg  }
3271*4d6fc14bSjoerg
3272*4d6fc14bSjoerg  using is_transparent = void;
3273*4d6fc14bSjoerg};
3274*4d6fc14bSjoerg
3275*4d6fc14bSjoergstruct greater_equal {
3276*4d6fc14bSjoerg  template <class _Tp, class _Up>
3277*4d6fc14bSjoerg  requires totally_ordered_with<_Tp, _Up>
3278*4d6fc14bSjoerg  [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3279*4d6fc14bSjoerg      noexcept(noexcept(bool(!(_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u))))) {
3280*4d6fc14bSjoerg    return !(_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u));
3281*4d6fc14bSjoerg  }
3282*4d6fc14bSjoerg
3283*4d6fc14bSjoerg  using is_transparent = void;
3284*4d6fc14bSjoerg};
3285*4d6fc14bSjoerg
3286*4d6fc14bSjoergstruct less_equal {
3287*4d6fc14bSjoerg  template <class _Tp, class _Up>
3288*4d6fc14bSjoerg  requires totally_ordered_with<_Tp, _Up>
3289*4d6fc14bSjoerg  [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3290*4d6fc14bSjoerg      noexcept(noexcept(bool(!(_VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t))))) {
3291*4d6fc14bSjoerg    return !(_VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t));
3292*4d6fc14bSjoerg  }
3293*4d6fc14bSjoerg
3294*4d6fc14bSjoerg  using is_transparent = void;
3295*4d6fc14bSjoerg};
3296*4d6fc14bSjoerg
3297*4d6fc14bSjoerg} // namespace ranges
3298*4d6fc14bSjoerg
3299*4d6fc14bSjoerg#endif // !defined(_LIBCPP_HAS_NO_RANGES)
3300*4d6fc14bSjoerg
3301*4d6fc14bSjoerg_LIBCPP_END_NAMESPACE_STD
3302*4d6fc14bSjoerg
3303*4d6fc14bSjoerg#endif // _LIBCPP_FUNCTIONAL
3304