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 216a48055ceSMarshall Clowtemplate <class T> constexpr bool is_bind_expression_v 217a48055ceSMarshall Clow = is_bind_expression<T>::value; // C++17 218a48055ceSMarshall Clowtemplate <class T> 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> 2383e519524SHoward Hinnantclass binder1st 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> 2523e519524SHoward Hinnantbinder1st<Operation> bind1st(const Operation& op, const T& x); 2533e519524SHoward Hinnant 2543e519524SHoward Hinnanttemplate <class Operation> 2553e519524SHoward Hinnantclass binder2nd 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> 2693e519524SHoward Hinnantbinder2nd<Operation> bind2nd(const Operation& op, const T& x); 2703e519524SHoward Hinnant 2713e519524SHoward Hinnanttemplate <class Arg, class Result> 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> 2803e519524SHoward Hinnantpointer_to_unary_function<Arg,Result> ptr_fun(Result (*f)(Arg)); 2813e519524SHoward Hinnant 2823e519524SHoward Hinnanttemplate <class Arg1, class Arg2, class Result> 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> 2913e519524SHoward Hinnantpointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1,Arg2)); 2923e519524SHoward Hinnant 2933e519524SHoward Hinnanttemplate<class S, class T> 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> 3023e519524SHoward Hinnantclass mem_fun1_t : public binary_function<T*, A, S> 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 3093e519524SHoward Hinnanttemplate<class S, class T> mem_fun_t<S,T> mem_fun(S (T::*f)()); 3103e519524SHoward Hinnanttemplate<class S, class T, class A> mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A)); 3113e519524SHoward Hinnant 3123e519524SHoward Hinnanttemplate<class S, class T> 3133e519524SHoward Hinnantclass mem_fun_ref_t : public unary_function<T, S> 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> 3213e519524SHoward Hinnantclass mem_fun1_ref_t : public binary_function<T, A, S> 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 3283e519524SHoward Hinnanttemplate<class S, class T> mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)()); 3293e519524SHoward Hinnanttemplate<class S, class T, class A> mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A)); 3303e519524SHoward Hinnant 3313e519524SHoward Hinnanttemplate <class S, class T> 3323e519524SHoward Hinnantclass const_mem_fun_t : public unary_function<const T*, S> 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> 3403e519524SHoward Hinnantclass const_mem_fun1_t : public binary_function<const T*, A, S> 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 3473e519524SHoward Hinnanttemplate <class S, class T> const_mem_fun_t<S,T> mem_fun(S (T::*f)() const); 3483e519524SHoward Hinnanttemplate <class S, class T, class A> const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const); 3493e519524SHoward Hinnant 3503e519524SHoward Hinnanttemplate <class S, class T> 3513e519524SHoward Hinnantclass const_mem_fun_ref_t : public unary_function<T, S> 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> 3593e519524SHoward Hinnantclass const_mem_fun1_ref_t : public binary_function<T, A, S> 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 3663e519524SHoward Hinnanttemplate <class S, class T> const_mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)() const); 3673e519524SHoward Hinnanttemplate <class S, class T, class A> const_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const); 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*>; 4733e519524SHoward Hinnant 4743e519524SHoward Hinnant} // std 4753e519524SHoward Hinnant 4763e519524SHoward HinnantPOLICY: For non-variadic implementations, the number of arguments is limited 4773e519524SHoward Hinnant to 3. It is hoped that the need for non-variadic implementations 4783e519524SHoward Hinnant will be minimal. 4793e519524SHoward Hinnant 4803e519524SHoward Hinnant*/ 4813e519524SHoward Hinnant 4823e519524SHoward Hinnant#include <__config> 4833e519524SHoward Hinnant#include <type_traits> 4843e519524SHoward Hinnant#include <typeinfo> 4853e519524SHoward Hinnant#include <exception> 4863e519524SHoward Hinnant#include <memory> 4873e519524SHoward Hinnant#include <tuple> 4883e519524SHoward Hinnant 4893e519524SHoward Hinnant#include <__functional_base> 4903e519524SHoward Hinnant 491073458b1SHoward Hinnant#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 4923e519524SHoward Hinnant#pragma GCC system_header 493073458b1SHoward Hinnant#endif 4943e519524SHoward Hinnant 4953e519524SHoward Hinnant_LIBCPP_BEGIN_NAMESPACE_STD 4963e519524SHoward Hinnant 49783c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 49883c08b44SMarshall Clowtemplate <class _Tp = void> 49983c08b44SMarshall Clow#else 5003e519524SHoward Hinnanttemplate <class _Tp> 50183c08b44SMarshall Clow#endif 502f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY plus : binary_function<_Tp, _Tp, _Tp> 5033e519524SHoward Hinnant{ 5043d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 5053d5134ddSMarshall Clow _Tp operator()(const _Tp& __x, const _Tp& __y) const 5063e519524SHoward Hinnant {return __x + __y;} 5073e519524SHoward Hinnant}; 5083e519524SHoward Hinnant 50983c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 51083c08b44SMarshall Clowtemplate <> 511f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY plus<void> 51283c08b44SMarshall Clow{ 51383c08b44SMarshall Clow template <class _T1, class _T2> 5143d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 5153d5134ddSMarshall Clow auto operator()(_T1&& __t, _T2&& __u) const 516a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))) 517a64f2fbcSMarshall Clow -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)) 51883c08b44SMarshall Clow { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); } 51925d3402cSMarshall Clow typedef void is_transparent; 52083c08b44SMarshall Clow}; 52183c08b44SMarshall Clow#endif 52283c08b44SMarshall Clow 52383c08b44SMarshall Clow 52483c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 52583c08b44SMarshall Clowtemplate <class _Tp = void> 52683c08b44SMarshall Clow#else 5273e519524SHoward Hinnanttemplate <class _Tp> 52883c08b44SMarshall Clow#endif 529f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY minus : binary_function<_Tp, _Tp, _Tp> 5303e519524SHoward Hinnant{ 5313d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 5323d5134ddSMarshall Clow _Tp operator()(const _Tp& __x, const _Tp& __y) const 5333e519524SHoward Hinnant {return __x - __y;} 5343e519524SHoward Hinnant}; 5353e519524SHoward Hinnant 53683c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 53783c08b44SMarshall Clowtemplate <> 538f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY minus<void> 53983c08b44SMarshall Clow{ 54083c08b44SMarshall Clow template <class _T1, class _T2> 5413d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 5423d5134ddSMarshall Clow auto operator()(_T1&& __t, _T2&& __u) const 543a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u))) 544a64f2fbcSMarshall Clow -> decltype (_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u)) 54583c08b44SMarshall Clow { return _VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u); } 54625d3402cSMarshall Clow typedef void is_transparent; 54783c08b44SMarshall Clow}; 54883c08b44SMarshall Clow#endif 54983c08b44SMarshall Clow 55083c08b44SMarshall Clow 55183c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 55283c08b44SMarshall Clowtemplate <class _Tp = void> 55383c08b44SMarshall Clow#else 5543e519524SHoward Hinnanttemplate <class _Tp> 55583c08b44SMarshall Clow#endif 556f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY multiplies : binary_function<_Tp, _Tp, _Tp> 5573e519524SHoward Hinnant{ 5583d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 5593d5134ddSMarshall Clow _Tp operator()(const _Tp& __x, const _Tp& __y) const 5603e519524SHoward Hinnant {return __x * __y;} 5613e519524SHoward Hinnant}; 5623e519524SHoward Hinnant 56383c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 56483c08b44SMarshall Clowtemplate <> 565f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY multiplies<void> 56683c08b44SMarshall Clow{ 56783c08b44SMarshall Clow template <class _T1, class _T2> 5683d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 5693d5134ddSMarshall Clow auto operator()(_T1&& __t, _T2&& __u) const 570a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u))) 571a64f2fbcSMarshall Clow -> decltype (_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u)) 57283c08b44SMarshall Clow { return _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u); } 57325d3402cSMarshall Clow typedef void is_transparent; 57483c08b44SMarshall Clow}; 57583c08b44SMarshall Clow#endif 57683c08b44SMarshall Clow 57783c08b44SMarshall Clow 57883c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 57983c08b44SMarshall Clowtemplate <class _Tp = void> 58083c08b44SMarshall Clow#else 5813e519524SHoward Hinnanttemplate <class _Tp> 58283c08b44SMarshall Clow#endif 583f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY divides : binary_function<_Tp, _Tp, _Tp> 5843e519524SHoward Hinnant{ 5853d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 5863d5134ddSMarshall Clow _Tp operator()(const _Tp& __x, const _Tp& __y) const 5873e519524SHoward Hinnant {return __x / __y;} 5883e519524SHoward Hinnant}; 5893e519524SHoward Hinnant 59083c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 59183c08b44SMarshall Clowtemplate <> 592f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY divides<void> 59383c08b44SMarshall Clow{ 59483c08b44SMarshall Clow template <class _T1, class _T2> 5953d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 5963d5134ddSMarshall Clow auto operator()(_T1&& __t, _T2&& __u) const 597a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u))) 598a64f2fbcSMarshall Clow -> decltype (_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u)) 59983c08b44SMarshall Clow { return _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u); } 60025d3402cSMarshall Clow typedef void is_transparent; 60183c08b44SMarshall Clow}; 60283c08b44SMarshall Clow#endif 60383c08b44SMarshall Clow 60483c08b44SMarshall Clow 60583c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 60683c08b44SMarshall Clowtemplate <class _Tp = void> 60783c08b44SMarshall Clow#else 6083e519524SHoward Hinnanttemplate <class _Tp> 60983c08b44SMarshall Clow#endif 610f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY modulus : binary_function<_Tp, _Tp, _Tp> 6113e519524SHoward Hinnant{ 6123d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 6133d5134ddSMarshall Clow _Tp operator()(const _Tp& __x, const _Tp& __y) const 6143e519524SHoward Hinnant {return __x % __y;} 6153e519524SHoward Hinnant}; 6163e519524SHoward Hinnant 61783c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 61883c08b44SMarshall Clowtemplate <> 619f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY modulus<void> 62083c08b44SMarshall Clow{ 62183c08b44SMarshall Clow template <class _T1, class _T2> 6223d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 6233d5134ddSMarshall Clow auto operator()(_T1&& __t, _T2&& __u) const 624a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u))) 625a64f2fbcSMarshall Clow -> decltype (_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u)) 62683c08b44SMarshall Clow { return _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u); } 62725d3402cSMarshall Clow typedef void is_transparent; 62883c08b44SMarshall Clow}; 62983c08b44SMarshall Clow#endif 63083c08b44SMarshall Clow 63183c08b44SMarshall Clow 63283c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 63383c08b44SMarshall Clowtemplate <class _Tp = void> 63483c08b44SMarshall Clow#else 6353e519524SHoward Hinnanttemplate <class _Tp> 63683c08b44SMarshall Clow#endif 637f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY negate : unary_function<_Tp, _Tp> 6383e519524SHoward Hinnant{ 6393d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 6403d5134ddSMarshall Clow _Tp operator()(const _Tp& __x) const 6413e519524SHoward Hinnant {return -__x;} 6423e519524SHoward Hinnant}; 6433e519524SHoward Hinnant 64483c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 64583c08b44SMarshall Clowtemplate <> 646f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY negate<void> 64783c08b44SMarshall Clow{ 6483e519524SHoward Hinnant template <class _Tp> 6493d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 6503d5134ddSMarshall Clow auto operator()(_Tp&& __x) const 651a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(- _VSTD::forward<_Tp>(__x))) 652a64f2fbcSMarshall Clow -> decltype (- _VSTD::forward<_Tp>(__x)) 65383c08b44SMarshall Clow { return - _VSTD::forward<_Tp>(__x); } 65425d3402cSMarshall Clow typedef void is_transparent; 65583c08b44SMarshall Clow}; 65683c08b44SMarshall Clow#endif 65783c08b44SMarshall Clow 65883c08b44SMarshall Clow 65983c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 66083c08b44SMarshall Clowtemplate <class _Tp = void> 66183c08b44SMarshall Clow#else 66283c08b44SMarshall Clowtemplate <class _Tp> 66383c08b44SMarshall Clow#endif 664f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY equal_to : binary_function<_Tp, _Tp, bool> 6653e519524SHoward Hinnant{ 6663d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 6673d5134ddSMarshall Clow bool operator()(const _Tp& __x, const _Tp& __y) const 6683e519524SHoward Hinnant {return __x == __y;} 6693e519524SHoward Hinnant}; 6703e519524SHoward Hinnant 67183c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 67283c08b44SMarshall Clowtemplate <> 673f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY equal_to<void> 67483c08b44SMarshall Clow{ 6753d5134ddSMarshall Clow template <class _T1, class _T2> 6763d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 67783c08b44SMarshall Clow auto operator()(_T1&& __t, _T2&& __u) const 678a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u))) 679a64f2fbcSMarshall Clow -> decltype (_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u)) 68083c08b44SMarshall Clow { return _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u); } 68125d3402cSMarshall Clow typedef void is_transparent; 68283c08b44SMarshall Clow}; 68383c08b44SMarshall Clow#endif 68483c08b44SMarshall Clow 68583c08b44SMarshall Clow 68683c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 68783c08b44SMarshall Clowtemplate <class _Tp = void> 68883c08b44SMarshall Clow#else 6893e519524SHoward Hinnanttemplate <class _Tp> 69083c08b44SMarshall Clow#endif 691f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY not_equal_to : binary_function<_Tp, _Tp, bool> 6923e519524SHoward Hinnant{ 6933d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 6943d5134ddSMarshall Clow bool operator()(const _Tp& __x, const _Tp& __y) const 6953e519524SHoward Hinnant {return __x != __y;} 6963e519524SHoward Hinnant}; 6973e519524SHoward Hinnant 69883c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 69983c08b44SMarshall Clowtemplate <> 700f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY not_equal_to<void> 70183c08b44SMarshall Clow{ 7023d5134ddSMarshall Clow template <class _T1, class _T2> 7033d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 70483c08b44SMarshall Clow auto operator()(_T1&& __t, _T2&& __u) const 705a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u))) 706a64f2fbcSMarshall Clow -> decltype (_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u)) 70783c08b44SMarshall Clow { return _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u); } 70825d3402cSMarshall Clow typedef void is_transparent; 70983c08b44SMarshall Clow}; 71083c08b44SMarshall Clow#endif 71183c08b44SMarshall Clow 71283c08b44SMarshall Clow 71383c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 71483c08b44SMarshall Clowtemplate <class _Tp = void> 71583c08b44SMarshall Clow#else 7163e519524SHoward Hinnanttemplate <class _Tp> 71783c08b44SMarshall Clow#endif 718f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY greater : binary_function<_Tp, _Tp, bool> 7193e519524SHoward Hinnant{ 7203d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 7213d5134ddSMarshall Clow bool operator()(const _Tp& __x, const _Tp& __y) const 7223e519524SHoward Hinnant {return __x > __y;} 7233e519524SHoward Hinnant}; 7243e519524SHoward Hinnant 72583c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 72683c08b44SMarshall Clowtemplate <> 727f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY greater<void> 72883c08b44SMarshall Clow{ 7293d5134ddSMarshall Clow template <class _T1, class _T2> 7303d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 73183c08b44SMarshall Clow auto operator()(_T1&& __t, _T2&& __u) const 732a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u))) 733a64f2fbcSMarshall Clow -> decltype (_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u)) 73483c08b44SMarshall Clow { return _VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u); } 73525d3402cSMarshall Clow typedef void is_transparent; 73683c08b44SMarshall Clow}; 73783c08b44SMarshall Clow#endif 73883c08b44SMarshall Clow 73983c08b44SMarshall Clow 74067f39647SHoward Hinnant// less in <__functional_base> 7413e519524SHoward Hinnant 74283c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 74383c08b44SMarshall Clowtemplate <class _Tp = void> 74483c08b44SMarshall Clow#else 7453e519524SHoward Hinnanttemplate <class _Tp> 74683c08b44SMarshall Clow#endif 747f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY greater_equal : binary_function<_Tp, _Tp, bool> 7483e519524SHoward Hinnant{ 7493d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 7503d5134ddSMarshall Clow bool operator()(const _Tp& __x, const _Tp& __y) const 7513e519524SHoward Hinnant {return __x >= __y;} 7523e519524SHoward Hinnant}; 7533e519524SHoward Hinnant 75483c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 75583c08b44SMarshall Clowtemplate <> 756f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY greater_equal<void> 75783c08b44SMarshall Clow{ 7583d5134ddSMarshall Clow template <class _T1, class _T2> 7593d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 76083c08b44SMarshall Clow auto operator()(_T1&& __t, _T2&& __u) const 761a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u))) 762a64f2fbcSMarshall Clow -> decltype (_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u)) 76383c08b44SMarshall Clow { return _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u); } 76425d3402cSMarshall Clow typedef void is_transparent; 76583c08b44SMarshall Clow}; 76683c08b44SMarshall Clow#endif 76783c08b44SMarshall Clow 76883c08b44SMarshall Clow 76983c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 77083c08b44SMarshall Clowtemplate <class _Tp = void> 77183c08b44SMarshall Clow#else 7723e519524SHoward Hinnanttemplate <class _Tp> 77383c08b44SMarshall Clow#endif 774f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY less_equal : binary_function<_Tp, _Tp, bool> 7753e519524SHoward Hinnant{ 7763d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 7773d5134ddSMarshall Clow bool operator()(const _Tp& __x, const _Tp& __y) const 7783e519524SHoward Hinnant {return __x <= __y;} 7793e519524SHoward Hinnant}; 7803e519524SHoward Hinnant 78183c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 78283c08b44SMarshall Clowtemplate <> 783f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY less_equal<void> 78483c08b44SMarshall Clow{ 7853d5134ddSMarshall Clow template <class _T1, class _T2> 7863d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 78783c08b44SMarshall Clow auto operator()(_T1&& __t, _T2&& __u) const 788a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u))) 789a64f2fbcSMarshall Clow -> decltype (_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u)) 79083c08b44SMarshall Clow { return _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u); } 79125d3402cSMarshall Clow typedef void is_transparent; 79283c08b44SMarshall Clow}; 79383c08b44SMarshall Clow#endif 79483c08b44SMarshall Clow 79583c08b44SMarshall Clow 79683c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 79783c08b44SMarshall Clowtemplate <class _Tp = void> 79883c08b44SMarshall Clow#else 7993e519524SHoward Hinnanttemplate <class _Tp> 80083c08b44SMarshall Clow#endif 801f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY logical_and : binary_function<_Tp, _Tp, bool> 8023e519524SHoward Hinnant{ 8033d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 8043d5134ddSMarshall Clow bool operator()(const _Tp& __x, const _Tp& __y) const 8053e519524SHoward Hinnant {return __x && __y;} 8063e519524SHoward Hinnant}; 8073e519524SHoward Hinnant 80883c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 80983c08b44SMarshall Clowtemplate <> 810f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY logical_and<void> 81183c08b44SMarshall Clow{ 8123d5134ddSMarshall Clow template <class _T1, class _T2> 8133d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 81483c08b44SMarshall Clow auto operator()(_T1&& __t, _T2&& __u) const 815a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u))) 816a64f2fbcSMarshall Clow -> decltype (_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u)) 81783c08b44SMarshall Clow { return _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u); } 81825d3402cSMarshall Clow typedef void is_transparent; 81983c08b44SMarshall Clow}; 82083c08b44SMarshall Clow#endif 82183c08b44SMarshall Clow 82283c08b44SMarshall Clow 82383c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 82483c08b44SMarshall Clowtemplate <class _Tp = void> 82583c08b44SMarshall Clow#else 8263e519524SHoward Hinnanttemplate <class _Tp> 82783c08b44SMarshall Clow#endif 828f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY logical_or : binary_function<_Tp, _Tp, bool> 8293e519524SHoward Hinnant{ 8303d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 8313d5134ddSMarshall Clow bool operator()(const _Tp& __x, const _Tp& __y) const 8323e519524SHoward Hinnant {return __x || __y;} 8333e519524SHoward Hinnant}; 8343e519524SHoward Hinnant 83583c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 83683c08b44SMarshall Clowtemplate <> 837f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY logical_or<void> 83883c08b44SMarshall Clow{ 8393d5134ddSMarshall Clow template <class _T1, class _T2> 8403d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 84183c08b44SMarshall Clow auto operator()(_T1&& __t, _T2&& __u) const 842a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u))) 843a64f2fbcSMarshall Clow -> decltype (_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u)) 84483c08b44SMarshall Clow { return _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u); } 84525d3402cSMarshall Clow typedef void is_transparent; 84683c08b44SMarshall Clow}; 84783c08b44SMarshall Clow#endif 84883c08b44SMarshall Clow 84983c08b44SMarshall Clow 85083c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 85183c08b44SMarshall Clowtemplate <class _Tp = void> 85283c08b44SMarshall Clow#else 8533e519524SHoward Hinnanttemplate <class _Tp> 85483c08b44SMarshall Clow#endif 855f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY logical_not : unary_function<_Tp, bool> 8563e519524SHoward Hinnant{ 8573d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 8583d5134ddSMarshall Clow bool operator()(const _Tp& __x) const 8593e519524SHoward Hinnant {return !__x;} 8603e519524SHoward Hinnant}; 8613e519524SHoward Hinnant 86283c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 86383c08b44SMarshall Clowtemplate <> 864f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY logical_not<void> 86583c08b44SMarshall Clow{ 8663e519524SHoward Hinnant template <class _Tp> 8673d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 8683d5134ddSMarshall Clow auto operator()(_Tp&& __x) const 869a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(!_VSTD::forward<_Tp>(__x))) 870a64f2fbcSMarshall Clow -> decltype (!_VSTD::forward<_Tp>(__x)) 87183c08b44SMarshall Clow { return !_VSTD::forward<_Tp>(__x); } 87225d3402cSMarshall Clow typedef void is_transparent; 87383c08b44SMarshall Clow}; 87483c08b44SMarshall Clow#endif 87583c08b44SMarshall Clow 87683c08b44SMarshall Clow 87783c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 87883c08b44SMarshall Clowtemplate <class _Tp = void> 87983c08b44SMarshall Clow#else 88083c08b44SMarshall Clowtemplate <class _Tp> 88183c08b44SMarshall Clow#endif 882f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY bit_and : binary_function<_Tp, _Tp, _Tp> 8833e519524SHoward Hinnant{ 8843d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 8853d5134ddSMarshall Clow _Tp operator()(const _Tp& __x, const _Tp& __y) const 8863e519524SHoward Hinnant {return __x & __y;} 8873e519524SHoward Hinnant}; 8883e519524SHoward Hinnant 88983c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 89083c08b44SMarshall Clowtemplate <> 891f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY bit_and<void> 89283c08b44SMarshall Clow{ 8933d5134ddSMarshall Clow template <class _T1, class _T2> 8943d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 89583c08b44SMarshall Clow auto operator()(_T1&& __t, _T2&& __u) const 896a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u))) 897a64f2fbcSMarshall Clow -> decltype (_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u)) 89883c08b44SMarshall Clow { return _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u); } 89925d3402cSMarshall Clow typedef void is_transparent; 90083c08b44SMarshall Clow}; 90183c08b44SMarshall Clow#endif 90283c08b44SMarshall Clow 90383c08b44SMarshall Clow 90483c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 90583c08b44SMarshall Clowtemplate <class _Tp = void> 90683c08b44SMarshall Clow#else 9073e519524SHoward Hinnanttemplate <class _Tp> 90883c08b44SMarshall Clow#endif 909f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY bit_or : binary_function<_Tp, _Tp, _Tp> 9103e519524SHoward Hinnant{ 9113d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 9123d5134ddSMarshall Clow _Tp operator()(const _Tp& __x, const _Tp& __y) const 9133e519524SHoward Hinnant {return __x | __y;} 9143e519524SHoward Hinnant}; 9153e519524SHoward Hinnant 91683c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 91783c08b44SMarshall Clowtemplate <> 918f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY bit_or<void> 91983c08b44SMarshall Clow{ 9203d5134ddSMarshall Clow template <class _T1, class _T2> 9213d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 92283c08b44SMarshall Clow auto operator()(_T1&& __t, _T2&& __u) const 923a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u))) 924a64f2fbcSMarshall Clow -> decltype (_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u)) 92583c08b44SMarshall Clow { return _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u); } 92625d3402cSMarshall Clow typedef void is_transparent; 92783c08b44SMarshall Clow}; 92883c08b44SMarshall Clow#endif 92983c08b44SMarshall Clow 93083c08b44SMarshall Clow 93183c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 93283c08b44SMarshall Clowtemplate <class _Tp = void> 93383c08b44SMarshall Clow#else 9343e519524SHoward Hinnanttemplate <class _Tp> 93583c08b44SMarshall Clow#endif 936f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY bit_xor : binary_function<_Tp, _Tp, _Tp> 9373e519524SHoward Hinnant{ 9383d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 9393d5134ddSMarshall Clow _Tp operator()(const _Tp& __x, const _Tp& __y) const 9403e519524SHoward Hinnant {return __x ^ __y;} 9413e519524SHoward Hinnant}; 9423e519524SHoward Hinnant 94383c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 94483c08b44SMarshall Clowtemplate <> 945f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY bit_xor<void> 94683c08b44SMarshall Clow{ 9473d5134ddSMarshall Clow template <class _T1, class _T2> 9483d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 94983c08b44SMarshall Clow auto operator()(_T1&& __t, _T2&& __u) const 950a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u))) 951a64f2fbcSMarshall Clow -> decltype (_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u)) 95283c08b44SMarshall Clow { return _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u); } 95325d3402cSMarshall Clow typedef void is_transparent; 95483c08b44SMarshall Clow}; 95583c08b44SMarshall Clow#endif 95683c08b44SMarshall Clow 95783c08b44SMarshall Clow 95883c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 95983c08b44SMarshall Clowtemplate <class _Tp = void> 960f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY bit_not : unary_function<_Tp, _Tp> 96183c08b44SMarshall Clow{ 9623d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 9633d5134ddSMarshall Clow _Tp operator()(const _Tp& __x) const 96483c08b44SMarshall Clow {return ~__x;} 96583c08b44SMarshall Clow}; 96683c08b44SMarshall Clow 96783c08b44SMarshall Clowtemplate <> 968f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY bit_not<void> 96983c08b44SMarshall Clow{ 97083c08b44SMarshall Clow template <class _Tp> 9713d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 9723d5134ddSMarshall Clow auto operator()(_Tp&& __x) const 973a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(~_VSTD::forward<_Tp>(__x))) 974a64f2fbcSMarshall Clow -> decltype (~_VSTD::forward<_Tp>(__x)) 97583c08b44SMarshall Clow { return ~_VSTD::forward<_Tp>(__x); } 97625d3402cSMarshall Clow typedef void is_transparent; 97783c08b44SMarshall Clow}; 97883c08b44SMarshall Clow#endif 97983c08b44SMarshall Clow 9803e519524SHoward Hinnanttemplate <class _Predicate> 981f0544c20SHoward Hinnantclass _LIBCPP_TYPE_VIS_ONLY unary_negate 9823e519524SHoward Hinnant : public unary_function<typename _Predicate::argument_type, bool> 9833e519524SHoward Hinnant{ 9843e519524SHoward Hinnant _Predicate __pred_; 9853e519524SHoward Hinnantpublic: 9863d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 9873d5134ddSMarshall Clow explicit unary_negate(const _Predicate& __pred) 9883e519524SHoward Hinnant : __pred_(__pred) {} 9893d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 9903d5134ddSMarshall Clow bool operator()(const typename _Predicate::argument_type& __x) const 9913e519524SHoward Hinnant {return !__pred_(__x);} 9923e519524SHoward Hinnant}; 9933e519524SHoward Hinnant 9943e519524SHoward Hinnanttemplate <class _Predicate> 9953d5134ddSMarshall Clowinline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 9963e519524SHoward Hinnantunary_negate<_Predicate> 9973e519524SHoward Hinnantnot1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);} 9983e519524SHoward Hinnant 9993e519524SHoward Hinnanttemplate <class _Predicate> 1000f0544c20SHoward Hinnantclass _LIBCPP_TYPE_VIS_ONLY binary_negate 10013e519524SHoward Hinnant : public binary_function<typename _Predicate::first_argument_type, 10023e519524SHoward Hinnant typename _Predicate::second_argument_type, 10033e519524SHoward Hinnant bool> 10043e519524SHoward Hinnant{ 10053e519524SHoward Hinnant _Predicate __pred_; 10063e519524SHoward Hinnantpublic: 10073d5134ddSMarshall Clow _LIBCPP_INLINE_VISIBILITY explicit _LIBCPP_CONSTEXPR_AFTER_CXX11 10083d5134ddSMarshall Clow binary_negate(const _Predicate& __pred) : __pred_(__pred) {} 10093d5134ddSMarshall Clow 10103d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 10113d5134ddSMarshall Clow bool operator()(const typename _Predicate::first_argument_type& __x, 10123e519524SHoward Hinnant const typename _Predicate::second_argument_type& __y) const 10133e519524SHoward Hinnant {return !__pred_(__x, __y);} 10143e519524SHoward Hinnant}; 10153e519524SHoward Hinnant 10163e519524SHoward Hinnanttemplate <class _Predicate> 10173d5134ddSMarshall Clowinline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 10183e519524SHoward Hinnantbinary_negate<_Predicate> 10193e519524SHoward Hinnantnot2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);} 10203e519524SHoward Hinnant 10213e519524SHoward Hinnanttemplate <class __Operation> 1022f0544c20SHoward Hinnantclass _LIBCPP_TYPE_VIS_ONLY binder1st 10233e519524SHoward Hinnant : public unary_function<typename __Operation::second_argument_type, 10243e519524SHoward Hinnant typename __Operation::result_type> 10253e519524SHoward Hinnant{ 10263e519524SHoward Hinnantprotected: 10273e519524SHoward Hinnant __Operation op; 10283e519524SHoward Hinnant typename __Operation::first_argument_type value; 10293e519524SHoward Hinnantpublic: 10303e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x, 10313e519524SHoward Hinnant const typename __Operation::first_argument_type __y) 10323e519524SHoward Hinnant : op(__x), value(__y) {} 10333e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() 10343e519524SHoward Hinnant (typename __Operation::second_argument_type& __x) const 10353e519524SHoward Hinnant {return op(value, __x);} 10363e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() 10373e519524SHoward Hinnant (const typename __Operation::second_argument_type& __x) const 10383e519524SHoward Hinnant {return op(value, __x);} 10393e519524SHoward Hinnant}; 10403e519524SHoward Hinnant 10413e519524SHoward Hinnanttemplate <class __Operation, class _Tp> 10423e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 10433e519524SHoward Hinnantbinder1st<__Operation> 10443e519524SHoward Hinnantbind1st(const __Operation& __op, const _Tp& __x) 10453e519524SHoward Hinnant {return binder1st<__Operation>(__op, __x);} 10463e519524SHoward Hinnant 10473e519524SHoward Hinnanttemplate <class __Operation> 1048f0544c20SHoward Hinnantclass _LIBCPP_TYPE_VIS_ONLY binder2nd 10493e519524SHoward Hinnant : public unary_function<typename __Operation::first_argument_type, 10503e519524SHoward Hinnant typename __Operation::result_type> 10513e519524SHoward Hinnant{ 10523e519524SHoward Hinnantprotected: 10533e519524SHoward Hinnant __Operation op; 10543e519524SHoward Hinnant typename __Operation::second_argument_type value; 10553e519524SHoward Hinnantpublic: 10560af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 10573e519524SHoward Hinnant binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y) 10583e519524SHoward Hinnant : op(__x), value(__y) {} 10593e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() 10603e519524SHoward Hinnant ( typename __Operation::first_argument_type& __x) const 10613e519524SHoward Hinnant {return op(__x, value);} 10623e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() 10633e519524SHoward Hinnant (const typename __Operation::first_argument_type& __x) const 10643e519524SHoward Hinnant {return op(__x, value);} 10653e519524SHoward Hinnant}; 10663e519524SHoward Hinnant 10673e519524SHoward Hinnanttemplate <class __Operation, class _Tp> 10683e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 10693e519524SHoward Hinnantbinder2nd<__Operation> 10703e519524SHoward Hinnantbind2nd(const __Operation& __op, const _Tp& __x) 10713e519524SHoward Hinnant {return binder2nd<__Operation>(__op, __x);} 10723e519524SHoward Hinnant 10733e519524SHoward Hinnanttemplate <class _Arg, class _Result> 1074f0544c20SHoward Hinnantclass _LIBCPP_TYPE_VIS_ONLY pointer_to_unary_function 10750af133f9SHoward Hinnant : public unary_function<_Arg, _Result> 10763e519524SHoward Hinnant{ 10773e519524SHoward Hinnant _Result (*__f_)(_Arg); 10783e519524SHoward Hinnantpublic: 10793e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg)) 10803e519524SHoward Hinnant : __f_(__f) {} 10813e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const 10823e519524SHoward Hinnant {return __f_(__x);} 10833e519524SHoward Hinnant}; 10843e519524SHoward Hinnant 10853e519524SHoward Hinnanttemplate <class _Arg, class _Result> 10863e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 10873e519524SHoward Hinnantpointer_to_unary_function<_Arg,_Result> 10883e519524SHoward Hinnantptr_fun(_Result (*__f)(_Arg)) 10893e519524SHoward Hinnant {return pointer_to_unary_function<_Arg,_Result>(__f);} 10903e519524SHoward Hinnant 10913e519524SHoward Hinnanttemplate <class _Arg1, class _Arg2, class _Result> 1092f0544c20SHoward Hinnantclass _LIBCPP_TYPE_VIS_ONLY pointer_to_binary_function 10930af133f9SHoward Hinnant : public binary_function<_Arg1, _Arg2, _Result> 10943e519524SHoward Hinnant{ 10953e519524SHoward Hinnant _Result (*__f_)(_Arg1, _Arg2); 10963e519524SHoward Hinnantpublic: 10973e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2)) 10983e519524SHoward Hinnant : __f_(__f) {} 10993e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const 11003e519524SHoward Hinnant {return __f_(__x, __y);} 11013e519524SHoward Hinnant}; 11023e519524SHoward Hinnant 11033e519524SHoward Hinnanttemplate <class _Arg1, class _Arg2, class _Result> 11043e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 11053e519524SHoward Hinnantpointer_to_binary_function<_Arg1,_Arg2,_Result> 11063e519524SHoward Hinnantptr_fun(_Result (*__f)(_Arg1,_Arg2)) 11073e519524SHoward Hinnant {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);} 11083e519524SHoward Hinnant 11093e519524SHoward Hinnanttemplate<class _Sp, class _Tp> 1110f0544c20SHoward Hinnantclass _LIBCPP_TYPE_VIS_ONLY mem_fun_t : public unary_function<_Tp*, _Sp> 11113e519524SHoward Hinnant{ 11123e519524SHoward Hinnant _Sp (_Tp::*__p_)(); 11133e519524SHoward Hinnantpublic: 11143e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)()) 11153e519524SHoward Hinnant : __p_(__p) {} 11163e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const 11173e519524SHoward Hinnant {return (__p->*__p_)();} 11183e519524SHoward Hinnant}; 11193e519524SHoward Hinnant 11203e519524SHoward Hinnanttemplate<class _Sp, class _Tp, class _Ap> 1121f0544c20SHoward Hinnantclass _LIBCPP_TYPE_VIS_ONLY mem_fun1_t : public binary_function<_Tp*, _Ap, _Sp> 11223e519524SHoward Hinnant{ 11233e519524SHoward Hinnant _Sp (_Tp::*__p_)(_Ap); 11243e519524SHoward Hinnantpublic: 11253e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap)) 11263e519524SHoward Hinnant : __p_(__p) {} 11273e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const 11283e519524SHoward Hinnant {return (__p->*__p_)(__x);} 11293e519524SHoward Hinnant}; 11303e519524SHoward Hinnant 11313e519524SHoward Hinnanttemplate<class _Sp, class _Tp> 11323e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 11333e519524SHoward Hinnantmem_fun_t<_Sp,_Tp> 11343e519524SHoward Hinnantmem_fun(_Sp (_Tp::*__f)()) 11353e519524SHoward Hinnant {return mem_fun_t<_Sp,_Tp>(__f);} 11363e519524SHoward Hinnant 11373e519524SHoward Hinnanttemplate<class _Sp, class _Tp, class _Ap> 11383e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 11393e519524SHoward Hinnantmem_fun1_t<_Sp,_Tp,_Ap> 11403e519524SHoward Hinnantmem_fun(_Sp (_Tp::*__f)(_Ap)) 11413e519524SHoward Hinnant {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);} 11423e519524SHoward Hinnant 11433e519524SHoward Hinnanttemplate<class _Sp, class _Tp> 1144f0544c20SHoward Hinnantclass _LIBCPP_TYPE_VIS_ONLY mem_fun_ref_t : public unary_function<_Tp, _Sp> 11453e519524SHoward Hinnant{ 11463e519524SHoward Hinnant _Sp (_Tp::*__p_)(); 11473e519524SHoward Hinnantpublic: 11483e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)()) 11493e519524SHoward Hinnant : __p_(__p) {} 11503e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const 11513e519524SHoward Hinnant {return (__p.*__p_)();} 11523e519524SHoward Hinnant}; 11533e519524SHoward Hinnant 11543e519524SHoward Hinnanttemplate<class _Sp, class _Tp, class _Ap> 1155f0544c20SHoward Hinnantclass _LIBCPP_TYPE_VIS_ONLY mem_fun1_ref_t : public binary_function<_Tp, _Ap, _Sp> 11563e519524SHoward Hinnant{ 11573e519524SHoward Hinnant _Sp (_Tp::*__p_)(_Ap); 11583e519524SHoward Hinnantpublic: 11593e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap)) 11603e519524SHoward Hinnant : __p_(__p) {} 11613e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const 11623e519524SHoward Hinnant {return (__p.*__p_)(__x);} 11633e519524SHoward Hinnant}; 11643e519524SHoward Hinnant 11653e519524SHoward Hinnanttemplate<class _Sp, class _Tp> 11663e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 11673e519524SHoward Hinnantmem_fun_ref_t<_Sp,_Tp> 11683e519524SHoward Hinnantmem_fun_ref(_Sp (_Tp::*__f)()) 11693e519524SHoward Hinnant {return mem_fun_ref_t<_Sp,_Tp>(__f);} 11703e519524SHoward Hinnant 11713e519524SHoward Hinnanttemplate<class _Sp, class _Tp, class _Ap> 11723e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 11733e519524SHoward Hinnantmem_fun1_ref_t<_Sp,_Tp,_Ap> 11743e519524SHoward Hinnantmem_fun_ref(_Sp (_Tp::*__f)(_Ap)) 11753e519524SHoward Hinnant {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);} 11763e519524SHoward Hinnant 11773e519524SHoward Hinnanttemplate <class _Sp, class _Tp> 1178f0544c20SHoward Hinnantclass _LIBCPP_TYPE_VIS_ONLY const_mem_fun_t : public unary_function<const _Tp*, _Sp> 11793e519524SHoward Hinnant{ 11803e519524SHoward Hinnant _Sp (_Tp::*__p_)() const; 11813e519524SHoward Hinnantpublic: 11823e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const) 11833e519524SHoward Hinnant : __p_(__p) {} 11843e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const 11853e519524SHoward Hinnant {return (__p->*__p_)();} 11863e519524SHoward Hinnant}; 11873e519524SHoward Hinnant 11883e519524SHoward Hinnanttemplate <class _Sp, class _Tp, class _Ap> 1189f0544c20SHoward Hinnantclass _LIBCPP_TYPE_VIS_ONLY const_mem_fun1_t : public binary_function<const _Tp*, _Ap, _Sp> 11903e519524SHoward Hinnant{ 11913e519524SHoward Hinnant _Sp (_Tp::*__p_)(_Ap) const; 11923e519524SHoward Hinnantpublic: 11933e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const) 11943e519524SHoward Hinnant : __p_(__p) {} 11953e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const 11963e519524SHoward Hinnant {return (__p->*__p_)(__x);} 11973e519524SHoward Hinnant}; 11983e519524SHoward Hinnant 11993e519524SHoward Hinnanttemplate <class _Sp, class _Tp> 12003e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 12013e519524SHoward Hinnantconst_mem_fun_t<_Sp,_Tp> 12023e519524SHoward Hinnantmem_fun(_Sp (_Tp::*__f)() const) 12033e519524SHoward Hinnant {return const_mem_fun_t<_Sp,_Tp>(__f);} 12043e519524SHoward Hinnant 12053e519524SHoward Hinnanttemplate <class _Sp, class _Tp, class _Ap> 12063e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 12073e519524SHoward Hinnantconst_mem_fun1_t<_Sp,_Tp,_Ap> 12083e519524SHoward Hinnantmem_fun(_Sp (_Tp::*__f)(_Ap) const) 12093e519524SHoward Hinnant {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);} 12103e519524SHoward Hinnant 12113e519524SHoward Hinnanttemplate <class _Sp, class _Tp> 1212f0544c20SHoward Hinnantclass _LIBCPP_TYPE_VIS_ONLY const_mem_fun_ref_t : public unary_function<_Tp, _Sp> 12133e519524SHoward Hinnant{ 12143e519524SHoward Hinnant _Sp (_Tp::*__p_)() const; 12153e519524SHoward Hinnantpublic: 12163e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const) 12173e519524SHoward Hinnant : __p_(__p) {} 12183e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const 12193e519524SHoward Hinnant {return (__p.*__p_)();} 12203e519524SHoward Hinnant}; 12213e519524SHoward Hinnant 12223e519524SHoward Hinnanttemplate <class _Sp, class _Tp, class _Ap> 1223f0544c20SHoward Hinnantclass _LIBCPP_TYPE_VIS_ONLY const_mem_fun1_ref_t 12240af133f9SHoward Hinnant : public binary_function<_Tp, _Ap, _Sp> 12253e519524SHoward Hinnant{ 12263e519524SHoward Hinnant _Sp (_Tp::*__p_)(_Ap) const; 12273e519524SHoward Hinnantpublic: 12283e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const) 12293e519524SHoward Hinnant : __p_(__p) {} 12303e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const 12313e519524SHoward Hinnant {return (__p.*__p_)(__x);} 12323e519524SHoward Hinnant}; 12333e519524SHoward Hinnant 12343e519524SHoward Hinnanttemplate <class _Sp, class _Tp> 12353e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 12363e519524SHoward Hinnantconst_mem_fun_ref_t<_Sp,_Tp> 12373e519524SHoward Hinnantmem_fun_ref(_Sp (_Tp::*__f)() const) 12383e519524SHoward Hinnant {return const_mem_fun_ref_t<_Sp,_Tp>(__f);} 12393e519524SHoward Hinnant 12403e519524SHoward Hinnanttemplate <class _Sp, class _Tp, class _Ap> 12413e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 12423e519524SHoward Hinnantconst_mem_fun1_ref_t<_Sp,_Tp,_Ap> 12433e519524SHoward Hinnantmem_fun_ref(_Sp (_Tp::*__f)(_Ap) const) 12443e519524SHoward Hinnant {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);} 12453e519524SHoward Hinnant 1246e5407178SEric Fiselier//////////////////////////////////////////////////////////////////////////////// 1247e5407178SEric Fiselier// MEMFUN 1248e5407178SEric Fiselier//============================================================================== 12493e519524SHoward Hinnant 12503e519524SHoward Hinnanttemplate <class _Tp> 12513e519524SHoward Hinnantclass __mem_fn 12523e519524SHoward Hinnant : public __weak_result_type<_Tp> 12533e519524SHoward Hinnant{ 12543e519524SHoward Hinnantpublic: 12553e519524SHoward Hinnant // types 12563e519524SHoward Hinnant typedef _Tp type; 12573e519524SHoward Hinnantprivate: 12583e519524SHoward Hinnant type __f_; 12593e519524SHoward Hinnant 12603e519524SHoward Hinnantpublic: 12613b72a6efSMarshall Clow _LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) _NOEXCEPT : __f_(__f) {} 12623e519524SHoward Hinnant 126300f512ebSEric Fiselier#ifndef _LIBCPP_HAS_NO_VARIADICS 12643e519524SHoward Hinnant // invoke 12653e519524SHoward Hinnant template <class... _ArgTypes> 12660af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 12673e519524SHoward Hinnant typename __invoke_return<type, _ArgTypes...>::type 126800f512ebSEric Fiselier operator() (_ArgTypes&&... __args) const { 1269ce48a113SHoward Hinnant return __invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...); 12703e519524SHoward Hinnant } 127100f512ebSEric Fiselier#else 127200f512ebSEric Fiselier 127300f512ebSEric Fiselier template <class _A0> 127470192a9eSEric Fiselier _LIBCPP_INLINE_VISIBILITY 127500f512ebSEric Fiselier typename __invoke_return0<type, _A0>::type 127600f512ebSEric Fiselier operator() (_A0& __a0) const { 127700f512ebSEric Fiselier return __invoke(__f_, __a0); 127800f512ebSEric Fiselier } 127900f512ebSEric Fiselier 128070192a9eSEric Fiselier template <class _A0> 128170192a9eSEric Fiselier _LIBCPP_INLINE_VISIBILITY 128270192a9eSEric Fiselier typename __invoke_return0<type, _A0 const>::type 128370192a9eSEric Fiselier operator() (_A0 const& __a0) const { 128470192a9eSEric Fiselier return __invoke(__f_, __a0); 128570192a9eSEric Fiselier } 128670192a9eSEric Fiselier 128700f512ebSEric Fiselier template <class _A0, class _A1> 128870192a9eSEric Fiselier _LIBCPP_INLINE_VISIBILITY 128900f512ebSEric Fiselier typename __invoke_return1<type, _A0, _A1>::type 129000f512ebSEric Fiselier operator() (_A0& __a0, _A1& __a1) const { 129100f512ebSEric Fiselier return __invoke(__f_, __a0, __a1); 129200f512ebSEric Fiselier } 129300f512ebSEric Fiselier 129470192a9eSEric Fiselier template <class _A0, class _A1> 129570192a9eSEric Fiselier _LIBCPP_INLINE_VISIBILITY 129670192a9eSEric Fiselier typename __invoke_return1<type, _A0 const, _A1>::type 129770192a9eSEric Fiselier operator() (_A0 const& __a0, _A1& __a1) const { 129870192a9eSEric Fiselier return __invoke(__f_, __a0, __a1); 129970192a9eSEric Fiselier } 130070192a9eSEric Fiselier 130170192a9eSEric Fiselier template <class _A0, class _A1> 130270192a9eSEric Fiselier _LIBCPP_INLINE_VISIBILITY 130370192a9eSEric Fiselier typename __invoke_return1<type, _A0, _A1 const>::type 130470192a9eSEric Fiselier operator() (_A0& __a0, _A1 const& __a1) const { 130570192a9eSEric Fiselier return __invoke(__f_, __a0, __a1); 130670192a9eSEric Fiselier } 130770192a9eSEric Fiselier 130870192a9eSEric Fiselier template <class _A0, class _A1> 130970192a9eSEric Fiselier _LIBCPP_INLINE_VISIBILITY 131070192a9eSEric Fiselier typename __invoke_return1<type, _A0 const, _A1 const>::type 131170192a9eSEric Fiselier operator() (_A0 const& __a0, _A1 const& __a1) const { 131270192a9eSEric Fiselier return __invoke(__f_, __a0, __a1); 131370192a9eSEric Fiselier } 131470192a9eSEric Fiselier 131500f512ebSEric Fiselier template <class _A0, class _A1, class _A2> 131670192a9eSEric Fiselier _LIBCPP_INLINE_VISIBILITY 131700f512ebSEric Fiselier typename __invoke_return2<type, _A0, _A1, _A2>::type 131800f512ebSEric Fiselier operator() (_A0& __a0, _A1& __a1, _A2& __a2) const { 131900f512ebSEric Fiselier return __invoke(__f_, __a0, __a1, __a2); 132000f512ebSEric Fiselier } 132170192a9eSEric Fiselier 132270192a9eSEric Fiselier template <class _A0, class _A1, class _A2> 132370192a9eSEric Fiselier _LIBCPP_INLINE_VISIBILITY 132470192a9eSEric Fiselier typename __invoke_return2<type, _A0 const, _A1, _A2>::type 132570192a9eSEric Fiselier operator() (_A0 const& __a0, _A1& __a1, _A2& __a2) const { 132670192a9eSEric Fiselier return __invoke(__f_, __a0, __a1, __a2); 132770192a9eSEric Fiselier } 132870192a9eSEric Fiselier 132970192a9eSEric Fiselier template <class _A0, class _A1, class _A2> 133070192a9eSEric Fiselier _LIBCPP_INLINE_VISIBILITY 133170192a9eSEric Fiselier typename __invoke_return2<type, _A0, _A1 const, _A2>::type 133270192a9eSEric Fiselier operator() (_A0& __a0, _A1 const& __a1, _A2& __a2) const { 133370192a9eSEric Fiselier return __invoke(__f_, __a0, __a1, __a2); 133470192a9eSEric Fiselier } 133570192a9eSEric Fiselier 133670192a9eSEric Fiselier template <class _A0, class _A1, class _A2> 133770192a9eSEric Fiselier _LIBCPP_INLINE_VISIBILITY 133870192a9eSEric Fiselier typename __invoke_return2<type, _A0, _A1, _A2 const>::type 133970192a9eSEric Fiselier operator() (_A0& __a0, _A1& __a1, _A2 const& __a2) const { 134070192a9eSEric Fiselier return __invoke(__f_, __a0, __a1, __a2); 134170192a9eSEric Fiselier } 134270192a9eSEric Fiselier 134370192a9eSEric Fiselier template <class _A0, class _A1, class _A2> 134470192a9eSEric Fiselier _LIBCPP_INLINE_VISIBILITY 134570192a9eSEric Fiselier typename __invoke_return2<type, _A0 const, _A1 const, _A2>::type 134670192a9eSEric Fiselier operator() (_A0 const& __a0, _A1 const& __a1, _A2& __a2) const { 134770192a9eSEric Fiselier return __invoke(__f_, __a0, __a1, __a2); 134870192a9eSEric Fiselier } 134970192a9eSEric Fiselier 135070192a9eSEric Fiselier template <class _A0, class _A1, class _A2> 135170192a9eSEric Fiselier _LIBCPP_INLINE_VISIBILITY 135270192a9eSEric Fiselier typename __invoke_return2<type, _A0 const, _A1, _A2 const>::type 135370192a9eSEric Fiselier operator() (_A0 const& __a0, _A1& __a1, _A2 const& __a2) const { 135470192a9eSEric Fiselier return __invoke(__f_, __a0, __a1, __a2); 135570192a9eSEric Fiselier } 135670192a9eSEric Fiselier 135770192a9eSEric Fiselier template <class _A0, class _A1, class _A2> 135870192a9eSEric Fiselier _LIBCPP_INLINE_VISIBILITY 135970192a9eSEric Fiselier typename __invoke_return2<type, _A0, _A1 const, _A2 const>::type 136070192a9eSEric Fiselier operator() (_A0& __a0, _A1 const& __a1, _A2 const& __a2) const { 136170192a9eSEric Fiselier return __invoke(__f_, __a0, __a1, __a2); 136270192a9eSEric Fiselier } 136370192a9eSEric Fiselier 136470192a9eSEric Fiselier template <class _A0, class _A1, class _A2> 136570192a9eSEric Fiselier _LIBCPP_INLINE_VISIBILITY 136670192a9eSEric Fiselier typename __invoke_return2<type, _A0 const, _A1 const, _A2 const>::type 136770192a9eSEric Fiselier operator() (_A0 const& __a0, _A1 const& __a1, _A2 const& __a2) const { 136870192a9eSEric Fiselier return __invoke(__f_, __a0, __a1, __a2); 136970192a9eSEric Fiselier } 137000f512ebSEric Fiselier#endif 13713e519524SHoward Hinnant}; 13723e519524SHoward Hinnant 1373c003db1fSHoward Hinnanttemplate<class _Rp, class _Tp> 13743e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 1375c003db1fSHoward Hinnant__mem_fn<_Rp _Tp::*> 13763b72a6efSMarshall Clowmem_fn(_Rp _Tp::* __pm) _NOEXCEPT 13773e519524SHoward Hinnant{ 1378c003db1fSHoward Hinnant return __mem_fn<_Rp _Tp::*>(__pm); 13793e519524SHoward Hinnant} 13803e519524SHoward Hinnant 1381e5407178SEric Fiselier//////////////////////////////////////////////////////////////////////////////// 1382e5407178SEric Fiselier// FUNCTION 1383e5407178SEric Fiselier//============================================================================== 1384e5407178SEric Fiselier 13853e519524SHoward Hinnant// bad_function_call 13863e519524SHoward Hinnant 13870af133f9SHoward Hinnantclass _LIBCPP_EXCEPTION_ABI bad_function_call 13883e519524SHoward Hinnant : public exception 13893e519524SHoward Hinnant{ 13903e519524SHoward Hinnant}; 13913e519524SHoward Hinnant 1392d437fa5cSMarshall Clow_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE 1393d437fa5cSMarshall Clowvoid __throw_bad_function_call() 1394d437fa5cSMarshall Clow{ 1395d437fa5cSMarshall Clow#ifndef _LIBCPP_NO_EXCEPTIONS 1396d437fa5cSMarshall Clow throw bad_function_call(); 1397d437fa5cSMarshall Clow#else 1398d437fa5cSMarshall Clow _VSTD::abort(); 1399d437fa5cSMarshall Clow#endif 1400d437fa5cSMarshall Clow} 1401d437fa5cSMarshall Clow 1402f0544c20SHoward Hinnanttemplate<class _Fp> class _LIBCPP_TYPE_VIS_ONLY function; // undefined 14033e519524SHoward Hinnant 14043e519524SHoward Hinnantnamespace __function 14053e519524SHoward Hinnant{ 14063e519524SHoward Hinnant 1407e5407178SEric Fiseliertemplate<class _Rp> 14083e519524SHoward Hinnantstruct __maybe_derive_from_unary_function 14093e519524SHoward Hinnant{ 14103e519524SHoward Hinnant}; 14113e519524SHoward Hinnant 1412c003db1fSHoward Hinnanttemplate<class _Rp, class _A1> 1413c003db1fSHoward Hinnantstruct __maybe_derive_from_unary_function<_Rp(_A1)> 1414c003db1fSHoward Hinnant : public unary_function<_A1, _Rp> 14153e519524SHoward Hinnant{ 14163e519524SHoward Hinnant}; 14173e519524SHoward Hinnant 1418e5407178SEric Fiseliertemplate<class _Rp> 14193e519524SHoward Hinnantstruct __maybe_derive_from_binary_function 14203e519524SHoward Hinnant{ 14213e519524SHoward Hinnant}; 14223e519524SHoward Hinnant 1423c003db1fSHoward Hinnanttemplate<class _Rp, class _A1, class _A2> 1424c003db1fSHoward Hinnantstruct __maybe_derive_from_binary_function<_Rp(_A1, _A2)> 1425c003db1fSHoward Hinnant : public binary_function<_A1, _A2, _Rp> 14263e519524SHoward Hinnant{ 14273e519524SHoward Hinnant}; 14283e519524SHoward Hinnant 14290d28f784SEric Fiseliertemplate <class _Fp> 14300d28f784SEric Fiselier_LIBCPP_INLINE_VISIBILITY 14310d28f784SEric Fiselierbool __not_null(_Fp const&) { return true; } 14320d28f784SEric Fiselier 14330d28f784SEric Fiseliertemplate <class _Fp> 14340d28f784SEric Fiselier_LIBCPP_INLINE_VISIBILITY 14350d28f784SEric Fiselierbool __not_null(_Fp* __ptr) { return __ptr; } 14360d28f784SEric Fiselier 14370d28f784SEric Fiseliertemplate <class _Ret, class _Class> 14380d28f784SEric Fiselier_LIBCPP_INLINE_VISIBILITY 14390d28f784SEric Fiselierbool __not_null(_Ret _Class::*__ptr) { return __ptr; } 14400d28f784SEric Fiselier 14410d28f784SEric Fiseliertemplate <class _Fp> 14420d28f784SEric Fiselier_LIBCPP_INLINE_VISIBILITY 14430d28f784SEric Fiselierbool __not_null(function<_Fp> const& __f) { return !!__f; } 14440d28f784SEric Fiselier 1445e5407178SEric Fiselier} // namespace __function 1446e5407178SEric Fiselier 1447e5407178SEric Fiselier#ifndef _LIBCPP_HAS_NO_VARIADICS 1448e5407178SEric Fiselier 1449e5407178SEric Fiseliernamespace __function { 1450e5407178SEric Fiselier 14513e519524SHoward Hinnanttemplate<class _Fp> class __base; 14523e519524SHoward Hinnant 1453c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 1454c003db1fSHoward Hinnantclass __base<_Rp(_ArgTypes...)> 14553e519524SHoward Hinnant{ 14563e519524SHoward Hinnant __base(const __base&); 14573e519524SHoward Hinnant __base& operator=(const __base&); 14583e519524SHoward Hinnantpublic: 14590af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY __base() {} 14600af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY virtual ~__base() {} 14613e519524SHoward Hinnant virtual __base* __clone() const = 0; 14623e519524SHoward Hinnant virtual void __clone(__base*) const = 0; 14636a07d6f0SHoward Hinnant virtual void destroy() _NOEXCEPT = 0; 14646a07d6f0SHoward Hinnant virtual void destroy_deallocate() _NOEXCEPT = 0; 1465c003db1fSHoward Hinnant virtual _Rp operator()(_ArgTypes&& ...) = 0; 146654b409fdSHoward Hinnant#ifndef _LIBCPP_NO_RTTI 14676a07d6f0SHoward Hinnant virtual const void* target(const type_info&) const _NOEXCEPT = 0; 14686a07d6f0SHoward Hinnant virtual const std::type_info& target_type() const _NOEXCEPT = 0; 1469b3371f6fSHoward Hinnant#endif // _LIBCPP_NO_RTTI 14703e519524SHoward Hinnant}; 14713e519524SHoward Hinnant 14723e519524SHoward Hinnanttemplate<class _FD, class _Alloc, class _FB> class __func; 14733e519524SHoward Hinnant 1474c003db1fSHoward Hinnanttemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 1475c003db1fSHoward Hinnantclass __func<_Fp, _Alloc, _Rp(_ArgTypes...)> 1476c003db1fSHoward Hinnant : public __base<_Rp(_ArgTypes...)> 14773e519524SHoward Hinnant{ 1478c003db1fSHoward Hinnant __compressed_pair<_Fp, _Alloc> __f_; 14793e519524SHoward Hinnantpublic: 14800af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 14819bb1429fSHoward Hinnant explicit __func(_Fp&& __f) 14829bb1429fSHoward Hinnant : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)), 14839bb1429fSHoward Hinnant _VSTD::forward_as_tuple()) {} 14840af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 14859bb1429fSHoward Hinnant explicit __func(const _Fp& __f, const _Alloc& __a) 14869bb1429fSHoward Hinnant : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f), 14879bb1429fSHoward Hinnant _VSTD::forward_as_tuple(__a)) {} 14889bb1429fSHoward Hinnant 14899bb1429fSHoward Hinnant _LIBCPP_INLINE_VISIBILITY 14909bb1429fSHoward Hinnant explicit __func(const _Fp& __f, _Alloc&& __a) 14919bb1429fSHoward Hinnant : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f), 14929bb1429fSHoward Hinnant _VSTD::forward_as_tuple(_VSTD::move(__a))) {} 14939bb1429fSHoward Hinnant 14949bb1429fSHoward Hinnant _LIBCPP_INLINE_VISIBILITY 14959bb1429fSHoward Hinnant explicit __func(_Fp&& __f, _Alloc&& __a) 14969bb1429fSHoward Hinnant : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)), 14979bb1429fSHoward Hinnant _VSTD::forward_as_tuple(_VSTD::move(__a))) {} 1498c003db1fSHoward Hinnant virtual __base<_Rp(_ArgTypes...)>* __clone() const; 1499c003db1fSHoward Hinnant virtual void __clone(__base<_Rp(_ArgTypes...)>*) const; 15006a07d6f0SHoward Hinnant virtual void destroy() _NOEXCEPT; 15016a07d6f0SHoward Hinnant virtual void destroy_deallocate() _NOEXCEPT; 1502c003db1fSHoward Hinnant virtual _Rp operator()(_ArgTypes&& ... __arg); 150354b409fdSHoward Hinnant#ifndef _LIBCPP_NO_RTTI 15046a07d6f0SHoward Hinnant virtual const void* target(const type_info&) const _NOEXCEPT; 15056a07d6f0SHoward Hinnant virtual const std::type_info& target_type() const _NOEXCEPT; 1506b3371f6fSHoward Hinnant#endif // _LIBCPP_NO_RTTI 15073e519524SHoward Hinnant}; 15083e519524SHoward Hinnant 1509c003db1fSHoward Hinnanttemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 1510c003db1fSHoward Hinnant__base<_Rp(_ArgTypes...)>* 1511c003db1fSHoward Hinnant__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const 15123e519524SHoward Hinnant{ 15136d370568SEric Fiselier typedef allocator_traits<_Alloc> __alloc_traits; 15141f508014SMarshall Clow typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; 1515c003db1fSHoward Hinnant _Ap __a(__f_.second()); 1516c003db1fSHoward Hinnant typedef __allocator_destructor<_Ap> _Dp; 1517c003db1fSHoward Hinnant unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); 15183e519524SHoward Hinnant ::new (__hold.get()) __func(__f_.first(), _Alloc(__a)); 15193e519524SHoward Hinnant return __hold.release(); 15203e519524SHoward Hinnant} 15213e519524SHoward Hinnant 1522c003db1fSHoward Hinnanttemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 15233e519524SHoward Hinnantvoid 1524c003db1fSHoward Hinnant__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const 15253e519524SHoward Hinnant{ 15263e519524SHoward Hinnant ::new (__p) __func(__f_.first(), __f_.second()); 15273e519524SHoward Hinnant} 15283e519524SHoward Hinnant 1529c003db1fSHoward Hinnanttemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 15303e519524SHoward Hinnantvoid 1531c003db1fSHoward Hinnant__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPT 15323e519524SHoward Hinnant{ 1533c003db1fSHoward Hinnant __f_.~__compressed_pair<_Fp, _Alloc>(); 15343e519524SHoward Hinnant} 15353e519524SHoward Hinnant 1536c003db1fSHoward Hinnanttemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 15373e519524SHoward Hinnantvoid 1538c003db1fSHoward Hinnant__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT 15393e519524SHoward Hinnant{ 15406d370568SEric Fiselier typedef allocator_traits<_Alloc> __alloc_traits; 15411f508014SMarshall Clow typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; 1542c003db1fSHoward Hinnant _Ap __a(__f_.second()); 1543c003db1fSHoward Hinnant __f_.~__compressed_pair<_Fp, _Alloc>(); 15443e519524SHoward Hinnant __a.deallocate(this, 1); 15453e519524SHoward Hinnant} 15463e519524SHoward Hinnant 1547c003db1fSHoward Hinnanttemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 1548c003db1fSHoward Hinnant_Rp 1549c003db1fSHoward Hinnant__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg) 15503e519524SHoward Hinnant{ 155154519a6bSEric Fiselier typedef __invoke_void_return_wrapper<_Rp> _Invoker; 155254519a6bSEric Fiselier return _Invoker::__call(__f_.first(), _VSTD::forward<_ArgTypes>(__arg)...); 15533e519524SHoward Hinnant} 15543e519524SHoward Hinnant 155554b409fdSHoward Hinnant#ifndef _LIBCPP_NO_RTTI 155654b409fdSHoward Hinnant 1557c003db1fSHoward Hinnanttemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 15583e519524SHoward Hinnantconst void* 1559c003db1fSHoward Hinnant__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT 15603e519524SHoward Hinnant{ 1561c003db1fSHoward Hinnant if (__ti == typeid(_Fp)) 15623e519524SHoward Hinnant return &__f_.first(); 15633e519524SHoward Hinnant return (const void*)0; 15643e519524SHoward Hinnant} 15653e519524SHoward Hinnant 1566c003db1fSHoward Hinnanttemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 15673e519524SHoward Hinnantconst std::type_info& 1568c003db1fSHoward Hinnant__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT 15693e519524SHoward Hinnant{ 1570c003db1fSHoward Hinnant return typeid(_Fp); 15713e519524SHoward Hinnant} 15723e519524SHoward Hinnant 1573b3371f6fSHoward Hinnant#endif // _LIBCPP_NO_RTTI 157454b409fdSHoward Hinnant 15753e519524SHoward Hinnant} // __function 15763e519524SHoward Hinnant 1577c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 1578f0544c20SHoward Hinnantclass _LIBCPP_TYPE_VIS_ONLY function<_Rp(_ArgTypes...)> 1579c003db1fSHoward Hinnant : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>, 1580c003db1fSHoward Hinnant public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)> 15813e519524SHoward Hinnant{ 1582c003db1fSHoward Hinnant typedef __function::__base<_Rp(_ArgTypes...)> __base; 15838d3e7974SHoward Hinnant typename aligned_storage<3*sizeof(void*)>::type __buf_; 15843e519524SHoward Hinnant __base* __f_; 15853e519524SHoward Hinnant 15863e58a6a7SEvgeniy Stepanov _LIBCPP_NO_CFI static __base *__as_base(void *p) { 15873e58a6a7SEvgeniy Stepanov return reinterpret_cast<__base*>(p); 15883e58a6a7SEvgeniy Stepanov } 15893e58a6a7SEvgeniy Stepanov 159014c56f6cSHoward Hinnant template <class _Fp, bool = !is_same<_Fp, function>::value && 159114c56f6cSHoward Hinnant __invokable<_Fp&, _ArgTypes...>::value> 1592542b2507SHoward Hinnant struct __callable; 1593c003db1fSHoward Hinnant template <class _Fp> 1594c003db1fSHoward Hinnant struct __callable<_Fp, true> 1595542b2507SHoward Hinnant { 159654519a6bSEric Fiselier static const bool value = is_same<void, _Rp>::value || 1597c003db1fSHoward Hinnant is_convertible<typename __invoke_of<_Fp&, _ArgTypes...>::type, 1598c003db1fSHoward Hinnant _Rp>::value; 1599542b2507SHoward Hinnant }; 1600c003db1fSHoward Hinnant template <class _Fp> 1601c003db1fSHoward Hinnant struct __callable<_Fp, false> 1602542b2507SHoward Hinnant { 1603542b2507SHoward Hinnant static const bool value = false; 1604542b2507SHoward Hinnant }; 16053e519524SHoward Hinnantpublic: 1606c003db1fSHoward Hinnant typedef _Rp result_type; 16073e519524SHoward Hinnant 16089b0b6d45SHoward Hinnant // construct/copy/destroy: 16090af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 16106a07d6f0SHoward Hinnant function() _NOEXCEPT : __f_(0) {} 16110af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 16126a07d6f0SHoward Hinnant function(nullptr_t) _NOEXCEPT : __f_(0) {} 16133e519524SHoward Hinnant function(const function&); 16146a07d6f0SHoward Hinnant function(function&&) _NOEXCEPT; 1615fd32ab92SEric Fiselier template<class _Fp, class = typename enable_if< 1616fd32ab92SEric Fiselier __callable<_Fp>::value && !is_same<_Fp, function>::value 1617fd32ab92SEric Fiselier >::type> 1618fd32ab92SEric Fiselier function(_Fp); 16193e519524SHoward Hinnant 16206ecac730SMarshall Clow#if _LIBCPP_STD_VER <= 14 16219b0b6d45SHoward Hinnant template<class _Alloc> 16220af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 16236a07d6f0SHoward Hinnant function(allocator_arg_t, const _Alloc&) _NOEXCEPT : __f_(0) {} 16249b0b6d45SHoward Hinnant template<class _Alloc> 16250af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 16266a07d6f0SHoward Hinnant function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT : __f_(0) {} 16279b0b6d45SHoward Hinnant template<class _Alloc> 16289b0b6d45SHoward Hinnant function(allocator_arg_t, const _Alloc&, const function&); 16299b0b6d45SHoward Hinnant template<class _Alloc> 16309b0b6d45SHoward Hinnant function(allocator_arg_t, const _Alloc&, function&&); 1631fd32ab92SEric Fiselier template<class _Fp, class _Alloc, class = typename enable_if<__callable<_Fp>::value>::type> 1632fd32ab92SEric Fiselier function(allocator_arg_t, const _Alloc& __a, _Fp __f); 16336ecac730SMarshall Clow#endif 16343e519524SHoward Hinnant 16353e519524SHoward Hinnant function& operator=(const function&); 16366a07d6f0SHoward Hinnant function& operator=(function&&) _NOEXCEPT; 16376a07d6f0SHoward Hinnant function& operator=(nullptr_t) _NOEXCEPT; 1638c003db1fSHoward Hinnant template<class _Fp> 16393e519524SHoward Hinnant typename enable_if 16403e519524SHoward Hinnant < 16419dbbf8deSHoward Hinnant __callable<typename decay<_Fp>::type>::value && 16429dbbf8deSHoward Hinnant !is_same<typename remove_reference<_Fp>::type, function>::value, 16433e519524SHoward Hinnant function& 16443e519524SHoward Hinnant >::type 1645c003db1fSHoward Hinnant operator=(_Fp&&); 16463e519524SHoward Hinnant 16473e519524SHoward Hinnant ~function(); 16483e519524SHoward Hinnant 16499b0b6d45SHoward Hinnant // function modifiers: 16506a07d6f0SHoward Hinnant void swap(function&) _NOEXCEPT; 16510aa1ccb0SMarshall Clow 16520aa1ccb0SMarshall Clow#if _LIBCPP_STD_VER <= 14 1653c003db1fSHoward Hinnant template<class _Fp, class _Alloc> 16540af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 1655c003db1fSHoward Hinnant void assign(_Fp&& __f, const _Alloc& __a) 1656c003db1fSHoward Hinnant {function(allocator_arg, __a, _VSTD::forward<_Fp>(__f)).swap(*this);} 16570aa1ccb0SMarshall Clow#endif 16583e519524SHoward Hinnant 16599b0b6d45SHoward Hinnant // function capacity: 16600af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 1661f2f2d8b9SHoward Hinnant _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return __f_;} 16623e519524SHoward Hinnant 16633e519524SHoward Hinnant // deleted overloads close possible hole in the type system 16643e519524SHoward Hinnant template<class _R2, class... _ArgTypes2> 166537030a77SHoward Hinnant bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete; 16663e519524SHoward Hinnant template<class _R2, class... _ArgTypes2> 166737030a77SHoward Hinnant bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete; 16683e519524SHoward Hinnantpublic: 16699b0b6d45SHoward Hinnant // function invocation: 1670c003db1fSHoward Hinnant _Rp operator()(_ArgTypes...) const; 16713e519524SHoward Hinnant 167254b409fdSHoward Hinnant#ifndef _LIBCPP_NO_RTTI 16739b0b6d45SHoward Hinnant // function target access: 16746a07d6f0SHoward Hinnant const std::type_info& target_type() const _NOEXCEPT; 1675c003db1fSHoward Hinnant template <typename _Tp> _Tp* target() _NOEXCEPT; 1676c003db1fSHoward Hinnant template <typename _Tp> const _Tp* target() const _NOEXCEPT; 1677b3371f6fSHoward Hinnant#endif // _LIBCPP_NO_RTTI 16783e519524SHoward Hinnant}; 16793e519524SHoward Hinnant 1680c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 1681c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::function(const function& __f) 16823e519524SHoward Hinnant{ 16833e519524SHoward Hinnant if (__f.__f_ == 0) 16843e519524SHoward Hinnant __f_ = 0; 16853e58a6a7SEvgeniy Stepanov else if ((void *)__f.__f_ == &__f.__buf_) 16863e519524SHoward Hinnant { 16873e58a6a7SEvgeniy Stepanov __f_ = __as_base(&__buf_); 16883e519524SHoward Hinnant __f.__f_->__clone(__f_); 16893e519524SHoward Hinnant } 16903e519524SHoward Hinnant else 16913e519524SHoward Hinnant __f_ = __f.__f_->__clone(); 16923e519524SHoward Hinnant} 16933e519524SHoward Hinnant 16946ecac730SMarshall Clow#if _LIBCPP_STD_VER <= 14 1695c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 16969b0b6d45SHoward Hinnanttemplate <class _Alloc> 1697c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, 16989b0b6d45SHoward Hinnant const function& __f) 16999b0b6d45SHoward Hinnant{ 17009b0b6d45SHoward Hinnant if (__f.__f_ == 0) 17019b0b6d45SHoward Hinnant __f_ = 0; 17023e58a6a7SEvgeniy Stepanov else if ((void *)__f.__f_ == &__f.__buf_) 17039b0b6d45SHoward Hinnant { 17043e58a6a7SEvgeniy Stepanov __f_ = __as_base(&__buf_); 17059b0b6d45SHoward Hinnant __f.__f_->__clone(__f_); 17069b0b6d45SHoward Hinnant } 17079b0b6d45SHoward Hinnant else 17089b0b6d45SHoward Hinnant __f_ = __f.__f_->__clone(); 17099b0b6d45SHoward Hinnant} 17106ecac730SMarshall Clow#endif 17119b0b6d45SHoward Hinnant 1712c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 1713c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT 17143e519524SHoward Hinnant{ 17153e519524SHoward Hinnant if (__f.__f_ == 0) 17163e519524SHoward Hinnant __f_ = 0; 17173e58a6a7SEvgeniy Stepanov else if ((void *)__f.__f_ == &__f.__buf_) 17183e519524SHoward Hinnant { 17193e58a6a7SEvgeniy Stepanov __f_ = __as_base(&__buf_); 17203e519524SHoward Hinnant __f.__f_->__clone(__f_); 17213e519524SHoward Hinnant } 17223e519524SHoward Hinnant else 17233e519524SHoward Hinnant { 17243e519524SHoward Hinnant __f_ = __f.__f_; 17253e519524SHoward Hinnant __f.__f_ = 0; 17263e519524SHoward Hinnant } 17273e519524SHoward Hinnant} 17283e519524SHoward Hinnant 17296ecac730SMarshall Clow#if _LIBCPP_STD_VER <= 14 1730c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 17319b0b6d45SHoward Hinnanttemplate <class _Alloc> 1732c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, 17339b0b6d45SHoward Hinnant function&& __f) 17349b0b6d45SHoward Hinnant{ 17359b0b6d45SHoward Hinnant if (__f.__f_ == 0) 17369b0b6d45SHoward Hinnant __f_ = 0; 17373e58a6a7SEvgeniy Stepanov else if ((void *)__f.__f_ == &__f.__buf_) 17389b0b6d45SHoward Hinnant { 17393e58a6a7SEvgeniy Stepanov __f_ = __as_base(&__buf_); 17409b0b6d45SHoward Hinnant __f.__f_->__clone(__f_); 17419b0b6d45SHoward Hinnant } 17429b0b6d45SHoward Hinnant else 17439b0b6d45SHoward Hinnant { 17449b0b6d45SHoward Hinnant __f_ = __f.__f_; 17459b0b6d45SHoward Hinnant __f.__f_ = 0; 17469b0b6d45SHoward Hinnant } 17479b0b6d45SHoward Hinnant} 17486ecac730SMarshall Clow#endif 17499b0b6d45SHoward Hinnant 1750c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 1751fd32ab92SEric Fiseliertemplate <class _Fp, class> 1752fd32ab92SEric Fiselierfunction<_Rp(_ArgTypes...)>::function(_Fp __f) 17533e519524SHoward Hinnant : __f_(0) 17543e519524SHoward Hinnant{ 17550d28f784SEric Fiselier if (__function::__not_null(__f)) 17563e519524SHoward Hinnant { 1757c003db1fSHoward Hinnant typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_ArgTypes...)> _FF; 1758c003db1fSHoward Hinnant if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value) 17593e519524SHoward Hinnant { 17603e58a6a7SEvgeniy Stepanov __f_ = ::new((void*)&__buf_) _FF(_VSTD::move(__f)); 17613e519524SHoward Hinnant } 17623e519524SHoward Hinnant else 17633e519524SHoward Hinnant { 1764c003db1fSHoward Hinnant typedef allocator<_FF> _Ap; 1765c003db1fSHoward Hinnant _Ap __a; 1766c003db1fSHoward Hinnant typedef __allocator_destructor<_Ap> _Dp; 1767c003db1fSHoward Hinnant unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); 1768c003db1fSHoward Hinnant ::new (__hold.get()) _FF(_VSTD::move(__f), allocator<_Fp>(__a)); 17693e519524SHoward Hinnant __f_ = __hold.release(); 17703e519524SHoward Hinnant } 17713e519524SHoward Hinnant } 17723e519524SHoward Hinnant} 17733e519524SHoward Hinnant 17746ecac730SMarshall Clow#if _LIBCPP_STD_VER <= 14 1775c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 1776fd32ab92SEric Fiseliertemplate <class _Fp, class _Alloc, class> 1777fd32ab92SEric Fiselierfunction<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f) 17789b0b6d45SHoward Hinnant : __f_(0) 17799b0b6d45SHoward Hinnant{ 17809b0b6d45SHoward Hinnant typedef allocator_traits<_Alloc> __alloc_traits; 17810d28f784SEric Fiselier if (__function::__not_null(__f)) 17829b0b6d45SHoward Hinnant { 1783c003db1fSHoward Hinnant typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _FF; 17841f508014SMarshall Clow typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap; 1785c003db1fSHoward Hinnant _Ap __a(__a0); 17865f7c2db2SMarshall Clow if (sizeof(_FF) <= sizeof(__buf_) && 17875f7c2db2SMarshall Clow is_nothrow_copy_constructible<_Fp>::value && is_nothrow_copy_constructible<_Ap>::value) 17885f7c2db2SMarshall Clow { 17893e58a6a7SEvgeniy Stepanov __f_ = ::new((void*)&__buf_) _FF(_VSTD::move(__f), _Alloc(__a)); 17905f7c2db2SMarshall Clow } 17915f7c2db2SMarshall Clow else 17925f7c2db2SMarshall Clow { 1793c003db1fSHoward Hinnant typedef __allocator_destructor<_Ap> _Dp; 1794c003db1fSHoward Hinnant unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); 1795ce48a113SHoward Hinnant ::new (__hold.get()) _FF(_VSTD::move(__f), _Alloc(__a)); 17969b0b6d45SHoward Hinnant __f_ = __hold.release(); 17979b0b6d45SHoward Hinnant } 17989b0b6d45SHoward Hinnant } 17999b0b6d45SHoward Hinnant} 18006ecac730SMarshall Clow#endif 18019b0b6d45SHoward Hinnant 1802c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 1803c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>& 1804c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::operator=(const function& __f) 18053e519524SHoward Hinnant{ 18063e519524SHoward Hinnant function(__f).swap(*this); 18073e519524SHoward Hinnant return *this; 18083e519524SHoward Hinnant} 18093e519524SHoward Hinnant 1810c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 1811c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>& 1812c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT 18133e519524SHoward Hinnant{ 18143e58a6a7SEvgeniy Stepanov if ((void *)__f_ == &__buf_) 18153e519524SHoward Hinnant __f_->destroy(); 18163e519524SHoward Hinnant else if (__f_) 18173e519524SHoward Hinnant __f_->destroy_deallocate(); 18183e519524SHoward Hinnant __f_ = 0; 18193e519524SHoward Hinnant if (__f.__f_ == 0) 18203e519524SHoward Hinnant __f_ = 0; 18213e58a6a7SEvgeniy Stepanov else if ((void *)__f.__f_ == &__f.__buf_) 18223e519524SHoward Hinnant { 18233e58a6a7SEvgeniy Stepanov __f_ = __as_base(&__buf_); 18243e519524SHoward Hinnant __f.__f_->__clone(__f_); 18253e519524SHoward Hinnant } 18263e519524SHoward Hinnant else 18273e519524SHoward Hinnant { 18283e519524SHoward Hinnant __f_ = __f.__f_; 18293e519524SHoward Hinnant __f.__f_ = 0; 18303e519524SHoward Hinnant } 183188db3171SArgyrios Kyrtzidis return *this; 18323e519524SHoward Hinnant} 18333e519524SHoward Hinnant 1834c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 1835c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>& 1836c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT 18373e519524SHoward Hinnant{ 18383e58a6a7SEvgeniy Stepanov if ((void *)__f_ == &__buf_) 18393e519524SHoward Hinnant __f_->destroy(); 18403e519524SHoward Hinnant else if (__f_) 18413e519524SHoward Hinnant __f_->destroy_deallocate(); 18423e519524SHoward Hinnant __f_ = 0; 184388db3171SArgyrios Kyrtzidis return *this; 18443e519524SHoward Hinnant} 18453e519524SHoward Hinnant 1846c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 1847c003db1fSHoward Hinnanttemplate <class _Fp> 18483e519524SHoward Hinnanttypename enable_if 18493e519524SHoward Hinnant< 18509dbbf8deSHoward Hinnant function<_Rp(_ArgTypes...)>::template __callable<typename decay<_Fp>::type>::value && 18519dbbf8deSHoward Hinnant !is_same<typename remove_reference<_Fp>::type, function<_Rp(_ArgTypes...)>>::value, 1852c003db1fSHoward Hinnant function<_Rp(_ArgTypes...)>& 18533e519524SHoward Hinnant>::type 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{ 18733e58a6a7SEvgeniy Stepanov if ((void *)__f_ == &__buf_ && (void *)__f.__f_ == &__f.__buf_) 18743e519524SHoward Hinnant { 18753e519524SHoward Hinnant typename aligned_storage<sizeof(__buf_)>::type __tempbuf; 18763e58a6a7SEvgeniy Stepanov __base* __t = __as_base(&__tempbuf); 18773e519524SHoward Hinnant __f_->__clone(__t); 18783e519524SHoward Hinnant __f_->destroy(); 18793e519524SHoward Hinnant __f_ = 0; 18803e58a6a7SEvgeniy Stepanov __f.__f_->__clone(__as_base(&__buf_)); 18813e519524SHoward Hinnant __f.__f_->destroy(); 18823e519524SHoward Hinnant __f.__f_ = 0; 18833e58a6a7SEvgeniy Stepanov __f_ = __as_base(&__buf_); 18843e58a6a7SEvgeniy Stepanov __t->__clone(__as_base(&__f.__buf_)); 18853e519524SHoward Hinnant __t->destroy(); 18863e58a6a7SEvgeniy Stepanov __f.__f_ = __as_base(&__f.__buf_); 18873e519524SHoward Hinnant } 18883e58a6a7SEvgeniy Stepanov else if ((void *)__f_ == &__buf_) 18893e519524SHoward Hinnant { 18903e58a6a7SEvgeniy Stepanov __f_->__clone(__as_base(&__f.__buf_)); 18913e519524SHoward Hinnant __f_->destroy(); 18923e519524SHoward Hinnant __f_ = __f.__f_; 18933e58a6a7SEvgeniy Stepanov __f.__f_ = __as_base(&__f.__buf_); 18943e519524SHoward Hinnant } 18953e58a6a7SEvgeniy Stepanov else if ((void *)__f.__f_ == &__f.__buf_) 18963e519524SHoward Hinnant { 18973e58a6a7SEvgeniy Stepanov __f.__f_->__clone(__as_base(&__buf_)); 18983e519524SHoward Hinnant __f.__f_->destroy(); 18993e519524SHoward Hinnant __f.__f_ = __f_; 19003e58a6a7SEvgeniy Stepanov __f_ = __as_base(&__buf_); 19013e519524SHoward Hinnant } 19023e519524SHoward Hinnant else 1903ce48a113SHoward Hinnant _VSTD::swap(__f_, __f.__f_); 19043e519524SHoward Hinnant} 19053e519524SHoward Hinnant 1906c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 1907c003db1fSHoward Hinnant_Rp 1908c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const 19093e519524SHoward Hinnant{ 19103e519524SHoward Hinnant if (__f_ == 0) 1911d437fa5cSMarshall Clow __throw_bad_function_call(); 1912ce48a113SHoward Hinnant return (*__f_)(_VSTD::forward<_ArgTypes>(__arg)...); 19133e519524SHoward Hinnant} 19143e519524SHoward Hinnant 191554b409fdSHoward Hinnant#ifndef _LIBCPP_NO_RTTI 191654b409fdSHoward Hinnant 1917c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 19183e519524SHoward Hinnantconst std::type_info& 1919c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT 19203e519524SHoward Hinnant{ 19213e519524SHoward Hinnant if (__f_ == 0) 19223e519524SHoward Hinnant return typeid(void); 19233e519524SHoward Hinnant return __f_->target_type(); 19243e519524SHoward Hinnant} 19253e519524SHoward Hinnant 1926c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 1927c003db1fSHoward Hinnanttemplate <typename _Tp> 1928c003db1fSHoward Hinnant_Tp* 1929c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::target() _NOEXCEPT 19303e519524SHoward Hinnant{ 19313e519524SHoward Hinnant if (__f_ == 0) 1932c003db1fSHoward Hinnant return (_Tp*)0; 1933c003db1fSHoward Hinnant return (_Tp*)__f_->target(typeid(_Tp)); 19343e519524SHoward Hinnant} 19353e519524SHoward Hinnant 1936c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 1937c003db1fSHoward Hinnanttemplate <typename _Tp> 1938c003db1fSHoward Hinnantconst _Tp* 1939c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::target() const _NOEXCEPT 19403e519524SHoward Hinnant{ 19413e519524SHoward Hinnant if (__f_ == 0) 1942c003db1fSHoward Hinnant return (const _Tp*)0; 1943c003db1fSHoward Hinnant return (const _Tp*)__f_->target(typeid(_Tp)); 19443e519524SHoward Hinnant} 19453e519524SHoward Hinnant 1946b3371f6fSHoward Hinnant#endif // _LIBCPP_NO_RTTI 194754b409fdSHoward Hinnant 1948c003db1fSHoward Hinnanttemplate <class _Rp, class... _ArgTypes> 19493e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 19503e519524SHoward Hinnantbool 1951c003db1fSHoward Hinnantoperator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;} 19523e519524SHoward Hinnant 1953c003db1fSHoward Hinnanttemplate <class _Rp, class... _ArgTypes> 19543e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 19553e519524SHoward Hinnantbool 1956c003db1fSHoward Hinnantoperator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;} 19573e519524SHoward Hinnant 1958c003db1fSHoward Hinnanttemplate <class _Rp, class... _ArgTypes> 19593e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 19603e519524SHoward Hinnantbool 1961c003db1fSHoward Hinnantoperator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;} 19623e519524SHoward Hinnant 1963c003db1fSHoward Hinnanttemplate <class _Rp, class... _ArgTypes> 19643e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 19653e519524SHoward Hinnantbool 1966c003db1fSHoward Hinnantoperator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;} 19673e519524SHoward Hinnant 1968c003db1fSHoward Hinnanttemplate <class _Rp, class... _ArgTypes> 19693e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 19703e519524SHoward Hinnantvoid 1971c003db1fSHoward Hinnantswap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT 19723e519524SHoward Hinnant{return __x.swap(__y);} 19733e519524SHoward Hinnant 197400f512ebSEric Fiselier#else // _LIBCPP_HAS_NO_VARIADICS 197500f512ebSEric Fiselier 197600f512ebSEric Fiselier#include <__functional_03> 197700f512ebSEric Fiselier 197800f512ebSEric Fiselier#endif 1979e5407178SEric Fiselier 1980e5407178SEric Fiselier//////////////////////////////////////////////////////////////////////////////// 1981e5407178SEric Fiselier// BIND 1982e5407178SEric Fiselier//============================================================================== 1983e5407178SEric Fiselier 19843e519524SHoward Hinnanttemplate<class _Tp> struct __is_bind_expression : public false_type {}; 1985f0544c20SHoward Hinnanttemplate<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_bind_expression 19863e519524SHoward Hinnant : public __is_bind_expression<typename remove_cv<_Tp>::type> {}; 19873e519524SHoward Hinnant 1988a48055ceSMarshall Clow#if _LIBCPP_STD_VER > 14 1989a48055ceSMarshall Clowtemplate <class _Tp> 1990a48055ceSMarshall Clowconstexpr size_t is_bind_expression_v = is_bind_expression<_Tp>::value; 1991a48055ceSMarshall Clow#endif 1992a48055ceSMarshall Clow 19933e519524SHoward Hinnanttemplate<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {}; 1994f0544c20SHoward Hinnanttemplate<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_placeholder 19953e519524SHoward Hinnant : public __is_placeholder<typename remove_cv<_Tp>::type> {}; 19963e519524SHoward Hinnant 1997a48055ceSMarshall Clow#if _LIBCPP_STD_VER > 14 1998a48055ceSMarshall Clowtemplate <class _Tp> 1999a48055ceSMarshall Clowconstexpr size_t is_placeholder_v = is_placeholder<_Tp>::value; 2000a48055ceSMarshall Clow#endif 2001a48055ceSMarshall Clow 20023e519524SHoward Hinnantnamespace placeholders 20033e519524SHoward Hinnant{ 20043e519524SHoward Hinnant 2005c003db1fSHoward Hinnanttemplate <int _Np> struct __ph {}; 20063e519524SHoward Hinnant 200755533071SEric Fiselier#if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_BIND) 200855533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<1> _1; 200955533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<2> _2; 201055533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<3> _3; 201155533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<4> _4; 201255533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<5> _5; 201355533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<6> _6; 201455533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<7> _7; 201555533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<8> _8; 201655533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<9> _9; 201755533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<10> _10; 201855533071SEric Fiselier#else 201955533071SEric Fiselierconstexpr __ph<1> _1{}; 202055533071SEric Fiselierconstexpr __ph<2> _2{}; 202155533071SEric Fiselierconstexpr __ph<3> _3{}; 202255533071SEric Fiselierconstexpr __ph<4> _4{}; 202355533071SEric Fiselierconstexpr __ph<5> _5{}; 202455533071SEric Fiselierconstexpr __ph<6> _6{}; 202555533071SEric Fiselierconstexpr __ph<7> _7{}; 202655533071SEric Fiselierconstexpr __ph<8> _8{}; 202755533071SEric Fiselierconstexpr __ph<9> _9{}; 202855533071SEric Fiselierconstexpr __ph<10> _10{}; 202955533071SEric Fiselier#endif // defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_BIND) 20303e519524SHoward Hinnant 20313e519524SHoward Hinnant} // placeholders 20323e519524SHoward Hinnant 2033c003db1fSHoward Hinnanttemplate<int _Np> 2034c003db1fSHoward Hinnantstruct __is_placeholder<placeholders::__ph<_Np> > 2035c003db1fSHoward Hinnant : public integral_constant<int, _Np> {}; 20363e519524SHoward Hinnant 2037e5407178SEric Fiselier 2038e5407178SEric Fiselier#ifndef _LIBCPP_HAS_NO_VARIADICS 2039e5407178SEric Fiselier 20403e519524SHoward Hinnanttemplate <class _Tp, class _Uj> 20413e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 20423e519524SHoward Hinnant_Tp& 20433e519524SHoward Hinnant__mu(reference_wrapper<_Tp> __t, _Uj&) 20443e519524SHoward Hinnant{ 20453e519524SHoward Hinnant return __t.get(); 20463e519524SHoward Hinnant} 20473e519524SHoward Hinnant 20483e519524SHoward Hinnanttemplate <class _Ti, class ..._Uj, size_t ..._Indx> 20493e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 20502344d6c1SHoward Hinnanttypename __invoke_of<_Ti&, _Uj...>::type 20512344d6c1SHoward Hinnant__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>) 20523e519524SHoward Hinnant{ 2053f9af6140SMarshall Clow return __ti(_VSTD::forward<_Uj>(_VSTD::get<_Indx>(__uj))...); 20543e519524SHoward Hinnant} 20553e519524SHoward Hinnant 20563e519524SHoward Hinnanttemplate <class _Ti, class ..._Uj> 20573e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 2058279663c1SEric Fiseliertypename __lazy_enable_if 20593e519524SHoward Hinnant< 20603e519524SHoward Hinnant is_bind_expression<_Ti>::value, 2061279663c1SEric Fiselier __invoke_of<_Ti&, _Uj...> 20623e519524SHoward Hinnant>::type 20633e519524SHoward Hinnant__mu(_Ti& __ti, tuple<_Uj...>& __uj) 20643e519524SHoward Hinnant{ 20653e519524SHoward Hinnant typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices; 20663e519524SHoward Hinnant return __mu_expand(__ti, __uj, __indices()); 20673e519524SHoward Hinnant} 20683e519524SHoward Hinnant 20693e519524SHoward Hinnanttemplate <bool IsPh, class _Ti, class _Uj> 20703e519524SHoward Hinnantstruct __mu_return2 {}; 20713e519524SHoward Hinnant 20723e519524SHoward Hinnanttemplate <class _Ti, class _Uj> 20733e519524SHoward Hinnantstruct __mu_return2<true, _Ti, _Uj> 20743e519524SHoward Hinnant{ 20753e519524SHoward Hinnant typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type; 20763e519524SHoward Hinnant}; 20773e519524SHoward Hinnant 20783e519524SHoward Hinnanttemplate <class _Ti, class _Uj> 20793e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 20803e519524SHoward Hinnanttypename enable_if 20813e519524SHoward Hinnant< 20823e519524SHoward Hinnant 0 < is_placeholder<_Ti>::value, 20833e519524SHoward Hinnant typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type 20843e519524SHoward Hinnant>::type 20853e519524SHoward Hinnant__mu(_Ti&, _Uj& __uj) 20863e519524SHoward Hinnant{ 20873e519524SHoward Hinnant const size_t _Indx = is_placeholder<_Ti>::value - 1; 2088f9af6140SMarshall Clow return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj)); 20893e519524SHoward Hinnant} 20903e519524SHoward Hinnant 20913e519524SHoward Hinnanttemplate <class _Ti, class _Uj> 20923e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 20933e519524SHoward Hinnanttypename enable_if 20943e519524SHoward Hinnant< 20953e519524SHoward Hinnant !is_bind_expression<_Ti>::value && 20963e519524SHoward Hinnant is_placeholder<_Ti>::value == 0 && 20973e519524SHoward Hinnant !__is_reference_wrapper<_Ti>::value, 20983e519524SHoward Hinnant _Ti& 20993e519524SHoward Hinnant>::type 2100c206366fSHoward Hinnant__mu(_Ti& __ti, _Uj&) 21013e519524SHoward Hinnant{ 21023e519524SHoward Hinnant return __ti; 21033e519524SHoward Hinnant} 21043e519524SHoward Hinnant 21052fa07ae9SHoward Hinnanttemplate <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh, 21062fa07ae9SHoward Hinnant class _TupleUj> 21073e519524SHoward Hinnantstruct ____mu_return; 21083e519524SHoward Hinnant 21099bf42533SHoward Hinnanttemplate <bool _Invokable, class _Ti, class ..._Uj> 21109bf42533SHoward Hinnantstruct ____mu_return_invokable // false 21119bf42533SHoward Hinnant{ 21129bf42533SHoward Hinnant typedef __nat type; 21139bf42533SHoward Hinnant}; 21149bf42533SHoward Hinnant 21153e519524SHoward Hinnanttemplate <class _Ti, class ..._Uj> 21169bf42533SHoward Hinnantstruct ____mu_return_invokable<true, _Ti, _Uj...> 21173e519524SHoward Hinnant{ 21182344d6c1SHoward Hinnant typedef typename __invoke_of<_Ti&, _Uj...>::type type; 21193e519524SHoward Hinnant}; 21203e519524SHoward Hinnant 21219bf42533SHoward Hinnanttemplate <class _Ti, class ..._Uj> 21229bf42533SHoward Hinnantstruct ____mu_return<_Ti, false, true, false, tuple<_Uj...> > 21239bf42533SHoward Hinnant : public ____mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...> 21249bf42533SHoward Hinnant{ 21259bf42533SHoward Hinnant}; 21269bf42533SHoward Hinnant 21273e519524SHoward Hinnanttemplate <class _Ti, class _TupleUj> 21282fa07ae9SHoward Hinnantstruct ____mu_return<_Ti, false, false, true, _TupleUj> 21293e519524SHoward Hinnant{ 21303e519524SHoward Hinnant typedef typename tuple_element<is_placeholder<_Ti>::value - 1, 21313e519524SHoward Hinnant _TupleUj>::type&& type; 21323e519524SHoward Hinnant}; 21333e519524SHoward Hinnant 21343e519524SHoward Hinnanttemplate <class _Ti, class _TupleUj> 21352fa07ae9SHoward Hinnantstruct ____mu_return<_Ti, true, false, false, _TupleUj> 21362fa07ae9SHoward Hinnant{ 21372fa07ae9SHoward Hinnant typedef typename _Ti::type& type; 21382fa07ae9SHoward Hinnant}; 21392fa07ae9SHoward Hinnant 21402fa07ae9SHoward Hinnanttemplate <class _Ti, class _TupleUj> 21412fa07ae9SHoward Hinnantstruct ____mu_return<_Ti, false, false, false, _TupleUj> 21423e519524SHoward Hinnant{ 21433e519524SHoward Hinnant typedef _Ti& type; 21443e519524SHoward Hinnant}; 21453e519524SHoward Hinnant 21463e519524SHoward Hinnanttemplate <class _Ti, class _TupleUj> 21473e519524SHoward Hinnantstruct __mu_return 21483e519524SHoward Hinnant : public ____mu_return<_Ti, 21492fa07ae9SHoward Hinnant __is_reference_wrapper<_Ti>::value, 21503e519524SHoward Hinnant is_bind_expression<_Ti>::value, 2151c0c9748cSHoward Hinnant 0 < is_placeholder<_Ti>::value && 2152c0c9748cSHoward Hinnant is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value, 21533e519524SHoward Hinnant _TupleUj> 21543e519524SHoward Hinnant{ 21553e519524SHoward Hinnant}; 21563e519524SHoward Hinnant 2157c003db1fSHoward Hinnanttemplate <class _Fp, class _BoundArgs, class _TupleUj> 215835cb2b28SEric Fiselierstruct __is_valid_bind_return 2159c0c9748cSHoward Hinnant{ 2160c0c9748cSHoward Hinnant static const bool value = false; 2161c0c9748cSHoward Hinnant}; 2162c0c9748cSHoward Hinnant 2163c0c9748cSHoward Hinnanttemplate <class _Fp, class ..._BoundArgs, class _TupleUj> 216435cb2b28SEric Fiselierstruct __is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj> 2165c0c9748cSHoward Hinnant{ 2166c0c9748cSHoward Hinnant static const bool value = __invokable<_Fp, 2167c0c9748cSHoward Hinnant typename __mu_return<_BoundArgs, _TupleUj>::type...>::value; 2168c0c9748cSHoward Hinnant}; 2169c0c9748cSHoward Hinnant 2170c0c9748cSHoward Hinnanttemplate <class _Fp, class ..._BoundArgs, class _TupleUj> 217135cb2b28SEric Fiselierstruct __is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj> 2172c0c9748cSHoward Hinnant{ 2173c0c9748cSHoward Hinnant static const bool value = __invokable<_Fp, 2174c0c9748cSHoward Hinnant typename __mu_return<const _BoundArgs, _TupleUj>::type...>::value; 2175c0c9748cSHoward Hinnant}; 2176c0c9748cSHoward Hinnant 2177c0c9748cSHoward Hinnanttemplate <class _Fp, class _BoundArgs, class _TupleUj, 217835cb2b28SEric Fiselier bool = __is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value> 21793e519524SHoward Hinnantstruct __bind_return; 21803e519524SHoward Hinnant 2181c003db1fSHoward Hinnanttemplate <class _Fp, class ..._BoundArgs, class _TupleUj> 2182c0c9748cSHoward Hinnantstruct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true> 21833e519524SHoward Hinnant{ 21842344d6c1SHoward Hinnant typedef typename __invoke_of 21853e519524SHoward Hinnant < 2186c003db1fSHoward Hinnant _Fp&, 21873e519524SHoward Hinnant typename __mu_return 21883e519524SHoward Hinnant < 21893e519524SHoward Hinnant _BoundArgs, 21903e519524SHoward Hinnant _TupleUj 21913e519524SHoward Hinnant >::type... 21923e519524SHoward Hinnant >::type type; 21933e519524SHoward Hinnant}; 21943e519524SHoward Hinnant 2195c003db1fSHoward Hinnanttemplate <class _Fp, class ..._BoundArgs, class _TupleUj> 2196c0c9748cSHoward Hinnantstruct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true> 21973e519524SHoward Hinnant{ 21982344d6c1SHoward Hinnant typedef typename __invoke_of 21993e519524SHoward Hinnant < 2200c003db1fSHoward Hinnant _Fp&, 22013e519524SHoward Hinnant typename __mu_return 22023e519524SHoward Hinnant < 22033e519524SHoward Hinnant const _BoundArgs, 22043e519524SHoward Hinnant _TupleUj 22053e519524SHoward Hinnant >::type... 22063e519524SHoward Hinnant >::type type; 22073e519524SHoward Hinnant}; 22083e519524SHoward Hinnant 2209c003db1fSHoward Hinnanttemplate <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args> 22103e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 2211c003db1fSHoward Hinnanttypename __bind_return<_Fp, _BoundArgs, _Args>::type 2212c003db1fSHoward Hinnant__apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>, 22133e519524SHoward Hinnant _Args&& __args) 22143e519524SHoward Hinnant{ 2215f9af6140SMarshall Clow return __invoke(__f, __mu(_VSTD::get<_Indx>(__bound_args), __args)...); 22163e519524SHoward Hinnant} 22173e519524SHoward Hinnant 2218c003db1fSHoward Hinnanttemplate<class _Fp, class ..._BoundArgs> 22193e519524SHoward Hinnantclass __bind 2220c003db1fSHoward Hinnant : public __weak_result_type<typename decay<_Fp>::type> 22213e519524SHoward Hinnant{ 2222c0c9748cSHoward Hinnantprotected: 2223c003db1fSHoward Hinnant typedef typename decay<_Fp>::type _Fd; 22242344d6c1SHoward Hinnant typedef tuple<typename decay<_BoundArgs>::type...> _Td; 2225c0c9748cSHoward Hinnantprivate: 22262344d6c1SHoward Hinnant _Fd __f_; 22272344d6c1SHoward Hinnant _Td __bound_args_; 22283e519524SHoward Hinnant 22293e519524SHoward Hinnant typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices; 22303e519524SHoward Hinnantpublic: 2231086d0de1SHoward Hinnant#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS 2232086d0de1SHoward Hinnant 2233086d0de1SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 2234086d0de1SHoward Hinnant __bind(const __bind& __b) 2235086d0de1SHoward Hinnant : __f_(__b.__f_), 2236086d0de1SHoward Hinnant __bound_args_(__b.__bound_args_) {} 2237086d0de1SHoward Hinnant 2238086d0de1SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 2239086d0de1SHoward Hinnant __bind& operator=(const __bind& __b) 2240086d0de1SHoward Hinnant { 2241086d0de1SHoward Hinnant __f_ = __b.__f_; 2242086d0de1SHoward Hinnant __bound_args_ = __b.__bound_args_; 2243086d0de1SHoward Hinnant return *this; 2244086d0de1SHoward Hinnant } 2245086d0de1SHoward Hinnant 22460af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 22473e519524SHoward Hinnant __bind(__bind&& __b) 2248ce48a113SHoward Hinnant : __f_(_VSTD::move(__b.__f_)), 2249ce48a113SHoward Hinnant __bound_args_(_VSTD::move(__b.__bound_args_)) {} 22503e519524SHoward Hinnant 2251086d0de1SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 2252086d0de1SHoward Hinnant __bind& operator=(__bind&& __b) 2253086d0de1SHoward Hinnant { 2254086d0de1SHoward Hinnant __f_ = _VSTD::move(__b.__f_); 2255086d0de1SHoward Hinnant __bound_args_ = _VSTD::move(__b.__bound_args_); 2256086d0de1SHoward Hinnant return *this; 2257086d0de1SHoward Hinnant } 2258086d0de1SHoward Hinnant 2259086d0de1SHoward Hinnant#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS 2260086d0de1SHoward Hinnant 2261df7aad41SHoward Hinnant template <class _Gp, class ..._BA, 2262df7aad41SHoward Hinnant class = typename enable_if 2263df7aad41SHoward Hinnant < 22649dbbf8deSHoward Hinnant is_constructible<_Fd, _Gp>::value && 22659dbbf8deSHoward Hinnant !is_same<typename remove_reference<_Gp>::type, 22669dbbf8deSHoward Hinnant __bind>::value 2267df7aad41SHoward Hinnant >::type> 22680af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 2269c003db1fSHoward Hinnant explicit __bind(_Gp&& __f, _BA&& ...__bound_args) 2270c003db1fSHoward Hinnant : __f_(_VSTD::forward<_Gp>(__f)), 2271ce48a113SHoward Hinnant __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {} 22723e519524SHoward Hinnant 22733e519524SHoward Hinnant template <class ..._Args> 22740af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 22752344d6c1SHoward Hinnant typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type 22763e519524SHoward Hinnant operator()(_Args&& ...__args) 22773e519524SHoward Hinnant { 22783e519524SHoward Hinnant return __apply_functor(__f_, __bound_args_, __indices(), 2279ce48a113SHoward Hinnant tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...)); 22803e519524SHoward Hinnant } 22813e519524SHoward Hinnant 22823e519524SHoward Hinnant template <class ..._Args> 22830af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 2284c0c9748cSHoward Hinnant typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type 22853e519524SHoward Hinnant operator()(_Args&& ...__args) const 22863e519524SHoward Hinnant { 22873e519524SHoward Hinnant return __apply_functor(__f_, __bound_args_, __indices(), 2288ce48a113SHoward Hinnant tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...)); 22893e519524SHoward Hinnant } 22903e519524SHoward Hinnant}; 22913e519524SHoward Hinnant 2292c003db1fSHoward Hinnanttemplate<class _Fp, class ..._BoundArgs> 2293c003db1fSHoward Hinnantstruct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {}; 22943e519524SHoward Hinnant 2295c003db1fSHoward Hinnanttemplate<class _Rp, class _Fp, class ..._BoundArgs> 22963e519524SHoward Hinnantclass __bind_r 2297c003db1fSHoward Hinnant : public __bind<_Fp, _BoundArgs...> 22983e519524SHoward Hinnant{ 2299c003db1fSHoward Hinnant typedef __bind<_Fp, _BoundArgs...> base; 2300c0c9748cSHoward Hinnant typedef typename base::_Fd _Fd; 2301c0c9748cSHoward Hinnant typedef typename base::_Td _Td; 23023e519524SHoward Hinnantpublic: 2303c003db1fSHoward Hinnant typedef _Rp result_type; 23043e519524SHoward Hinnant 2305086d0de1SHoward Hinnant#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS 2306086d0de1SHoward Hinnant 2307086d0de1SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 2308086d0de1SHoward Hinnant __bind_r(const __bind_r& __b) 2309086d0de1SHoward Hinnant : base(_VSTD::forward<const base&>(__b)) {} 2310086d0de1SHoward Hinnant 2311086d0de1SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 2312086d0de1SHoward Hinnant __bind_r& operator=(const __bind_r& __b) 2313086d0de1SHoward Hinnant { 2314086d0de1SHoward Hinnant base::operator=(_VSTD::forward<const base&>(__b)); 2315086d0de1SHoward Hinnant return *this; 2316086d0de1SHoward Hinnant } 2317086d0de1SHoward Hinnant 231807de7bcaSHoward Hinnant _LIBCPP_INLINE_VISIBILITY 231907de7bcaSHoward Hinnant __bind_r(__bind_r&& __b) 2320ce48a113SHoward Hinnant : base(_VSTD::forward<base>(__b)) {} 232107de7bcaSHoward Hinnant 2322086d0de1SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 2323086d0de1SHoward Hinnant __bind_r& operator=(__bind_r&& __b) 2324086d0de1SHoward Hinnant { 2325086d0de1SHoward Hinnant base::operator=(_VSTD::forward<base>(__b)); 2326086d0de1SHoward Hinnant return *this; 2327086d0de1SHoward Hinnant } 2328086d0de1SHoward Hinnant 2329086d0de1SHoward Hinnant#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS 2330086d0de1SHoward Hinnant 23319dbbf8deSHoward Hinnant template <class _Gp, class ..._BA, 23329dbbf8deSHoward Hinnant class = typename enable_if 23339dbbf8deSHoward Hinnant < 23349dbbf8deSHoward Hinnant is_constructible<_Fd, _Gp>::value && 23359dbbf8deSHoward Hinnant !is_same<typename remove_reference<_Gp>::type, 23369dbbf8deSHoward Hinnant __bind_r>::value 23379dbbf8deSHoward Hinnant >::type> 23380af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 2339c003db1fSHoward Hinnant explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args) 2340c003db1fSHoward Hinnant : base(_VSTD::forward<_Gp>(__f), 2341ce48a113SHoward Hinnant _VSTD::forward<_BA>(__bound_args)...) {} 23423e519524SHoward Hinnant 23433e519524SHoward Hinnant template <class ..._Args> 23440af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 2345c0c9748cSHoward Hinnant typename enable_if 2346c0c9748cSHoward Hinnant < 2347c0c9748cSHoward Hinnant is_convertible<typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type, 23482d15f15fSEric Fiselier result_type>::value || is_void<_Rp>::value, 23493e519524SHoward Hinnant result_type 2350c0c9748cSHoward Hinnant >::type 23513e519524SHoward Hinnant operator()(_Args&& ...__args) 23523e519524SHoward Hinnant { 23532d15f15fSEric Fiselier typedef __invoke_void_return_wrapper<_Rp> _Invoker; 23542d15f15fSEric Fiselier return _Invoker::__call(static_cast<base&>(*this), _VSTD::forward<_Args>(__args)...); 23553e519524SHoward Hinnant } 23563e519524SHoward Hinnant 23573e519524SHoward Hinnant template <class ..._Args> 23580af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 2359c0c9748cSHoward Hinnant typename enable_if 2360c0c9748cSHoward Hinnant < 2361c0c9748cSHoward Hinnant is_convertible<typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type, 23622d15f15fSEric Fiselier result_type>::value || is_void<_Rp>::value, 23633e519524SHoward Hinnant result_type 2364c0c9748cSHoward Hinnant >::type 23653e519524SHoward Hinnant operator()(_Args&& ...__args) const 23663e519524SHoward Hinnant { 23672d15f15fSEric Fiselier typedef __invoke_void_return_wrapper<_Rp> _Invoker; 23682d15f15fSEric Fiselier return _Invoker::__call(static_cast<base const&>(*this), _VSTD::forward<_Args>(__args)...); 23693e519524SHoward Hinnant } 23703e519524SHoward Hinnant}; 23713e519524SHoward Hinnant 2372c003db1fSHoward Hinnanttemplate<class _Rp, class _Fp, class ..._BoundArgs> 2373c003db1fSHoward Hinnantstruct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {}; 23743e519524SHoward Hinnant 2375c003db1fSHoward Hinnanttemplate<class _Fp, class ..._BoundArgs> 23763e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 2377c003db1fSHoward Hinnant__bind<_Fp, _BoundArgs...> 2378c003db1fSHoward Hinnantbind(_Fp&& __f, _BoundArgs&&... __bound_args) 23793e519524SHoward Hinnant{ 2380c003db1fSHoward Hinnant typedef __bind<_Fp, _BoundArgs...> type; 2381c003db1fSHoward Hinnant return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...); 23823e519524SHoward Hinnant} 23833e519524SHoward Hinnant 2384c003db1fSHoward Hinnanttemplate<class _Rp, class _Fp, class ..._BoundArgs> 23853e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 2386c003db1fSHoward Hinnant__bind_r<_Rp, _Fp, _BoundArgs...> 2387c003db1fSHoward Hinnantbind(_Fp&& __f, _BoundArgs&&... __bound_args) 23883e519524SHoward Hinnant{ 2389c003db1fSHoward Hinnant typedef __bind_r<_Rp, _Fp, _BoundArgs...> type; 2390c003db1fSHoward Hinnant return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...); 23913e519524SHoward Hinnant} 23923e519524SHoward Hinnant 23933e519524SHoward Hinnant#endif // _LIBCPP_HAS_NO_VARIADICS 23943e519524SHoward Hinnant 23953e519524SHoward Hinnanttemplate <> 2396f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY hash<bool> 23973e519524SHoward Hinnant : public unary_function<bool, size_t> 23983e519524SHoward Hinnant{ 23990af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 24006a07d6f0SHoward Hinnant size_t operator()(bool __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 24013e519524SHoward Hinnant}; 24023e519524SHoward Hinnant 24033e519524SHoward Hinnanttemplate <> 2404f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY hash<char> 24053e519524SHoward Hinnant : public unary_function<char, size_t> 24063e519524SHoward Hinnant{ 24070af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 24086a07d6f0SHoward Hinnant size_t operator()(char __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 24093e519524SHoward Hinnant}; 24103e519524SHoward Hinnant 24113e519524SHoward Hinnanttemplate <> 2412f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY hash<signed char> 24133e519524SHoward Hinnant : public unary_function<signed char, size_t> 24143e519524SHoward Hinnant{ 24150af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 24166a07d6f0SHoward Hinnant size_t operator()(signed char __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 24173e519524SHoward Hinnant}; 24183e519524SHoward Hinnant 24193e519524SHoward Hinnanttemplate <> 2420f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY hash<unsigned char> 24213e519524SHoward Hinnant : public unary_function<unsigned char, size_t> 24223e519524SHoward Hinnant{ 24230af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 24246a07d6f0SHoward Hinnant size_t operator()(unsigned char __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 24253e519524SHoward Hinnant}; 24263e519524SHoward Hinnant 24273e519524SHoward Hinnant#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS 24283e519524SHoward Hinnant 24293e519524SHoward Hinnanttemplate <> 2430f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY hash<char16_t> 24313e519524SHoward Hinnant : public unary_function<char16_t, size_t> 24323e519524SHoward Hinnant{ 24330af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 24346a07d6f0SHoward Hinnant size_t operator()(char16_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 24353e519524SHoward Hinnant}; 24363e519524SHoward Hinnant 24373e519524SHoward Hinnanttemplate <> 2438f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY hash<char32_t> 24393e519524SHoward Hinnant : public unary_function<char32_t, size_t> 24403e519524SHoward Hinnant{ 24410af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 24426a07d6f0SHoward Hinnant size_t operator()(char32_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 24433e519524SHoward Hinnant}; 24443e519524SHoward Hinnant 2445b3371f6fSHoward Hinnant#endif // _LIBCPP_HAS_NO_UNICODE_CHARS 24463e519524SHoward Hinnant 24473e519524SHoward Hinnanttemplate <> 2448f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY hash<wchar_t> 24493e519524SHoward Hinnant : public unary_function<wchar_t, size_t> 24503e519524SHoward Hinnant{ 24510af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 24526a07d6f0SHoward Hinnant size_t operator()(wchar_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 24533e519524SHoward Hinnant}; 24543e519524SHoward Hinnant 24553e519524SHoward Hinnanttemplate <> 2456f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY hash<short> 24573e519524SHoward Hinnant : public unary_function<short, size_t> 24583e519524SHoward Hinnant{ 24590af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 24606a07d6f0SHoward Hinnant size_t operator()(short __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 24613e519524SHoward Hinnant}; 24623e519524SHoward Hinnant 24633e519524SHoward Hinnanttemplate <> 2464f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY hash<unsigned short> 24653e519524SHoward Hinnant : public unary_function<unsigned short, size_t> 24663e519524SHoward Hinnant{ 24670af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 24686a07d6f0SHoward Hinnant size_t operator()(unsigned short __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 24693e519524SHoward Hinnant}; 24703e519524SHoward Hinnant 24713e519524SHoward Hinnanttemplate <> 2472f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY hash<int> 24733e519524SHoward Hinnant : public unary_function<int, size_t> 24743e519524SHoward Hinnant{ 24750af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 24766a07d6f0SHoward Hinnant size_t operator()(int __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 24773e519524SHoward Hinnant}; 24783e519524SHoward Hinnant 24793e519524SHoward Hinnanttemplate <> 2480f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY hash<unsigned int> 24813e519524SHoward Hinnant : public unary_function<unsigned int, size_t> 24823e519524SHoward Hinnant{ 24830af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 24846a07d6f0SHoward Hinnant size_t operator()(unsigned int __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 24853e519524SHoward Hinnant}; 24863e519524SHoward Hinnant 24873e519524SHoward Hinnanttemplate <> 2488f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY hash<long> 24893e519524SHoward Hinnant : public unary_function<long, size_t> 24903e519524SHoward Hinnant{ 24910af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 24926a07d6f0SHoward Hinnant size_t operator()(long __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 24933e519524SHoward Hinnant}; 24943e519524SHoward Hinnant 24953e519524SHoward Hinnanttemplate <> 2496f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY hash<unsigned long> 24973e519524SHoward Hinnant : public unary_function<unsigned long, size_t> 24983e519524SHoward Hinnant{ 24990af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 25006a07d6f0SHoward Hinnant size_t operator()(unsigned long __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 25013e519524SHoward Hinnant}; 25023e519524SHoward Hinnant 25033e519524SHoward Hinnanttemplate <> 2504f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY hash<long long> 25059b0cd149SHoward Hinnant : public __scalar_hash<long long> 25063e519524SHoward Hinnant{ 25073e519524SHoward Hinnant}; 25083e519524SHoward Hinnant 25093e519524SHoward Hinnanttemplate <> 2510f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY hash<unsigned long long> 25119b0cd149SHoward Hinnant : public __scalar_hash<unsigned long long> 25123e519524SHoward Hinnant{ 25133e519524SHoward Hinnant}; 25143e519524SHoward Hinnant 2515df691e18SEric Fiselier#ifndef _LIBCPP_HAS_NO_INT128 2516df691e18SEric Fiselier 2517df691e18SEric Fiseliertemplate <> 2518df691e18SEric Fiselierstruct _LIBCPP_TYPE_VIS_ONLY hash<__int128_t> 2519df691e18SEric Fiselier : public __scalar_hash<__int128_t> 2520df691e18SEric Fiselier{ 2521df691e18SEric Fiselier}; 2522df691e18SEric Fiselier 2523df691e18SEric Fiseliertemplate <> 2524df691e18SEric Fiselierstruct _LIBCPP_TYPE_VIS_ONLY hash<__uint128_t> 2525df691e18SEric Fiselier : public __scalar_hash<__uint128_t> 2526df691e18SEric Fiselier{ 2527df691e18SEric Fiselier}; 2528df691e18SEric Fiselier 2529df691e18SEric Fiselier#endif 2530df691e18SEric Fiselier 25313e519524SHoward Hinnanttemplate <> 2532f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY hash<float> 25339b0cd149SHoward Hinnant : public __scalar_hash<float> 25343e519524SHoward Hinnant{ 25350af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 25366a07d6f0SHoward Hinnant size_t operator()(float __v) const _NOEXCEPT 25373e519524SHoward Hinnant { 25389b0cd149SHoward Hinnant // -0.0 and 0.0 should return same hash 25393e519524SHoward Hinnant if (__v == 0) 25403e519524SHoward Hinnant return 0; 25419b0cd149SHoward Hinnant return __scalar_hash<float>::operator()(__v); 25423e519524SHoward Hinnant } 25433e519524SHoward Hinnant}; 25443e519524SHoward Hinnant 25453e519524SHoward Hinnanttemplate <> 2546f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY hash<double> 25479b0cd149SHoward Hinnant : public __scalar_hash<double> 25483e519524SHoward Hinnant{ 25490af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 25506a07d6f0SHoward Hinnant size_t operator()(double __v) const _NOEXCEPT 25513e519524SHoward Hinnant { 25529b0cd149SHoward Hinnant // -0.0 and 0.0 should return same hash 25533e519524SHoward Hinnant if (__v == 0) 25543e519524SHoward Hinnant return 0; 25559b0cd149SHoward Hinnant return __scalar_hash<double>::operator()(__v); 25563e519524SHoward Hinnant } 25573e519524SHoward Hinnant}; 25583e519524SHoward Hinnant 25593e519524SHoward Hinnanttemplate <> 2560f0544c20SHoward Hinnantstruct _LIBCPP_TYPE_VIS_ONLY hash<long double> 25619b0cd149SHoward Hinnant : public __scalar_hash<long double> 25623e519524SHoward Hinnant{ 25630af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 25646a07d6f0SHoward Hinnant size_t operator()(long double __v) const _NOEXCEPT 25653e519524SHoward Hinnant { 25669b0cd149SHoward Hinnant // -0.0 and 0.0 should return same hash 25673e519524SHoward Hinnant if (__v == 0) 25683e519524SHoward Hinnant return 0; 25699b0cd149SHoward Hinnant#if defined(__i386__) 25709b0cd149SHoward Hinnant // Zero out padding bits 25717f3884d5SHoward Hinnant union 25727f3884d5SHoward Hinnant { 25739b0cd149SHoward Hinnant long double __t; 25749b0cd149SHoward Hinnant struct 25759b0cd149SHoward Hinnant { 25769b0cd149SHoward Hinnant size_t __a; 25779b0cd149SHoward Hinnant size_t __b; 25789b0cd149SHoward Hinnant size_t __c; 25797f3884d5SHoward Hinnant size_t __d; 258087a82490SEric Fiselier } __s; 25817f3884d5SHoward Hinnant } __u; 258287a82490SEric Fiselier __u.__s.__a = 0; 258387a82490SEric Fiselier __u.__s.__b = 0; 258487a82490SEric Fiselier __u.__s.__c = 0; 258587a82490SEric Fiselier __u.__s.__d = 0; 25869b0cd149SHoward Hinnant __u.__t = __v; 258787a82490SEric Fiselier return __u.__s.__a ^ __u.__s.__b ^ __u.__s.__c ^ __u.__s.__d; 25889b0cd149SHoward Hinnant#elif defined(__x86_64__) 25899b0cd149SHoward Hinnant // Zero out padding bits 25909b0cd149SHoward Hinnant union 25919b0cd149SHoward Hinnant { 25929b0cd149SHoward Hinnant long double __t; 25939b0cd149SHoward Hinnant struct 25949b0cd149SHoward Hinnant { 25959b0cd149SHoward Hinnant size_t __a; 25969b0cd149SHoward Hinnant size_t __b; 259787a82490SEric Fiselier } __s; 25987f3884d5SHoward Hinnant } __u; 259987a82490SEric Fiselier __u.__s.__a = 0; 260087a82490SEric Fiselier __u.__s.__b = 0; 26019b0cd149SHoward Hinnant __u.__t = __v; 260287a82490SEric Fiselier return __u.__s.__a ^ __u.__s.__b; 26039b0cd149SHoward Hinnant#else 26049b0cd149SHoward Hinnant return __scalar_hash<long double>::operator()(__v); 26059b0cd149SHoward Hinnant#endif 26063e519524SHoward Hinnant } 26073e519524SHoward Hinnant}; 26083e519524SHoward Hinnant 26095155a569SMarshall Clow#if _LIBCPP_STD_VER > 11 261045b7b448SEric Fiselier 261145b7b448SEric Fiseliertemplate <class _Tp, bool = is_enum<_Tp>::value> 261245b7b448SEric Fiselierstruct _LIBCPP_TYPE_VIS_ONLY __enum_hash 26135155a569SMarshall Clow : public unary_function<_Tp, size_t> 26145155a569SMarshall Clow{ 26155155a569SMarshall Clow _LIBCPP_INLINE_VISIBILITY 26165155a569SMarshall Clow size_t operator()(_Tp __v) const _NOEXCEPT 26175155a569SMarshall Clow { 26185155a569SMarshall Clow typedef typename underlying_type<_Tp>::type type; 26195155a569SMarshall Clow return hash<type>{}(static_cast<type>(__v)); 26205155a569SMarshall Clow } 26215155a569SMarshall Clow}; 262245b7b448SEric Fiseliertemplate <class _Tp> 262345b7b448SEric Fiselierstruct _LIBCPP_TYPE_VIS_ONLY __enum_hash<_Tp, false> { 262445b7b448SEric Fiselier __enum_hash() = delete; 262545b7b448SEric Fiselier __enum_hash(__enum_hash const&) = delete; 262645b7b448SEric Fiselier __enum_hash& operator=(__enum_hash const&) = delete; 262745b7b448SEric Fiselier}; 262845b7b448SEric Fiselier 262945b7b448SEric Fiseliertemplate <class _Tp> 263045b7b448SEric Fiselierstruct _LIBCPP_TYPE_VIS_ONLY hash : public __enum_hash<_Tp> 263145b7b448SEric Fiselier{ 263245b7b448SEric Fiselier}; 26335155a569SMarshall Clow#endif 26345155a569SMarshall Clow 26355be45129SEric Fiselier 26365be45129SEric Fiselier#if _LIBCPP_STD_VER > 14 263757257567SEric Fiselier 2638*498ee00aSEric Fiselier#define __cpp_lib_invoke 201411 2639*498ee00aSEric Fiselier 26405be45129SEric Fiseliertemplate <class _Fn, class ..._Args> 26415be45129SEric Fiselierresult_of_t<_Fn&&(_Args&&...)> 264257257567SEric Fiselierinvoke(_Fn&& __f, _Args&&... __args) 264357257567SEric Fiselier noexcept(noexcept(_VSTD::__invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...))) 264457257567SEric Fiselier{ 264557257567SEric Fiselier return _VSTD::__invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...); 26465be45129SEric Fiselier} 264757257567SEric Fiselier 264857257567SEric Fiseliertemplate <class _DecayFunc> 264957257567SEric Fiselierclass _LIBCPP_TYPE_VIS_ONLY __not_fn_imp { 265057257567SEric Fiselier _DecayFunc __fd; 265157257567SEric Fiselier 265257257567SEric Fiselierpublic: 265357257567SEric Fiselier __not_fn_imp() = delete; 265457257567SEric Fiselier 265557257567SEric Fiselier template <class ..._Args> 265657257567SEric Fiselier _LIBCPP_INLINE_VISIBILITY 26579372d8bcSEric Fiselier auto operator()(_Args&& ...__args) & 265857257567SEric Fiselier noexcept(noexcept(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...))) 265957257567SEric Fiselier -> decltype( !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)) 266057257567SEric Fiselier { return !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); } 266157257567SEric Fiselier 266257257567SEric Fiselier template <class ..._Args> 266357257567SEric Fiselier _LIBCPP_INLINE_VISIBILITY 26649372d8bcSEric Fiselier auto operator()(_Args&& ...__args) && 26659372d8bcSEric Fiselier noexcept(noexcept(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...))) 26669372d8bcSEric Fiselier -> decltype( !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)) 26679372d8bcSEric Fiselier { return !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); } 26689372d8bcSEric Fiselier 26699372d8bcSEric Fiselier template <class ..._Args> 26709372d8bcSEric Fiselier _LIBCPP_INLINE_VISIBILITY 26719372d8bcSEric Fiselier auto operator()(_Args&& ...__args) const& 267257257567SEric Fiselier noexcept(noexcept(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...))) 267357257567SEric Fiselier -> decltype( !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)) 267457257567SEric Fiselier { return !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); } 267557257567SEric Fiselier 26769372d8bcSEric Fiselier 26779372d8bcSEric Fiselier template <class ..._Args> 26789372d8bcSEric Fiselier _LIBCPP_INLINE_VISIBILITY 26799372d8bcSEric Fiselier auto operator()(_Args&& ...__args) const&& 26809372d8bcSEric Fiselier noexcept(noexcept(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...))) 26819372d8bcSEric Fiselier -> decltype( !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)) 26829372d8bcSEric Fiselier { return !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); } 26839372d8bcSEric Fiselier 268457257567SEric Fiselierprivate: 268557257567SEric Fiselier template <class _RawFunc, 268657257567SEric Fiselier class = enable_if_t<!is_same<decay_t<_RawFunc>, __not_fn_imp>::value>> 268757257567SEric Fiselier _LIBCPP_INLINE_VISIBILITY 268857257567SEric Fiselier explicit __not_fn_imp(_RawFunc&& __rf) 268957257567SEric Fiselier : __fd(_VSTD::forward<_RawFunc>(__rf)) {} 269057257567SEric Fiselier 269157257567SEric Fiselier template <class _RawFunc> 269257257567SEric Fiselier friend inline _LIBCPP_INLINE_VISIBILITY 269357257567SEric Fiselier __not_fn_imp<decay_t<_RawFunc>> not_fn(_RawFunc&&); 269457257567SEric Fiselier}; 269557257567SEric Fiselier 269657257567SEric Fiseliertemplate <class _RawFunc> 269757257567SEric Fiselierinline _LIBCPP_INLINE_VISIBILITY 269857257567SEric Fiselier__not_fn_imp<decay_t<_RawFunc>> not_fn(_RawFunc&& __fn) { 269957257567SEric Fiselier return __not_fn_imp<decay_t<_RawFunc>>(_VSTD::forward<_RawFunc>(__fn)); 270057257567SEric Fiselier} 270157257567SEric Fiselier 27025be45129SEric Fiselier#endif 27035be45129SEric Fiselier 2704d1803b6cSHoward Hinnant// struct hash<T*> in <memory> 27053e519524SHoward Hinnant 27063e519524SHoward Hinnant_LIBCPP_END_NAMESPACE_STD 27073e519524SHoward Hinnant 27083e519524SHoward Hinnant#endif // _LIBCPP_FUNCTIONAL 2709