13e519524SHoward Hinnant// -*- C++ -*-
23e519524SHoward Hinnant//===------------------------ functional ----------------------------------===//
33e519524SHoward Hinnant//
45b08a8a4SHoward Hinnant//                     The LLVM Compiler Infrastructure
53e519524SHoward Hinnant//
6412dbebeSHoward Hinnant// This file is dual licensed under the MIT and the University of Illinois Open
7412dbebeSHoward Hinnant// Source Licenses. See LICENSE.TXT for details.
83e519524SHoward Hinnant//
93e519524SHoward Hinnant//===----------------------------------------------------------------------===//
103e519524SHoward Hinnant
113e519524SHoward Hinnant#ifndef _LIBCPP_FUNCTIONAL
123e519524SHoward Hinnant#define _LIBCPP_FUNCTIONAL
133e519524SHoward Hinnant
143e519524SHoward Hinnant/*
153e519524SHoward Hinnant    functional synopsis
163e519524SHoward Hinnant
173e519524SHoward Hinnantnamespace std
183e519524SHoward Hinnant{
193e519524SHoward Hinnant
203e519524SHoward Hinnanttemplate <class Arg, class Result>
213e519524SHoward Hinnantstruct unary_function
223e519524SHoward Hinnant{
233e519524SHoward Hinnant    typedef Arg    argument_type;
243e519524SHoward Hinnant    typedef Result result_type;
253e519524SHoward Hinnant};
263e519524SHoward Hinnant
273e519524SHoward Hinnanttemplate <class Arg1, class Arg2, class Result>
283e519524SHoward Hinnantstruct binary_function
293e519524SHoward Hinnant{
303e519524SHoward Hinnant    typedef Arg1   first_argument_type;
313e519524SHoward Hinnant    typedef Arg2   second_argument_type;
323e519524SHoward Hinnant    typedef Result result_type;
333e519524SHoward Hinnant};
343e519524SHoward Hinnant
359b0b6d45SHoward Hinnanttemplate <class T>
363e519524SHoward Hinnantclass reference_wrapper
373e519524SHoward Hinnant    : public unary_function<T1, R> // if wrapping a unary functor
383e519524SHoward Hinnant    : public binary_function<T1, T2, R> // if wraping a binary functor
393e519524SHoward Hinnant{
403e519524SHoward Hinnantpublic:
413e519524SHoward Hinnant    // types
423e519524SHoward Hinnant    typedef T type;
433e519524SHoward Hinnant    typedef see below result_type; // Not always defined
443e519524SHoward Hinnant
453e519524SHoward Hinnant    // construct/copy/destroy
466a07d6f0SHoward Hinnant    reference_wrapper(T&) noexcept;
473e519524SHoward Hinnant    reference_wrapper(T&&) = delete; // do not bind to temps
486a07d6f0SHoward Hinnant    reference_wrapper(const reference_wrapper<T>& x) noexcept;
493e519524SHoward Hinnant
503e519524SHoward Hinnant    // assignment
516a07d6f0SHoward Hinnant    reference_wrapper& operator=(const reference_wrapper<T>& x) noexcept;
523e519524SHoward Hinnant
533e519524SHoward Hinnant    // access
546a07d6f0SHoward Hinnant    operator T& () const noexcept;
556a07d6f0SHoward Hinnant    T& get() const noexcept;
563e519524SHoward Hinnant
573e519524SHoward Hinnant    // invoke
583e519524SHoward Hinnant    template <class... ArgTypes>
59b76e6a95SHoward Hinnant      typename result_of<T&(ArgTypes&&...)>::type
603e519524SHoward Hinnant          operator() (ArgTypes&&...) const;
613e519524SHoward Hinnant};
623e519524SHoward Hinnant
636a07d6f0SHoward Hinnanttemplate <class T> reference_wrapper<T> ref(T& t) noexcept;
649b0b6d45SHoward Hinnanttemplate <class T> void ref(const T&& t) = delete;
656a07d6f0SHoward Hinnanttemplate <class T> reference_wrapper<T> ref(reference_wrapper<T>t) noexcept;
663e519524SHoward Hinnant
676a07d6f0SHoward Hinnanttemplate <class T> reference_wrapper<const T> cref(const T& t) noexcept;
689b0b6d45SHoward Hinnanttemplate <class T> void cref(const T&& t) = delete;
696a07d6f0SHoward Hinnanttemplate <class T> reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept;
703e519524SHoward Hinnant
7183c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14
723e519524SHoward Hinnantstruct plus : binary_function<T, T, T>
733e519524SHoward Hinnant{
743e519524SHoward Hinnant    T operator()(const T& x, const T& y) const;
753e519524SHoward Hinnant};
763e519524SHoward Hinnant
7783c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14
783e519524SHoward Hinnantstruct minus : binary_function<T, T, T>
793e519524SHoward Hinnant{
803e519524SHoward Hinnant    T operator()(const T& x, const T& y) const;
813e519524SHoward Hinnant};
823e519524SHoward Hinnant
8383c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14
843e519524SHoward Hinnantstruct multiplies : binary_function<T, T, T>
853e519524SHoward Hinnant{
863e519524SHoward Hinnant    T operator()(const T& x, const T& y) const;
873e519524SHoward Hinnant};
883e519524SHoward Hinnant
8983c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14
903e519524SHoward Hinnantstruct divides : binary_function<T, T, T>
913e519524SHoward Hinnant{
923e519524SHoward Hinnant    T operator()(const T& x, const T& y) const;
933e519524SHoward Hinnant};
943e519524SHoward Hinnant
9583c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14
963e519524SHoward Hinnantstruct modulus : binary_function<T, T, T>
973e519524SHoward Hinnant{
983e519524SHoward Hinnant    T operator()(const T& x, const T& y) const;
993e519524SHoward Hinnant};
1003e519524SHoward Hinnant
10183c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14
1023e519524SHoward Hinnantstruct negate : unary_function<T, T>
1033e519524SHoward Hinnant{
1043e519524SHoward Hinnant    T operator()(const T& x) const;
1053e519524SHoward Hinnant};
1063e519524SHoward Hinnant
10783c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14
1083e519524SHoward Hinnantstruct equal_to : binary_function<T, T, bool>
1093e519524SHoward Hinnant{
1103e519524SHoward Hinnant    bool operator()(const T& x, const T& y) const;
1113e519524SHoward Hinnant};
1123e519524SHoward Hinnant
11383c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14
1143e519524SHoward Hinnantstruct not_equal_to : binary_function<T, T, bool>
1153e519524SHoward Hinnant{
1163e519524SHoward Hinnant    bool operator()(const T& x, const T& y) const;
1173e519524SHoward Hinnant};
1183e519524SHoward Hinnant
11983c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14
1203e519524SHoward Hinnantstruct greater : binary_function<T, T, bool>
1213e519524SHoward Hinnant{
1223e519524SHoward Hinnant    bool operator()(const T& x, const T& y) const;
1233e519524SHoward Hinnant};
1243e519524SHoward Hinnant
12583c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14
1263e519524SHoward Hinnantstruct less : binary_function<T, T, bool>
1273e519524SHoward Hinnant{
1283e519524SHoward Hinnant    bool operator()(const T& x, const T& y) const;
1293e519524SHoward Hinnant};
1303e519524SHoward Hinnant
13183c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14
1323e519524SHoward Hinnantstruct greater_equal : binary_function<T, T, bool>
1333e519524SHoward Hinnant{
1343e519524SHoward Hinnant    bool operator()(const T& x, const T& y) const;
1353e519524SHoward Hinnant};
1363e519524SHoward Hinnant
13783c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14
1383e519524SHoward Hinnantstruct less_equal : binary_function<T, T, bool>
1393e519524SHoward Hinnant{
1403e519524SHoward Hinnant    bool operator()(const T& x, const T& y) const;
1413e519524SHoward Hinnant};
1423e519524SHoward Hinnant
14383c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14
1443e519524SHoward Hinnantstruct logical_and : binary_function<T, T, bool>
1453e519524SHoward Hinnant{
1463e519524SHoward Hinnant    bool operator()(const T& x, const T& y) const;
1473e519524SHoward Hinnant};
1483e519524SHoward Hinnant
14983c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14
1503e519524SHoward Hinnantstruct logical_or : binary_function<T, T, bool>
1513e519524SHoward Hinnant{
1523e519524SHoward Hinnant    bool operator()(const T& x, const T& y) const;
1533e519524SHoward Hinnant};
1543e519524SHoward Hinnant
15583c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14
1563e519524SHoward Hinnantstruct logical_not : unary_function<T, bool>
1573e519524SHoward Hinnant{
1583e519524SHoward Hinnant    bool operator()(const T& x) const;
1593e519524SHoward Hinnant};
1603e519524SHoward Hinnant
16183c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14
16283c08b44SMarshall Clowstruct bit_and : unary_function<T, bool>
16383c08b44SMarshall Clow{
16483c08b44SMarshall Clow    bool operator()(const T& x, const T& y) const;
16583c08b44SMarshall Clow};
16683c08b44SMarshall Clow
16783c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14
16883c08b44SMarshall Clowstruct bit_or : unary_function<T, bool>
16983c08b44SMarshall Clow{
17083c08b44SMarshall Clow    bool operator()(const T& x, const T& y) const;
17183c08b44SMarshall Clow};
17283c08b44SMarshall Clow
17383c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14
17483c08b44SMarshall Clowstruct bit_xor : unary_function<T, bool>
17583c08b44SMarshall Clow{
17683c08b44SMarshall Clow    bool operator()(const T& x, const T& y) const;
17783c08b44SMarshall Clow};
17883c08b44SMarshall Clow
17983c08b44SMarshall Clowtemplate <class T=void> // C++14
18083c08b44SMarshall Clowstruct bit_xor : unary_function<T, bool>
18183c08b44SMarshall Clow{
18283c08b44SMarshall Clow    bool operator()(const T& x) const;
18383c08b44SMarshall Clow};
18483c08b44SMarshall Clow
1853e519524SHoward Hinnanttemplate <class Predicate>
1863e519524SHoward Hinnantclass unary_negate
1873e519524SHoward Hinnant    : public unary_function<typename Predicate::argument_type, bool>
1883e519524SHoward Hinnant{
1893e519524SHoward Hinnantpublic:
1903e519524SHoward Hinnant    explicit unary_negate(const Predicate& pred);
1913e519524SHoward Hinnant    bool operator()(const typename Predicate::argument_type& x) const;
1923e519524SHoward Hinnant};
1933e519524SHoward Hinnant
1943e519524SHoward Hinnanttemplate <class Predicate> unary_negate<Predicate> not1(const Predicate& pred);
1953e519524SHoward Hinnant
1963e519524SHoward Hinnanttemplate <class Predicate>
1973e519524SHoward Hinnantclass binary_negate
1983e519524SHoward Hinnant    : public binary_function<typename Predicate::first_argument_type,
1993e519524SHoward Hinnant                             typename Predicate::second_argument_type,
2003e519524SHoward Hinnant                             bool>
2013e519524SHoward Hinnant{
2023e519524SHoward Hinnantpublic:
2033e519524SHoward Hinnant    explicit binary_negate(const Predicate& pred);
2043e519524SHoward Hinnant    bool operator()(const typename Predicate::first_argument_type& x,
2053e519524SHoward Hinnant                    const typename Predicate::second_argument_type& y) const;
2063e519524SHoward Hinnant};
2073e519524SHoward Hinnant
2083e519524SHoward Hinnanttemplate <class Predicate> binary_negate<Predicate> not2(const Predicate& pred);
2093e519524SHoward Hinnant
21057257567SEric Fiseliertemplate <class F> unspecified not_fn(F&& f); // C++17
21157257567SEric Fiselier
2123e519524SHoward Hinnanttemplate<class T> struct is_bind_expression;
2133e519524SHoward Hinnanttemplate<class T> struct is_placeholder;
2143e519524SHoward Hinnant
215a48055ceSMarshall Clow    // See C++14 20.9.9, Function object binders
21640a01d53SMarshall Clowtemplate <class T> inline constexpr bool is_bind_expression_v
217a48055ceSMarshall Clow  = is_bind_expression<T>::value; // C++17
21840a01d53SMarshall Clowtemplate <class T> inline constexpr int is_placeholder_v
219a48055ceSMarshall Clow  = is_placeholder<T>::value; // C++17
220a48055ceSMarshall Clow
221a48055ceSMarshall Clow
2229b0b6d45SHoward Hinnanttemplate<class Fn, class... BoundArgs>
2239b0b6d45SHoward Hinnant  unspecified bind(Fn&&, BoundArgs&&...);
2249b0b6d45SHoward Hinnanttemplate<class R, class Fn, class... BoundArgs>
2259b0b6d45SHoward Hinnant  unspecified bind(Fn&&, BoundArgs&&...);
2263e519524SHoward Hinnant
2273e519524SHoward Hinnantnamespace placeholders {
2283e519524SHoward Hinnant  // M is the implementation-defined number of placeholders
2293e519524SHoward Hinnant  extern unspecified _1;
2303e519524SHoward Hinnant  extern unspecified _2;
2313e519524SHoward Hinnant  .
2323e519524SHoward Hinnant  .
2333e519524SHoward Hinnant  .
234c003db1fSHoward Hinnant  extern unspecified _Mp;
2353e519524SHoward Hinnant}
2363e519524SHoward Hinnant
2373e519524SHoward Hinnanttemplate <class Operation>
2387d210c78SMarshall Clowclass binder1st     // deprecated in C++11, removed in C++17
2393e519524SHoward Hinnant    : public unary_function<typename Operation::second_argument_type,
2403e519524SHoward Hinnant                            typename Operation::result_type>
2413e519524SHoward Hinnant{
2423e519524SHoward Hinnantprotected:
2433e519524SHoward Hinnant    Operation                               op;
2443e519524SHoward Hinnant    typename Operation::first_argument_type value;
2453e519524SHoward Hinnantpublic:
2463e519524SHoward Hinnant    binder1st(const Operation& x, const typename Operation::first_argument_type y);
2473e519524SHoward Hinnant    typename Operation::result_type operator()(      typename Operation::second_argument_type& x) const;
2483e519524SHoward Hinnant    typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const;
2493e519524SHoward Hinnant};
2503e519524SHoward Hinnant
2513e519524SHoward Hinnanttemplate <class Operation, class T>
2527d210c78SMarshall Clowbinder1st<Operation> bind1st(const Operation& op, const T& x);  // deprecated in C++11, removed in C++17
2533e519524SHoward Hinnant
2543e519524SHoward Hinnanttemplate <class Operation>
2557d210c78SMarshall Clowclass binder2nd     // deprecated in C++11, removed in C++17
2563e519524SHoward Hinnant    : public unary_function<typename Operation::first_argument_type,
2573e519524SHoward Hinnant                            typename Operation::result_type>
2583e519524SHoward Hinnant{
2593e519524SHoward Hinnantprotected:
2603e519524SHoward Hinnant    Operation                                op;
2613e519524SHoward Hinnant    typename Operation::second_argument_type value;
2623e519524SHoward Hinnantpublic:
2633e519524SHoward Hinnant    binder2nd(const Operation& x, const typename Operation::second_argument_type y);
2643e519524SHoward Hinnant    typename Operation::result_type operator()(      typename Operation::first_argument_type& x) const;
2653e519524SHoward Hinnant    typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const;
2663e519524SHoward Hinnant};
2673e519524SHoward Hinnant
2683e519524SHoward Hinnanttemplate <class Operation, class T>
2697d210c78SMarshall Clowbinder2nd<Operation> bind2nd(const Operation& op, const T& x);  // deprecated in C++11, removed in C++17
2703e519524SHoward Hinnant
2717d210c78SMarshall Clowtemplate <class Arg, class Result>      // deprecated in C++11, removed in C++17
2723e519524SHoward Hinnantclass pointer_to_unary_function : public unary_function<Arg, Result>
2733e519524SHoward Hinnant{
2743e519524SHoward Hinnantpublic:
2753e519524SHoward Hinnant    explicit pointer_to_unary_function(Result (*f)(Arg));
2763e519524SHoward Hinnant    Result operator()(Arg x) const;
2773e519524SHoward Hinnant};
2783e519524SHoward Hinnant
2793e519524SHoward Hinnanttemplate <class Arg, class Result>
2807d210c78SMarshall Clowpointer_to_unary_function<Arg,Result> ptr_fun(Result (*f)(Arg));      // deprecated in C++11, removed in C++17
2813e519524SHoward Hinnant
2827d210c78SMarshall Clowtemplate <class Arg1, class Arg2, class Result>      // deprecated in C++11, removed in C++17
2833e519524SHoward Hinnantclass pointer_to_binary_function : public binary_function<Arg1, Arg2, Result>
2843e519524SHoward Hinnant{
2853e519524SHoward Hinnantpublic:
2863e519524SHoward Hinnant    explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2));
2873e519524SHoward Hinnant    Result operator()(Arg1 x, Arg2 y) const;
2883e519524SHoward Hinnant};
2893e519524SHoward Hinnant
2903e519524SHoward Hinnanttemplate <class Arg1, class Arg2, class Result>
2917d210c78SMarshall Clowpointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1,Arg2));      // deprecated in C++11, removed in C++17
2923e519524SHoward Hinnant
2937d210c78SMarshall Clowtemplate<class S, class T>      // deprecated in C++11, removed in C++17
2943e519524SHoward Hinnantclass mem_fun_t : public unary_function<T*, S>
2953e519524SHoward Hinnant{
2963e519524SHoward Hinnantpublic:
2973e519524SHoward Hinnant    explicit mem_fun_t(S (T::*p)());
2983e519524SHoward Hinnant    S operator()(T* p) const;
2993e519524SHoward Hinnant};
3003e519524SHoward Hinnant
3013e519524SHoward Hinnanttemplate<class S, class T, class A>
3027d210c78SMarshall Clowclass mem_fun1_t : public binary_function<T*, A, S>      // deprecated in C++11, removed in C++17
3033e519524SHoward Hinnant{
3043e519524SHoward Hinnantpublic:
3053e519524SHoward Hinnant    explicit mem_fun1_t(S (T::*p)(A));
3063e519524SHoward Hinnant    S operator()(T* p, A x) const;
3073e519524SHoward Hinnant};
3083e519524SHoward Hinnant
3097d210c78SMarshall Clowtemplate<class S, class T>          mem_fun_t<S,T>    mem_fun(S (T::*f)());      // deprecated in C++11, removed in C++17
3107d210c78SMarshall Clowtemplate<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
3113e519524SHoward Hinnant
3123e519524SHoward Hinnanttemplate<class S, class T>
3137d210c78SMarshall Clowclass mem_fun_ref_t : public unary_function<T, S>      // deprecated in C++11, removed in C++17
3143e519524SHoward Hinnant{
3153e519524SHoward Hinnantpublic:
3163e519524SHoward Hinnant    explicit mem_fun_ref_t(S (T::*p)());
3173e519524SHoward Hinnant    S operator()(T& p) const;
3183e519524SHoward Hinnant};
3193e519524SHoward Hinnant
3203e519524SHoward Hinnanttemplate<class S, class T, class A>
3217d210c78SMarshall Clowclass mem_fun1_ref_t : public binary_function<T, A, S>      // deprecated in C++11, removed in C++17
3223e519524SHoward Hinnant{
3233e519524SHoward Hinnantpublic:
3243e519524SHoward Hinnant    explicit mem_fun1_ref_t(S (T::*p)(A));
3253e519524SHoward Hinnant    S operator()(T& p, A x) const;
3263e519524SHoward Hinnant};
3273e519524SHoward Hinnant
3287d210c78SMarshall Clowtemplate<class S, class T>          mem_fun_ref_t<S,T>    mem_fun_ref(S (T::*f)());      // deprecated in C++11, removed in C++17
3297d210c78SMarshall Clowtemplate<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
3303e519524SHoward Hinnant
3313e519524SHoward Hinnanttemplate <class S, class T>
3327d210c78SMarshall Clowclass const_mem_fun_t : public unary_function<const T*, S>      // deprecated in C++11, removed in C++17
3333e519524SHoward Hinnant{
3343e519524SHoward Hinnantpublic:
3353e519524SHoward Hinnant    explicit const_mem_fun_t(S (T::*p)() const);
3363e519524SHoward Hinnant    S operator()(const T* p) const;
3373e519524SHoward Hinnant};
3383e519524SHoward Hinnant
3393e519524SHoward Hinnanttemplate <class S, class T, class A>
3407d210c78SMarshall Clowclass const_mem_fun1_t : public binary_function<const T*, A, S>      // deprecated in C++11, removed in C++17
3413e519524SHoward Hinnant{
3423e519524SHoward Hinnantpublic:
3433e519524SHoward Hinnant    explicit const_mem_fun1_t(S (T::*p)(A) const);
3443e519524SHoward Hinnant    S operator()(const T* p, A x) const;
3453e519524SHoward Hinnant};
3463e519524SHoward Hinnant
3477d210c78SMarshall Clowtemplate <class S, class T>          const_mem_fun_t<S,T>    mem_fun(S (T::*f)() const);      // deprecated in C++11, removed in C++17
3487d210c78SMarshall Clowtemplate <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
3493e519524SHoward Hinnant
3503e519524SHoward Hinnanttemplate <class S, class T>
3517d210c78SMarshall Clowclass const_mem_fun_ref_t : public unary_function<T, S>      // deprecated in C++11, removed in C++17
3523e519524SHoward Hinnant{
3533e519524SHoward Hinnantpublic:
3543e519524SHoward Hinnant    explicit const_mem_fun_ref_t(S (T::*p)() const);
3553e519524SHoward Hinnant    S operator()(const T& p) const;
3563e519524SHoward Hinnant};
3573e519524SHoward Hinnant
3583e519524SHoward Hinnanttemplate <class S, class T, class A>
3597d210c78SMarshall Clowclass const_mem_fun1_ref_t : public binary_function<T, A, S>      // deprecated in C++11, removed in C++17
3603e519524SHoward Hinnant{
3613e519524SHoward Hinnantpublic:
3623e519524SHoward Hinnant    explicit const_mem_fun1_ref_t(S (T::*p)(A) const);
3633e519524SHoward Hinnant    S operator()(const T& p, A x) const;
3643e519524SHoward Hinnant};
3653e519524SHoward Hinnant
3667d210c78SMarshall Clowtemplate <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
3677d210c78SMarshall Clowtemplate <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
3683e519524SHoward Hinnant
3699b0b6d45SHoward Hinnanttemplate<class R, class T> unspecified mem_fn(R T::*);
3709b0b6d45SHoward Hinnant
3713e519524SHoward Hinnantclass bad_function_call
3723e519524SHoward Hinnant    : public exception
3733e519524SHoward Hinnant{
3743e519524SHoward Hinnant};
3753e519524SHoward Hinnant
3769b0b6d45SHoward Hinnanttemplate<class> class function; // undefined
3773e519524SHoward Hinnant
3789b0b6d45SHoward Hinnanttemplate<class R, class... ArgTypes>
3793e519524SHoward Hinnantclass function<R(ArgTypes...)>
3803e519524SHoward Hinnant  : public unary_function<T1, R>      // iff sizeof...(ArgTypes) == 1 and
3813e519524SHoward Hinnant                                      // ArgTypes contains T1
3823e519524SHoward Hinnant  : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and
3833e519524SHoward Hinnant                                      // ArgTypes contains T1 and T2
3843e519524SHoward Hinnant{
3853e519524SHoward Hinnantpublic:
3863e519524SHoward Hinnant    typedef R result_type;
3873e519524SHoward Hinnant
3889b0b6d45SHoward Hinnant    // construct/copy/destroy:
3896a07d6f0SHoward Hinnant    function() noexcept;
3906a07d6f0SHoward Hinnant    function(nullptr_t) noexcept;
3913e519524SHoward Hinnant    function(const function&);
3926a07d6f0SHoward Hinnant    function(function&&) noexcept;
3933e519524SHoward Hinnant    template<class F>
3943e519524SHoward Hinnant      function(F);
3953e519524SHoward Hinnant    template<Allocator Alloc>
3966ecac730SMarshall Clow      function(allocator_arg_t, const Alloc&) noexcept;            // removed in C++17
3973e519524SHoward Hinnant    template<Allocator Alloc>
3986ecac730SMarshall Clow      function(allocator_arg_t, const Alloc&, nullptr_t) noexcept; // removed in C++17
3993e519524SHoward Hinnant    template<Allocator Alloc>
4006ecac730SMarshall Clow      function(allocator_arg_t, const Alloc&, const function&);    // removed in C++17
4013e519524SHoward Hinnant    template<Allocator Alloc>
4026ecac730SMarshall Clow      function(allocator_arg_t, const Alloc&, function&&);         // removed in C++17
4033e519524SHoward Hinnant    template<class F, Allocator Alloc>
4046ecac730SMarshall Clow      function(allocator_arg_t, const Alloc&, F);                  // removed in C++17
4053e519524SHoward Hinnant
4063e519524SHoward Hinnant    function& operator=(const function&);
4076a07d6f0SHoward Hinnant    function& operator=(function&&) noexcept;
408af152c84SHoward Hinnant    function& operator=(nullptr_t) noexcept;
4093e519524SHoward Hinnant    template<class F>
4109b0b6d45SHoward Hinnant      function& operator=(F&&);
4113e519524SHoward Hinnant    template<class F>
4126a07d6f0SHoward Hinnant      function& operator=(reference_wrapper<F>) noexcept;
4133e519524SHoward Hinnant
4143e519524SHoward Hinnant    ~function();
4153e519524SHoward Hinnant
4169b0b6d45SHoward Hinnant    // function modifiers:
4176a07d6f0SHoward Hinnant    void swap(function&) noexcept;
4189b0b6d45SHoward Hinnant    template<class F, class Alloc>
4190aa1ccb0SMarshall Clow      void assign(F&&, const Alloc&);                 // Removed in C++17
4203e519524SHoward Hinnant
4219b0b6d45SHoward Hinnant    // function capacity:
4226a07d6f0SHoward Hinnant    explicit operator bool() const noexcept;
4233e519524SHoward Hinnant
4249b0b6d45SHoward Hinnant    // function invocation:
4253e519524SHoward Hinnant    R operator()(ArgTypes...) const;
4263e519524SHoward Hinnant
4279b0b6d45SHoward Hinnant    // function target access:
4286a07d6f0SHoward Hinnant    const std::type_info& target_type() const noexcept;
4296a07d6f0SHoward Hinnant    template <typename T>       T* target() noexcept;
4306a07d6f0SHoward Hinnant    template <typename T> const T* target() const noexcept;
4313e519524SHoward Hinnant};
4323e519524SHoward Hinnant
4339b0b6d45SHoward Hinnant// Null pointer comparisons:
4349b0b6d45SHoward Hinnanttemplate <class R, class ... ArgTypes>
4356a07d6f0SHoward Hinnant  bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
4363e519524SHoward Hinnant
4379b0b6d45SHoward Hinnanttemplate <class R, class ... ArgTypes>
4386a07d6f0SHoward Hinnant  bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
4393e519524SHoward Hinnant
4409b0b6d45SHoward Hinnanttemplate <class R, class ... ArgTypes>
4416a07d6f0SHoward Hinnant  bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
4423e519524SHoward Hinnant
4439b0b6d45SHoward Hinnanttemplate <class  R, class ... ArgTypes>
4446a07d6f0SHoward Hinnant  bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
4453e519524SHoward Hinnant
4469b0b6d45SHoward Hinnant// specialized algorithms:
4479b0b6d45SHoward Hinnanttemplate <class  R, class ... ArgTypes>
4486a07d6f0SHoward Hinnant  void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
4493e519524SHoward Hinnant
4503e519524SHoward Hinnanttemplate <class T> struct hash;
4513e519524SHoward Hinnant
4523e519524SHoward Hinnanttemplate <> struct hash<bool>;
4533e519524SHoward Hinnanttemplate <> struct hash<char>;
4543e519524SHoward Hinnanttemplate <> struct hash<signed char>;
4553e519524SHoward Hinnanttemplate <> struct hash<unsigned char>;
4563e519524SHoward Hinnanttemplate <> struct hash<char16_t>;
4573e519524SHoward Hinnanttemplate <> struct hash<char32_t>;
4583e519524SHoward Hinnanttemplate <> struct hash<wchar_t>;
4593e519524SHoward Hinnanttemplate <> struct hash<short>;
4603e519524SHoward Hinnanttemplate <> struct hash<unsigned short>;
4613e519524SHoward Hinnanttemplate <> struct hash<int>;
4623e519524SHoward Hinnanttemplate <> struct hash<unsigned int>;
4633e519524SHoward Hinnanttemplate <> struct hash<long>;
4643e519524SHoward Hinnanttemplate <> struct hash<long long>;
4653e519524SHoward Hinnanttemplate <> struct hash<unsigned long>;
4663e519524SHoward Hinnanttemplate <> struct hash<unsigned long long>;
4673e519524SHoward Hinnant
4683e519524SHoward Hinnanttemplate <> struct hash<float>;
4693e519524SHoward Hinnanttemplate <> struct hash<double>;
4703e519524SHoward Hinnanttemplate <> struct hash<long double>;
4713e519524SHoward Hinnant
4723e519524SHoward Hinnanttemplate<class T> struct hash<T*>;
473d8323168SMarshall Clowtemplate <> struct hash<nullptr_t>;  // C++17
4743e519524SHoward Hinnant
4753e519524SHoward Hinnant}  // std
4763e519524SHoward Hinnant
4773e519524SHoward HinnantPOLICY:  For non-variadic implementations, the number of arguments is limited
4783e519524SHoward Hinnant         to 3.  It is hoped that the need for non-variadic implementations
4793e519524SHoward Hinnant         will be minimal.
4803e519524SHoward Hinnant
4813e519524SHoward Hinnant*/
4823e519524SHoward Hinnant
4833e519524SHoward Hinnant#include <__config>
4843e519524SHoward Hinnant#include <type_traits>
4853e519524SHoward Hinnant#include <typeinfo>
4863e519524SHoward Hinnant#include <exception>
4873e519524SHoward Hinnant#include <memory>
4883e519524SHoward Hinnant#include <tuple>
489f9127593SEric Fiselier#include <utility>
490*f56972e2SMarshall Clow#include <version>
4913e519524SHoward Hinnant
4923e519524SHoward Hinnant#include <__functional_base>
4933e519524SHoward Hinnant
494073458b1SHoward Hinnant#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
4953e519524SHoward Hinnant#pragma GCC system_header
496073458b1SHoward Hinnant#endif
4973e519524SHoward Hinnant
4983e519524SHoward Hinnant_LIBCPP_BEGIN_NAMESPACE_STD
4993e519524SHoward Hinnant
50083c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11
50183c08b44SMarshall Clowtemplate <class _Tp = void>
50283c08b44SMarshall Clow#else
5033e519524SHoward Hinnanttemplate <class _Tp>
50483c08b44SMarshall Clow#endif
505e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS plus : binary_function<_Tp, _Tp, _Tp>
5063e519524SHoward Hinnant{
5073d5134ddSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
5083d5134ddSMarshall Clow    _Tp operator()(const _Tp& __x, const _Tp& __y) const
5093e519524SHoward Hinnant        {return __x + __y;}
5103e519524SHoward Hinnant};
5113e519524SHoward Hinnant
51283c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11
51383c08b44SMarshall Clowtemplate <>
514e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS plus<void>
51583c08b44SMarshall Clow{
51683c08b44SMarshall Clow    template <class _T1, class _T2>
5173d5134ddSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
5183d5134ddSMarshall Clow    auto operator()(_T1&& __t, _T2&& __u) const
519a64f2fbcSMarshall Clow    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
520a64f2fbcSMarshall Clow    -> decltype        (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
52183c08b44SMarshall Clow        { return        _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
52225d3402cSMarshall Clow    typedef void is_transparent;
52383c08b44SMarshall Clow};
52483c08b44SMarshall Clow#endif
52583c08b44SMarshall Clow
52683c08b44SMarshall Clow
52783c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11
52883c08b44SMarshall Clowtemplate <class _Tp = void>
52983c08b44SMarshall Clow#else
5303e519524SHoward Hinnanttemplate <class _Tp>
53183c08b44SMarshall Clow#endif
532e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS minus : binary_function<_Tp, _Tp, _Tp>
5333e519524SHoward Hinnant{
5343d5134ddSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
5353d5134ddSMarshall Clow    _Tp operator()(const _Tp& __x, const _Tp& __y) const
5363e519524SHoward Hinnant        {return __x - __y;}
5373e519524SHoward Hinnant};
5383e519524SHoward Hinnant
53983c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11
54083c08b44SMarshall Clowtemplate <>
541e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS minus<void>
54283c08b44SMarshall Clow{
54383c08b44SMarshall Clow    template <class _T1, class _T2>
5443d5134ddSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
5453d5134ddSMarshall Clow    auto operator()(_T1&& __t, _T2&& __u) const
546a64f2fbcSMarshall Clow    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u)))
547a64f2fbcSMarshall Clow    -> decltype        (_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u))
54883c08b44SMarshall Clow        { return        _VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u); }
54925d3402cSMarshall Clow    typedef void is_transparent;
55083c08b44SMarshall Clow};
55183c08b44SMarshall Clow#endif
55283c08b44SMarshall Clow
55383c08b44SMarshall Clow
55483c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11
55583c08b44SMarshall Clowtemplate <class _Tp = void>
55683c08b44SMarshall Clow#else
5573e519524SHoward Hinnanttemplate <class _Tp>
55883c08b44SMarshall Clow#endif
559e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS multiplies : binary_function<_Tp, _Tp, _Tp>
5603e519524SHoward Hinnant{
5613d5134ddSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
5623d5134ddSMarshall Clow    _Tp operator()(const _Tp& __x, const _Tp& __y) const
5633e519524SHoward Hinnant        {return __x * __y;}
5643e519524SHoward Hinnant};
5653e519524SHoward Hinnant
56683c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11
56783c08b44SMarshall Clowtemplate <>
568e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS multiplies<void>
56983c08b44SMarshall Clow{
57083c08b44SMarshall Clow    template <class _T1, class _T2>
5713d5134ddSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
5723d5134ddSMarshall Clow    auto operator()(_T1&& __t, _T2&& __u) const
573a64f2fbcSMarshall Clow    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u)))
574a64f2fbcSMarshall Clow    -> decltype        (_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u))
57583c08b44SMarshall Clow        { return        _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u); }
57625d3402cSMarshall Clow    typedef void is_transparent;
57783c08b44SMarshall Clow};
57883c08b44SMarshall Clow#endif
57983c08b44SMarshall Clow
58083c08b44SMarshall Clow
58183c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11
58283c08b44SMarshall Clowtemplate <class _Tp = void>
58383c08b44SMarshall Clow#else
5843e519524SHoward Hinnanttemplate <class _Tp>
58583c08b44SMarshall Clow#endif
586e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS divides : binary_function<_Tp, _Tp, _Tp>
5873e519524SHoward Hinnant{
5883d5134ddSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
5893d5134ddSMarshall Clow    _Tp operator()(const _Tp& __x, const _Tp& __y) const
5903e519524SHoward Hinnant        {return __x / __y;}
5913e519524SHoward Hinnant};
5923e519524SHoward Hinnant
59383c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11
59483c08b44SMarshall Clowtemplate <>
595e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS divides<void>
59683c08b44SMarshall Clow{
59783c08b44SMarshall Clow    template <class _T1, class _T2>
5983d5134ddSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
5993d5134ddSMarshall Clow    auto operator()(_T1&& __t, _T2&& __u) const
600a64f2fbcSMarshall Clow    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u)))
601a64f2fbcSMarshall Clow    -> decltype        (_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u))
60283c08b44SMarshall Clow        { return        _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u); }
60325d3402cSMarshall Clow    typedef void is_transparent;
60483c08b44SMarshall Clow};
60583c08b44SMarshall Clow#endif
60683c08b44SMarshall Clow
60783c08b44SMarshall Clow
60883c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11
60983c08b44SMarshall Clowtemplate <class _Tp = void>
61083c08b44SMarshall Clow#else
6113e519524SHoward Hinnanttemplate <class _Tp>
61283c08b44SMarshall Clow#endif
613e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS modulus : binary_function<_Tp, _Tp, _Tp>
6143e519524SHoward Hinnant{
6153d5134ddSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
6163d5134ddSMarshall Clow    _Tp operator()(const _Tp& __x, const _Tp& __y) const
6173e519524SHoward Hinnant        {return __x % __y;}
6183e519524SHoward Hinnant};
6193e519524SHoward Hinnant
62083c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11
62183c08b44SMarshall Clowtemplate <>
622e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS modulus<void>
62383c08b44SMarshall Clow{
62483c08b44SMarshall Clow    template <class _T1, class _T2>
6253d5134ddSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
6263d5134ddSMarshall Clow    auto operator()(_T1&& __t, _T2&& __u) const
627a64f2fbcSMarshall Clow    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u)))
628a64f2fbcSMarshall Clow    -> decltype        (_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u))
62983c08b44SMarshall Clow        { return        _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u); }
63025d3402cSMarshall Clow    typedef void is_transparent;
63183c08b44SMarshall Clow};
63283c08b44SMarshall Clow#endif
63383c08b44SMarshall Clow
63483c08b44SMarshall Clow
63583c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11
63683c08b44SMarshall Clowtemplate <class _Tp = void>
63783c08b44SMarshall Clow#else
6383e519524SHoward Hinnanttemplate <class _Tp>
63983c08b44SMarshall Clow#endif
640e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS negate : unary_function<_Tp, _Tp>
6413e519524SHoward Hinnant{
6423d5134ddSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
6433d5134ddSMarshall Clow    _Tp operator()(const _Tp& __x) const
6443e519524SHoward Hinnant        {return -__x;}
6453e519524SHoward Hinnant};
6463e519524SHoward Hinnant
64783c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11
64883c08b44SMarshall Clowtemplate <>
649e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS negate<void>
65083c08b44SMarshall Clow{
6513e519524SHoward Hinnant    template <class _Tp>
6523d5134ddSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
6533d5134ddSMarshall Clow    auto operator()(_Tp&& __x) const
654a64f2fbcSMarshall Clow    _NOEXCEPT_(noexcept(- _VSTD::forward<_Tp>(__x)))
655a64f2fbcSMarshall Clow    -> decltype        (- _VSTD::forward<_Tp>(__x))
65683c08b44SMarshall Clow        { return        - _VSTD::forward<_Tp>(__x); }
65725d3402cSMarshall Clow    typedef void is_transparent;
65883c08b44SMarshall Clow};
65983c08b44SMarshall Clow#endif
66083c08b44SMarshall Clow
66183c08b44SMarshall Clow
66283c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11
66383c08b44SMarshall Clowtemplate <class _Tp = void>
66483c08b44SMarshall Clow#else
66583c08b44SMarshall Clowtemplate <class _Tp>
66683c08b44SMarshall Clow#endif
667e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS equal_to : binary_function<_Tp, _Tp, bool>
6683e519524SHoward Hinnant{
6693d5134ddSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
6703d5134ddSMarshall Clow    bool operator()(const _Tp& __x, const _Tp& __y) const
6713e519524SHoward Hinnant        {return __x == __y;}
6723e519524SHoward Hinnant};
6733e519524SHoward Hinnant
67483c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11
67583c08b44SMarshall Clowtemplate <>
676e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS equal_to<void>
67783c08b44SMarshall Clow{
6783d5134ddSMarshall Clow    template <class _T1, class _T2>
6793d5134ddSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
68083c08b44SMarshall Clow    auto operator()(_T1&& __t, _T2&& __u) const
681a64f2fbcSMarshall Clow    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u)))
682a64f2fbcSMarshall Clow    -> decltype        (_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u))
68383c08b44SMarshall Clow        { return        _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u); }
68425d3402cSMarshall Clow    typedef void is_transparent;
68583c08b44SMarshall Clow};
68683c08b44SMarshall Clow#endif
68783c08b44SMarshall Clow
68883c08b44SMarshall Clow
68983c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11
69083c08b44SMarshall Clowtemplate <class _Tp = void>
69183c08b44SMarshall Clow#else
6923e519524SHoward Hinnanttemplate <class _Tp>
69383c08b44SMarshall Clow#endif
694e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS not_equal_to : binary_function<_Tp, _Tp, bool>
6953e519524SHoward Hinnant{
6963d5134ddSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
6973d5134ddSMarshall Clow    bool operator()(const _Tp& __x, const _Tp& __y) const
6983e519524SHoward Hinnant        {return __x != __y;}
6993e519524SHoward Hinnant};
7003e519524SHoward Hinnant
70183c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11
70283c08b44SMarshall Clowtemplate <>
703e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS not_equal_to<void>
70483c08b44SMarshall Clow{
7053d5134ddSMarshall Clow    template <class _T1, class _T2>
7063d5134ddSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
70783c08b44SMarshall Clow    auto operator()(_T1&& __t, _T2&& __u) const
708a64f2fbcSMarshall Clow    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u)))
709a64f2fbcSMarshall Clow    -> decltype        (_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u))
71083c08b44SMarshall Clow        { return        _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u); }
71125d3402cSMarshall Clow    typedef void is_transparent;
71283c08b44SMarshall Clow};
71383c08b44SMarshall Clow#endif
71483c08b44SMarshall Clow
71583c08b44SMarshall Clow
71683c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11
71783c08b44SMarshall Clowtemplate <class _Tp = void>
71883c08b44SMarshall Clow#else
7193e519524SHoward Hinnanttemplate <class _Tp>
72083c08b44SMarshall Clow#endif
721e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS greater : binary_function<_Tp, _Tp, bool>
7223e519524SHoward Hinnant{
7233d5134ddSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
7243d5134ddSMarshall Clow    bool operator()(const _Tp& __x, const _Tp& __y) const
7253e519524SHoward Hinnant        {return __x > __y;}
7263e519524SHoward Hinnant};
7273e519524SHoward Hinnant
72883c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11
72983c08b44SMarshall Clowtemplate <>
730e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS greater<void>
73183c08b44SMarshall Clow{
7323d5134ddSMarshall Clow    template <class _T1, class _T2>
7333d5134ddSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
73483c08b44SMarshall Clow    auto operator()(_T1&& __t, _T2&& __u) const
735a64f2fbcSMarshall Clow    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u)))
736a64f2fbcSMarshall Clow    -> decltype        (_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u))
73783c08b44SMarshall Clow        { return        _VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u); }
73825d3402cSMarshall Clow    typedef void is_transparent;
73983c08b44SMarshall Clow};
74083c08b44SMarshall Clow#endif
74183c08b44SMarshall Clow
74283c08b44SMarshall Clow
74367f39647SHoward Hinnant// less in <__functional_base>
7443e519524SHoward Hinnant
74583c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11
74683c08b44SMarshall Clowtemplate <class _Tp = void>
74783c08b44SMarshall Clow#else
7483e519524SHoward Hinnanttemplate <class _Tp>
74983c08b44SMarshall Clow#endif
750e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS greater_equal : binary_function<_Tp, _Tp, bool>
7513e519524SHoward Hinnant{
7523d5134ddSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
7533d5134ddSMarshall Clow    bool operator()(const _Tp& __x, const _Tp& __y) const
7543e519524SHoward Hinnant        {return __x >= __y;}
7553e519524SHoward Hinnant};
7563e519524SHoward Hinnant
75783c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11
75883c08b44SMarshall Clowtemplate <>
759e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS greater_equal<void>
76083c08b44SMarshall Clow{
7613d5134ddSMarshall Clow    template <class _T1, class _T2>
7623d5134ddSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
76383c08b44SMarshall Clow    auto operator()(_T1&& __t, _T2&& __u) const
764a64f2fbcSMarshall Clow    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u)))
765a64f2fbcSMarshall Clow    -> decltype        (_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u))
76683c08b44SMarshall Clow        { return        _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u); }
76725d3402cSMarshall Clow    typedef void is_transparent;
76883c08b44SMarshall Clow};
76983c08b44SMarshall Clow#endif
77083c08b44SMarshall Clow
77183c08b44SMarshall Clow
77283c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11
77383c08b44SMarshall Clowtemplate <class _Tp = void>
77483c08b44SMarshall Clow#else
7753e519524SHoward Hinnanttemplate <class _Tp>
77683c08b44SMarshall Clow#endif
777e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS less_equal : binary_function<_Tp, _Tp, bool>
7783e519524SHoward Hinnant{
7793d5134ddSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
7803d5134ddSMarshall Clow    bool operator()(const _Tp& __x, const _Tp& __y) const
7813e519524SHoward Hinnant        {return __x <= __y;}
7823e519524SHoward Hinnant};
7833e519524SHoward Hinnant
78483c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11
78583c08b44SMarshall Clowtemplate <>
786e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS less_equal<void>
78783c08b44SMarshall Clow{
7883d5134ddSMarshall Clow    template <class _T1, class _T2>
7893d5134ddSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
79083c08b44SMarshall Clow    auto operator()(_T1&& __t, _T2&& __u) const
791a64f2fbcSMarshall Clow    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u)))
792a64f2fbcSMarshall Clow    -> decltype        (_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u))
79383c08b44SMarshall Clow        { return        _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u); }
79425d3402cSMarshall Clow    typedef void is_transparent;
79583c08b44SMarshall Clow};
79683c08b44SMarshall Clow#endif
79783c08b44SMarshall Clow
79883c08b44SMarshall Clow
79983c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11
80083c08b44SMarshall Clowtemplate <class _Tp = void>
80183c08b44SMarshall Clow#else
8023e519524SHoward Hinnanttemplate <class _Tp>
80383c08b44SMarshall Clow#endif
804e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS logical_and : binary_function<_Tp, _Tp, bool>
8053e519524SHoward Hinnant{
8063d5134ddSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
8073d5134ddSMarshall Clow    bool operator()(const _Tp& __x, const _Tp& __y) const
8083e519524SHoward Hinnant        {return __x && __y;}
8093e519524SHoward Hinnant};
8103e519524SHoward Hinnant
81183c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11
81283c08b44SMarshall Clowtemplate <>
813e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS logical_and<void>
81483c08b44SMarshall Clow{
8153d5134ddSMarshall Clow    template <class _T1, class _T2>
8163d5134ddSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
81783c08b44SMarshall Clow    auto operator()(_T1&& __t, _T2&& __u) const
818a64f2fbcSMarshall Clow    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u)))
819a64f2fbcSMarshall Clow    -> decltype        (_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u))
82083c08b44SMarshall Clow        { return        _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u); }
82125d3402cSMarshall Clow    typedef void is_transparent;
82283c08b44SMarshall Clow};
82383c08b44SMarshall Clow#endif
82483c08b44SMarshall Clow
82583c08b44SMarshall Clow
82683c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11
82783c08b44SMarshall Clowtemplate <class _Tp = void>
82883c08b44SMarshall Clow#else
8293e519524SHoward Hinnanttemplate <class _Tp>
83083c08b44SMarshall Clow#endif
831e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS logical_or : binary_function<_Tp, _Tp, bool>
8323e519524SHoward Hinnant{
8333d5134ddSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
8343d5134ddSMarshall Clow    bool operator()(const _Tp& __x, const _Tp& __y) const
8353e519524SHoward Hinnant        {return __x || __y;}
8363e519524SHoward Hinnant};
8373e519524SHoward Hinnant
83883c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11
83983c08b44SMarshall Clowtemplate <>
840e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS logical_or<void>
84183c08b44SMarshall Clow{
8423d5134ddSMarshall Clow    template <class _T1, class _T2>
8433d5134ddSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
84483c08b44SMarshall Clow    auto operator()(_T1&& __t, _T2&& __u) const
845a64f2fbcSMarshall Clow    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u)))
846a64f2fbcSMarshall Clow    -> decltype        (_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u))
84783c08b44SMarshall Clow        { return        _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u); }
84825d3402cSMarshall Clow    typedef void is_transparent;
84983c08b44SMarshall Clow};
85083c08b44SMarshall Clow#endif
85183c08b44SMarshall Clow
85283c08b44SMarshall Clow
85383c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11
85483c08b44SMarshall Clowtemplate <class _Tp = void>
85583c08b44SMarshall Clow#else
8563e519524SHoward Hinnanttemplate <class _Tp>
85783c08b44SMarshall Clow#endif
858e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS logical_not : unary_function<_Tp, bool>
8593e519524SHoward Hinnant{
8603d5134ddSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
8613d5134ddSMarshall Clow    bool operator()(const _Tp& __x) const
8623e519524SHoward Hinnant        {return !__x;}
8633e519524SHoward Hinnant};
8643e519524SHoward Hinnant
86583c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11
86683c08b44SMarshall Clowtemplate <>
867e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS logical_not<void>
86883c08b44SMarshall Clow{
8693e519524SHoward Hinnant    template <class _Tp>
8703d5134ddSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
8713d5134ddSMarshall Clow    auto operator()(_Tp&& __x) const
872a64f2fbcSMarshall Clow    _NOEXCEPT_(noexcept(!_VSTD::forward<_Tp>(__x)))
873a64f2fbcSMarshall Clow    -> decltype        (!_VSTD::forward<_Tp>(__x))
87483c08b44SMarshall Clow        { return        !_VSTD::forward<_Tp>(__x); }
87525d3402cSMarshall Clow    typedef void is_transparent;
87683c08b44SMarshall Clow};
87783c08b44SMarshall Clow#endif
87883c08b44SMarshall Clow
87983c08b44SMarshall Clow
88083c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11
88183c08b44SMarshall Clowtemplate <class _Tp = void>
88283c08b44SMarshall Clow#else
88383c08b44SMarshall Clowtemplate <class _Tp>
88483c08b44SMarshall Clow#endif
885e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS bit_and : binary_function<_Tp, _Tp, _Tp>
8863e519524SHoward Hinnant{
8873d5134ddSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
8883d5134ddSMarshall Clow    _Tp operator()(const _Tp& __x, const _Tp& __y) const
8893e519524SHoward Hinnant        {return __x & __y;}
8903e519524SHoward Hinnant};
8913e519524SHoward Hinnant
89283c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11
89383c08b44SMarshall Clowtemplate <>
894e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS bit_and<void>
89583c08b44SMarshall Clow{
8963d5134ddSMarshall Clow    template <class _T1, class _T2>
8973d5134ddSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
89883c08b44SMarshall Clow    auto operator()(_T1&& __t, _T2&& __u) const
899a64f2fbcSMarshall Clow    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u)))
900a64f2fbcSMarshall Clow    -> decltype        (_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u))
90183c08b44SMarshall Clow        { return        _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u); }
90225d3402cSMarshall Clow    typedef void is_transparent;
90383c08b44SMarshall Clow};
90483c08b44SMarshall Clow#endif
90583c08b44SMarshall Clow
90683c08b44SMarshall Clow
90783c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11
90883c08b44SMarshall Clowtemplate <class _Tp = void>
90983c08b44SMarshall Clow#else
9103e519524SHoward Hinnanttemplate <class _Tp>
91183c08b44SMarshall Clow#endif
912e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS bit_or : binary_function<_Tp, _Tp, _Tp>
9133e519524SHoward Hinnant{
9143d5134ddSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
9153d5134ddSMarshall Clow    _Tp operator()(const _Tp& __x, const _Tp& __y) const
9163e519524SHoward Hinnant        {return __x | __y;}
9173e519524SHoward Hinnant};
9183e519524SHoward Hinnant
91983c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11
92083c08b44SMarshall Clowtemplate <>
921e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS bit_or<void>
92283c08b44SMarshall Clow{
9233d5134ddSMarshall Clow    template <class _T1, class _T2>
9243d5134ddSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
92583c08b44SMarshall Clow    auto operator()(_T1&& __t, _T2&& __u) const
926a64f2fbcSMarshall Clow    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u)))
927a64f2fbcSMarshall Clow    -> decltype        (_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u))
92883c08b44SMarshall Clow        { return        _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u); }
92925d3402cSMarshall Clow    typedef void is_transparent;
93083c08b44SMarshall Clow};
93183c08b44SMarshall Clow#endif
93283c08b44SMarshall Clow
93383c08b44SMarshall Clow
93483c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11
93583c08b44SMarshall Clowtemplate <class _Tp = void>
93683c08b44SMarshall Clow#else
9373e519524SHoward Hinnanttemplate <class _Tp>
93883c08b44SMarshall Clow#endif
939e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS bit_xor : binary_function<_Tp, _Tp, _Tp>
9403e519524SHoward Hinnant{
9413d5134ddSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
9423d5134ddSMarshall Clow    _Tp operator()(const _Tp& __x, const _Tp& __y) const
9433e519524SHoward Hinnant        {return __x ^ __y;}
9443e519524SHoward Hinnant};
9453e519524SHoward Hinnant
94683c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11
94783c08b44SMarshall Clowtemplate <>
948e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS bit_xor<void>
94983c08b44SMarshall Clow{
9503d5134ddSMarshall Clow    template <class _T1, class _T2>
9513d5134ddSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
95283c08b44SMarshall Clow    auto operator()(_T1&& __t, _T2&& __u) const
953a64f2fbcSMarshall Clow    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u)))
954a64f2fbcSMarshall Clow    -> decltype        (_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u))
95583c08b44SMarshall Clow        { return        _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u); }
95625d3402cSMarshall Clow    typedef void is_transparent;
95783c08b44SMarshall Clow};
95883c08b44SMarshall Clow#endif
95983c08b44SMarshall Clow
96083c08b44SMarshall Clow
96183c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11
96283c08b44SMarshall Clowtemplate <class _Tp = void>
963e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS bit_not : unary_function<_Tp, _Tp>
96483c08b44SMarshall Clow{
9653d5134ddSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
9663d5134ddSMarshall Clow    _Tp operator()(const _Tp& __x) const
96783c08b44SMarshall Clow        {return ~__x;}
96883c08b44SMarshall Clow};
96983c08b44SMarshall Clow
97083c08b44SMarshall Clowtemplate <>
971e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS bit_not<void>
97283c08b44SMarshall Clow{
97383c08b44SMarshall Clow    template <class _Tp>
9743d5134ddSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
9753d5134ddSMarshall Clow    auto operator()(_Tp&& __x) const
976a64f2fbcSMarshall Clow    _NOEXCEPT_(noexcept(~_VSTD::forward<_Tp>(__x)))
977a64f2fbcSMarshall Clow    -> decltype        (~_VSTD::forward<_Tp>(__x))
97883c08b44SMarshall Clow        { return        ~_VSTD::forward<_Tp>(__x); }
97925d3402cSMarshall Clow    typedef void is_transparent;
98083c08b44SMarshall Clow};
98183c08b44SMarshall Clow#endif
98283c08b44SMarshall Clow
9833e519524SHoward Hinnanttemplate <class _Predicate>
984e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS unary_negate
9853e519524SHoward Hinnant    : public unary_function<typename _Predicate::argument_type, bool>
9863e519524SHoward Hinnant{
9873e519524SHoward Hinnant    _Predicate __pred_;
9883e519524SHoward Hinnantpublic:
9893d5134ddSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
9903d5134ddSMarshall Clow    explicit unary_negate(const _Predicate& __pred)
9913e519524SHoward Hinnant        : __pred_(__pred) {}
9923d5134ddSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
9933d5134ddSMarshall Clow    bool operator()(const typename _Predicate::argument_type& __x) const
9943e519524SHoward Hinnant        {return !__pred_(__x);}
9953e519524SHoward Hinnant};
9963e519524SHoward Hinnant
9973e519524SHoward Hinnanttemplate <class _Predicate>
9983d5134ddSMarshall Clowinline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
9993e519524SHoward Hinnantunary_negate<_Predicate>
10003e519524SHoward Hinnantnot1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);}
10013e519524SHoward Hinnant
10023e519524SHoward Hinnanttemplate <class _Predicate>
1003e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS binary_negate
10043e519524SHoward Hinnant    : public binary_function<typename _Predicate::first_argument_type,
10053e519524SHoward Hinnant                             typename _Predicate::second_argument_type,
10063e519524SHoward Hinnant                             bool>
10073e519524SHoward Hinnant{
10083e519524SHoward Hinnant    _Predicate __pred_;
10093e519524SHoward Hinnantpublic:
10103d5134ddSMarshall Clow    _LIBCPP_INLINE_VISIBILITY explicit _LIBCPP_CONSTEXPR_AFTER_CXX11
10113d5134ddSMarshall Clow    binary_negate(const _Predicate& __pred) : __pred_(__pred) {}
10123d5134ddSMarshall Clow
10133d5134ddSMarshall Clow    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
10143d5134ddSMarshall Clow    bool operator()(const typename _Predicate::first_argument_type& __x,
10153e519524SHoward Hinnant                    const typename _Predicate::second_argument_type& __y) const
10163e519524SHoward Hinnant        {return !__pred_(__x, __y);}
10173e519524SHoward Hinnant};
10183e519524SHoward Hinnant
10193e519524SHoward Hinnanttemplate <class _Predicate>
10203d5134ddSMarshall Clowinline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
10213e519524SHoward Hinnantbinary_negate<_Predicate>
10223e519524SHoward Hinnantnot2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);}
10233e519524SHoward Hinnant
10247d210c78SMarshall Clow#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS)
10253e519524SHoward Hinnanttemplate <class __Operation>
1026e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS binder1st
10273e519524SHoward Hinnant    : public unary_function<typename __Operation::second_argument_type,
10283e519524SHoward Hinnant                            typename __Operation::result_type>
10293e519524SHoward Hinnant{
10303e519524SHoward Hinnantprotected:
10313e519524SHoward Hinnant    __Operation                               op;
10323e519524SHoward Hinnant    typename __Operation::first_argument_type value;
10333e519524SHoward Hinnantpublic:
10343e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x,
10353e519524SHoward Hinnant                               const typename __Operation::first_argument_type __y)
10363e519524SHoward Hinnant        : op(__x), value(__y) {}
10373e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
10383e519524SHoward Hinnant        (typename __Operation::second_argument_type& __x) const
10393e519524SHoward Hinnant            {return op(value, __x);}
10403e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
10413e519524SHoward Hinnant        (const typename __Operation::second_argument_type& __x) const
10423e519524SHoward Hinnant            {return op(value, __x);}
10433e519524SHoward Hinnant};
10443e519524SHoward Hinnant
10453e519524SHoward Hinnanttemplate <class __Operation, class _Tp>
10463e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
10473e519524SHoward Hinnantbinder1st<__Operation>
10483e519524SHoward Hinnantbind1st(const __Operation& __op, const _Tp& __x)
10493e519524SHoward Hinnant    {return binder1st<__Operation>(__op, __x);}
10503e519524SHoward Hinnant
10513e519524SHoward Hinnanttemplate <class __Operation>
1052e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS binder2nd
10533e519524SHoward Hinnant    : public unary_function<typename __Operation::first_argument_type,
10543e519524SHoward Hinnant                            typename __Operation::result_type>
10553e519524SHoward Hinnant{
10563e519524SHoward Hinnantprotected:
10573e519524SHoward Hinnant    __Operation                                op;
10583e519524SHoward Hinnant    typename __Operation::second_argument_type value;
10593e519524SHoward Hinnantpublic:
10600af133f9SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
10613e519524SHoward Hinnant    binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y)
10623e519524SHoward Hinnant        : op(__x), value(__y) {}
10633e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
10643e519524SHoward Hinnant        (      typename __Operation::first_argument_type& __x) const
10653e519524SHoward Hinnant            {return op(__x, value);}
10663e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
10673e519524SHoward Hinnant        (const typename __Operation::first_argument_type& __x) const
10683e519524SHoward Hinnant            {return op(__x, value);}
10693e519524SHoward Hinnant};
10703e519524SHoward Hinnant
10713e519524SHoward Hinnanttemplate <class __Operation, class _Tp>
10723e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
10733e519524SHoward Hinnantbinder2nd<__Operation>
10743e519524SHoward Hinnantbind2nd(const __Operation& __op, const _Tp& __x)
10753e519524SHoward Hinnant    {return binder2nd<__Operation>(__op, __x);}
10763e519524SHoward Hinnant
10773e519524SHoward Hinnanttemplate <class _Arg, class _Result>
1078e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS pointer_to_unary_function
10790af133f9SHoward Hinnant    : public unary_function<_Arg, _Result>
10803e519524SHoward Hinnant{
10813e519524SHoward Hinnant    _Result (*__f_)(_Arg);
10823e519524SHoward Hinnantpublic:
10833e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg))
10843e519524SHoward Hinnant        : __f_(__f) {}
10853e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const
10863e519524SHoward Hinnant        {return __f_(__x);}
10873e519524SHoward Hinnant};
10883e519524SHoward Hinnant
10893e519524SHoward Hinnanttemplate <class _Arg, class _Result>
10903e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
10913e519524SHoward Hinnantpointer_to_unary_function<_Arg,_Result>
10923e519524SHoward Hinnantptr_fun(_Result (*__f)(_Arg))
10933e519524SHoward Hinnant    {return pointer_to_unary_function<_Arg,_Result>(__f);}
10943e519524SHoward Hinnant
10953e519524SHoward Hinnanttemplate <class _Arg1, class _Arg2, class _Result>
1096e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS pointer_to_binary_function
10970af133f9SHoward Hinnant    : public binary_function<_Arg1, _Arg2, _Result>
10983e519524SHoward Hinnant{
10993e519524SHoward Hinnant    _Result (*__f_)(_Arg1, _Arg2);
11003e519524SHoward Hinnantpublic:
11013e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2))
11023e519524SHoward Hinnant        : __f_(__f) {}
11033e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const
11043e519524SHoward Hinnant        {return __f_(__x, __y);}
11053e519524SHoward Hinnant};
11063e519524SHoward Hinnant
11073e519524SHoward Hinnanttemplate <class _Arg1, class _Arg2, class _Result>
11083e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
11093e519524SHoward Hinnantpointer_to_binary_function<_Arg1,_Arg2,_Result>
11103e519524SHoward Hinnantptr_fun(_Result (*__f)(_Arg1,_Arg2))
11113e519524SHoward Hinnant    {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);}
11123e519524SHoward Hinnant
11133e519524SHoward Hinnanttemplate<class _Sp, class _Tp>
1114e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS mem_fun_t : public unary_function<_Tp*, _Sp>
11153e519524SHoward Hinnant{
11163e519524SHoward Hinnant    _Sp (_Tp::*__p_)();
11173e519524SHoward Hinnantpublic:
11183e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)())
11193e519524SHoward Hinnant        : __p_(__p) {}
11203e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const
11213e519524SHoward Hinnant        {return (__p->*__p_)();}
11223e519524SHoward Hinnant};
11233e519524SHoward Hinnant
11243e519524SHoward Hinnanttemplate<class _Sp, class _Tp, class _Ap>
1125e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS mem_fun1_t : public binary_function<_Tp*, _Ap, _Sp>
11263e519524SHoward Hinnant{
11273e519524SHoward Hinnant    _Sp (_Tp::*__p_)(_Ap);
11283e519524SHoward Hinnantpublic:
11293e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap))
11303e519524SHoward Hinnant        : __p_(__p) {}
11313e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const
11323e519524SHoward Hinnant        {return (__p->*__p_)(__x);}
11333e519524SHoward Hinnant};
11343e519524SHoward Hinnant
11353e519524SHoward Hinnanttemplate<class _Sp, class _Tp>
11363e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
11373e519524SHoward Hinnantmem_fun_t<_Sp,_Tp>
11383e519524SHoward Hinnantmem_fun(_Sp (_Tp::*__f)())
11393e519524SHoward Hinnant    {return mem_fun_t<_Sp,_Tp>(__f);}
11403e519524SHoward Hinnant
11413e519524SHoward Hinnanttemplate<class _Sp, class _Tp, class _Ap>
11423e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
11433e519524SHoward Hinnantmem_fun1_t<_Sp,_Tp,_Ap>
11443e519524SHoward Hinnantmem_fun(_Sp (_Tp::*__f)(_Ap))
11453e519524SHoward Hinnant    {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
11463e519524SHoward Hinnant
11473e519524SHoward Hinnanttemplate<class _Sp, class _Tp>
1148e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS mem_fun_ref_t : public unary_function<_Tp, _Sp>
11493e519524SHoward Hinnant{
11503e519524SHoward Hinnant    _Sp (_Tp::*__p_)();
11513e519524SHoward Hinnantpublic:
11523e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)())
11533e519524SHoward Hinnant        : __p_(__p) {}
11543e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const
11553e519524SHoward Hinnant        {return (__p.*__p_)();}
11563e519524SHoward Hinnant};
11573e519524SHoward Hinnant
11583e519524SHoward Hinnanttemplate<class _Sp, class _Tp, class _Ap>
1159e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS mem_fun1_ref_t : public binary_function<_Tp, _Ap, _Sp>
11603e519524SHoward Hinnant{
11613e519524SHoward Hinnant    _Sp (_Tp::*__p_)(_Ap);
11623e519524SHoward Hinnantpublic:
11633e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap))
11643e519524SHoward Hinnant        : __p_(__p) {}
11653e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const
11663e519524SHoward Hinnant        {return (__p.*__p_)(__x);}
11673e519524SHoward Hinnant};
11683e519524SHoward Hinnant
11693e519524SHoward Hinnanttemplate<class _Sp, class _Tp>
11703e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
11713e519524SHoward Hinnantmem_fun_ref_t<_Sp,_Tp>
11723e519524SHoward Hinnantmem_fun_ref(_Sp (_Tp::*__f)())
11733e519524SHoward Hinnant    {return mem_fun_ref_t<_Sp,_Tp>(__f);}
11743e519524SHoward Hinnant
11753e519524SHoward Hinnanttemplate<class _Sp, class _Tp, class _Ap>
11763e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
11773e519524SHoward Hinnantmem_fun1_ref_t<_Sp,_Tp,_Ap>
11783e519524SHoward Hinnantmem_fun_ref(_Sp (_Tp::*__f)(_Ap))
11793e519524SHoward Hinnant    {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
11803e519524SHoward Hinnant
11813e519524SHoward Hinnanttemplate <class _Sp, class _Tp>
1182e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS const_mem_fun_t : public unary_function<const _Tp*, _Sp>
11833e519524SHoward Hinnant{
11843e519524SHoward Hinnant    _Sp (_Tp::*__p_)() const;
11853e519524SHoward Hinnantpublic:
11863e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const)
11873e519524SHoward Hinnant        : __p_(__p) {}
11883e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const
11893e519524SHoward Hinnant        {return (__p->*__p_)();}
11903e519524SHoward Hinnant};
11913e519524SHoward Hinnant
11923e519524SHoward Hinnanttemplate <class _Sp, class _Tp, class _Ap>
1193e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS const_mem_fun1_t : public binary_function<const _Tp*, _Ap, _Sp>
11943e519524SHoward Hinnant{
11953e519524SHoward Hinnant    _Sp (_Tp::*__p_)(_Ap) const;
11963e519524SHoward Hinnantpublic:
11973e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const)
11983e519524SHoward Hinnant        : __p_(__p) {}
11993e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const
12003e519524SHoward Hinnant        {return (__p->*__p_)(__x);}
12013e519524SHoward Hinnant};
12023e519524SHoward Hinnant
12033e519524SHoward Hinnanttemplate <class _Sp, class _Tp>
12043e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
12053e519524SHoward Hinnantconst_mem_fun_t<_Sp,_Tp>
12063e519524SHoward Hinnantmem_fun(_Sp (_Tp::*__f)() const)
12073e519524SHoward Hinnant    {return const_mem_fun_t<_Sp,_Tp>(__f);}
12083e519524SHoward Hinnant
12093e519524SHoward Hinnanttemplate <class _Sp, class _Tp, class _Ap>
12103e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
12113e519524SHoward Hinnantconst_mem_fun1_t<_Sp,_Tp,_Ap>
12123e519524SHoward Hinnantmem_fun(_Sp (_Tp::*__f)(_Ap) const)
12133e519524SHoward Hinnant    {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
12143e519524SHoward Hinnant
12153e519524SHoward Hinnanttemplate <class _Sp, class _Tp>
1216e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS const_mem_fun_ref_t : public unary_function<_Tp, _Sp>
12173e519524SHoward Hinnant{
12183e519524SHoward Hinnant    _Sp (_Tp::*__p_)() const;
12193e519524SHoward Hinnantpublic:
12203e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const)
12213e519524SHoward Hinnant        : __p_(__p) {}
12223e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const
12233e519524SHoward Hinnant        {return (__p.*__p_)();}
12243e519524SHoward Hinnant};
12253e519524SHoward Hinnant
12263e519524SHoward Hinnanttemplate <class _Sp, class _Tp, class _Ap>
1227e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS const_mem_fun1_ref_t
12280af133f9SHoward Hinnant    : public binary_function<_Tp, _Ap, _Sp>
12293e519524SHoward Hinnant{
12303e519524SHoward Hinnant    _Sp (_Tp::*__p_)(_Ap) const;
12313e519524SHoward Hinnantpublic:
12323e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const)
12333e519524SHoward Hinnant        : __p_(__p) {}
12343e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const
12353e519524SHoward Hinnant        {return (__p.*__p_)(__x);}
12363e519524SHoward Hinnant};
12373e519524SHoward Hinnant
12383e519524SHoward Hinnanttemplate <class _Sp, class _Tp>
12393e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
12403e519524SHoward Hinnantconst_mem_fun_ref_t<_Sp,_Tp>
12413e519524SHoward Hinnantmem_fun_ref(_Sp (_Tp::*__f)() const)
12423e519524SHoward Hinnant    {return const_mem_fun_ref_t<_Sp,_Tp>(__f);}
12433e519524SHoward Hinnant
12443e519524SHoward Hinnanttemplate <class _Sp, class _Tp, class _Ap>
12453e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
12463e519524SHoward Hinnantconst_mem_fun1_ref_t<_Sp,_Tp,_Ap>
12473e519524SHoward Hinnantmem_fun_ref(_Sp (_Tp::*__f)(_Ap) const)
12483e519524SHoward Hinnant    {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
12497d210c78SMarshall Clow#endif
12503e519524SHoward Hinnant
1251e5407178SEric Fiselier////////////////////////////////////////////////////////////////////////////////
1252e5407178SEric Fiselier//                                MEMFUN
1253e5407178SEric Fiselier//==============================================================================
12543e519524SHoward Hinnant
12553e519524SHoward Hinnanttemplate <class _Tp>
12563e519524SHoward Hinnantclass __mem_fn
12573e519524SHoward Hinnant    : public __weak_result_type<_Tp>
12583e519524SHoward Hinnant{
12593e519524SHoward Hinnantpublic:
12603e519524SHoward Hinnant    // types
12613e519524SHoward Hinnant    typedef _Tp type;
12623e519524SHoward Hinnantprivate:
12633e519524SHoward Hinnant    type __f_;
12643e519524SHoward Hinnant
12653e519524SHoward Hinnantpublic:
12663b72a6efSMarshall Clow    _LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) _NOEXCEPT : __f_(__f) {}
12673e519524SHoward Hinnant
12687e23afcbSEric Fiselier#ifndef _LIBCPP_CXX03_LANG
12693e519524SHoward Hinnant    // invoke
12703e519524SHoward Hinnant    template <class... _ArgTypes>
12710af133f9SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
12723e519524SHoward Hinnant    typename __invoke_return<type, _ArgTypes...>::type
127300f512ebSEric Fiselier    operator() (_ArgTypes&&... __args) const {
1274ce48a113SHoward Hinnant        return __invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...);
12753e519524SHoward Hinnant    }
127600f512ebSEric Fiselier#else
127700f512ebSEric Fiselier
127800f512ebSEric Fiselier    template <class _A0>
127970192a9eSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
128000f512ebSEric Fiselier    typename __invoke_return0<type, _A0>::type
128100f512ebSEric Fiselier    operator() (_A0& __a0) const {
128200f512ebSEric Fiselier        return __invoke(__f_, __a0);
128300f512ebSEric Fiselier    }
128400f512ebSEric Fiselier
128570192a9eSEric Fiselier    template <class _A0>
128670192a9eSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
128770192a9eSEric Fiselier    typename __invoke_return0<type, _A0 const>::type
128870192a9eSEric Fiselier    operator() (_A0 const& __a0) const {
128970192a9eSEric Fiselier        return __invoke(__f_, __a0);
129070192a9eSEric Fiselier    }
129170192a9eSEric Fiselier
129200f512ebSEric Fiselier    template <class _A0, class _A1>
129370192a9eSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
129400f512ebSEric Fiselier    typename __invoke_return1<type, _A0, _A1>::type
129500f512ebSEric Fiselier    operator() (_A0& __a0, _A1& __a1) const {
129600f512ebSEric Fiselier        return __invoke(__f_, __a0, __a1);
129700f512ebSEric Fiselier    }
129800f512ebSEric Fiselier
129970192a9eSEric Fiselier    template <class _A0, class _A1>
130070192a9eSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
130170192a9eSEric Fiselier    typename __invoke_return1<type, _A0 const, _A1>::type
130270192a9eSEric Fiselier    operator() (_A0 const& __a0, _A1& __a1) const {
130370192a9eSEric Fiselier        return __invoke(__f_, __a0, __a1);
130470192a9eSEric Fiselier    }
130570192a9eSEric Fiselier
130670192a9eSEric Fiselier    template <class _A0, class _A1>
130770192a9eSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
130870192a9eSEric Fiselier    typename __invoke_return1<type, _A0, _A1 const>::type
130970192a9eSEric Fiselier    operator() (_A0& __a0, _A1 const& __a1) const {
131070192a9eSEric Fiselier        return __invoke(__f_, __a0, __a1);
131170192a9eSEric Fiselier    }
131270192a9eSEric Fiselier
131370192a9eSEric Fiselier    template <class _A0, class _A1>
131470192a9eSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
131570192a9eSEric Fiselier    typename __invoke_return1<type, _A0 const, _A1 const>::type
131670192a9eSEric Fiselier    operator() (_A0 const& __a0, _A1 const& __a1) const {
131770192a9eSEric Fiselier        return __invoke(__f_, __a0, __a1);
131870192a9eSEric Fiselier    }
131970192a9eSEric Fiselier
132000f512ebSEric Fiselier    template <class _A0, class _A1, class _A2>
132170192a9eSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
132200f512ebSEric Fiselier    typename __invoke_return2<type, _A0, _A1, _A2>::type
132300f512ebSEric Fiselier    operator() (_A0& __a0, _A1& __a1, _A2& __a2) const {
132400f512ebSEric Fiselier        return __invoke(__f_, __a0, __a1, __a2);
132500f512ebSEric Fiselier    }
132670192a9eSEric Fiselier
132770192a9eSEric Fiselier    template <class _A0, class _A1, class _A2>
132870192a9eSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
132970192a9eSEric Fiselier    typename __invoke_return2<type, _A0 const, _A1, _A2>::type
133070192a9eSEric Fiselier    operator() (_A0 const& __a0, _A1& __a1, _A2& __a2) const {
133170192a9eSEric Fiselier        return __invoke(__f_, __a0, __a1, __a2);
133270192a9eSEric Fiselier    }
133370192a9eSEric Fiselier
133470192a9eSEric Fiselier    template <class _A0, class _A1, class _A2>
133570192a9eSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
133670192a9eSEric Fiselier    typename __invoke_return2<type, _A0, _A1 const, _A2>::type
133770192a9eSEric Fiselier    operator() (_A0& __a0, _A1 const& __a1, _A2& __a2) const {
133870192a9eSEric Fiselier        return __invoke(__f_, __a0, __a1, __a2);
133970192a9eSEric Fiselier    }
134070192a9eSEric Fiselier
134170192a9eSEric Fiselier    template <class _A0, class _A1, class _A2>
134270192a9eSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
134370192a9eSEric Fiselier    typename __invoke_return2<type, _A0, _A1, _A2 const>::type
134470192a9eSEric Fiselier    operator() (_A0& __a0, _A1& __a1, _A2 const& __a2) const {
134570192a9eSEric Fiselier        return __invoke(__f_, __a0, __a1, __a2);
134670192a9eSEric Fiselier    }
134770192a9eSEric Fiselier
134870192a9eSEric Fiselier    template <class _A0, class _A1, class _A2>
134970192a9eSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
135070192a9eSEric Fiselier    typename __invoke_return2<type, _A0 const, _A1 const, _A2>::type
135170192a9eSEric Fiselier    operator() (_A0 const& __a0, _A1 const& __a1, _A2& __a2) const {
135270192a9eSEric Fiselier        return __invoke(__f_, __a0, __a1, __a2);
135370192a9eSEric Fiselier    }
135470192a9eSEric Fiselier
135570192a9eSEric Fiselier    template <class _A0, class _A1, class _A2>
135670192a9eSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
135770192a9eSEric Fiselier    typename __invoke_return2<type, _A0 const, _A1, _A2 const>::type
135870192a9eSEric Fiselier    operator() (_A0 const& __a0, _A1& __a1, _A2 const& __a2) const {
135970192a9eSEric Fiselier        return __invoke(__f_, __a0, __a1, __a2);
136070192a9eSEric Fiselier    }
136170192a9eSEric Fiselier
136270192a9eSEric Fiselier    template <class _A0, class _A1, class _A2>
136370192a9eSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
136470192a9eSEric Fiselier    typename __invoke_return2<type, _A0, _A1 const, _A2 const>::type
136570192a9eSEric Fiselier    operator() (_A0& __a0, _A1 const& __a1, _A2 const& __a2) const {
136670192a9eSEric Fiselier        return __invoke(__f_, __a0, __a1, __a2);
136770192a9eSEric Fiselier    }
136870192a9eSEric Fiselier
136970192a9eSEric Fiselier    template <class _A0, class _A1, class _A2>
137070192a9eSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
137170192a9eSEric Fiselier    typename __invoke_return2<type, _A0 const, _A1 const, _A2 const>::type
137270192a9eSEric Fiselier    operator() (_A0 const& __a0, _A1 const& __a1, _A2 const& __a2) const {
137370192a9eSEric Fiselier        return __invoke(__f_, __a0, __a1, __a2);
137470192a9eSEric Fiselier    }
137500f512ebSEric Fiselier#endif
13763e519524SHoward Hinnant};
13773e519524SHoward Hinnant
1378c003db1fSHoward Hinnanttemplate<class _Rp, class _Tp>
13793e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
1380c003db1fSHoward Hinnant__mem_fn<_Rp _Tp::*>
13813b72a6efSMarshall Clowmem_fn(_Rp _Tp::* __pm) _NOEXCEPT
13823e519524SHoward Hinnant{
1383c003db1fSHoward Hinnant    return __mem_fn<_Rp _Tp::*>(__pm);
13843e519524SHoward Hinnant}
13853e519524SHoward Hinnant
1386e5407178SEric Fiselier////////////////////////////////////////////////////////////////////////////////
1387e5407178SEric Fiselier//                                FUNCTION
1388e5407178SEric Fiselier//==============================================================================
1389e5407178SEric Fiselier
13903e519524SHoward Hinnant// bad_function_call
13913e519524SHoward Hinnant
13920af133f9SHoward Hinnantclass _LIBCPP_EXCEPTION_ABI bad_function_call
13933e519524SHoward Hinnant    : public exception
13943e519524SHoward Hinnant{
1395c7cd73e8SShoaib Meenai#ifdef _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
1396c7cd73e8SShoaib Meenaipublic:
1397c7cd73e8SShoaib Meenai    virtual ~bad_function_call() _NOEXCEPT;
1398c7cd73e8SShoaib Meenai
1399c7cd73e8SShoaib Meenai    virtual const char* what() const _NOEXCEPT;
1400c7cd73e8SShoaib Meenai#endif
14013e519524SHoward Hinnant};
14023e519524SHoward Hinnant
1403dc7200b4SLouis Dionne_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
1404d437fa5cSMarshall Clowvoid __throw_bad_function_call()
1405d437fa5cSMarshall Clow{
1406d437fa5cSMarshall Clow#ifndef _LIBCPP_NO_EXCEPTIONS
1407d437fa5cSMarshall Clow    throw bad_function_call();
1408d437fa5cSMarshall Clow#else
1409d437fa5cSMarshall Clow    _VSTD::abort();
1410d437fa5cSMarshall Clow#endif
1411d437fa5cSMarshall Clow}
1412d437fa5cSMarshall Clow
1413e2f2d1edSEric Fiseliertemplate<class _Fp> class _LIBCPP_TEMPLATE_VIS function; // undefined
14143e519524SHoward Hinnant
14153e519524SHoward Hinnantnamespace __function
14163e519524SHoward Hinnant{
14173e519524SHoward Hinnant
1418e5407178SEric Fiseliertemplate<class _Rp>
14193e519524SHoward Hinnantstruct __maybe_derive_from_unary_function
14203e519524SHoward Hinnant{
14213e519524SHoward Hinnant};
14223e519524SHoward Hinnant
1423c003db1fSHoward Hinnanttemplate<class _Rp, class _A1>
1424c003db1fSHoward Hinnantstruct __maybe_derive_from_unary_function<_Rp(_A1)>
1425c003db1fSHoward Hinnant    : public unary_function<_A1, _Rp>
14263e519524SHoward Hinnant{
14273e519524SHoward Hinnant};
14283e519524SHoward Hinnant
1429e5407178SEric Fiseliertemplate<class _Rp>
14303e519524SHoward Hinnantstruct __maybe_derive_from_binary_function
14313e519524SHoward Hinnant{
14323e519524SHoward Hinnant};
14333e519524SHoward Hinnant
1434c003db1fSHoward Hinnanttemplate<class _Rp, class _A1, class _A2>
1435c003db1fSHoward Hinnantstruct __maybe_derive_from_binary_function<_Rp(_A1, _A2)>
1436c003db1fSHoward Hinnant    : public binary_function<_A1, _A2, _Rp>
14373e519524SHoward Hinnant{
14383e519524SHoward Hinnant};
14393e519524SHoward Hinnant
14400d28f784SEric Fiseliertemplate <class _Fp>
14410d28f784SEric Fiselier_LIBCPP_INLINE_VISIBILITY
14420d28f784SEric Fiselierbool __not_null(_Fp const&) { return true; }
14430d28f784SEric Fiselier
14440d28f784SEric Fiseliertemplate <class _Fp>
14450d28f784SEric Fiselier_LIBCPP_INLINE_VISIBILITY
14460d28f784SEric Fiselierbool __not_null(_Fp* __ptr) { return __ptr; }
14470d28f784SEric Fiselier
14480d28f784SEric Fiseliertemplate <class _Ret, class _Class>
14490d28f784SEric Fiselier_LIBCPP_INLINE_VISIBILITY
14500d28f784SEric Fiselierbool __not_null(_Ret _Class::*__ptr) { return __ptr; }
14510d28f784SEric Fiselier
14520d28f784SEric Fiseliertemplate <class _Fp>
14530d28f784SEric Fiselier_LIBCPP_INLINE_VISIBILITY
14540d28f784SEric Fiselierbool __not_null(function<_Fp> const& __f) { return !!__f; }
14550d28f784SEric Fiselier
1456e5407178SEric Fiselier} // namespace __function
1457e5407178SEric Fiselier
14587e23afcbSEric Fiselier#ifndef _LIBCPP_CXX03_LANG
1459e5407178SEric Fiselier
1460e5407178SEric Fiseliernamespace __function {
1461e5407178SEric Fiselier
14623e519524SHoward Hinnanttemplate<class _Fp> class __base;
14633e519524SHoward Hinnant
1464c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes>
1465c003db1fSHoward Hinnantclass __base<_Rp(_ArgTypes...)>
14663e519524SHoward Hinnant{
14673e519524SHoward Hinnant    __base(const __base&);
14683e519524SHoward Hinnant    __base& operator=(const __base&);
14693e519524SHoward Hinnantpublic:
14700af133f9SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY __base() {}
14710af133f9SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY virtual ~__base() {}
14723e519524SHoward Hinnant    virtual __base* __clone() const = 0;
14733e519524SHoward Hinnant    virtual void __clone(__base*) const = 0;
14746a07d6f0SHoward Hinnant    virtual void destroy() _NOEXCEPT = 0;
14756a07d6f0SHoward Hinnant    virtual void destroy_deallocate() _NOEXCEPT = 0;
1476c003db1fSHoward Hinnant    virtual _Rp operator()(_ArgTypes&& ...) = 0;
147754b409fdSHoward Hinnant#ifndef _LIBCPP_NO_RTTI
14786a07d6f0SHoward Hinnant    virtual const void* target(const type_info&) const _NOEXCEPT = 0;
14796a07d6f0SHoward Hinnant    virtual const std::type_info& target_type() const _NOEXCEPT = 0;
1480b3371f6fSHoward Hinnant#endif  // _LIBCPP_NO_RTTI
14813e519524SHoward Hinnant};
14823e519524SHoward Hinnant
14833e519524SHoward Hinnanttemplate<class _FD, class _Alloc, class _FB> class __func;
14843e519524SHoward Hinnant
1485c003db1fSHoward Hinnanttemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1486c003db1fSHoward Hinnantclass __func<_Fp, _Alloc, _Rp(_ArgTypes...)>
1487c003db1fSHoward Hinnant    : public  __base<_Rp(_ArgTypes...)>
14883e519524SHoward Hinnant{
1489c003db1fSHoward Hinnant    __compressed_pair<_Fp, _Alloc> __f_;
14903e519524SHoward Hinnantpublic:
14910af133f9SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
14929bb1429fSHoward Hinnant    explicit __func(_Fp&& __f)
14939bb1429fSHoward Hinnant        : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
14949bb1429fSHoward Hinnant                                    _VSTD::forward_as_tuple()) {}
14950af133f9SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
14969bb1429fSHoward Hinnant    explicit __func(const _Fp& __f, const _Alloc& __a)
14979bb1429fSHoward Hinnant        : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
14989bb1429fSHoward Hinnant                                    _VSTD::forward_as_tuple(__a)) {}
14999bb1429fSHoward Hinnant
15009bb1429fSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
15019bb1429fSHoward Hinnant    explicit __func(const _Fp& __f, _Alloc&& __a)
15029bb1429fSHoward Hinnant        : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
15039bb1429fSHoward Hinnant                                    _VSTD::forward_as_tuple(_VSTD::move(__a))) {}
15049bb1429fSHoward Hinnant
15059bb1429fSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
15069bb1429fSHoward Hinnant    explicit __func(_Fp&& __f, _Alloc&& __a)
15079bb1429fSHoward Hinnant        : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
15089bb1429fSHoward Hinnant                                    _VSTD::forward_as_tuple(_VSTD::move(__a))) {}
1509c003db1fSHoward Hinnant    virtual __base<_Rp(_ArgTypes...)>* __clone() const;
1510c003db1fSHoward Hinnant    virtual void __clone(__base<_Rp(_ArgTypes...)>*) const;
15116a07d6f0SHoward Hinnant    virtual void destroy() _NOEXCEPT;
15126a07d6f0SHoward Hinnant    virtual void destroy_deallocate() _NOEXCEPT;
1513c003db1fSHoward Hinnant    virtual _Rp operator()(_ArgTypes&& ... __arg);
151454b409fdSHoward Hinnant#ifndef _LIBCPP_NO_RTTI
15156a07d6f0SHoward Hinnant    virtual const void* target(const type_info&) const _NOEXCEPT;
15166a07d6f0SHoward Hinnant    virtual const std::type_info& target_type() const _NOEXCEPT;
1517b3371f6fSHoward Hinnant#endif  // _LIBCPP_NO_RTTI
15183e519524SHoward Hinnant};
15193e519524SHoward Hinnant
1520c003db1fSHoward Hinnanttemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1521c003db1fSHoward Hinnant__base<_Rp(_ArgTypes...)>*
1522c003db1fSHoward Hinnant__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const
15233e519524SHoward Hinnant{
15246d370568SEric Fiselier    typedef allocator_traits<_Alloc> __alloc_traits;
15251f508014SMarshall Clow    typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
1526c003db1fSHoward Hinnant    _Ap __a(__f_.second());
1527c003db1fSHoward Hinnant    typedef __allocator_destructor<_Ap> _Dp;
1528c003db1fSHoward Hinnant    unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
15293e519524SHoward Hinnant    ::new (__hold.get()) __func(__f_.first(), _Alloc(__a));
15303e519524SHoward Hinnant    return __hold.release();
15313e519524SHoward Hinnant}
15323e519524SHoward Hinnant
1533c003db1fSHoward Hinnanttemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
15343e519524SHoward Hinnantvoid
1535c003db1fSHoward Hinnant__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const
15363e519524SHoward Hinnant{
15373e519524SHoward Hinnant    ::new (__p) __func(__f_.first(), __f_.second());
15383e519524SHoward Hinnant}
15393e519524SHoward Hinnant
1540c003db1fSHoward Hinnanttemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
15413e519524SHoward Hinnantvoid
1542c003db1fSHoward Hinnant__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPT
15433e519524SHoward Hinnant{
1544c003db1fSHoward Hinnant    __f_.~__compressed_pair<_Fp, _Alloc>();
15453e519524SHoward Hinnant}
15463e519524SHoward Hinnant
1547c003db1fSHoward Hinnanttemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
15483e519524SHoward Hinnantvoid
1549c003db1fSHoward Hinnant__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT
15503e519524SHoward Hinnant{
15516d370568SEric Fiselier    typedef allocator_traits<_Alloc> __alloc_traits;
15521f508014SMarshall Clow    typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
1553c003db1fSHoward Hinnant    _Ap __a(__f_.second());
1554c003db1fSHoward Hinnant    __f_.~__compressed_pair<_Fp, _Alloc>();
15553e519524SHoward Hinnant    __a.deallocate(this, 1);
15563e519524SHoward Hinnant}
15573e519524SHoward Hinnant
1558c003db1fSHoward Hinnanttemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1559c003db1fSHoward Hinnant_Rp
1560c003db1fSHoward Hinnant__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg)
15613e519524SHoward Hinnant{
156254519a6bSEric Fiselier    typedef __invoke_void_return_wrapper<_Rp> _Invoker;
156354519a6bSEric Fiselier    return _Invoker::__call(__f_.first(), _VSTD::forward<_ArgTypes>(__arg)...);
15643e519524SHoward Hinnant}
15653e519524SHoward Hinnant
156654b409fdSHoward Hinnant#ifndef _LIBCPP_NO_RTTI
156754b409fdSHoward Hinnant
1568c003db1fSHoward Hinnanttemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
15693e519524SHoward Hinnantconst void*
1570c003db1fSHoward Hinnant__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT
15713e519524SHoward Hinnant{
1572c003db1fSHoward Hinnant    if (__ti == typeid(_Fp))
15733e519524SHoward Hinnant        return &__f_.first();
15743e519524SHoward Hinnant    return (const void*)0;
15753e519524SHoward Hinnant}
15763e519524SHoward Hinnant
1577c003db1fSHoward Hinnanttemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
15783e519524SHoward Hinnantconst std::type_info&
1579c003db1fSHoward Hinnant__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
15803e519524SHoward Hinnant{
1581c003db1fSHoward Hinnant    return typeid(_Fp);
15823e519524SHoward Hinnant}
15833e519524SHoward Hinnant
1584b3371f6fSHoward Hinnant#endif  // _LIBCPP_NO_RTTI
158554b409fdSHoward Hinnant
15863e519524SHoward Hinnant}  // __function
15873e519524SHoward Hinnant
1588c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes>
1589e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS function<_Rp(_ArgTypes...)>
1590c003db1fSHoward Hinnant    : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>,
1591c003db1fSHoward Hinnant      public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)>
15923e519524SHoward Hinnant{
1593c003db1fSHoward Hinnant    typedef __function::__base<_Rp(_ArgTypes...)> __base;
15948d3e7974SHoward Hinnant    typename aligned_storage<3*sizeof(void*)>::type __buf_;
15953e519524SHoward Hinnant    __base* __f_;
15963e519524SHoward Hinnant
15973e58a6a7SEvgeniy Stepanov    _LIBCPP_NO_CFI static __base *__as_base(void *p) {
15983e58a6a7SEvgeniy Stepanov      return reinterpret_cast<__base*>(p);
15993e58a6a7SEvgeniy Stepanov    }
16003e58a6a7SEvgeniy Stepanov
160194d55511SEric Fiselier    template <class _Fp, bool = __lazy_and<
160294d55511SEric Fiselier        integral_constant<bool, !is_same<__uncvref_t<_Fp>, function>::value>,
160394d55511SEric Fiselier        __invokable<_Fp&, _ArgTypes...>
160494d55511SEric Fiselier    >::value>
1605542b2507SHoward Hinnant    struct __callable;
1606c003db1fSHoward Hinnant    template <class _Fp>
1607c003db1fSHoward Hinnant        struct __callable<_Fp, true>
1608542b2507SHoward Hinnant        {
160954519a6bSEric Fiselier            static const bool value = is_same<void, _Rp>::value ||
1610c003db1fSHoward Hinnant                is_convertible<typename __invoke_of<_Fp&, _ArgTypes...>::type,
1611c003db1fSHoward Hinnant                               _Rp>::value;
1612542b2507SHoward Hinnant        };
1613c003db1fSHoward Hinnant    template <class _Fp>
1614c003db1fSHoward Hinnant        struct __callable<_Fp, false>
1615542b2507SHoward Hinnant        {
1616542b2507SHoward Hinnant            static const bool value = false;
1617542b2507SHoward Hinnant        };
161894d55511SEric Fiselier
161994d55511SEric Fiselier  template <class _Fp>
162094d55511SEric Fiselier  using _EnableIfCallable = typename enable_if<__callable<_Fp>::value>::type;
16213e519524SHoward Hinnantpublic:
1622c003db1fSHoward Hinnant    typedef _Rp result_type;
16233e519524SHoward Hinnant
16249b0b6d45SHoward Hinnant    // construct/copy/destroy:
16250af133f9SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
16266a07d6f0SHoward Hinnant    function() _NOEXCEPT : __f_(0) {}
16270af133f9SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
16286a07d6f0SHoward Hinnant    function(nullptr_t) _NOEXCEPT : __f_(0) {}
16293e519524SHoward Hinnant    function(const function&);
16306a07d6f0SHoward Hinnant    function(function&&) _NOEXCEPT;
163194d55511SEric Fiselier    template<class _Fp, class = _EnableIfCallable<_Fp>>
1632fd32ab92SEric Fiselier    function(_Fp);
16333e519524SHoward Hinnant
16346ecac730SMarshall Clow#if _LIBCPP_STD_VER <= 14
16359b0b6d45SHoward Hinnant    template<class _Alloc>
16360af133f9SHoward Hinnant      _LIBCPP_INLINE_VISIBILITY
16376a07d6f0SHoward Hinnant      function(allocator_arg_t, const _Alloc&) _NOEXCEPT : __f_(0) {}
16389b0b6d45SHoward Hinnant    template<class _Alloc>
16390af133f9SHoward Hinnant      _LIBCPP_INLINE_VISIBILITY
16406a07d6f0SHoward Hinnant      function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT : __f_(0) {}
16419b0b6d45SHoward Hinnant    template<class _Alloc>
16429b0b6d45SHoward Hinnant      function(allocator_arg_t, const _Alloc&, const function&);
16439b0b6d45SHoward Hinnant    template<class _Alloc>
16449b0b6d45SHoward Hinnant      function(allocator_arg_t, const _Alloc&, function&&);
164594d55511SEric Fiselier    template<class _Fp, class _Alloc, class = _EnableIfCallable<_Fp>>
1646fd32ab92SEric Fiselier      function(allocator_arg_t, const _Alloc& __a, _Fp __f);
16476ecac730SMarshall Clow#endif
16483e519524SHoward Hinnant
16493e519524SHoward Hinnant    function& operator=(const function&);
16506a07d6f0SHoward Hinnant    function& operator=(function&&) _NOEXCEPT;
16516a07d6f0SHoward Hinnant    function& operator=(nullptr_t) _NOEXCEPT;
165294d55511SEric Fiselier    template<class _Fp, class = _EnableIfCallable<_Fp>>
165394d55511SEric Fiselier    function& operator=(_Fp&&);
16543e519524SHoward Hinnant
16553e519524SHoward Hinnant    ~function();
16563e519524SHoward Hinnant
16579b0b6d45SHoward Hinnant    // function modifiers:
16586a07d6f0SHoward Hinnant    void swap(function&) _NOEXCEPT;
16590aa1ccb0SMarshall Clow
16600aa1ccb0SMarshall Clow#if _LIBCPP_STD_VER <= 14
1661c003db1fSHoward Hinnant    template<class _Fp, class _Alloc>
16620af133f9SHoward Hinnant      _LIBCPP_INLINE_VISIBILITY
1663c003db1fSHoward Hinnant      void assign(_Fp&& __f, const _Alloc& __a)
1664c003db1fSHoward Hinnant        {function(allocator_arg, __a, _VSTD::forward<_Fp>(__f)).swap(*this);}
16650aa1ccb0SMarshall Clow#endif
16663e519524SHoward Hinnant
16679b0b6d45SHoward Hinnant    // function capacity:
16680af133f9SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
1669f2f2d8b9SHoward Hinnant        _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return __f_;}
16703e519524SHoward Hinnant
16713e519524SHoward Hinnant    // deleted overloads close possible hole in the type system
16723e519524SHoward Hinnant    template<class _R2, class... _ArgTypes2>
167337030a77SHoward Hinnant      bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete;
16743e519524SHoward Hinnant    template<class _R2, class... _ArgTypes2>
167537030a77SHoward Hinnant      bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete;
16763e519524SHoward Hinnantpublic:
16779b0b6d45SHoward Hinnant    // function invocation:
1678c003db1fSHoward Hinnant    _Rp operator()(_ArgTypes...) const;
16793e519524SHoward Hinnant
168054b409fdSHoward Hinnant#ifndef _LIBCPP_NO_RTTI
16819b0b6d45SHoward Hinnant    // function target access:
16826a07d6f0SHoward Hinnant    const std::type_info& target_type() const _NOEXCEPT;
1683c003db1fSHoward Hinnant    template <typename _Tp> _Tp* target() _NOEXCEPT;
1684c003db1fSHoward Hinnant    template <typename _Tp> const _Tp* target() const _NOEXCEPT;
1685b3371f6fSHoward Hinnant#endif  // _LIBCPP_NO_RTTI
16863e519524SHoward Hinnant};
16873e519524SHoward Hinnant
1688c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes>
1689c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::function(const function& __f)
16903e519524SHoward Hinnant{
16913e519524SHoward Hinnant    if (__f.__f_ == 0)
16923e519524SHoward Hinnant        __f_ = 0;
16933e58a6a7SEvgeniy Stepanov    else if ((void *)__f.__f_ == &__f.__buf_)
16943e519524SHoward Hinnant    {
16953e58a6a7SEvgeniy Stepanov        __f_ = __as_base(&__buf_);
16963e519524SHoward Hinnant        __f.__f_->__clone(__f_);
16973e519524SHoward Hinnant    }
16983e519524SHoward Hinnant    else
16993e519524SHoward Hinnant        __f_ = __f.__f_->__clone();
17003e519524SHoward Hinnant}
17013e519524SHoward Hinnant
17026ecac730SMarshall Clow#if _LIBCPP_STD_VER <= 14
1703c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes>
17049b0b6d45SHoward Hinnanttemplate <class _Alloc>
1705c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
17069b0b6d45SHoward Hinnant                                     const function& __f)
17079b0b6d45SHoward Hinnant{
17089b0b6d45SHoward Hinnant    if (__f.__f_ == 0)
17099b0b6d45SHoward Hinnant        __f_ = 0;
17103e58a6a7SEvgeniy Stepanov    else if ((void *)__f.__f_ == &__f.__buf_)
17119b0b6d45SHoward Hinnant    {
17123e58a6a7SEvgeniy Stepanov        __f_ = __as_base(&__buf_);
17139b0b6d45SHoward Hinnant        __f.__f_->__clone(__f_);
17149b0b6d45SHoward Hinnant    }
17159b0b6d45SHoward Hinnant    else
17169b0b6d45SHoward Hinnant        __f_ = __f.__f_->__clone();
17179b0b6d45SHoward Hinnant}
17186ecac730SMarshall Clow#endif
17199b0b6d45SHoward Hinnant
1720c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes>
1721c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT
17223e519524SHoward Hinnant{
17233e519524SHoward Hinnant    if (__f.__f_ == 0)
17243e519524SHoward Hinnant        __f_ = 0;
17253e58a6a7SEvgeniy Stepanov    else if ((void *)__f.__f_ == &__f.__buf_)
17263e519524SHoward Hinnant    {
17273e58a6a7SEvgeniy Stepanov        __f_ = __as_base(&__buf_);
17283e519524SHoward Hinnant        __f.__f_->__clone(__f_);
17293e519524SHoward Hinnant    }
17303e519524SHoward Hinnant    else
17313e519524SHoward Hinnant    {
17323e519524SHoward Hinnant        __f_ = __f.__f_;
17333e519524SHoward Hinnant        __f.__f_ = 0;
17343e519524SHoward Hinnant    }
17353e519524SHoward Hinnant}
17363e519524SHoward Hinnant
17376ecac730SMarshall Clow#if _LIBCPP_STD_VER <= 14
1738c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes>
17399b0b6d45SHoward Hinnanttemplate <class _Alloc>
1740c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
17419b0b6d45SHoward Hinnant                                     function&& __f)
17429b0b6d45SHoward Hinnant{
17439b0b6d45SHoward Hinnant    if (__f.__f_ == 0)
17449b0b6d45SHoward Hinnant        __f_ = 0;
17453e58a6a7SEvgeniy Stepanov    else if ((void *)__f.__f_ == &__f.__buf_)
17469b0b6d45SHoward Hinnant    {
17473e58a6a7SEvgeniy Stepanov        __f_ = __as_base(&__buf_);
17489b0b6d45SHoward Hinnant        __f.__f_->__clone(__f_);
17499b0b6d45SHoward Hinnant    }
17509b0b6d45SHoward Hinnant    else
17519b0b6d45SHoward Hinnant    {
17529b0b6d45SHoward Hinnant        __f_ = __f.__f_;
17539b0b6d45SHoward Hinnant        __f.__f_ = 0;
17549b0b6d45SHoward Hinnant    }
17559b0b6d45SHoward Hinnant}
17566ecac730SMarshall Clow#endif
17579b0b6d45SHoward Hinnant
1758c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes>
1759fd32ab92SEric Fiseliertemplate <class _Fp, class>
1760fd32ab92SEric Fiselierfunction<_Rp(_ArgTypes...)>::function(_Fp __f)
17613e519524SHoward Hinnant    : __f_(0)
17623e519524SHoward Hinnant{
17630d28f784SEric Fiselier    if (__function::__not_null(__f))
17643e519524SHoward Hinnant    {
1765c003db1fSHoward Hinnant        typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_ArgTypes...)> _FF;
1766c003db1fSHoward Hinnant        if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value)
17673e519524SHoward Hinnant        {
17683e58a6a7SEvgeniy Stepanov            __f_ = ::new((void*)&__buf_) _FF(_VSTD::move(__f));
17693e519524SHoward Hinnant        }
17703e519524SHoward Hinnant        else
17713e519524SHoward Hinnant        {
1772c003db1fSHoward Hinnant            typedef allocator<_FF> _Ap;
1773c003db1fSHoward Hinnant            _Ap __a;
1774c003db1fSHoward Hinnant            typedef __allocator_destructor<_Ap> _Dp;
1775c003db1fSHoward Hinnant            unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1776c003db1fSHoward Hinnant            ::new (__hold.get()) _FF(_VSTD::move(__f), allocator<_Fp>(__a));
17773e519524SHoward Hinnant            __f_ = __hold.release();
17783e519524SHoward Hinnant        }
17793e519524SHoward Hinnant    }
17803e519524SHoward Hinnant}
17813e519524SHoward Hinnant
17826ecac730SMarshall Clow#if _LIBCPP_STD_VER <= 14
1783c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes>
1784fd32ab92SEric Fiseliertemplate <class _Fp, class _Alloc, class>
1785fd32ab92SEric Fiselierfunction<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f)
17869b0b6d45SHoward Hinnant    : __f_(0)
17879b0b6d45SHoward Hinnant{
17889b0b6d45SHoward Hinnant    typedef allocator_traits<_Alloc> __alloc_traits;
17890d28f784SEric Fiselier    if (__function::__not_null(__f))
17909b0b6d45SHoward Hinnant    {
1791c003db1fSHoward Hinnant        typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _FF;
17921f508014SMarshall Clow        typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap;
1793c003db1fSHoward Hinnant        _Ap __a(__a0);
17945f7c2db2SMarshall Clow        if (sizeof(_FF) <= sizeof(__buf_) &&
17955f7c2db2SMarshall Clow            is_nothrow_copy_constructible<_Fp>::value && is_nothrow_copy_constructible<_Ap>::value)
17965f7c2db2SMarshall Clow        {
17973e58a6a7SEvgeniy Stepanov            __f_ = ::new((void*)&__buf_) _FF(_VSTD::move(__f), _Alloc(__a));
17985f7c2db2SMarshall Clow        }
17995f7c2db2SMarshall Clow        else
18005f7c2db2SMarshall Clow        {
1801c003db1fSHoward Hinnant            typedef __allocator_destructor<_Ap> _Dp;
1802c003db1fSHoward Hinnant            unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1803ce48a113SHoward Hinnant            ::new (__hold.get()) _FF(_VSTD::move(__f), _Alloc(__a));
18049b0b6d45SHoward Hinnant            __f_ = __hold.release();
18059b0b6d45SHoward Hinnant        }
18069b0b6d45SHoward Hinnant    }
18079b0b6d45SHoward Hinnant}
18086ecac730SMarshall Clow#endif
18099b0b6d45SHoward Hinnant
1810c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes>
1811c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>&
1812c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::operator=(const function& __f)
18133e519524SHoward Hinnant{
18143e519524SHoward Hinnant    function(__f).swap(*this);
18153e519524SHoward Hinnant    return *this;
18163e519524SHoward Hinnant}
18173e519524SHoward Hinnant
1818c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes>
1819c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>&
1820c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT
18213e519524SHoward Hinnant{
1822aa208791SVolodymyr Sapsai    *this = nullptr;
18233e519524SHoward Hinnant    if (__f.__f_ == 0)
18243e519524SHoward Hinnant        __f_ = 0;
18253e58a6a7SEvgeniy Stepanov    else if ((void *)__f.__f_ == &__f.__buf_)
18263e519524SHoward Hinnant    {
18273e58a6a7SEvgeniy Stepanov        __f_ = __as_base(&__buf_);
18283e519524SHoward Hinnant        __f.__f_->__clone(__f_);
18293e519524SHoward Hinnant    }
18303e519524SHoward Hinnant    else
18313e519524SHoward Hinnant    {
18323e519524SHoward Hinnant        __f_ = __f.__f_;
18333e519524SHoward Hinnant        __f.__f_ = 0;
18343e519524SHoward Hinnant    }
183588db3171SArgyrios Kyrtzidis    return *this;
18363e519524SHoward Hinnant}
18373e519524SHoward Hinnant
1838c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes>
1839c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>&
1840c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT
18413e519524SHoward Hinnant{
1842aa208791SVolodymyr Sapsai    __base* __t = __f_;
18433e519524SHoward Hinnant    __f_ = 0;
1844aa208791SVolodymyr Sapsai    if ((void *)__t == &__buf_)
1845aa208791SVolodymyr Sapsai        __t->destroy();
1846aa208791SVolodymyr Sapsai    else if (__t)
1847aa208791SVolodymyr Sapsai        __t->destroy_deallocate();
184888db3171SArgyrios Kyrtzidis    return *this;
18493e519524SHoward Hinnant}
18503e519524SHoward Hinnant
1851c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes>
185294d55511SEric Fiseliertemplate <class _Fp, class>
1853c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>&
1854c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::operator=(_Fp&& __f)
18553e519524SHoward Hinnant{
1856c003db1fSHoward Hinnant    function(_VSTD::forward<_Fp>(__f)).swap(*this);
18573e519524SHoward Hinnant    return *this;
18583e519524SHoward Hinnant}
18593e519524SHoward Hinnant
1860c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes>
1861c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::~function()
18623e519524SHoward Hinnant{
18633e58a6a7SEvgeniy Stepanov    if ((void *)__f_ == &__buf_)
18643e519524SHoward Hinnant        __f_->destroy();
18653e519524SHoward Hinnant    else if (__f_)
18663e519524SHoward Hinnant        __f_->destroy_deallocate();
18673e519524SHoward Hinnant}
18683e519524SHoward Hinnant
1869c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes>
18703e519524SHoward Hinnantvoid
1871c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT
18723e519524SHoward Hinnant{
1873d566c345SEric Fiselier    if (_VSTD::addressof(__f) == this)
1874d566c345SEric Fiselier      return;
18753e58a6a7SEvgeniy Stepanov    if ((void *)__f_ == &__buf_ && (void *)__f.__f_ == &__f.__buf_)
18763e519524SHoward Hinnant    {
18773e519524SHoward Hinnant        typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
18783e58a6a7SEvgeniy Stepanov        __base* __t = __as_base(&__tempbuf);
18793e519524SHoward Hinnant        __f_->__clone(__t);
18803e519524SHoward Hinnant        __f_->destroy();
18813e519524SHoward Hinnant        __f_ = 0;
18823e58a6a7SEvgeniy Stepanov        __f.__f_->__clone(__as_base(&__buf_));
18833e519524SHoward Hinnant        __f.__f_->destroy();
18843e519524SHoward Hinnant        __f.__f_ = 0;
18853e58a6a7SEvgeniy Stepanov        __f_ = __as_base(&__buf_);
18863e58a6a7SEvgeniy Stepanov        __t->__clone(__as_base(&__f.__buf_));
18873e519524SHoward Hinnant        __t->destroy();
18883e58a6a7SEvgeniy Stepanov        __f.__f_ = __as_base(&__f.__buf_);
18893e519524SHoward Hinnant    }
18903e58a6a7SEvgeniy Stepanov    else if ((void *)__f_ == &__buf_)
18913e519524SHoward Hinnant    {
18923e58a6a7SEvgeniy Stepanov        __f_->__clone(__as_base(&__f.__buf_));
18933e519524SHoward Hinnant        __f_->destroy();
18943e519524SHoward Hinnant        __f_ = __f.__f_;
18953e58a6a7SEvgeniy Stepanov        __f.__f_ = __as_base(&__f.__buf_);
18963e519524SHoward Hinnant    }
18973e58a6a7SEvgeniy Stepanov    else if ((void *)__f.__f_ == &__f.__buf_)
18983e519524SHoward Hinnant    {
18993e58a6a7SEvgeniy Stepanov        __f.__f_->__clone(__as_base(&__buf_));
19003e519524SHoward Hinnant        __f.__f_->destroy();
19013e519524SHoward Hinnant        __f.__f_ = __f_;
19023e58a6a7SEvgeniy Stepanov        __f_ = __as_base(&__buf_);
19033e519524SHoward Hinnant    }
19043e519524SHoward Hinnant    else
1905ce48a113SHoward Hinnant        _VSTD::swap(__f_, __f.__f_);
19063e519524SHoward Hinnant}
19073e519524SHoward Hinnant
1908c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes>
1909c003db1fSHoward Hinnant_Rp
1910c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const
19113e519524SHoward Hinnant{
19123e519524SHoward Hinnant    if (__f_ == 0)
1913d437fa5cSMarshall Clow        __throw_bad_function_call();
1914ce48a113SHoward Hinnant    return (*__f_)(_VSTD::forward<_ArgTypes>(__arg)...);
19153e519524SHoward Hinnant}
19163e519524SHoward Hinnant
191754b409fdSHoward Hinnant#ifndef _LIBCPP_NO_RTTI
191854b409fdSHoward Hinnant
1919c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes>
19203e519524SHoward Hinnantconst std::type_info&
1921c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
19223e519524SHoward Hinnant{
19233e519524SHoward Hinnant    if (__f_ == 0)
19243e519524SHoward Hinnant        return typeid(void);
19253e519524SHoward Hinnant    return __f_->target_type();
19263e519524SHoward Hinnant}
19273e519524SHoward Hinnant
1928c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes>
1929c003db1fSHoward Hinnanttemplate <typename _Tp>
1930c003db1fSHoward Hinnant_Tp*
1931c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::target() _NOEXCEPT
19323e519524SHoward Hinnant{
19333e519524SHoward Hinnant    if (__f_ == 0)
19348b086e38SMarshall Clow        return nullptr;
19358b086e38SMarshall Clow    return (_Tp*) const_cast<void *>(__f_->target(typeid(_Tp)));
19363e519524SHoward Hinnant}
19373e519524SHoward Hinnant
1938c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes>
1939c003db1fSHoward Hinnanttemplate <typename _Tp>
1940c003db1fSHoward Hinnantconst _Tp*
1941c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::target() const _NOEXCEPT
19423e519524SHoward Hinnant{
19433e519524SHoward Hinnant    if (__f_ == 0)
19448b086e38SMarshall Clow        return nullptr;
1945c003db1fSHoward Hinnant    return (const _Tp*)__f_->target(typeid(_Tp));
19463e519524SHoward Hinnant}
19473e519524SHoward Hinnant
1948b3371f6fSHoward Hinnant#endif  // _LIBCPP_NO_RTTI
194954b409fdSHoward Hinnant
1950c003db1fSHoward Hinnanttemplate <class _Rp, class... _ArgTypes>
19513e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
19523e519524SHoward Hinnantbool
1953c003db1fSHoward Hinnantoperator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;}
19543e519524SHoward Hinnant
1955c003db1fSHoward Hinnanttemplate <class _Rp, class... _ArgTypes>
19563e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
19573e519524SHoward Hinnantbool
1958c003db1fSHoward Hinnantoperator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;}
19593e519524SHoward Hinnant
1960c003db1fSHoward Hinnanttemplate <class _Rp, class... _ArgTypes>
19613e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
19623e519524SHoward Hinnantbool
1963c003db1fSHoward Hinnantoperator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;}
19643e519524SHoward Hinnant
1965c003db1fSHoward Hinnanttemplate <class _Rp, class... _ArgTypes>
19663e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
19673e519524SHoward Hinnantbool
1968c003db1fSHoward Hinnantoperator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;}
19693e519524SHoward Hinnant
1970c003db1fSHoward Hinnanttemplate <class _Rp, class... _ArgTypes>
19713e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
19723e519524SHoward Hinnantvoid
1973c003db1fSHoward Hinnantswap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT
19743e519524SHoward Hinnant{return __x.swap(__y);}
19753e519524SHoward Hinnant
19767e23afcbSEric Fiselier#else // _LIBCPP_CXX03_LANG
197700f512ebSEric Fiselier
197800f512ebSEric Fiselier#include <__functional_03>
197900f512ebSEric Fiselier
198000f512ebSEric Fiselier#endif
1981e5407178SEric Fiselier
1982e5407178SEric Fiselier////////////////////////////////////////////////////////////////////////////////
1983e5407178SEric Fiselier//                                  BIND
1984e5407178SEric Fiselier//==============================================================================
1985e5407178SEric Fiselier
19863e519524SHoward Hinnanttemplate<class _Tp> struct __is_bind_expression : public false_type {};
1987e2f2d1edSEric Fiseliertemplate<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_bind_expression
19883e519524SHoward Hinnant    : public __is_bind_expression<typename remove_cv<_Tp>::type> {};
19893e519524SHoward Hinnant
1990a48055ceSMarshall Clow#if _LIBCPP_STD_VER > 14
1991a48055ceSMarshall Clowtemplate <class _Tp>
199240a01d53SMarshall Clow_LIBCPP_INLINE_VAR constexpr size_t is_bind_expression_v = is_bind_expression<_Tp>::value;
1993a48055ceSMarshall Clow#endif
1994a48055ceSMarshall Clow
19953e519524SHoward Hinnanttemplate<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {};
1996e2f2d1edSEric Fiseliertemplate<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_placeholder
19973e519524SHoward Hinnant    : public __is_placeholder<typename remove_cv<_Tp>::type> {};
19983e519524SHoward Hinnant
1999a48055ceSMarshall Clow#if _LIBCPP_STD_VER > 14
2000a48055ceSMarshall Clowtemplate <class _Tp>
200140a01d53SMarshall Clow_LIBCPP_INLINE_VAR constexpr size_t is_placeholder_v = is_placeholder<_Tp>::value;
2002a48055ceSMarshall Clow#endif
2003a48055ceSMarshall Clow
20043e519524SHoward Hinnantnamespace placeholders
20053e519524SHoward Hinnant{
20063e519524SHoward Hinnant
2007c003db1fSHoward Hinnanttemplate <int _Np> struct __ph {};
20083e519524SHoward Hinnant
2009c8e84ff2SLouis Dionne#if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY)
201055533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<1>   _1;
201155533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<2>   _2;
201255533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<3>   _3;
201355533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<4>   _4;
201455533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<5>   _5;
201555533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<6>   _6;
201655533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<7>   _7;
201755533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<8>   _8;
201855533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<9>   _9;
201955533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<10> _10;
202055533071SEric Fiselier#else
2021a911f39dSMarshall Clow/* _LIBCPP_INLINE_VAR */ constexpr __ph<1>   _1{};
2022a911f39dSMarshall Clow/* _LIBCPP_INLINE_VAR */ constexpr __ph<2>   _2{};
2023a911f39dSMarshall Clow/* _LIBCPP_INLINE_VAR */ constexpr __ph<3>   _3{};
2024a911f39dSMarshall Clow/* _LIBCPP_INLINE_VAR */ constexpr __ph<4>   _4{};
2025a911f39dSMarshall Clow/* _LIBCPP_INLINE_VAR */ constexpr __ph<5>   _5{};
2026a911f39dSMarshall Clow/* _LIBCPP_INLINE_VAR */ constexpr __ph<6>   _6{};
2027a911f39dSMarshall Clow/* _LIBCPP_INLINE_VAR */ constexpr __ph<7>   _7{};
2028a911f39dSMarshall Clow/* _LIBCPP_INLINE_VAR */ constexpr __ph<8>   _8{};
2029a911f39dSMarshall Clow/* _LIBCPP_INLINE_VAR */ constexpr __ph<9>   _9{};
2030a911f39dSMarshall Clow/* _LIBCPP_INLINE_VAR */ constexpr __ph<10> _10{};
2031c8e84ff2SLouis Dionne#endif // defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY)
20323e519524SHoward Hinnant
20333e519524SHoward Hinnant}  // placeholders
20343e519524SHoward Hinnant
2035c003db1fSHoward Hinnanttemplate<int _Np>
2036c003db1fSHoward Hinnantstruct __is_placeholder<placeholders::__ph<_Np> >
2037c003db1fSHoward Hinnant    : public integral_constant<int, _Np> {};
20383e519524SHoward Hinnant
2039e5407178SEric Fiselier
20407e23afcbSEric Fiselier#ifndef _LIBCPP_CXX03_LANG
2041e5407178SEric Fiselier
20423e519524SHoward Hinnanttemplate <class _Tp, class _Uj>
20433e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
20443e519524SHoward Hinnant_Tp&
20453e519524SHoward Hinnant__mu(reference_wrapper<_Tp> __t, _Uj&)
20463e519524SHoward Hinnant{
20473e519524SHoward Hinnant    return __t.get();
20483e519524SHoward Hinnant}
20493e519524SHoward Hinnant
20503e519524SHoward Hinnanttemplate <class _Ti, class ..._Uj, size_t ..._Indx>
20513e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
20522344d6c1SHoward Hinnanttypename __invoke_of<_Ti&, _Uj...>::type
20532344d6c1SHoward Hinnant__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>)
20543e519524SHoward Hinnant{
2055f9af6140SMarshall Clow    return __ti(_VSTD::forward<_Uj>(_VSTD::get<_Indx>(__uj))...);
20563e519524SHoward Hinnant}
20573e519524SHoward Hinnant
20583e519524SHoward Hinnanttemplate <class _Ti, class ..._Uj>
20593e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
2060279663c1SEric Fiseliertypename __lazy_enable_if
20613e519524SHoward Hinnant<
20623e519524SHoward Hinnant    is_bind_expression<_Ti>::value,
2063279663c1SEric Fiselier    __invoke_of<_Ti&, _Uj...>
20643e519524SHoward Hinnant>::type
20653e519524SHoward Hinnant__mu(_Ti& __ti, tuple<_Uj...>& __uj)
20663e519524SHoward Hinnant{
20673e519524SHoward Hinnant    typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices;
20683e519524SHoward Hinnant    return  __mu_expand(__ti, __uj, __indices());
20693e519524SHoward Hinnant}
20703e519524SHoward Hinnant
20713e519524SHoward Hinnanttemplate <bool IsPh, class _Ti, class _Uj>
20723e519524SHoward Hinnantstruct __mu_return2 {};
20733e519524SHoward Hinnant
20743e519524SHoward Hinnanttemplate <class _Ti, class _Uj>
20753e519524SHoward Hinnantstruct __mu_return2<true, _Ti, _Uj>
20763e519524SHoward Hinnant{
20773e519524SHoward Hinnant    typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type;
20783e519524SHoward Hinnant};
20793e519524SHoward Hinnant
20803e519524SHoward Hinnanttemplate <class _Ti, class _Uj>
20813e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
20823e519524SHoward Hinnanttypename enable_if
20833e519524SHoward Hinnant<
20843e519524SHoward Hinnant    0 < is_placeholder<_Ti>::value,
20853e519524SHoward Hinnant    typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type
20863e519524SHoward Hinnant>::type
20873e519524SHoward Hinnant__mu(_Ti&, _Uj& __uj)
20883e519524SHoward Hinnant{
20893e519524SHoward Hinnant    const size_t _Indx = is_placeholder<_Ti>::value - 1;
2090f9af6140SMarshall Clow    return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj));
20913e519524SHoward Hinnant}
20923e519524SHoward Hinnant
20933e519524SHoward Hinnanttemplate <class _Ti, class _Uj>
20943e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
20953e519524SHoward Hinnanttypename enable_if
20963e519524SHoward Hinnant<
20973e519524SHoward Hinnant    !is_bind_expression<_Ti>::value &&
20983e519524SHoward Hinnant    is_placeholder<_Ti>::value == 0 &&
20993e519524SHoward Hinnant    !__is_reference_wrapper<_Ti>::value,
21003e519524SHoward Hinnant    _Ti&
21013e519524SHoward Hinnant>::type
2102c206366fSHoward Hinnant__mu(_Ti& __ti, _Uj&)
21033e519524SHoward Hinnant{
21043e519524SHoward Hinnant    return __ti;
21053e519524SHoward Hinnant}
21063e519524SHoward Hinnant
21072fa07ae9SHoward Hinnanttemplate <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh,
21082fa07ae9SHoward Hinnant          class _TupleUj>
21093e519524SHoward Hinnantstruct ____mu_return;
21103e519524SHoward Hinnant
21119bf42533SHoward Hinnanttemplate <bool _Invokable, class _Ti, class ..._Uj>
21129bf42533SHoward Hinnantstruct ____mu_return_invokable  // false
21139bf42533SHoward Hinnant{
21149bf42533SHoward Hinnant    typedef __nat type;
21159bf42533SHoward Hinnant};
21169bf42533SHoward Hinnant
21173e519524SHoward Hinnanttemplate <class _Ti, class ..._Uj>
21189bf42533SHoward Hinnantstruct ____mu_return_invokable<true, _Ti, _Uj...>
21193e519524SHoward Hinnant{
21202344d6c1SHoward Hinnant    typedef typename __invoke_of<_Ti&, _Uj...>::type type;
21213e519524SHoward Hinnant};
21223e519524SHoward Hinnant
21239bf42533SHoward Hinnanttemplate <class _Ti, class ..._Uj>
21249bf42533SHoward Hinnantstruct ____mu_return<_Ti, false, true, false, tuple<_Uj...> >
21259bf42533SHoward Hinnant    : public ____mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...>
21269bf42533SHoward Hinnant{
21279bf42533SHoward Hinnant};
21289bf42533SHoward Hinnant
21293e519524SHoward Hinnanttemplate <class _Ti, class _TupleUj>
21302fa07ae9SHoward Hinnantstruct ____mu_return<_Ti, false, false, true, _TupleUj>
21313e519524SHoward Hinnant{
21323e519524SHoward Hinnant    typedef typename tuple_element<is_placeholder<_Ti>::value - 1,
21333e519524SHoward Hinnant                                   _TupleUj>::type&& type;
21343e519524SHoward Hinnant};
21353e519524SHoward Hinnant
21363e519524SHoward Hinnanttemplate <class _Ti, class _TupleUj>
21372fa07ae9SHoward Hinnantstruct ____mu_return<_Ti, true, false, false, _TupleUj>
21382fa07ae9SHoward Hinnant{
21392fa07ae9SHoward Hinnant    typedef typename _Ti::type& type;
21402fa07ae9SHoward Hinnant};
21412fa07ae9SHoward Hinnant
21422fa07ae9SHoward Hinnanttemplate <class _Ti, class _TupleUj>
21432fa07ae9SHoward Hinnantstruct ____mu_return<_Ti, false, false, false, _TupleUj>
21443e519524SHoward Hinnant{
21453e519524SHoward Hinnant    typedef _Ti& type;
21463e519524SHoward Hinnant};
21473e519524SHoward Hinnant
21483e519524SHoward Hinnanttemplate <class _Ti, class _TupleUj>
21493e519524SHoward Hinnantstruct __mu_return
21503e519524SHoward Hinnant    : public ____mu_return<_Ti,
21512fa07ae9SHoward Hinnant                           __is_reference_wrapper<_Ti>::value,
21523e519524SHoward Hinnant                           is_bind_expression<_Ti>::value,
2153c0c9748cSHoward Hinnant                           0 < is_placeholder<_Ti>::value &&
2154c0c9748cSHoward Hinnant                           is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value,
21553e519524SHoward Hinnant                           _TupleUj>
21563e519524SHoward Hinnant{
21573e519524SHoward Hinnant};
21583e519524SHoward Hinnant
2159c003db1fSHoward Hinnanttemplate <class _Fp, class _BoundArgs, class _TupleUj>
216035cb2b28SEric Fiselierstruct __is_valid_bind_return
2161c0c9748cSHoward Hinnant{
2162c0c9748cSHoward Hinnant    static const bool value = false;
2163c0c9748cSHoward Hinnant};
2164c0c9748cSHoward Hinnant
2165c0c9748cSHoward Hinnanttemplate <class _Fp, class ..._BoundArgs, class _TupleUj>
216635cb2b28SEric Fiselierstruct __is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj>
2167c0c9748cSHoward Hinnant{
2168c0c9748cSHoward Hinnant    static const bool value = __invokable<_Fp,
2169c0c9748cSHoward Hinnant                    typename __mu_return<_BoundArgs, _TupleUj>::type...>::value;
2170c0c9748cSHoward Hinnant};
2171c0c9748cSHoward Hinnant
2172c0c9748cSHoward Hinnanttemplate <class _Fp, class ..._BoundArgs, class _TupleUj>
217335cb2b28SEric Fiselierstruct __is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj>
2174c0c9748cSHoward Hinnant{
2175c0c9748cSHoward Hinnant    static const bool value = __invokable<_Fp,
2176c0c9748cSHoward Hinnant                    typename __mu_return<const _BoundArgs, _TupleUj>::type...>::value;
2177c0c9748cSHoward Hinnant};
2178c0c9748cSHoward Hinnant
2179c0c9748cSHoward Hinnanttemplate <class _Fp, class _BoundArgs, class _TupleUj,
218035cb2b28SEric Fiselier          bool = __is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value>
21813e519524SHoward Hinnantstruct __bind_return;
21823e519524SHoward Hinnant
2183c003db1fSHoward Hinnanttemplate <class _Fp, class ..._BoundArgs, class _TupleUj>
2184c0c9748cSHoward Hinnantstruct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true>
21853e519524SHoward Hinnant{
21862344d6c1SHoward Hinnant    typedef typename __invoke_of
21873e519524SHoward Hinnant    <
2188c003db1fSHoward Hinnant        _Fp&,
21893e519524SHoward Hinnant        typename __mu_return
21903e519524SHoward Hinnant        <
21913e519524SHoward Hinnant            _BoundArgs,
21923e519524SHoward Hinnant            _TupleUj
21933e519524SHoward Hinnant        >::type...
21943e519524SHoward Hinnant    >::type type;
21953e519524SHoward Hinnant};
21963e519524SHoward Hinnant
2197c003db1fSHoward Hinnanttemplate <class _Fp, class ..._BoundArgs, class _TupleUj>
2198c0c9748cSHoward Hinnantstruct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true>
21993e519524SHoward Hinnant{
22002344d6c1SHoward Hinnant    typedef typename __invoke_of
22013e519524SHoward Hinnant    <
2202c003db1fSHoward Hinnant        _Fp&,
22033e519524SHoward Hinnant        typename __mu_return
22043e519524SHoward Hinnant        <
22053e519524SHoward Hinnant            const _BoundArgs,
22063e519524SHoward Hinnant            _TupleUj
22073e519524SHoward Hinnant        >::type...
22083e519524SHoward Hinnant    >::type type;
22093e519524SHoward Hinnant};
22103e519524SHoward Hinnant
2211c003db1fSHoward Hinnanttemplate <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args>
22123e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
2213c003db1fSHoward Hinnanttypename __bind_return<_Fp, _BoundArgs, _Args>::type
2214c003db1fSHoward Hinnant__apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
22153e519524SHoward Hinnant                _Args&& __args)
22163e519524SHoward Hinnant{
22171f8b73d1SEric Fiselier    return _VSTD::__invoke(__f, _VSTD::__mu(_VSTD::get<_Indx>(__bound_args), __args)...);
22183e519524SHoward Hinnant}
22193e519524SHoward Hinnant
2220c003db1fSHoward Hinnanttemplate<class _Fp, class ..._BoundArgs>
22213e519524SHoward Hinnantclass __bind
2222c003db1fSHoward Hinnant    : public __weak_result_type<typename decay<_Fp>::type>
22233e519524SHoward Hinnant{
2224c0c9748cSHoward Hinnantprotected:
2225c003db1fSHoward Hinnant    typedef typename decay<_Fp>::type _Fd;
22262344d6c1SHoward Hinnant    typedef tuple<typename decay<_BoundArgs>::type...> _Td;
2227c0c9748cSHoward Hinnantprivate:
22282344d6c1SHoward Hinnant    _Fd __f_;
22292344d6c1SHoward Hinnant    _Td __bound_args_;
22303e519524SHoward Hinnant
22313e519524SHoward Hinnant    typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices;
22323e519524SHoward Hinnantpublic:
2233df7aad41SHoward Hinnant    template <class _Gp, class ..._BA,
2234df7aad41SHoward Hinnant              class = typename enable_if
2235df7aad41SHoward Hinnant                               <
22369dbbf8deSHoward Hinnant                                  is_constructible<_Fd, _Gp>::value &&
22379dbbf8deSHoward Hinnant                                  !is_same<typename remove_reference<_Gp>::type,
22389dbbf8deSHoward Hinnant                                           __bind>::value
2239df7aad41SHoward Hinnant                               >::type>
22400af133f9SHoward Hinnant      _LIBCPP_INLINE_VISIBILITY
2241c003db1fSHoward Hinnant      explicit __bind(_Gp&& __f, _BA&& ...__bound_args)
2242c003db1fSHoward Hinnant        : __f_(_VSTD::forward<_Gp>(__f)),
2243ce48a113SHoward Hinnant          __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {}
22443e519524SHoward Hinnant
22453e519524SHoward Hinnant    template <class ..._Args>
22460af133f9SHoward Hinnant        _LIBCPP_INLINE_VISIBILITY
22472344d6c1SHoward Hinnant        typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type
22483e519524SHoward Hinnant        operator()(_Args&& ...__args)
22493e519524SHoward Hinnant        {
22501f8b73d1SEric Fiselier            return _VSTD::__apply_functor(__f_, __bound_args_, __indices(),
2251ce48a113SHoward Hinnant                                  tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
22523e519524SHoward Hinnant        }
22533e519524SHoward Hinnant
22543e519524SHoward Hinnant    template <class ..._Args>
22550af133f9SHoward Hinnant        _LIBCPP_INLINE_VISIBILITY
2256c0c9748cSHoward Hinnant        typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type
22573e519524SHoward Hinnant        operator()(_Args&& ...__args) const
22583e519524SHoward Hinnant        {
22591f8b73d1SEric Fiselier            return _VSTD::__apply_functor(__f_, __bound_args_, __indices(),
2260ce48a113SHoward Hinnant                                   tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
22613e519524SHoward Hinnant        }
22623e519524SHoward Hinnant};
22633e519524SHoward Hinnant
2264c003db1fSHoward Hinnanttemplate<class _Fp, class ..._BoundArgs>
2265c003db1fSHoward Hinnantstruct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {};
22663e519524SHoward Hinnant
2267c003db1fSHoward Hinnanttemplate<class _Rp, class _Fp, class ..._BoundArgs>
22683e519524SHoward Hinnantclass __bind_r
2269c003db1fSHoward Hinnant    : public __bind<_Fp, _BoundArgs...>
22703e519524SHoward Hinnant{
2271c003db1fSHoward Hinnant    typedef __bind<_Fp, _BoundArgs...> base;
2272c0c9748cSHoward Hinnant    typedef typename base::_Fd _Fd;
2273c0c9748cSHoward Hinnant    typedef typename base::_Td _Td;
22743e519524SHoward Hinnantpublic:
2275c003db1fSHoward Hinnant    typedef _Rp result_type;
22763e519524SHoward Hinnant
2277086d0de1SHoward Hinnant
22789dbbf8deSHoward Hinnant    template <class _Gp, class ..._BA,
22799dbbf8deSHoward Hinnant              class = typename enable_if
22809dbbf8deSHoward Hinnant                               <
22819dbbf8deSHoward Hinnant                                  is_constructible<_Fd, _Gp>::value &&
22829dbbf8deSHoward Hinnant                                  !is_same<typename remove_reference<_Gp>::type,
22839dbbf8deSHoward Hinnant                                           __bind_r>::value
22849dbbf8deSHoward Hinnant                               >::type>
22850af133f9SHoward Hinnant      _LIBCPP_INLINE_VISIBILITY
2286c003db1fSHoward Hinnant      explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args)
2287c003db1fSHoward Hinnant        : base(_VSTD::forward<_Gp>(__f),
2288ce48a113SHoward Hinnant               _VSTD::forward<_BA>(__bound_args)...) {}
22893e519524SHoward Hinnant
22903e519524SHoward Hinnant    template <class ..._Args>
22910af133f9SHoward Hinnant        _LIBCPP_INLINE_VISIBILITY
2292c0c9748cSHoward Hinnant        typename enable_if
2293c0c9748cSHoward Hinnant        <
2294c0c9748cSHoward Hinnant            is_convertible<typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type,
22952d15f15fSEric Fiselier                           result_type>::value || is_void<_Rp>::value,
22963e519524SHoward Hinnant            result_type
2297c0c9748cSHoward Hinnant        >::type
22983e519524SHoward Hinnant        operator()(_Args&& ...__args)
22993e519524SHoward Hinnant        {
23002d15f15fSEric Fiselier            typedef __invoke_void_return_wrapper<_Rp> _Invoker;
23012d15f15fSEric Fiselier            return _Invoker::__call(static_cast<base&>(*this), _VSTD::forward<_Args>(__args)...);
23023e519524SHoward Hinnant        }
23033e519524SHoward Hinnant
23043e519524SHoward Hinnant    template <class ..._Args>
23050af133f9SHoward Hinnant        _LIBCPP_INLINE_VISIBILITY
2306c0c9748cSHoward Hinnant        typename enable_if
2307c0c9748cSHoward Hinnant        <
2308c0c9748cSHoward Hinnant            is_convertible<typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type,
23092d15f15fSEric Fiselier                           result_type>::value || is_void<_Rp>::value,
23103e519524SHoward Hinnant            result_type
2311c0c9748cSHoward Hinnant        >::type
23123e519524SHoward Hinnant        operator()(_Args&& ...__args) const
23133e519524SHoward Hinnant        {
23142d15f15fSEric Fiselier            typedef __invoke_void_return_wrapper<_Rp> _Invoker;
23152d15f15fSEric Fiselier            return _Invoker::__call(static_cast<base const&>(*this), _VSTD::forward<_Args>(__args)...);
23163e519524SHoward Hinnant        }
23173e519524SHoward Hinnant};
23183e519524SHoward Hinnant
2319c003db1fSHoward Hinnanttemplate<class _Rp, class _Fp, class ..._BoundArgs>
2320c003db1fSHoward Hinnantstruct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {};
23213e519524SHoward Hinnant
2322c003db1fSHoward Hinnanttemplate<class _Fp, class ..._BoundArgs>
23233e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
2324c003db1fSHoward Hinnant__bind<_Fp, _BoundArgs...>
2325c003db1fSHoward Hinnantbind(_Fp&& __f, _BoundArgs&&... __bound_args)
23263e519524SHoward Hinnant{
2327c003db1fSHoward Hinnant    typedef __bind<_Fp, _BoundArgs...> type;
2328c003db1fSHoward Hinnant    return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
23293e519524SHoward Hinnant}
23303e519524SHoward Hinnant
2331c003db1fSHoward Hinnanttemplate<class _Rp, class _Fp, class ..._BoundArgs>
23323e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
2333c003db1fSHoward Hinnant__bind_r<_Rp, _Fp, _BoundArgs...>
2334c003db1fSHoward Hinnantbind(_Fp&& __f, _BoundArgs&&... __bound_args)
23353e519524SHoward Hinnant{
2336c003db1fSHoward Hinnant    typedef __bind_r<_Rp, _Fp, _BoundArgs...> type;
2337c003db1fSHoward Hinnant    return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
23383e519524SHoward Hinnant}
23393e519524SHoward Hinnant
23407e23afcbSEric Fiselier#endif  // _LIBCPP_CXX03_LANG
23413e519524SHoward Hinnant
23425be45129SEric Fiselier#if _LIBCPP_STD_VER > 14
234357257567SEric Fiselier
23445be45129SEric Fiseliertemplate <class _Fn, class ..._Args>
23455be45129SEric Fiselierresult_of_t<_Fn&&(_Args&&...)>
234657257567SEric Fiselierinvoke(_Fn&& __f, _Args&&... __args)
234757257567SEric Fiselier    noexcept(noexcept(_VSTD::__invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...)))
234857257567SEric Fiselier{
234957257567SEric Fiselier    return _VSTD::__invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...);
23505be45129SEric Fiselier}
235157257567SEric Fiselier
235257257567SEric Fiseliertemplate <class _DecayFunc>
2353e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS __not_fn_imp {
235457257567SEric Fiselier  _DecayFunc __fd;
235557257567SEric Fiselier
235657257567SEric Fiselierpublic:
235757257567SEric Fiselier    __not_fn_imp() = delete;
235857257567SEric Fiselier
235957257567SEric Fiselier    template <class ..._Args>
236057257567SEric Fiselier    _LIBCPP_INLINE_VISIBILITY
23619372d8bcSEric Fiselier    auto operator()(_Args&& ...__args) &
236257257567SEric Fiselier            noexcept(noexcept(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)))
236357257567SEric Fiselier        -> decltype(          !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...))
236457257567SEric Fiselier        { return              !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); }
236557257567SEric Fiselier
236657257567SEric Fiselier    template <class ..._Args>
236757257567SEric Fiselier    _LIBCPP_INLINE_VISIBILITY
23689372d8bcSEric Fiselier    auto operator()(_Args&& ...__args) &&
23699372d8bcSEric Fiselier            noexcept(noexcept(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)))
23709372d8bcSEric Fiselier        -> decltype(          !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...))
23719372d8bcSEric Fiselier        { return              !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); }
23729372d8bcSEric Fiselier
23739372d8bcSEric Fiselier    template <class ..._Args>
23749372d8bcSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
23759372d8bcSEric Fiselier    auto operator()(_Args&& ...__args) const&
237657257567SEric Fiselier            noexcept(noexcept(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)))
237757257567SEric Fiselier        -> decltype(          !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...))
237857257567SEric Fiselier        { return              !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); }
237957257567SEric Fiselier
23809372d8bcSEric Fiselier
23819372d8bcSEric Fiselier    template <class ..._Args>
23829372d8bcSEric Fiselier    _LIBCPP_INLINE_VISIBILITY
23839372d8bcSEric Fiselier    auto operator()(_Args&& ...__args) const&&
23849372d8bcSEric Fiselier            noexcept(noexcept(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)))
23859372d8bcSEric Fiselier        -> decltype(          !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...))
23869372d8bcSEric Fiselier        { return              !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); }
23879372d8bcSEric Fiselier
238857257567SEric Fiselierprivate:
238957257567SEric Fiselier    template <class _RawFunc,
239057257567SEric Fiselier              class = enable_if_t<!is_same<decay_t<_RawFunc>, __not_fn_imp>::value>>
239157257567SEric Fiselier    _LIBCPP_INLINE_VISIBILITY
239257257567SEric Fiselier    explicit __not_fn_imp(_RawFunc&& __rf)
239357257567SEric Fiselier        : __fd(_VSTD::forward<_RawFunc>(__rf)) {}
239457257567SEric Fiselier
239557257567SEric Fiselier    template <class _RawFunc>
239657257567SEric Fiselier    friend inline _LIBCPP_INLINE_VISIBILITY
239757257567SEric Fiselier    __not_fn_imp<decay_t<_RawFunc>> not_fn(_RawFunc&&);
239857257567SEric Fiselier};
239957257567SEric Fiselier
240057257567SEric Fiseliertemplate <class _RawFunc>
240157257567SEric Fiselierinline _LIBCPP_INLINE_VISIBILITY
240257257567SEric Fiselier__not_fn_imp<decay_t<_RawFunc>> not_fn(_RawFunc&& __fn) {
240357257567SEric Fiselier    return __not_fn_imp<decay_t<_RawFunc>>(_VSTD::forward<_RawFunc>(__fn));
240457257567SEric Fiselier}
240557257567SEric Fiselier
24065be45129SEric Fiselier#endif
24075be45129SEric Fiselier
2408d1803b6cSHoward Hinnant// struct hash<T*> in <memory>
24093e519524SHoward Hinnant
2410d835e592SMarshall Clowtemplate <class _BinaryPredicate, class _ForwardIterator1, class _ForwardIterator2>
241112f0a779SMarshall Clowpair<_ForwardIterator1, _ForwardIterator1> _LIBCPP_CONSTEXPR_AFTER_CXX11
2412d835e592SMarshall Clow__search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
2413d835e592SMarshall Clow         _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred,
2414d835e592SMarshall Clow         forward_iterator_tag, forward_iterator_tag)
2415d835e592SMarshall Clow{
2416d835e592SMarshall Clow    if (__first2 == __last2)
2417d835e592SMarshall Clow        return make_pair(__first1, __first1);  // Everything matches an empty sequence
2418d835e592SMarshall Clow    while (true)
2419d835e592SMarshall Clow    {
2420d835e592SMarshall Clow        // Find first element in sequence 1 that matchs *__first2, with a mininum of loop checks
2421d835e592SMarshall Clow        while (true)
2422d835e592SMarshall Clow        {
2423d835e592SMarshall Clow            if (__first1 == __last1)  // return __last1 if no element matches *__first2
2424d835e592SMarshall Clow                return make_pair(__last1, __last1);
2425d835e592SMarshall Clow            if (__pred(*__first1, *__first2))
2426d835e592SMarshall Clow                break;
2427d835e592SMarshall Clow            ++__first1;
2428d835e592SMarshall Clow        }
2429d835e592SMarshall Clow        // *__first1 matches *__first2, now match elements after here
2430d835e592SMarshall Clow        _ForwardIterator1 __m1 = __first1;
2431d835e592SMarshall Clow        _ForwardIterator2 __m2 = __first2;
2432d835e592SMarshall Clow        while (true)
2433d835e592SMarshall Clow        {
2434d835e592SMarshall Clow            if (++__m2 == __last2)  // If pattern exhausted, __first1 is the answer (works for 1 element pattern)
2435d835e592SMarshall Clow                return make_pair(__first1, __m1);
2436d835e592SMarshall Clow            if (++__m1 == __last1)  // Otherwise if source exhaused, pattern not found
2437d835e592SMarshall Clow                return make_pair(__last1, __last1);
2438d835e592SMarshall Clow            if (!__pred(*__m1, *__m2))  // if there is a mismatch, restart with a new __first1
2439d835e592SMarshall Clow            {
2440d835e592SMarshall Clow                ++__first1;
2441d835e592SMarshall Clow                break;
2442d835e592SMarshall Clow            }  // else there is a match, check next elements
2443d835e592SMarshall Clow        }
2444d835e592SMarshall Clow    }
2445d835e592SMarshall Clow}
2446d835e592SMarshall Clow
2447d835e592SMarshall Clowtemplate <class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2>
2448d835e592SMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11
2449d835e592SMarshall Clowpair<_RandomAccessIterator1, _RandomAccessIterator1>
2450d835e592SMarshall Clow__search(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1,
2451d835e592SMarshall Clow         _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __pred,
2452d835e592SMarshall Clow           random_access_iterator_tag, random_access_iterator_tag)
2453d835e592SMarshall Clow{
2454d835e592SMarshall Clow    typedef typename iterator_traits<_RandomAccessIterator1>::difference_type _D1;
2455d835e592SMarshall Clow    typedef typename iterator_traits<_RandomAccessIterator2>::difference_type _D2;
2456d835e592SMarshall Clow    // Take advantage of knowing source and pattern lengths.  Stop short when source is smaller than pattern
2457d835e592SMarshall Clow    const _D2 __len2 = __last2 - __first2;
2458d835e592SMarshall Clow    if (__len2 == 0)
2459d835e592SMarshall Clow        return make_pair(__first1, __first1);
2460d835e592SMarshall Clow    const _D1 __len1 = __last1 - __first1;
2461d835e592SMarshall Clow    if (__len1 < __len2)
2462d835e592SMarshall Clow        return make_pair(__last1, __last1);
2463d835e592SMarshall Clow    const _RandomAccessIterator1 __s = __last1 - (__len2 - 1);  // Start of pattern match can't go beyond here
2464d835e592SMarshall Clow
2465d835e592SMarshall Clow    while (true)
2466d835e592SMarshall Clow    {
2467d835e592SMarshall Clow        while (true)
2468d835e592SMarshall Clow        {
2469d835e592SMarshall Clow            if (__first1 == __s)
2470d835e592SMarshall Clow                return make_pair(__last1, __last1);
2471d835e592SMarshall Clow            if (__pred(*__first1, *__first2))
2472d835e592SMarshall Clow                break;
2473d835e592SMarshall Clow            ++__first1;
2474d835e592SMarshall Clow        }
2475d835e592SMarshall Clow
2476d835e592SMarshall Clow        _RandomAccessIterator1 __m1 = __first1;
2477d835e592SMarshall Clow        _RandomAccessIterator2 __m2 = __first2;
2478d835e592SMarshall Clow         while (true)
2479d835e592SMarshall Clow         {
2480d835e592SMarshall Clow             if (++__m2 == __last2)
2481d835e592SMarshall Clow                 return make_pair(__first1, __first1 + __len2);
2482d835e592SMarshall Clow             ++__m1;          // no need to check range on __m1 because __s guarantees we have enough source
2483d835e592SMarshall Clow             if (!__pred(*__m1, *__m2))
2484d835e592SMarshall Clow             {
2485d835e592SMarshall Clow                 ++__first1;
2486d835e592SMarshall Clow                 break;
2487d835e592SMarshall Clow             }
2488d835e592SMarshall Clow         }
2489d835e592SMarshall Clow    }
2490d835e592SMarshall Clow}
2491d835e592SMarshall Clow
2492d835e592SMarshall Clow#if _LIBCPP_STD_VER > 14
2493d835e592SMarshall Clow
2494d835e592SMarshall Clow// default searcher
2495d835e592SMarshall Clowtemplate<class _ForwardIterator, class _BinaryPredicate = equal_to<>>
24961b1b80f4SDimitry Andricclass _LIBCPP_TYPE_VIS default_searcher {
2497d835e592SMarshall Clowpublic:
2498d835e592SMarshall Clow    _LIBCPP_INLINE_VISIBILITY
2499d835e592SMarshall Clow    default_searcher(_ForwardIterator __f, _ForwardIterator __l,
2500d835e592SMarshall Clow                       _BinaryPredicate __p = _BinaryPredicate())
2501d835e592SMarshall Clow        : __first_(__f), __last_(__l), __pred_(__p) {}
2502d835e592SMarshall Clow
2503d835e592SMarshall Clow    template <typename _ForwardIterator2>
2504d835e592SMarshall Clow    _LIBCPP_INLINE_VISIBILITY
2505d835e592SMarshall Clow    pair<_ForwardIterator2, _ForwardIterator2>
2506d835e592SMarshall Clow    operator () (_ForwardIterator2 __f, _ForwardIterator2 __l) const
2507d835e592SMarshall Clow    {
2508d835e592SMarshall Clow        return _VSTD::__search(__f, __l, __first_, __last_, __pred_,
2509d835e592SMarshall Clow            typename _VSTD::iterator_traits<_ForwardIterator>::iterator_category(),
2510d835e592SMarshall Clow            typename _VSTD::iterator_traits<_ForwardIterator2>::iterator_category());
2511d835e592SMarshall Clow    }
2512d835e592SMarshall Clow
2513d835e592SMarshall Clowprivate:
2514d835e592SMarshall Clow    _ForwardIterator __first_;
2515d835e592SMarshall Clow    _ForwardIterator __last_;
2516d835e592SMarshall Clow    _BinaryPredicate __pred_;
2517d835e592SMarshall Clow    };
2518d835e592SMarshall Clow
2519d835e592SMarshall Clow#endif // _LIBCPP_STD_VER > 14
2520d835e592SMarshall Clow
25213e519524SHoward Hinnant_LIBCPP_END_NAMESPACE_STD
25223e519524SHoward Hinnant
25233e519524SHoward Hinnant#endif  // _LIBCPP_FUNCTIONAL
2524