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 502*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS 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 <> 511*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS 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 529*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS 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 <> 538*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS 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 556*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS 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 <> 565*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS 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 583*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS 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 <> 592*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS 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 610*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS 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 <> 619*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS 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 637*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS 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 <> 646*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS 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 664*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS 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 <> 673*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS 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 691*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS 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 <> 700*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS 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 718*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS 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 <> 727*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS 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 747*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS 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 <> 756*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS 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 774*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS 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 <> 783*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS 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 801*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS 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 <> 810*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS 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 828*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS 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 <> 837*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS 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 855*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS 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 <> 864*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS 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 882*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS 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 <> 891*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS 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 909*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS 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 <> 918*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS 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 936*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS 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 <> 945*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS 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> 960*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS 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 <> 968*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS 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> 981*e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS 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> 1000*e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS 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> 1022*e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS 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> 1048*e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS 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> 1074*e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS 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> 1092*e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS 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> 1110*e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS 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> 1121*e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS 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> 1144*e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS 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> 1155*e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS 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> 1178*e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS 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> 1189*e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS 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> 1212*e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS 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> 1223*e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS 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 1402*e2f2d1edSEric Fiseliertemplate<class _Fp> class _LIBCPP_TEMPLATE_VIS 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> 1578*e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS 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{ 1873d566c345SEric Fiselier if (_VSTD::addressof(__f) == this) 1874d566c345SEric Fiselier return; 18753e58a6a7SEvgeniy Stepanov if ((void *)__f_ == &__buf_ && (void *)__f.__f_ == &__f.__buf_) 18763e519524SHoward Hinnant { 18773e519524SHoward Hinnant typename aligned_storage<sizeof(__buf_)>::type __tempbuf; 18783e58a6a7SEvgeniy Stepanov __base* __t = __as_base(&__tempbuf); 18793e519524SHoward Hinnant __f_->__clone(__t); 18803e519524SHoward Hinnant __f_->destroy(); 18813e519524SHoward Hinnant __f_ = 0; 18823e58a6a7SEvgeniy Stepanov __f.__f_->__clone(__as_base(&__buf_)); 18833e519524SHoward Hinnant __f.__f_->destroy(); 18843e519524SHoward Hinnant __f.__f_ = 0; 18853e58a6a7SEvgeniy Stepanov __f_ = __as_base(&__buf_); 18863e58a6a7SEvgeniy Stepanov __t->__clone(__as_base(&__f.__buf_)); 18873e519524SHoward Hinnant __t->destroy(); 18883e58a6a7SEvgeniy Stepanov __f.__f_ = __as_base(&__f.__buf_); 18893e519524SHoward Hinnant } 18903e58a6a7SEvgeniy Stepanov else if ((void *)__f_ == &__buf_) 18913e519524SHoward Hinnant { 18923e58a6a7SEvgeniy Stepanov __f_->__clone(__as_base(&__f.__buf_)); 18933e519524SHoward Hinnant __f_->destroy(); 18943e519524SHoward Hinnant __f_ = __f.__f_; 18953e58a6a7SEvgeniy Stepanov __f.__f_ = __as_base(&__f.__buf_); 18963e519524SHoward Hinnant } 18973e58a6a7SEvgeniy Stepanov else if ((void *)__f.__f_ == &__f.__buf_) 18983e519524SHoward Hinnant { 18993e58a6a7SEvgeniy Stepanov __f.__f_->__clone(__as_base(&__buf_)); 19003e519524SHoward Hinnant __f.__f_->destroy(); 19013e519524SHoward Hinnant __f.__f_ = __f_; 19023e58a6a7SEvgeniy Stepanov __f_ = __as_base(&__buf_); 19033e519524SHoward Hinnant } 19043e519524SHoward Hinnant else 1905ce48a113SHoward Hinnant _VSTD::swap(__f_, __f.__f_); 19063e519524SHoward Hinnant} 19073e519524SHoward Hinnant 1908c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 1909c003db1fSHoward Hinnant_Rp 1910c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const 19113e519524SHoward Hinnant{ 19123e519524SHoward Hinnant if (__f_ == 0) 1913d437fa5cSMarshall Clow __throw_bad_function_call(); 1914ce48a113SHoward Hinnant return (*__f_)(_VSTD::forward<_ArgTypes>(__arg)...); 19153e519524SHoward Hinnant} 19163e519524SHoward Hinnant 191754b409fdSHoward Hinnant#ifndef _LIBCPP_NO_RTTI 191854b409fdSHoward Hinnant 1919c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 19203e519524SHoward Hinnantconst std::type_info& 1921c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT 19223e519524SHoward Hinnant{ 19233e519524SHoward Hinnant if (__f_ == 0) 19243e519524SHoward Hinnant return typeid(void); 19253e519524SHoward Hinnant return __f_->target_type(); 19263e519524SHoward Hinnant} 19273e519524SHoward Hinnant 1928c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 1929c003db1fSHoward Hinnanttemplate <typename _Tp> 1930c003db1fSHoward Hinnant_Tp* 1931c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::target() _NOEXCEPT 19323e519524SHoward Hinnant{ 19333e519524SHoward Hinnant if (__f_ == 0) 1934c003db1fSHoward Hinnant return (_Tp*)0; 1935c003db1fSHoward Hinnant return (_Tp*)__f_->target(typeid(_Tp)); 19363e519524SHoward Hinnant} 19373e519524SHoward Hinnant 1938c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 1939c003db1fSHoward Hinnanttemplate <typename _Tp> 1940c003db1fSHoward Hinnantconst _Tp* 1941c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::target() const _NOEXCEPT 19423e519524SHoward Hinnant{ 19433e519524SHoward Hinnant if (__f_ == 0) 1944c003db1fSHoward Hinnant return (const _Tp*)0; 1945c003db1fSHoward Hinnant return (const _Tp*)__f_->target(typeid(_Tp)); 19463e519524SHoward Hinnant} 19473e519524SHoward Hinnant 1948b3371f6fSHoward Hinnant#endif // _LIBCPP_NO_RTTI 194954b409fdSHoward Hinnant 1950c003db1fSHoward Hinnanttemplate <class _Rp, class... _ArgTypes> 19513e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 19523e519524SHoward Hinnantbool 1953c003db1fSHoward Hinnantoperator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;} 19543e519524SHoward Hinnant 1955c003db1fSHoward Hinnanttemplate <class _Rp, class... _ArgTypes> 19563e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 19573e519524SHoward Hinnantbool 1958c003db1fSHoward Hinnantoperator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;} 19593e519524SHoward Hinnant 1960c003db1fSHoward Hinnanttemplate <class _Rp, class... _ArgTypes> 19613e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 19623e519524SHoward Hinnantbool 1963c003db1fSHoward Hinnantoperator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;} 19643e519524SHoward Hinnant 1965c003db1fSHoward Hinnanttemplate <class _Rp, class... _ArgTypes> 19663e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 19673e519524SHoward Hinnantbool 1968c003db1fSHoward Hinnantoperator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;} 19693e519524SHoward Hinnant 1970c003db1fSHoward Hinnanttemplate <class _Rp, class... _ArgTypes> 19713e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 19723e519524SHoward Hinnantvoid 1973c003db1fSHoward Hinnantswap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT 19743e519524SHoward Hinnant{return __x.swap(__y);} 19753e519524SHoward Hinnant 197600f512ebSEric Fiselier#else // _LIBCPP_HAS_NO_VARIADICS 197700f512ebSEric Fiselier 197800f512ebSEric Fiselier#include <__functional_03> 197900f512ebSEric Fiselier 198000f512ebSEric Fiselier#endif 1981e5407178SEric Fiselier 1982e5407178SEric Fiselier//////////////////////////////////////////////////////////////////////////////// 1983e5407178SEric Fiselier// BIND 1984e5407178SEric Fiselier//============================================================================== 1985e5407178SEric Fiselier 19863e519524SHoward Hinnanttemplate<class _Tp> struct __is_bind_expression : public false_type {}; 1987*e2f2d1edSEric Fiseliertemplate<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_bind_expression 19883e519524SHoward Hinnant : public __is_bind_expression<typename remove_cv<_Tp>::type> {}; 19893e519524SHoward Hinnant 1990a48055ceSMarshall Clow#if _LIBCPP_STD_VER > 14 1991a48055ceSMarshall Clowtemplate <class _Tp> 1992a48055ceSMarshall Clowconstexpr size_t is_bind_expression_v = is_bind_expression<_Tp>::value; 1993a48055ceSMarshall Clow#endif 1994a48055ceSMarshall Clow 19953e519524SHoward Hinnanttemplate<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {}; 1996*e2f2d1edSEric Fiseliertemplate<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_placeholder 19973e519524SHoward Hinnant : public __is_placeholder<typename remove_cv<_Tp>::type> {}; 19983e519524SHoward Hinnant 1999a48055ceSMarshall Clow#if _LIBCPP_STD_VER > 14 2000a48055ceSMarshall Clowtemplate <class _Tp> 2001a48055ceSMarshall Clowconstexpr size_t is_placeholder_v = is_placeholder<_Tp>::value; 2002a48055ceSMarshall Clow#endif 2003a48055ceSMarshall Clow 20043e519524SHoward Hinnantnamespace placeholders 20053e519524SHoward Hinnant{ 20063e519524SHoward Hinnant 2007c003db1fSHoward Hinnanttemplate <int _Np> struct __ph {}; 20083e519524SHoward Hinnant 200955533071SEric Fiselier#if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_BIND) 201055533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<1> _1; 201155533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<2> _2; 201255533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<3> _3; 201355533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<4> _4; 201455533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<5> _5; 201555533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<6> _6; 201655533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<7> _7; 201755533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<8> _8; 201855533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<9> _9; 201955533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<10> _10; 202055533071SEric Fiselier#else 202155533071SEric Fiselierconstexpr __ph<1> _1{}; 202255533071SEric Fiselierconstexpr __ph<2> _2{}; 202355533071SEric Fiselierconstexpr __ph<3> _3{}; 202455533071SEric Fiselierconstexpr __ph<4> _4{}; 202555533071SEric Fiselierconstexpr __ph<5> _5{}; 202655533071SEric Fiselierconstexpr __ph<6> _6{}; 202755533071SEric Fiselierconstexpr __ph<7> _7{}; 202855533071SEric Fiselierconstexpr __ph<8> _8{}; 202955533071SEric Fiselierconstexpr __ph<9> _9{}; 203055533071SEric Fiselierconstexpr __ph<10> _10{}; 203155533071SEric Fiselier#endif // defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_BIND) 20323e519524SHoward Hinnant 20333e519524SHoward Hinnant} // placeholders 20343e519524SHoward Hinnant 2035c003db1fSHoward Hinnanttemplate<int _Np> 2036c003db1fSHoward Hinnantstruct __is_placeholder<placeholders::__ph<_Np> > 2037c003db1fSHoward Hinnant : public integral_constant<int, _Np> {}; 20383e519524SHoward Hinnant 2039e5407178SEric Fiselier 2040e5407178SEric Fiselier#ifndef _LIBCPP_HAS_NO_VARIADICS 2041e5407178SEric Fiselier 20423e519524SHoward Hinnanttemplate <class _Tp, class _Uj> 20433e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 20443e519524SHoward Hinnant_Tp& 20453e519524SHoward Hinnant__mu(reference_wrapper<_Tp> __t, _Uj&) 20463e519524SHoward Hinnant{ 20473e519524SHoward Hinnant return __t.get(); 20483e519524SHoward Hinnant} 20493e519524SHoward Hinnant 20503e519524SHoward Hinnanttemplate <class _Ti, class ..._Uj, size_t ..._Indx> 20513e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 20522344d6c1SHoward Hinnanttypename __invoke_of<_Ti&, _Uj...>::type 20532344d6c1SHoward Hinnant__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>) 20543e519524SHoward Hinnant{ 2055f9af6140SMarshall Clow return __ti(_VSTD::forward<_Uj>(_VSTD::get<_Indx>(__uj))...); 20563e519524SHoward Hinnant} 20573e519524SHoward Hinnant 20583e519524SHoward Hinnanttemplate <class _Ti, class ..._Uj> 20593e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 2060279663c1SEric Fiseliertypename __lazy_enable_if 20613e519524SHoward Hinnant< 20623e519524SHoward Hinnant is_bind_expression<_Ti>::value, 2063279663c1SEric Fiselier __invoke_of<_Ti&, _Uj...> 20643e519524SHoward Hinnant>::type 20653e519524SHoward Hinnant__mu(_Ti& __ti, tuple<_Uj...>& __uj) 20663e519524SHoward Hinnant{ 20673e519524SHoward Hinnant typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices; 20683e519524SHoward Hinnant return __mu_expand(__ti, __uj, __indices()); 20693e519524SHoward Hinnant} 20703e519524SHoward Hinnant 20713e519524SHoward Hinnanttemplate <bool IsPh, class _Ti, class _Uj> 20723e519524SHoward Hinnantstruct __mu_return2 {}; 20733e519524SHoward Hinnant 20743e519524SHoward Hinnanttemplate <class _Ti, class _Uj> 20753e519524SHoward Hinnantstruct __mu_return2<true, _Ti, _Uj> 20763e519524SHoward Hinnant{ 20773e519524SHoward Hinnant typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type; 20783e519524SHoward Hinnant}; 20793e519524SHoward Hinnant 20803e519524SHoward Hinnanttemplate <class _Ti, class _Uj> 20813e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 20823e519524SHoward Hinnanttypename enable_if 20833e519524SHoward Hinnant< 20843e519524SHoward Hinnant 0 < is_placeholder<_Ti>::value, 20853e519524SHoward Hinnant typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type 20863e519524SHoward Hinnant>::type 20873e519524SHoward Hinnant__mu(_Ti&, _Uj& __uj) 20883e519524SHoward Hinnant{ 20893e519524SHoward Hinnant const size_t _Indx = is_placeholder<_Ti>::value - 1; 2090f9af6140SMarshall Clow return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj)); 20913e519524SHoward Hinnant} 20923e519524SHoward Hinnant 20933e519524SHoward Hinnanttemplate <class _Ti, class _Uj> 20943e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 20953e519524SHoward Hinnanttypename enable_if 20963e519524SHoward Hinnant< 20973e519524SHoward Hinnant !is_bind_expression<_Ti>::value && 20983e519524SHoward Hinnant is_placeholder<_Ti>::value == 0 && 20993e519524SHoward Hinnant !__is_reference_wrapper<_Ti>::value, 21003e519524SHoward Hinnant _Ti& 21013e519524SHoward Hinnant>::type 2102c206366fSHoward Hinnant__mu(_Ti& __ti, _Uj&) 21033e519524SHoward Hinnant{ 21043e519524SHoward Hinnant return __ti; 21053e519524SHoward Hinnant} 21063e519524SHoward Hinnant 21072fa07ae9SHoward Hinnanttemplate <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh, 21082fa07ae9SHoward Hinnant class _TupleUj> 21093e519524SHoward Hinnantstruct ____mu_return; 21103e519524SHoward Hinnant 21119bf42533SHoward Hinnanttemplate <bool _Invokable, class _Ti, class ..._Uj> 21129bf42533SHoward Hinnantstruct ____mu_return_invokable // false 21139bf42533SHoward Hinnant{ 21149bf42533SHoward Hinnant typedef __nat type; 21159bf42533SHoward Hinnant}; 21169bf42533SHoward Hinnant 21173e519524SHoward Hinnanttemplate <class _Ti, class ..._Uj> 21189bf42533SHoward Hinnantstruct ____mu_return_invokable<true, _Ti, _Uj...> 21193e519524SHoward Hinnant{ 21202344d6c1SHoward Hinnant typedef typename __invoke_of<_Ti&, _Uj...>::type type; 21213e519524SHoward Hinnant}; 21223e519524SHoward Hinnant 21239bf42533SHoward Hinnanttemplate <class _Ti, class ..._Uj> 21249bf42533SHoward Hinnantstruct ____mu_return<_Ti, false, true, false, tuple<_Uj...> > 21259bf42533SHoward Hinnant : public ____mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...> 21269bf42533SHoward Hinnant{ 21279bf42533SHoward Hinnant}; 21289bf42533SHoward Hinnant 21293e519524SHoward Hinnanttemplate <class _Ti, class _TupleUj> 21302fa07ae9SHoward Hinnantstruct ____mu_return<_Ti, false, false, true, _TupleUj> 21313e519524SHoward Hinnant{ 21323e519524SHoward Hinnant typedef typename tuple_element<is_placeholder<_Ti>::value - 1, 21333e519524SHoward Hinnant _TupleUj>::type&& type; 21343e519524SHoward Hinnant}; 21353e519524SHoward Hinnant 21363e519524SHoward Hinnanttemplate <class _Ti, class _TupleUj> 21372fa07ae9SHoward Hinnantstruct ____mu_return<_Ti, true, false, false, _TupleUj> 21382fa07ae9SHoward Hinnant{ 21392fa07ae9SHoward Hinnant typedef typename _Ti::type& type; 21402fa07ae9SHoward Hinnant}; 21412fa07ae9SHoward Hinnant 21422fa07ae9SHoward Hinnanttemplate <class _Ti, class _TupleUj> 21432fa07ae9SHoward Hinnantstruct ____mu_return<_Ti, false, false, false, _TupleUj> 21443e519524SHoward Hinnant{ 21453e519524SHoward Hinnant typedef _Ti& type; 21463e519524SHoward Hinnant}; 21473e519524SHoward Hinnant 21483e519524SHoward Hinnanttemplate <class _Ti, class _TupleUj> 21493e519524SHoward Hinnantstruct __mu_return 21503e519524SHoward Hinnant : public ____mu_return<_Ti, 21512fa07ae9SHoward Hinnant __is_reference_wrapper<_Ti>::value, 21523e519524SHoward Hinnant is_bind_expression<_Ti>::value, 2153c0c9748cSHoward Hinnant 0 < is_placeholder<_Ti>::value && 2154c0c9748cSHoward Hinnant is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value, 21553e519524SHoward Hinnant _TupleUj> 21563e519524SHoward Hinnant{ 21573e519524SHoward Hinnant}; 21583e519524SHoward Hinnant 2159c003db1fSHoward Hinnanttemplate <class _Fp, class _BoundArgs, class _TupleUj> 216035cb2b28SEric Fiselierstruct __is_valid_bind_return 2161c0c9748cSHoward Hinnant{ 2162c0c9748cSHoward Hinnant static const bool value = false; 2163c0c9748cSHoward Hinnant}; 2164c0c9748cSHoward Hinnant 2165c0c9748cSHoward Hinnanttemplate <class _Fp, class ..._BoundArgs, class _TupleUj> 216635cb2b28SEric Fiselierstruct __is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj> 2167c0c9748cSHoward Hinnant{ 2168c0c9748cSHoward Hinnant static const bool value = __invokable<_Fp, 2169c0c9748cSHoward Hinnant typename __mu_return<_BoundArgs, _TupleUj>::type...>::value; 2170c0c9748cSHoward Hinnant}; 2171c0c9748cSHoward Hinnant 2172c0c9748cSHoward Hinnanttemplate <class _Fp, class ..._BoundArgs, class _TupleUj> 217335cb2b28SEric Fiselierstruct __is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj> 2174c0c9748cSHoward Hinnant{ 2175c0c9748cSHoward Hinnant static const bool value = __invokable<_Fp, 2176c0c9748cSHoward Hinnant typename __mu_return<const _BoundArgs, _TupleUj>::type...>::value; 2177c0c9748cSHoward Hinnant}; 2178c0c9748cSHoward Hinnant 2179c0c9748cSHoward Hinnanttemplate <class _Fp, class _BoundArgs, class _TupleUj, 218035cb2b28SEric Fiselier bool = __is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value> 21813e519524SHoward Hinnantstruct __bind_return; 21823e519524SHoward Hinnant 2183c003db1fSHoward Hinnanttemplate <class _Fp, class ..._BoundArgs, class _TupleUj> 2184c0c9748cSHoward Hinnantstruct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true> 21853e519524SHoward Hinnant{ 21862344d6c1SHoward Hinnant typedef typename __invoke_of 21873e519524SHoward Hinnant < 2188c003db1fSHoward Hinnant _Fp&, 21893e519524SHoward Hinnant typename __mu_return 21903e519524SHoward Hinnant < 21913e519524SHoward Hinnant _BoundArgs, 21923e519524SHoward Hinnant _TupleUj 21933e519524SHoward Hinnant >::type... 21943e519524SHoward Hinnant >::type type; 21953e519524SHoward Hinnant}; 21963e519524SHoward Hinnant 2197c003db1fSHoward Hinnanttemplate <class _Fp, class ..._BoundArgs, class _TupleUj> 2198c0c9748cSHoward Hinnantstruct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true> 21993e519524SHoward Hinnant{ 22002344d6c1SHoward Hinnant typedef typename __invoke_of 22013e519524SHoward Hinnant < 2202c003db1fSHoward Hinnant _Fp&, 22033e519524SHoward Hinnant typename __mu_return 22043e519524SHoward Hinnant < 22053e519524SHoward Hinnant const _BoundArgs, 22063e519524SHoward Hinnant _TupleUj 22073e519524SHoward Hinnant >::type... 22083e519524SHoward Hinnant >::type type; 22093e519524SHoward Hinnant}; 22103e519524SHoward Hinnant 2211c003db1fSHoward Hinnanttemplate <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args> 22123e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 2213c003db1fSHoward Hinnanttypename __bind_return<_Fp, _BoundArgs, _Args>::type 2214c003db1fSHoward Hinnant__apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>, 22153e519524SHoward Hinnant _Args&& __args) 22163e519524SHoward Hinnant{ 2217f9af6140SMarshall Clow return __invoke(__f, __mu(_VSTD::get<_Indx>(__bound_args), __args)...); 22183e519524SHoward Hinnant} 22193e519524SHoward Hinnant 2220c003db1fSHoward Hinnanttemplate<class _Fp, class ..._BoundArgs> 22213e519524SHoward Hinnantclass __bind 2222c003db1fSHoward Hinnant : public __weak_result_type<typename decay<_Fp>::type> 22233e519524SHoward Hinnant{ 2224c0c9748cSHoward Hinnantprotected: 2225c003db1fSHoward Hinnant typedef typename decay<_Fp>::type _Fd; 22262344d6c1SHoward Hinnant typedef tuple<typename decay<_BoundArgs>::type...> _Td; 2227c0c9748cSHoward Hinnantprivate: 22282344d6c1SHoward Hinnant _Fd __f_; 22292344d6c1SHoward Hinnant _Td __bound_args_; 22303e519524SHoward Hinnant 22313e519524SHoward Hinnant typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices; 22323e519524SHoward Hinnantpublic: 2233df7aad41SHoward Hinnant template <class _Gp, class ..._BA, 2234df7aad41SHoward Hinnant class = typename enable_if 2235df7aad41SHoward Hinnant < 22369dbbf8deSHoward Hinnant is_constructible<_Fd, _Gp>::value && 22379dbbf8deSHoward Hinnant !is_same<typename remove_reference<_Gp>::type, 22389dbbf8deSHoward Hinnant __bind>::value 2239df7aad41SHoward Hinnant >::type> 22400af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 2241c003db1fSHoward Hinnant explicit __bind(_Gp&& __f, _BA&& ...__bound_args) 2242c003db1fSHoward Hinnant : __f_(_VSTD::forward<_Gp>(__f)), 2243ce48a113SHoward Hinnant __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {} 22443e519524SHoward Hinnant 22453e519524SHoward Hinnant template <class ..._Args> 22460af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 22472344d6c1SHoward Hinnant typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type 22483e519524SHoward Hinnant operator()(_Args&& ...__args) 22493e519524SHoward Hinnant { 22503e519524SHoward Hinnant return __apply_functor(__f_, __bound_args_, __indices(), 2251ce48a113SHoward Hinnant tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...)); 22523e519524SHoward Hinnant } 22533e519524SHoward Hinnant 22543e519524SHoward Hinnant template <class ..._Args> 22550af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 2256c0c9748cSHoward Hinnant typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type 22573e519524SHoward Hinnant operator()(_Args&& ...__args) const 22583e519524SHoward Hinnant { 22593e519524SHoward Hinnant return __apply_functor(__f_, __bound_args_, __indices(), 2260ce48a113SHoward Hinnant tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...)); 22613e519524SHoward Hinnant } 22623e519524SHoward Hinnant}; 22633e519524SHoward Hinnant 2264c003db1fSHoward Hinnanttemplate<class _Fp, class ..._BoundArgs> 2265c003db1fSHoward Hinnantstruct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {}; 22663e519524SHoward Hinnant 2267c003db1fSHoward Hinnanttemplate<class _Rp, class _Fp, class ..._BoundArgs> 22683e519524SHoward Hinnantclass __bind_r 2269c003db1fSHoward Hinnant : public __bind<_Fp, _BoundArgs...> 22703e519524SHoward Hinnant{ 2271c003db1fSHoward Hinnant typedef __bind<_Fp, _BoundArgs...> base; 2272c0c9748cSHoward Hinnant typedef typename base::_Fd _Fd; 2273c0c9748cSHoward Hinnant typedef typename base::_Td _Td; 22743e519524SHoward Hinnantpublic: 2275c003db1fSHoward Hinnant typedef _Rp result_type; 22763e519524SHoward Hinnant 2277086d0de1SHoward Hinnant 22789dbbf8deSHoward Hinnant template <class _Gp, class ..._BA, 22799dbbf8deSHoward Hinnant class = typename enable_if 22809dbbf8deSHoward Hinnant < 22819dbbf8deSHoward Hinnant is_constructible<_Fd, _Gp>::value && 22829dbbf8deSHoward Hinnant !is_same<typename remove_reference<_Gp>::type, 22839dbbf8deSHoward Hinnant __bind_r>::value 22849dbbf8deSHoward Hinnant >::type> 22850af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 2286c003db1fSHoward Hinnant explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args) 2287c003db1fSHoward Hinnant : base(_VSTD::forward<_Gp>(__f), 2288ce48a113SHoward Hinnant _VSTD::forward<_BA>(__bound_args)...) {} 22893e519524SHoward Hinnant 22903e519524SHoward Hinnant template <class ..._Args> 22910af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 2292c0c9748cSHoward Hinnant typename enable_if 2293c0c9748cSHoward Hinnant < 2294c0c9748cSHoward Hinnant is_convertible<typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type, 22952d15f15fSEric Fiselier result_type>::value || is_void<_Rp>::value, 22963e519524SHoward Hinnant result_type 2297c0c9748cSHoward Hinnant >::type 22983e519524SHoward Hinnant operator()(_Args&& ...__args) 22993e519524SHoward Hinnant { 23002d15f15fSEric Fiselier typedef __invoke_void_return_wrapper<_Rp> _Invoker; 23012d15f15fSEric Fiselier return _Invoker::__call(static_cast<base&>(*this), _VSTD::forward<_Args>(__args)...); 23023e519524SHoward Hinnant } 23033e519524SHoward Hinnant 23043e519524SHoward Hinnant template <class ..._Args> 23050af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 2306c0c9748cSHoward Hinnant typename enable_if 2307c0c9748cSHoward Hinnant < 2308c0c9748cSHoward Hinnant is_convertible<typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type, 23092d15f15fSEric Fiselier result_type>::value || is_void<_Rp>::value, 23103e519524SHoward Hinnant result_type 2311c0c9748cSHoward Hinnant >::type 23123e519524SHoward Hinnant operator()(_Args&& ...__args) const 23133e519524SHoward Hinnant { 23142d15f15fSEric Fiselier typedef __invoke_void_return_wrapper<_Rp> _Invoker; 23152d15f15fSEric Fiselier return _Invoker::__call(static_cast<base const&>(*this), _VSTD::forward<_Args>(__args)...); 23163e519524SHoward Hinnant } 23173e519524SHoward Hinnant}; 23183e519524SHoward Hinnant 2319c003db1fSHoward Hinnanttemplate<class _Rp, class _Fp, class ..._BoundArgs> 2320c003db1fSHoward Hinnantstruct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {}; 23213e519524SHoward Hinnant 2322c003db1fSHoward Hinnanttemplate<class _Fp, class ..._BoundArgs> 23233e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 2324c003db1fSHoward Hinnant__bind<_Fp, _BoundArgs...> 2325c003db1fSHoward Hinnantbind(_Fp&& __f, _BoundArgs&&... __bound_args) 23263e519524SHoward Hinnant{ 2327c003db1fSHoward Hinnant typedef __bind<_Fp, _BoundArgs...> type; 2328c003db1fSHoward Hinnant return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...); 23293e519524SHoward Hinnant} 23303e519524SHoward Hinnant 2331c003db1fSHoward Hinnanttemplate<class _Rp, class _Fp, class ..._BoundArgs> 23323e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 2333c003db1fSHoward Hinnant__bind_r<_Rp, _Fp, _BoundArgs...> 2334c003db1fSHoward Hinnantbind(_Fp&& __f, _BoundArgs&&... __bound_args) 23353e519524SHoward Hinnant{ 2336c003db1fSHoward Hinnant typedef __bind_r<_Rp, _Fp, _BoundArgs...> type; 2337c003db1fSHoward Hinnant return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...); 23383e519524SHoward Hinnant} 23393e519524SHoward Hinnant 23403e519524SHoward Hinnant#endif // _LIBCPP_HAS_NO_VARIADICS 23413e519524SHoward Hinnant 23423e519524SHoward Hinnanttemplate <> 2343*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS hash<bool> 23443e519524SHoward Hinnant : public unary_function<bool, size_t> 23453e519524SHoward Hinnant{ 23460af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 23476a07d6f0SHoward Hinnant size_t operator()(bool __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 23483e519524SHoward Hinnant}; 23493e519524SHoward Hinnant 23503e519524SHoward Hinnanttemplate <> 2351*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS hash<char> 23523e519524SHoward Hinnant : public unary_function<char, size_t> 23533e519524SHoward Hinnant{ 23540af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 23556a07d6f0SHoward Hinnant size_t operator()(char __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 23563e519524SHoward Hinnant}; 23573e519524SHoward Hinnant 23583e519524SHoward Hinnanttemplate <> 2359*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS hash<signed char> 23603e519524SHoward Hinnant : public unary_function<signed char, size_t> 23613e519524SHoward Hinnant{ 23620af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 23636a07d6f0SHoward Hinnant size_t operator()(signed char __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 23643e519524SHoward Hinnant}; 23653e519524SHoward Hinnant 23663e519524SHoward Hinnanttemplate <> 2367*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS hash<unsigned char> 23683e519524SHoward Hinnant : public unary_function<unsigned char, size_t> 23693e519524SHoward Hinnant{ 23700af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 23716a07d6f0SHoward Hinnant size_t operator()(unsigned char __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 23723e519524SHoward Hinnant}; 23733e519524SHoward Hinnant 23743e519524SHoward Hinnant#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS 23753e519524SHoward Hinnant 23763e519524SHoward Hinnanttemplate <> 2377*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS hash<char16_t> 23783e519524SHoward Hinnant : public unary_function<char16_t, size_t> 23793e519524SHoward Hinnant{ 23800af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 23816a07d6f0SHoward Hinnant size_t operator()(char16_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 23823e519524SHoward Hinnant}; 23833e519524SHoward Hinnant 23843e519524SHoward Hinnanttemplate <> 2385*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS hash<char32_t> 23863e519524SHoward Hinnant : public unary_function<char32_t, size_t> 23873e519524SHoward Hinnant{ 23880af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 23896a07d6f0SHoward Hinnant size_t operator()(char32_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 23903e519524SHoward Hinnant}; 23913e519524SHoward Hinnant 2392b3371f6fSHoward Hinnant#endif // _LIBCPP_HAS_NO_UNICODE_CHARS 23933e519524SHoward Hinnant 23943e519524SHoward Hinnanttemplate <> 2395*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS hash<wchar_t> 23963e519524SHoward Hinnant : public unary_function<wchar_t, size_t> 23973e519524SHoward Hinnant{ 23980af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 23996a07d6f0SHoward Hinnant size_t operator()(wchar_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 24003e519524SHoward Hinnant}; 24013e519524SHoward Hinnant 24023e519524SHoward Hinnanttemplate <> 2403*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS hash<short> 24043e519524SHoward Hinnant : public unary_function<short, size_t> 24053e519524SHoward Hinnant{ 24060af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 24076a07d6f0SHoward Hinnant size_t operator()(short __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 24083e519524SHoward Hinnant}; 24093e519524SHoward Hinnant 24103e519524SHoward Hinnanttemplate <> 2411*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS hash<unsigned short> 24123e519524SHoward Hinnant : public unary_function<unsigned short, size_t> 24133e519524SHoward Hinnant{ 24140af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 24156a07d6f0SHoward Hinnant size_t operator()(unsigned short __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 24163e519524SHoward Hinnant}; 24173e519524SHoward Hinnant 24183e519524SHoward Hinnanttemplate <> 2419*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS hash<int> 24203e519524SHoward Hinnant : public unary_function<int, size_t> 24213e519524SHoward Hinnant{ 24220af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 24236a07d6f0SHoward Hinnant size_t operator()(int __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 24243e519524SHoward Hinnant}; 24253e519524SHoward Hinnant 24263e519524SHoward Hinnanttemplate <> 2427*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS hash<unsigned int> 24283e519524SHoward Hinnant : public unary_function<unsigned int, size_t> 24293e519524SHoward Hinnant{ 24300af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 24316a07d6f0SHoward Hinnant size_t operator()(unsigned int __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 24323e519524SHoward Hinnant}; 24333e519524SHoward Hinnant 24343e519524SHoward Hinnanttemplate <> 2435*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS hash<long> 24363e519524SHoward Hinnant : public unary_function<long, size_t> 24373e519524SHoward Hinnant{ 24380af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 24396a07d6f0SHoward Hinnant size_t operator()(long __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 24403e519524SHoward Hinnant}; 24413e519524SHoward Hinnant 24423e519524SHoward Hinnanttemplate <> 2443*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS hash<unsigned long> 24443e519524SHoward Hinnant : public unary_function<unsigned long, size_t> 24453e519524SHoward Hinnant{ 24460af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 24476a07d6f0SHoward Hinnant size_t operator()(unsigned long __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 24483e519524SHoward Hinnant}; 24493e519524SHoward Hinnant 24503e519524SHoward Hinnanttemplate <> 2451*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS hash<long long> 24529b0cd149SHoward Hinnant : public __scalar_hash<long long> 24533e519524SHoward Hinnant{ 24543e519524SHoward Hinnant}; 24553e519524SHoward Hinnant 24563e519524SHoward Hinnanttemplate <> 2457*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS hash<unsigned long long> 24589b0cd149SHoward Hinnant : public __scalar_hash<unsigned long long> 24593e519524SHoward Hinnant{ 24603e519524SHoward Hinnant}; 24613e519524SHoward Hinnant 2462df691e18SEric Fiselier#ifndef _LIBCPP_HAS_NO_INT128 2463df691e18SEric Fiselier 2464df691e18SEric Fiseliertemplate <> 2465*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS hash<__int128_t> 2466df691e18SEric Fiselier : public __scalar_hash<__int128_t> 2467df691e18SEric Fiselier{ 2468df691e18SEric Fiselier}; 2469df691e18SEric Fiselier 2470df691e18SEric Fiseliertemplate <> 2471*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS hash<__uint128_t> 2472df691e18SEric Fiselier : public __scalar_hash<__uint128_t> 2473df691e18SEric Fiselier{ 2474df691e18SEric Fiselier}; 2475df691e18SEric Fiselier 2476df691e18SEric Fiselier#endif 2477df691e18SEric Fiselier 24783e519524SHoward Hinnanttemplate <> 2479*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS hash<float> 24809b0cd149SHoward Hinnant : public __scalar_hash<float> 24813e519524SHoward Hinnant{ 24820af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 24836a07d6f0SHoward Hinnant size_t operator()(float __v) const _NOEXCEPT 24843e519524SHoward Hinnant { 24859b0cd149SHoward Hinnant // -0.0 and 0.0 should return same hash 24863e519524SHoward Hinnant if (__v == 0) 24873e519524SHoward Hinnant return 0; 24889b0cd149SHoward Hinnant return __scalar_hash<float>::operator()(__v); 24893e519524SHoward Hinnant } 24903e519524SHoward Hinnant}; 24913e519524SHoward Hinnant 24923e519524SHoward Hinnanttemplate <> 2493*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS hash<double> 24949b0cd149SHoward Hinnant : public __scalar_hash<double> 24953e519524SHoward Hinnant{ 24960af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 24976a07d6f0SHoward Hinnant size_t operator()(double __v) const _NOEXCEPT 24983e519524SHoward Hinnant { 24999b0cd149SHoward Hinnant // -0.0 and 0.0 should return same hash 25003e519524SHoward Hinnant if (__v == 0) 25013e519524SHoward Hinnant return 0; 25029b0cd149SHoward Hinnant return __scalar_hash<double>::operator()(__v); 25033e519524SHoward Hinnant } 25043e519524SHoward Hinnant}; 25053e519524SHoward Hinnant 25063e519524SHoward Hinnanttemplate <> 2507*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS hash<long double> 25089b0cd149SHoward Hinnant : public __scalar_hash<long double> 25093e519524SHoward Hinnant{ 25100af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 25116a07d6f0SHoward Hinnant size_t operator()(long double __v) const _NOEXCEPT 25123e519524SHoward Hinnant { 25139b0cd149SHoward Hinnant // -0.0 and 0.0 should return same hash 25143e519524SHoward Hinnant if (__v == 0) 25153e519524SHoward Hinnant return 0; 25169b0cd149SHoward Hinnant#if defined(__i386__) 25179b0cd149SHoward Hinnant // Zero out padding bits 25187f3884d5SHoward Hinnant union 25197f3884d5SHoward Hinnant { 25209b0cd149SHoward Hinnant long double __t; 25219b0cd149SHoward Hinnant struct 25229b0cd149SHoward Hinnant { 25239b0cd149SHoward Hinnant size_t __a; 25249b0cd149SHoward Hinnant size_t __b; 25259b0cd149SHoward Hinnant size_t __c; 25267f3884d5SHoward Hinnant size_t __d; 252787a82490SEric Fiselier } __s; 25287f3884d5SHoward Hinnant } __u; 252987a82490SEric Fiselier __u.__s.__a = 0; 253087a82490SEric Fiselier __u.__s.__b = 0; 253187a82490SEric Fiselier __u.__s.__c = 0; 253287a82490SEric Fiselier __u.__s.__d = 0; 25339b0cd149SHoward Hinnant __u.__t = __v; 253487a82490SEric Fiselier return __u.__s.__a ^ __u.__s.__b ^ __u.__s.__c ^ __u.__s.__d; 25359b0cd149SHoward Hinnant#elif defined(__x86_64__) 25369b0cd149SHoward Hinnant // Zero out padding bits 25379b0cd149SHoward Hinnant union 25389b0cd149SHoward Hinnant { 25399b0cd149SHoward Hinnant long double __t; 25409b0cd149SHoward Hinnant struct 25419b0cd149SHoward Hinnant { 25429b0cd149SHoward Hinnant size_t __a; 25439b0cd149SHoward Hinnant size_t __b; 254487a82490SEric Fiselier } __s; 25457f3884d5SHoward Hinnant } __u; 254687a82490SEric Fiselier __u.__s.__a = 0; 254787a82490SEric Fiselier __u.__s.__b = 0; 25489b0cd149SHoward Hinnant __u.__t = __v; 254987a82490SEric Fiselier return __u.__s.__a ^ __u.__s.__b; 25509b0cd149SHoward Hinnant#else 25519b0cd149SHoward Hinnant return __scalar_hash<long double>::operator()(__v); 25529b0cd149SHoward Hinnant#endif 25533e519524SHoward Hinnant } 25543e519524SHoward Hinnant}; 25553e519524SHoward Hinnant 25565155a569SMarshall Clow#if _LIBCPP_STD_VER > 11 255745b7b448SEric Fiselier 255845b7b448SEric Fiseliertemplate <class _Tp, bool = is_enum<_Tp>::value> 2559*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS __enum_hash 25605155a569SMarshall Clow : public unary_function<_Tp, size_t> 25615155a569SMarshall Clow{ 25625155a569SMarshall Clow _LIBCPP_INLINE_VISIBILITY 25635155a569SMarshall Clow size_t operator()(_Tp __v) const _NOEXCEPT 25645155a569SMarshall Clow { 25655155a569SMarshall Clow typedef typename underlying_type<_Tp>::type type; 25665155a569SMarshall Clow return hash<type>{}(static_cast<type>(__v)); 25675155a569SMarshall Clow } 25685155a569SMarshall Clow}; 256945b7b448SEric Fiseliertemplate <class _Tp> 2570*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS __enum_hash<_Tp, false> { 257145b7b448SEric Fiselier __enum_hash() = delete; 257245b7b448SEric Fiselier __enum_hash(__enum_hash const&) = delete; 257345b7b448SEric Fiselier __enum_hash& operator=(__enum_hash const&) = delete; 257445b7b448SEric Fiselier}; 257545b7b448SEric Fiselier 257645b7b448SEric Fiseliertemplate <class _Tp> 2577*e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS hash : public __enum_hash<_Tp> 257845b7b448SEric Fiselier{ 257945b7b448SEric Fiselier}; 25805155a569SMarshall Clow#endif 25815155a569SMarshall Clow 25825be45129SEric Fiselier 25835be45129SEric Fiselier#if _LIBCPP_STD_VER > 14 258457257567SEric Fiselier 2585498ee00aSEric Fiselier#define __cpp_lib_invoke 201411 2586498ee00aSEric Fiselier 25875be45129SEric Fiseliertemplate <class _Fn, class ..._Args> 25885be45129SEric Fiselierresult_of_t<_Fn&&(_Args&&...)> 258957257567SEric Fiselierinvoke(_Fn&& __f, _Args&&... __args) 259057257567SEric Fiselier noexcept(noexcept(_VSTD::__invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...))) 259157257567SEric Fiselier{ 259257257567SEric Fiselier return _VSTD::__invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...); 25935be45129SEric Fiselier} 259457257567SEric Fiselier 259557257567SEric Fiseliertemplate <class _DecayFunc> 2596*e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS __not_fn_imp { 259757257567SEric Fiselier _DecayFunc __fd; 259857257567SEric Fiselier 259957257567SEric Fiselierpublic: 260057257567SEric Fiselier __not_fn_imp() = delete; 260157257567SEric Fiselier 260257257567SEric Fiselier template <class ..._Args> 260357257567SEric Fiselier _LIBCPP_INLINE_VISIBILITY 26049372d8bcSEric Fiselier auto operator()(_Args&& ...__args) & 260557257567SEric Fiselier noexcept(noexcept(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...))) 260657257567SEric Fiselier -> decltype( !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)) 260757257567SEric Fiselier { return !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); } 260857257567SEric Fiselier 260957257567SEric Fiselier template <class ..._Args> 261057257567SEric Fiselier _LIBCPP_INLINE_VISIBILITY 26119372d8bcSEric Fiselier auto operator()(_Args&& ...__args) && 26129372d8bcSEric Fiselier noexcept(noexcept(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...))) 26139372d8bcSEric Fiselier -> decltype( !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)) 26149372d8bcSEric Fiselier { return !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); } 26159372d8bcSEric Fiselier 26169372d8bcSEric Fiselier template <class ..._Args> 26179372d8bcSEric Fiselier _LIBCPP_INLINE_VISIBILITY 26189372d8bcSEric Fiselier auto operator()(_Args&& ...__args) const& 261957257567SEric Fiselier noexcept(noexcept(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...))) 262057257567SEric Fiselier -> decltype( !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)) 262157257567SEric Fiselier { return !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); } 262257257567SEric Fiselier 26239372d8bcSEric Fiselier 26249372d8bcSEric Fiselier template <class ..._Args> 26259372d8bcSEric Fiselier _LIBCPP_INLINE_VISIBILITY 26269372d8bcSEric Fiselier auto operator()(_Args&& ...__args) const&& 26279372d8bcSEric Fiselier noexcept(noexcept(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...))) 26289372d8bcSEric Fiselier -> decltype( !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)) 26299372d8bcSEric Fiselier { return !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); } 26309372d8bcSEric Fiselier 263157257567SEric Fiselierprivate: 263257257567SEric Fiselier template <class _RawFunc, 263357257567SEric Fiselier class = enable_if_t<!is_same<decay_t<_RawFunc>, __not_fn_imp>::value>> 263457257567SEric Fiselier _LIBCPP_INLINE_VISIBILITY 263557257567SEric Fiselier explicit __not_fn_imp(_RawFunc&& __rf) 263657257567SEric Fiselier : __fd(_VSTD::forward<_RawFunc>(__rf)) {} 263757257567SEric Fiselier 263857257567SEric Fiselier template <class _RawFunc> 263957257567SEric Fiselier friend inline _LIBCPP_INLINE_VISIBILITY 264057257567SEric Fiselier __not_fn_imp<decay_t<_RawFunc>> not_fn(_RawFunc&&); 264157257567SEric Fiselier}; 264257257567SEric Fiselier 264357257567SEric Fiseliertemplate <class _RawFunc> 264457257567SEric Fiselierinline _LIBCPP_INLINE_VISIBILITY 264557257567SEric Fiselier__not_fn_imp<decay_t<_RawFunc>> not_fn(_RawFunc&& __fn) { 264657257567SEric Fiselier return __not_fn_imp<decay_t<_RawFunc>>(_VSTD::forward<_RawFunc>(__fn)); 264757257567SEric Fiselier} 264857257567SEric Fiselier 26495be45129SEric Fiselier#endif 26505be45129SEric Fiselier 2651d1803b6cSHoward Hinnant// struct hash<T*> in <memory> 26523e519524SHoward Hinnant 26533e519524SHoward Hinnant_LIBCPP_END_NAMESPACE_STD 26543e519524SHoward Hinnant 26553e519524SHoward Hinnant#endif // _LIBCPP_FUNCTIONAL 2656