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 71*bb9ca6d0SLouis Dionnetemplate <class T> struct unwrap_reference; // since C++20 72*bb9ca6d0SLouis Dionnetemplate <class T> struct unwrap_ref_decay : unwrap_reference<decay_t<T>> { }; // since C++20 73*bb9ca6d0SLouis Dionnetemplate <class T> using unwrap_reference_t = typename unwrap_reference<T>::type; // since C++20 74*bb9ca6d0SLouis Dionnetemplate <class T> using unwrap_ref_decay_t = typename unwrap_ref_decay<T>::type; // since C++20 75*bb9ca6d0SLouis Dionne 7683c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14 773e519524SHoward Hinnantstruct plus : binary_function<T, T, T> 783e519524SHoward Hinnant{ 793e519524SHoward Hinnant T operator()(const T& x, const T& y) const; 803e519524SHoward Hinnant}; 813e519524SHoward Hinnant 8283c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14 833e519524SHoward Hinnantstruct minus : binary_function<T, T, T> 843e519524SHoward Hinnant{ 853e519524SHoward Hinnant T operator()(const T& x, const T& y) const; 863e519524SHoward Hinnant}; 873e519524SHoward Hinnant 8883c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14 893e519524SHoward Hinnantstruct multiplies : binary_function<T, T, T> 903e519524SHoward Hinnant{ 913e519524SHoward Hinnant T operator()(const T& x, const T& y) const; 923e519524SHoward Hinnant}; 933e519524SHoward Hinnant 9483c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14 953e519524SHoward Hinnantstruct divides : binary_function<T, T, T> 963e519524SHoward Hinnant{ 973e519524SHoward Hinnant T operator()(const T& x, const T& y) const; 983e519524SHoward Hinnant}; 993e519524SHoward Hinnant 10083c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14 1013e519524SHoward Hinnantstruct modulus : binary_function<T, T, T> 1023e519524SHoward Hinnant{ 1033e519524SHoward Hinnant T operator()(const T& x, const T& y) const; 1043e519524SHoward Hinnant}; 1053e519524SHoward Hinnant 10683c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14 1073e519524SHoward Hinnantstruct negate : unary_function<T, T> 1083e519524SHoward Hinnant{ 1093e519524SHoward Hinnant T operator()(const T& x) const; 1103e519524SHoward Hinnant}; 1113e519524SHoward Hinnant 11283c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14 1133e519524SHoward Hinnantstruct equal_to : binary_function<T, T, bool> 1143e519524SHoward Hinnant{ 1153e519524SHoward Hinnant bool operator()(const T& x, const T& y) const; 1163e519524SHoward Hinnant}; 1173e519524SHoward Hinnant 11883c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14 1193e519524SHoward Hinnantstruct not_equal_to : binary_function<T, T, bool> 1203e519524SHoward Hinnant{ 1213e519524SHoward Hinnant bool operator()(const T& x, const T& y) const; 1223e519524SHoward Hinnant}; 1233e519524SHoward Hinnant 12483c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14 1253e519524SHoward Hinnantstruct greater : binary_function<T, T, bool> 1263e519524SHoward Hinnant{ 1273e519524SHoward Hinnant bool operator()(const T& x, const T& y) const; 1283e519524SHoward Hinnant}; 1293e519524SHoward Hinnant 13083c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14 1313e519524SHoward Hinnantstruct less : binary_function<T, T, bool> 1323e519524SHoward Hinnant{ 1333e519524SHoward Hinnant bool operator()(const T& x, const T& y) const; 1343e519524SHoward Hinnant}; 1353e519524SHoward Hinnant 13683c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14 1373e519524SHoward Hinnantstruct greater_equal : binary_function<T, T, bool> 1383e519524SHoward Hinnant{ 1393e519524SHoward Hinnant bool operator()(const T& x, const T& y) const; 1403e519524SHoward Hinnant}; 1413e519524SHoward Hinnant 14283c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14 1433e519524SHoward Hinnantstruct less_equal : binary_function<T, T, bool> 1443e519524SHoward Hinnant{ 1453e519524SHoward Hinnant bool operator()(const T& x, const T& y) const; 1463e519524SHoward Hinnant}; 1473e519524SHoward Hinnant 14883c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14 1493e519524SHoward Hinnantstruct logical_and : binary_function<T, T, bool> 1503e519524SHoward Hinnant{ 1513e519524SHoward Hinnant bool operator()(const T& x, const T& y) const; 1523e519524SHoward Hinnant}; 1533e519524SHoward Hinnant 15483c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14 1553e519524SHoward Hinnantstruct logical_or : binary_function<T, T, bool> 1563e519524SHoward Hinnant{ 1573e519524SHoward Hinnant bool operator()(const T& x, const T& y) const; 1583e519524SHoward Hinnant}; 1593e519524SHoward Hinnant 16083c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14 1613e519524SHoward Hinnantstruct logical_not : unary_function<T, bool> 1623e519524SHoward Hinnant{ 1633e519524SHoward Hinnant bool operator()(const T& x) const; 1643e519524SHoward Hinnant}; 1653e519524SHoward Hinnant 16683c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14 16783c08b44SMarshall Clowstruct bit_and : unary_function<T, bool> 16883c08b44SMarshall Clow{ 16983c08b44SMarshall Clow bool operator()(const T& x, const T& y) const; 17083c08b44SMarshall Clow}; 17183c08b44SMarshall Clow 17283c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14 17383c08b44SMarshall Clowstruct bit_or : unary_function<T, bool> 17483c08b44SMarshall Clow{ 17583c08b44SMarshall Clow bool operator()(const T& x, const T& y) const; 17683c08b44SMarshall Clow}; 17783c08b44SMarshall Clow 17883c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14 17983c08b44SMarshall Clowstruct bit_xor : unary_function<T, bool> 18083c08b44SMarshall Clow{ 18183c08b44SMarshall Clow bool operator()(const T& x, const T& y) const; 18283c08b44SMarshall Clow}; 18383c08b44SMarshall Clow 18483c08b44SMarshall Clowtemplate <class T=void> // C++14 18583c08b44SMarshall Clowstruct bit_xor : unary_function<T, bool> 18683c08b44SMarshall Clow{ 18783c08b44SMarshall Clow bool operator()(const T& x) const; 18883c08b44SMarshall Clow}; 18983c08b44SMarshall Clow 1903e519524SHoward Hinnanttemplate <class Predicate> 191ea5cd3b4SLouis Dionneclass unary_negate // deprecated in C++17 1923e519524SHoward Hinnant : public unary_function<typename Predicate::argument_type, bool> 1933e519524SHoward Hinnant{ 1943e519524SHoward Hinnantpublic: 1953e519524SHoward Hinnant explicit unary_negate(const Predicate& pred); 1963e519524SHoward Hinnant bool operator()(const typename Predicate::argument_type& x) const; 1973e519524SHoward Hinnant}; 1983e519524SHoward Hinnant 199ea5cd3b4SLouis Dionnetemplate <class Predicate> // deprecated in C++17 200ea5cd3b4SLouis Dionneunary_negate<Predicate> not1(const Predicate& pred); 2013e519524SHoward Hinnant 2023e519524SHoward Hinnanttemplate <class Predicate> 203ea5cd3b4SLouis Dionneclass binary_negate // deprecated in C++17 2043e519524SHoward Hinnant : public binary_function<typename Predicate::first_argument_type, 2053e519524SHoward Hinnant typename Predicate::second_argument_type, 2063e519524SHoward Hinnant bool> 2073e519524SHoward Hinnant{ 2083e519524SHoward Hinnantpublic: 2093e519524SHoward Hinnant explicit binary_negate(const Predicate& pred); 2103e519524SHoward Hinnant bool operator()(const typename Predicate::first_argument_type& x, 2113e519524SHoward Hinnant const typename Predicate::second_argument_type& y) const; 2123e519524SHoward Hinnant}; 2133e519524SHoward Hinnant 214ea5cd3b4SLouis Dionnetemplate <class Predicate> // deprecated in C++17 215ea5cd3b4SLouis Dionnebinary_negate<Predicate> not2(const Predicate& pred); 2163e519524SHoward Hinnant 21757257567SEric Fiseliertemplate <class F> unspecified not_fn(F&& f); // C++17 21857257567SEric Fiselier 2193e519524SHoward Hinnanttemplate<class T> struct is_bind_expression; 2203e519524SHoward Hinnanttemplate<class T> struct is_placeholder; 2213e519524SHoward Hinnant 222a48055ceSMarshall Clow // See C++14 20.9.9, Function object binders 22340a01d53SMarshall Clowtemplate <class T> inline constexpr bool is_bind_expression_v 224a48055ceSMarshall Clow = is_bind_expression<T>::value; // C++17 22540a01d53SMarshall Clowtemplate <class T> inline constexpr int is_placeholder_v 226a48055ceSMarshall Clow = is_placeholder<T>::value; // C++17 227a48055ceSMarshall Clow 228a48055ceSMarshall Clow 2299b0b6d45SHoward Hinnanttemplate<class Fn, class... BoundArgs> 2309b0b6d45SHoward Hinnant unspecified bind(Fn&&, BoundArgs&&...); 2319b0b6d45SHoward Hinnanttemplate<class R, class Fn, class... BoundArgs> 2329b0b6d45SHoward Hinnant unspecified bind(Fn&&, BoundArgs&&...); 2333e519524SHoward Hinnant 2343e519524SHoward Hinnantnamespace placeholders { 2353e519524SHoward Hinnant // M is the implementation-defined number of placeholders 2363e519524SHoward Hinnant extern unspecified _1; 2373e519524SHoward Hinnant extern unspecified _2; 2383e519524SHoward Hinnant . 2393e519524SHoward Hinnant . 2403e519524SHoward Hinnant . 241c003db1fSHoward Hinnant extern unspecified _Mp; 2423e519524SHoward Hinnant} 2433e519524SHoward Hinnant 2443e519524SHoward Hinnanttemplate <class Operation> 2457d210c78SMarshall Clowclass binder1st // deprecated in C++11, removed in C++17 2463e519524SHoward Hinnant : public unary_function<typename Operation::second_argument_type, 2473e519524SHoward Hinnant typename Operation::result_type> 2483e519524SHoward Hinnant{ 2493e519524SHoward Hinnantprotected: 2503e519524SHoward Hinnant Operation op; 2513e519524SHoward Hinnant typename Operation::first_argument_type value; 2523e519524SHoward Hinnantpublic: 2533e519524SHoward Hinnant binder1st(const Operation& x, const typename Operation::first_argument_type y); 2543e519524SHoward Hinnant typename Operation::result_type operator()( typename Operation::second_argument_type& x) const; 2553e519524SHoward Hinnant typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const; 2563e519524SHoward Hinnant}; 2573e519524SHoward Hinnant 2583e519524SHoward Hinnanttemplate <class Operation, class T> 2597d210c78SMarshall Clowbinder1st<Operation> bind1st(const Operation& op, const T& x); // deprecated in C++11, removed in C++17 2603e519524SHoward Hinnant 2613e519524SHoward Hinnanttemplate <class Operation> 2627d210c78SMarshall Clowclass binder2nd // deprecated in C++11, removed in C++17 2633e519524SHoward Hinnant : public unary_function<typename Operation::first_argument_type, 2643e519524SHoward Hinnant typename Operation::result_type> 2653e519524SHoward Hinnant{ 2663e519524SHoward Hinnantprotected: 2673e519524SHoward Hinnant Operation op; 2683e519524SHoward Hinnant typename Operation::second_argument_type value; 2693e519524SHoward Hinnantpublic: 2703e519524SHoward Hinnant binder2nd(const Operation& x, const typename Operation::second_argument_type y); 2713e519524SHoward Hinnant typename Operation::result_type operator()( typename Operation::first_argument_type& x) const; 2723e519524SHoward Hinnant typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const; 2733e519524SHoward Hinnant}; 2743e519524SHoward Hinnant 2753e519524SHoward Hinnanttemplate <class Operation, class T> 2767d210c78SMarshall Clowbinder2nd<Operation> bind2nd(const Operation& op, const T& x); // deprecated in C++11, removed in C++17 2773e519524SHoward Hinnant 2787d210c78SMarshall Clowtemplate <class Arg, class Result> // deprecated in C++11, removed in C++17 2793e519524SHoward Hinnantclass pointer_to_unary_function : public unary_function<Arg, Result> 2803e519524SHoward Hinnant{ 2813e519524SHoward Hinnantpublic: 2823e519524SHoward Hinnant explicit pointer_to_unary_function(Result (*f)(Arg)); 2833e519524SHoward Hinnant Result operator()(Arg x) const; 2843e519524SHoward Hinnant}; 2853e519524SHoward Hinnant 2863e519524SHoward Hinnanttemplate <class Arg, class Result> 2877d210c78SMarshall Clowpointer_to_unary_function<Arg,Result> ptr_fun(Result (*f)(Arg)); // deprecated in C++11, removed in C++17 2883e519524SHoward Hinnant 2897d210c78SMarshall Clowtemplate <class Arg1, class Arg2, class Result> // deprecated in C++11, removed in C++17 2903e519524SHoward Hinnantclass pointer_to_binary_function : public binary_function<Arg1, Arg2, Result> 2913e519524SHoward Hinnant{ 2923e519524SHoward Hinnantpublic: 2933e519524SHoward Hinnant explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2)); 2943e519524SHoward Hinnant Result operator()(Arg1 x, Arg2 y) const; 2953e519524SHoward Hinnant}; 2963e519524SHoward Hinnant 2973e519524SHoward Hinnanttemplate <class Arg1, class Arg2, class Result> 2987d210c78SMarshall Clowpointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1,Arg2)); // deprecated in C++11, removed in C++17 2993e519524SHoward Hinnant 3007d210c78SMarshall Clowtemplate<class S, class T> // deprecated in C++11, removed in C++17 3013e519524SHoward Hinnantclass mem_fun_t : public unary_function<T*, S> 3023e519524SHoward Hinnant{ 3033e519524SHoward Hinnantpublic: 3043e519524SHoward Hinnant explicit mem_fun_t(S (T::*p)()); 3053e519524SHoward Hinnant S operator()(T* p) const; 3063e519524SHoward Hinnant}; 3073e519524SHoward Hinnant 3083e519524SHoward Hinnanttemplate<class S, class T, class A> 3097d210c78SMarshall Clowclass mem_fun1_t : public binary_function<T*, A, S> // deprecated in C++11, removed in C++17 3103e519524SHoward Hinnant{ 3113e519524SHoward Hinnantpublic: 3123e519524SHoward Hinnant explicit mem_fun1_t(S (T::*p)(A)); 3133e519524SHoward Hinnant S operator()(T* p, A x) const; 3143e519524SHoward Hinnant}; 3153e519524SHoward Hinnant 3167d210c78SMarshall Clowtemplate<class S, class T> mem_fun_t<S,T> mem_fun(S (T::*f)()); // deprecated in C++11, removed in C++17 3177d210c78SMarshall Clowtemplate<class S, class T, class A> mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A)); // deprecated in C++11, removed in C++17 3183e519524SHoward Hinnant 3193e519524SHoward Hinnanttemplate<class S, class T> 3207d210c78SMarshall Clowclass mem_fun_ref_t : public unary_function<T, S> // deprecated in C++11, removed in C++17 3213e519524SHoward Hinnant{ 3223e519524SHoward Hinnantpublic: 3233e519524SHoward Hinnant explicit mem_fun_ref_t(S (T::*p)()); 3243e519524SHoward Hinnant S operator()(T& p) const; 3253e519524SHoward Hinnant}; 3263e519524SHoward Hinnant 3273e519524SHoward Hinnanttemplate<class S, class T, class A> 3287d210c78SMarshall Clowclass mem_fun1_ref_t : public binary_function<T, A, S> // deprecated in C++11, removed in C++17 3293e519524SHoward Hinnant{ 3303e519524SHoward Hinnantpublic: 3313e519524SHoward Hinnant explicit mem_fun1_ref_t(S (T::*p)(A)); 3323e519524SHoward Hinnant S operator()(T& p, A x) const; 3333e519524SHoward Hinnant}; 3343e519524SHoward Hinnant 3357d210c78SMarshall Clowtemplate<class S, class T> mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)()); // deprecated in C++11, removed in C++17 3367d210c78SMarshall Clowtemplate<class S, class T, class A> mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A)); // deprecated in C++11, removed in C++17 3373e519524SHoward Hinnant 3383e519524SHoward Hinnanttemplate <class S, class T> 3397d210c78SMarshall Clowclass const_mem_fun_t : public unary_function<const T*, S> // deprecated in C++11, removed in C++17 3403e519524SHoward Hinnant{ 3413e519524SHoward Hinnantpublic: 3423e519524SHoward Hinnant explicit const_mem_fun_t(S (T::*p)() const); 3433e519524SHoward Hinnant S operator()(const T* p) const; 3443e519524SHoward Hinnant}; 3453e519524SHoward Hinnant 3463e519524SHoward Hinnanttemplate <class S, class T, class A> 3477d210c78SMarshall Clowclass const_mem_fun1_t : public binary_function<const T*, A, S> // deprecated in C++11, removed in C++17 3483e519524SHoward Hinnant{ 3493e519524SHoward Hinnantpublic: 3503e519524SHoward Hinnant explicit const_mem_fun1_t(S (T::*p)(A) const); 3513e519524SHoward Hinnant S operator()(const T* p, A x) const; 3523e519524SHoward Hinnant}; 3533e519524SHoward Hinnant 3547d210c78SMarshall Clowtemplate <class S, class T> const_mem_fun_t<S,T> mem_fun(S (T::*f)() const); // deprecated in C++11, removed in C++17 3557d210c78SMarshall Clowtemplate <class S, class T, class A> const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const); // deprecated in C++11, removed in C++17 3563e519524SHoward Hinnant 3573e519524SHoward Hinnanttemplate <class S, class T> 3587d210c78SMarshall Clowclass const_mem_fun_ref_t : public unary_function<T, S> // deprecated in C++11, removed in C++17 3593e519524SHoward Hinnant{ 3603e519524SHoward Hinnantpublic: 3613e519524SHoward Hinnant explicit const_mem_fun_ref_t(S (T::*p)() const); 3623e519524SHoward Hinnant S operator()(const T& p) const; 3633e519524SHoward Hinnant}; 3643e519524SHoward Hinnant 3653e519524SHoward Hinnanttemplate <class S, class T, class A> 3667d210c78SMarshall Clowclass const_mem_fun1_ref_t : public binary_function<T, A, S> // deprecated in C++11, removed in C++17 3673e519524SHoward Hinnant{ 3683e519524SHoward Hinnantpublic: 3693e519524SHoward Hinnant explicit const_mem_fun1_ref_t(S (T::*p)(A) const); 3703e519524SHoward Hinnant S operator()(const T& p, A x) const; 3713e519524SHoward Hinnant}; 3723e519524SHoward Hinnant 3737d210c78SMarshall Clowtemplate <class S, class T> const_mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)() const); // deprecated in C++11, removed in C++17 3747d210c78SMarshall Clowtemplate <class S, class T, class A> const_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const); // deprecated in C++11, removed in C++17 3753e519524SHoward Hinnant 3769b0b6d45SHoward Hinnanttemplate<class R, class T> unspecified mem_fn(R T::*); 3779b0b6d45SHoward Hinnant 3783e519524SHoward Hinnantclass bad_function_call 3793e519524SHoward Hinnant : public exception 3803e519524SHoward Hinnant{ 3813e519524SHoward Hinnant}; 3823e519524SHoward Hinnant 3839b0b6d45SHoward Hinnanttemplate<class> class function; // undefined 3843e519524SHoward Hinnant 3859b0b6d45SHoward Hinnanttemplate<class R, class... ArgTypes> 3863e519524SHoward Hinnantclass function<R(ArgTypes...)> 3873e519524SHoward Hinnant : public unary_function<T1, R> // iff sizeof...(ArgTypes) == 1 and 3883e519524SHoward Hinnant // ArgTypes contains T1 3893e519524SHoward Hinnant : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and 3903e519524SHoward Hinnant // ArgTypes contains T1 and T2 3913e519524SHoward Hinnant{ 3923e519524SHoward Hinnantpublic: 3933e519524SHoward Hinnant typedef R result_type; 3943e519524SHoward Hinnant 3959b0b6d45SHoward Hinnant // construct/copy/destroy: 3966a07d6f0SHoward Hinnant function() noexcept; 3976a07d6f0SHoward Hinnant function(nullptr_t) noexcept; 3983e519524SHoward Hinnant function(const function&); 3996a07d6f0SHoward Hinnant function(function&&) noexcept; 4003e519524SHoward Hinnant template<class F> 4013e519524SHoward Hinnant function(F); 4023e519524SHoward Hinnant template<Allocator Alloc> 4036ecac730SMarshall Clow function(allocator_arg_t, const Alloc&) noexcept; // removed in C++17 4043e519524SHoward Hinnant template<Allocator Alloc> 4056ecac730SMarshall Clow function(allocator_arg_t, const Alloc&, nullptr_t) noexcept; // removed in C++17 4063e519524SHoward Hinnant template<Allocator Alloc> 4076ecac730SMarshall Clow function(allocator_arg_t, const Alloc&, const function&); // removed in C++17 4083e519524SHoward Hinnant template<Allocator Alloc> 4096ecac730SMarshall Clow function(allocator_arg_t, const Alloc&, function&&); // removed in C++17 4103e519524SHoward Hinnant template<class F, Allocator Alloc> 4116ecac730SMarshall Clow function(allocator_arg_t, const Alloc&, F); // removed in C++17 4123e519524SHoward Hinnant 4133e519524SHoward Hinnant function& operator=(const function&); 4146a07d6f0SHoward Hinnant function& operator=(function&&) noexcept; 415af152c84SHoward Hinnant function& operator=(nullptr_t) noexcept; 4163e519524SHoward Hinnant template<class F> 4179b0b6d45SHoward Hinnant function& operator=(F&&); 4183e519524SHoward Hinnant template<class F> 4196a07d6f0SHoward Hinnant function& operator=(reference_wrapper<F>) noexcept; 4203e519524SHoward Hinnant 4213e519524SHoward Hinnant ~function(); 4223e519524SHoward Hinnant 4239b0b6d45SHoward Hinnant // function modifiers: 4246a07d6f0SHoward Hinnant void swap(function&) noexcept; 4259b0b6d45SHoward Hinnant template<class F, class Alloc> 4260aa1ccb0SMarshall Clow void assign(F&&, const Alloc&); // Removed in C++17 4273e519524SHoward Hinnant 4289b0b6d45SHoward Hinnant // function capacity: 4296a07d6f0SHoward Hinnant explicit operator bool() const noexcept; 4303e519524SHoward Hinnant 4319b0b6d45SHoward Hinnant // function invocation: 4323e519524SHoward Hinnant R operator()(ArgTypes...) const; 4333e519524SHoward Hinnant 4349b0b6d45SHoward Hinnant // function target access: 4356a07d6f0SHoward Hinnant const std::type_info& target_type() const noexcept; 4366a07d6f0SHoward Hinnant template <typename T> T* target() noexcept; 4376a07d6f0SHoward Hinnant template <typename T> const T* target() const noexcept; 4383e519524SHoward Hinnant}; 4393e519524SHoward Hinnant 4409b0b6d45SHoward Hinnant// Null pointer comparisons: 4419b0b6d45SHoward Hinnanttemplate <class R, class ... ArgTypes> 4426a07d6f0SHoward Hinnant bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept; 4433e519524SHoward Hinnant 4449b0b6d45SHoward Hinnanttemplate <class R, class ... ArgTypes> 4456a07d6f0SHoward Hinnant bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept; 4463e519524SHoward Hinnant 4479b0b6d45SHoward Hinnanttemplate <class R, class ... ArgTypes> 4486a07d6f0SHoward Hinnant bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept; 4493e519524SHoward Hinnant 4509b0b6d45SHoward Hinnanttemplate <class R, class ... ArgTypes> 4516a07d6f0SHoward Hinnant bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept; 4523e519524SHoward Hinnant 4539b0b6d45SHoward Hinnant// specialized algorithms: 4549b0b6d45SHoward Hinnanttemplate <class R, class ... ArgTypes> 4556a07d6f0SHoward Hinnant void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept; 4563e519524SHoward Hinnant 4573e519524SHoward Hinnanttemplate <class T> struct hash; 4583e519524SHoward Hinnant 4593e519524SHoward Hinnanttemplate <> struct hash<bool>; 4603e519524SHoward Hinnanttemplate <> struct hash<char>; 4613e519524SHoward Hinnanttemplate <> struct hash<signed char>; 4623e519524SHoward Hinnanttemplate <> struct hash<unsigned char>; 4633e519524SHoward Hinnanttemplate <> struct hash<char16_t>; 4643e519524SHoward Hinnanttemplate <> struct hash<char32_t>; 4653e519524SHoward Hinnanttemplate <> struct hash<wchar_t>; 4663e519524SHoward Hinnanttemplate <> struct hash<short>; 4673e519524SHoward Hinnanttemplate <> struct hash<unsigned short>; 4683e519524SHoward Hinnanttemplate <> struct hash<int>; 4693e519524SHoward Hinnanttemplate <> struct hash<unsigned int>; 4703e519524SHoward Hinnanttemplate <> struct hash<long>; 4713e519524SHoward Hinnanttemplate <> struct hash<long long>; 4723e519524SHoward Hinnanttemplate <> struct hash<unsigned long>; 4733e519524SHoward Hinnanttemplate <> struct hash<unsigned long long>; 4743e519524SHoward Hinnant 4753e519524SHoward Hinnanttemplate <> struct hash<float>; 4763e519524SHoward Hinnanttemplate <> struct hash<double>; 4773e519524SHoward Hinnanttemplate <> struct hash<long double>; 4783e519524SHoward Hinnant 4793e519524SHoward Hinnanttemplate<class T> struct hash<T*>; 480d8323168SMarshall Clowtemplate <> struct hash<nullptr_t>; // C++17 4813e519524SHoward Hinnant 4823e519524SHoward Hinnant} // std 4833e519524SHoward Hinnant 4843e519524SHoward HinnantPOLICY: For non-variadic implementations, the number of arguments is limited 4853e519524SHoward Hinnant to 3. It is hoped that the need for non-variadic implementations 4863e519524SHoward Hinnant will be minimal. 4873e519524SHoward Hinnant 4883e519524SHoward Hinnant*/ 4893e519524SHoward Hinnant 4903e519524SHoward Hinnant#include <__config> 4913e519524SHoward Hinnant#include <type_traits> 4923e519524SHoward Hinnant#include <typeinfo> 4933e519524SHoward Hinnant#include <exception> 4943e519524SHoward Hinnant#include <memory> 4953e519524SHoward Hinnant#include <tuple> 496f9127593SEric Fiselier#include <utility> 497f56972e2SMarshall Clow#include <version> 4983e519524SHoward Hinnant 4993e519524SHoward Hinnant#include <__functional_base> 5003e519524SHoward Hinnant 501073458b1SHoward Hinnant#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 5023e519524SHoward Hinnant#pragma GCC system_header 503073458b1SHoward Hinnant#endif 5043e519524SHoward Hinnant 5053e519524SHoward Hinnant_LIBCPP_BEGIN_NAMESPACE_STD 5063e519524SHoward Hinnant 50783c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 50883c08b44SMarshall Clowtemplate <class _Tp = void> 50983c08b44SMarshall Clow#else 5103e519524SHoward Hinnanttemplate <class _Tp> 51183c08b44SMarshall Clow#endif 512e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS plus : binary_function<_Tp, _Tp, _Tp> 5133e519524SHoward Hinnant{ 5143d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 5153d5134ddSMarshall Clow _Tp operator()(const _Tp& __x, const _Tp& __y) const 5163e519524SHoward Hinnant {return __x + __y;} 5173e519524SHoward Hinnant}; 5183e519524SHoward Hinnant 51983c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 52083c08b44SMarshall Clowtemplate <> 521e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS plus<void> 52283c08b44SMarshall Clow{ 52383c08b44SMarshall Clow template <class _T1, class _T2> 5243d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 5253d5134ddSMarshall Clow auto operator()(_T1&& __t, _T2&& __u) const 526a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))) 527a64f2fbcSMarshall Clow -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)) 52883c08b44SMarshall Clow { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); } 52925d3402cSMarshall Clow typedef void is_transparent; 53083c08b44SMarshall Clow}; 53183c08b44SMarshall Clow#endif 53283c08b44SMarshall Clow 53383c08b44SMarshall Clow 53483c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 53583c08b44SMarshall Clowtemplate <class _Tp = void> 53683c08b44SMarshall Clow#else 5373e519524SHoward Hinnanttemplate <class _Tp> 53883c08b44SMarshall Clow#endif 539e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS minus : binary_function<_Tp, _Tp, _Tp> 5403e519524SHoward Hinnant{ 5413d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 5423d5134ddSMarshall Clow _Tp operator()(const _Tp& __x, const _Tp& __y) const 5433e519524SHoward Hinnant {return __x - __y;} 5443e519524SHoward Hinnant}; 5453e519524SHoward Hinnant 54683c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 54783c08b44SMarshall Clowtemplate <> 548e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS minus<void> 54983c08b44SMarshall Clow{ 55083c08b44SMarshall Clow template <class _T1, class _T2> 5513d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 5523d5134ddSMarshall Clow auto operator()(_T1&& __t, _T2&& __u) const 553a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u))) 554a64f2fbcSMarshall Clow -> decltype (_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u)) 55583c08b44SMarshall Clow { return _VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u); } 55625d3402cSMarshall Clow typedef void is_transparent; 55783c08b44SMarshall Clow}; 55883c08b44SMarshall Clow#endif 55983c08b44SMarshall Clow 56083c08b44SMarshall Clow 56183c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 56283c08b44SMarshall Clowtemplate <class _Tp = void> 56383c08b44SMarshall Clow#else 5643e519524SHoward Hinnanttemplate <class _Tp> 56583c08b44SMarshall Clow#endif 566e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS multiplies : binary_function<_Tp, _Tp, _Tp> 5673e519524SHoward Hinnant{ 5683d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 5693d5134ddSMarshall Clow _Tp operator()(const _Tp& __x, const _Tp& __y) const 5703e519524SHoward Hinnant {return __x * __y;} 5713e519524SHoward Hinnant}; 5723e519524SHoward Hinnant 57383c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 57483c08b44SMarshall Clowtemplate <> 575e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS multiplies<void> 57683c08b44SMarshall Clow{ 57783c08b44SMarshall Clow template <class _T1, class _T2> 5783d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 5793d5134ddSMarshall Clow auto operator()(_T1&& __t, _T2&& __u) const 580a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u))) 581a64f2fbcSMarshall Clow -> decltype (_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u)) 58283c08b44SMarshall Clow { return _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u); } 58325d3402cSMarshall Clow typedef void is_transparent; 58483c08b44SMarshall Clow}; 58583c08b44SMarshall Clow#endif 58683c08b44SMarshall Clow 58783c08b44SMarshall Clow 58883c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 58983c08b44SMarshall Clowtemplate <class _Tp = void> 59083c08b44SMarshall Clow#else 5913e519524SHoward Hinnanttemplate <class _Tp> 59283c08b44SMarshall Clow#endif 593e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS divides : binary_function<_Tp, _Tp, _Tp> 5943e519524SHoward Hinnant{ 5953d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 5963d5134ddSMarshall Clow _Tp operator()(const _Tp& __x, const _Tp& __y) const 5973e519524SHoward Hinnant {return __x / __y;} 5983e519524SHoward Hinnant}; 5993e519524SHoward Hinnant 60083c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 60183c08b44SMarshall Clowtemplate <> 602e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS divides<void> 60383c08b44SMarshall Clow{ 60483c08b44SMarshall Clow template <class _T1, class _T2> 6053d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 6063d5134ddSMarshall Clow auto operator()(_T1&& __t, _T2&& __u) const 607a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u))) 608a64f2fbcSMarshall Clow -> decltype (_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u)) 60983c08b44SMarshall Clow { return _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u); } 61025d3402cSMarshall Clow typedef void is_transparent; 61183c08b44SMarshall Clow}; 61283c08b44SMarshall Clow#endif 61383c08b44SMarshall Clow 61483c08b44SMarshall Clow 61583c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 61683c08b44SMarshall Clowtemplate <class _Tp = void> 61783c08b44SMarshall Clow#else 6183e519524SHoward Hinnanttemplate <class _Tp> 61983c08b44SMarshall Clow#endif 620e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS modulus : binary_function<_Tp, _Tp, _Tp> 6213e519524SHoward Hinnant{ 6223d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 6233d5134ddSMarshall Clow _Tp operator()(const _Tp& __x, const _Tp& __y) const 6243e519524SHoward Hinnant {return __x % __y;} 6253e519524SHoward Hinnant}; 6263e519524SHoward Hinnant 62783c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 62883c08b44SMarshall Clowtemplate <> 629e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS modulus<void> 63083c08b44SMarshall Clow{ 63183c08b44SMarshall Clow template <class _T1, class _T2> 6323d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 6333d5134ddSMarshall Clow auto operator()(_T1&& __t, _T2&& __u) const 634a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u))) 635a64f2fbcSMarshall Clow -> decltype (_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u)) 63683c08b44SMarshall Clow { return _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u); } 63725d3402cSMarshall Clow typedef void is_transparent; 63883c08b44SMarshall Clow}; 63983c08b44SMarshall Clow#endif 64083c08b44SMarshall Clow 64183c08b44SMarshall Clow 64283c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 64383c08b44SMarshall Clowtemplate <class _Tp = void> 64483c08b44SMarshall Clow#else 6453e519524SHoward Hinnanttemplate <class _Tp> 64683c08b44SMarshall Clow#endif 647e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS negate : unary_function<_Tp, _Tp> 6483e519524SHoward Hinnant{ 6493d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 6503d5134ddSMarshall Clow _Tp operator()(const _Tp& __x) const 6513e519524SHoward Hinnant {return -__x;} 6523e519524SHoward Hinnant}; 6533e519524SHoward Hinnant 65483c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 65583c08b44SMarshall Clowtemplate <> 656e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS negate<void> 65783c08b44SMarshall Clow{ 6583e519524SHoward Hinnant template <class _Tp> 6593d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 6603d5134ddSMarshall Clow auto operator()(_Tp&& __x) const 661a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(- _VSTD::forward<_Tp>(__x))) 662a64f2fbcSMarshall Clow -> decltype (- _VSTD::forward<_Tp>(__x)) 66383c08b44SMarshall Clow { return - _VSTD::forward<_Tp>(__x); } 66425d3402cSMarshall Clow typedef void is_transparent; 66583c08b44SMarshall Clow}; 66683c08b44SMarshall Clow#endif 66783c08b44SMarshall Clow 66883c08b44SMarshall Clow 66983c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 67083c08b44SMarshall Clowtemplate <class _Tp = void> 67183c08b44SMarshall Clow#else 67283c08b44SMarshall Clowtemplate <class _Tp> 67383c08b44SMarshall Clow#endif 674e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS equal_to : binary_function<_Tp, _Tp, bool> 6753e519524SHoward Hinnant{ 6763d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 6773d5134ddSMarshall Clow bool operator()(const _Tp& __x, const _Tp& __y) const 6783e519524SHoward Hinnant {return __x == __y;} 6793e519524SHoward Hinnant}; 6803e519524SHoward Hinnant 68183c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 68283c08b44SMarshall Clowtemplate <> 683e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS equal_to<void> 68483c08b44SMarshall Clow{ 6853d5134ddSMarshall Clow template <class _T1, class _T2> 6863d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 68783c08b44SMarshall Clow auto operator()(_T1&& __t, _T2&& __u) const 688a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u))) 689a64f2fbcSMarshall Clow -> decltype (_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u)) 69083c08b44SMarshall Clow { return _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u); } 69125d3402cSMarshall Clow typedef void is_transparent; 69283c08b44SMarshall Clow}; 69383c08b44SMarshall Clow#endif 69483c08b44SMarshall Clow 69583c08b44SMarshall Clow 69683c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 69783c08b44SMarshall Clowtemplate <class _Tp = void> 69883c08b44SMarshall Clow#else 6993e519524SHoward Hinnanttemplate <class _Tp> 70083c08b44SMarshall Clow#endif 701e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS not_equal_to : binary_function<_Tp, _Tp, bool> 7023e519524SHoward Hinnant{ 7033d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 7043d5134ddSMarshall Clow bool operator()(const _Tp& __x, const _Tp& __y) const 7053e519524SHoward Hinnant {return __x != __y;} 7063e519524SHoward Hinnant}; 7073e519524SHoward Hinnant 70883c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 70983c08b44SMarshall Clowtemplate <> 710e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS not_equal_to<void> 71183c08b44SMarshall Clow{ 7123d5134ddSMarshall Clow template <class _T1, class _T2> 7133d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 71483c08b44SMarshall Clow auto operator()(_T1&& __t, _T2&& __u) const 715a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u))) 716a64f2fbcSMarshall Clow -> decltype (_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u)) 71783c08b44SMarshall Clow { return _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u); } 71825d3402cSMarshall Clow typedef void is_transparent; 71983c08b44SMarshall Clow}; 72083c08b44SMarshall Clow#endif 72183c08b44SMarshall Clow 72283c08b44SMarshall Clow 72383c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 72483c08b44SMarshall Clowtemplate <class _Tp = void> 72583c08b44SMarshall Clow#else 7263e519524SHoward Hinnanttemplate <class _Tp> 72783c08b44SMarshall Clow#endif 728e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS greater : binary_function<_Tp, _Tp, bool> 7293e519524SHoward Hinnant{ 7303d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 7313d5134ddSMarshall Clow bool operator()(const _Tp& __x, const _Tp& __y) const 7323e519524SHoward Hinnant {return __x > __y;} 7333e519524SHoward Hinnant}; 7343e519524SHoward Hinnant 73583c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 73683c08b44SMarshall Clowtemplate <> 737e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS greater<void> 73883c08b44SMarshall Clow{ 7393d5134ddSMarshall Clow template <class _T1, class _T2> 7403d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 74183c08b44SMarshall Clow auto operator()(_T1&& __t, _T2&& __u) const 742a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u))) 743a64f2fbcSMarshall Clow -> decltype (_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u)) 74483c08b44SMarshall Clow { return _VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u); } 74525d3402cSMarshall Clow typedef void is_transparent; 74683c08b44SMarshall Clow}; 74783c08b44SMarshall Clow#endif 74883c08b44SMarshall Clow 74983c08b44SMarshall Clow 75067f39647SHoward Hinnant// less in <__functional_base> 7513e519524SHoward Hinnant 75283c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 75383c08b44SMarshall Clowtemplate <class _Tp = void> 75483c08b44SMarshall Clow#else 7553e519524SHoward Hinnanttemplate <class _Tp> 75683c08b44SMarshall Clow#endif 757e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS greater_equal : binary_function<_Tp, _Tp, bool> 7583e519524SHoward Hinnant{ 7593d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 7603d5134ddSMarshall Clow bool operator()(const _Tp& __x, const _Tp& __y) const 7613e519524SHoward Hinnant {return __x >= __y;} 7623e519524SHoward Hinnant}; 7633e519524SHoward Hinnant 76483c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 76583c08b44SMarshall Clowtemplate <> 766e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS greater_equal<void> 76783c08b44SMarshall Clow{ 7683d5134ddSMarshall Clow template <class _T1, class _T2> 7693d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 77083c08b44SMarshall Clow auto operator()(_T1&& __t, _T2&& __u) const 771a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u))) 772a64f2fbcSMarshall Clow -> decltype (_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u)) 77383c08b44SMarshall Clow { return _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u); } 77425d3402cSMarshall Clow typedef void is_transparent; 77583c08b44SMarshall Clow}; 77683c08b44SMarshall Clow#endif 77783c08b44SMarshall Clow 77883c08b44SMarshall Clow 77983c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 78083c08b44SMarshall Clowtemplate <class _Tp = void> 78183c08b44SMarshall Clow#else 7823e519524SHoward Hinnanttemplate <class _Tp> 78383c08b44SMarshall Clow#endif 784e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS less_equal : binary_function<_Tp, _Tp, bool> 7853e519524SHoward Hinnant{ 7863d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 7873d5134ddSMarshall Clow bool operator()(const _Tp& __x, const _Tp& __y) const 7883e519524SHoward Hinnant {return __x <= __y;} 7893e519524SHoward Hinnant}; 7903e519524SHoward Hinnant 79183c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 79283c08b44SMarshall Clowtemplate <> 793e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS less_equal<void> 79483c08b44SMarshall Clow{ 7953d5134ddSMarshall Clow template <class _T1, class _T2> 7963d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 79783c08b44SMarshall Clow auto operator()(_T1&& __t, _T2&& __u) const 798a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u))) 799a64f2fbcSMarshall Clow -> decltype (_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u)) 80083c08b44SMarshall Clow { return _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u); } 80125d3402cSMarshall Clow typedef void is_transparent; 80283c08b44SMarshall Clow}; 80383c08b44SMarshall Clow#endif 80483c08b44SMarshall Clow 80583c08b44SMarshall Clow 80683c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 80783c08b44SMarshall Clowtemplate <class _Tp = void> 80883c08b44SMarshall Clow#else 8093e519524SHoward Hinnanttemplate <class _Tp> 81083c08b44SMarshall Clow#endif 811e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS logical_and : binary_function<_Tp, _Tp, bool> 8123e519524SHoward Hinnant{ 8133d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 8143d5134ddSMarshall Clow bool operator()(const _Tp& __x, const _Tp& __y) const 8153e519524SHoward Hinnant {return __x && __y;} 8163e519524SHoward Hinnant}; 8173e519524SHoward Hinnant 81883c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 81983c08b44SMarshall Clowtemplate <> 820e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS logical_and<void> 82183c08b44SMarshall Clow{ 8223d5134ddSMarshall Clow template <class _T1, class _T2> 8233d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 82483c08b44SMarshall Clow auto operator()(_T1&& __t, _T2&& __u) const 825a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u))) 826a64f2fbcSMarshall Clow -> decltype (_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u)) 82783c08b44SMarshall Clow { return _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u); } 82825d3402cSMarshall Clow typedef void is_transparent; 82983c08b44SMarshall Clow}; 83083c08b44SMarshall Clow#endif 83183c08b44SMarshall Clow 83283c08b44SMarshall Clow 83383c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 83483c08b44SMarshall Clowtemplate <class _Tp = void> 83583c08b44SMarshall Clow#else 8363e519524SHoward Hinnanttemplate <class _Tp> 83783c08b44SMarshall Clow#endif 838e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS logical_or : binary_function<_Tp, _Tp, bool> 8393e519524SHoward Hinnant{ 8403d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 8413d5134ddSMarshall Clow bool operator()(const _Tp& __x, const _Tp& __y) const 8423e519524SHoward Hinnant {return __x || __y;} 8433e519524SHoward Hinnant}; 8443e519524SHoward Hinnant 84583c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 84683c08b44SMarshall Clowtemplate <> 847e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS logical_or<void> 84883c08b44SMarshall Clow{ 8493d5134ddSMarshall Clow template <class _T1, class _T2> 8503d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 85183c08b44SMarshall Clow auto operator()(_T1&& __t, _T2&& __u) const 852a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u))) 853a64f2fbcSMarshall Clow -> decltype (_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u)) 85483c08b44SMarshall Clow { return _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u); } 85525d3402cSMarshall Clow typedef void is_transparent; 85683c08b44SMarshall Clow}; 85783c08b44SMarshall Clow#endif 85883c08b44SMarshall Clow 85983c08b44SMarshall Clow 86083c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 86183c08b44SMarshall Clowtemplate <class _Tp = void> 86283c08b44SMarshall Clow#else 8633e519524SHoward Hinnanttemplate <class _Tp> 86483c08b44SMarshall Clow#endif 865e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS logical_not : unary_function<_Tp, bool> 8663e519524SHoward Hinnant{ 8673d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 8683d5134ddSMarshall Clow bool operator()(const _Tp& __x) const 8693e519524SHoward Hinnant {return !__x;} 8703e519524SHoward Hinnant}; 8713e519524SHoward Hinnant 87283c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 87383c08b44SMarshall Clowtemplate <> 874e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS logical_not<void> 87583c08b44SMarshall Clow{ 8763e519524SHoward Hinnant template <class _Tp> 8773d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 8783d5134ddSMarshall Clow auto operator()(_Tp&& __x) const 879a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(!_VSTD::forward<_Tp>(__x))) 880a64f2fbcSMarshall Clow -> decltype (!_VSTD::forward<_Tp>(__x)) 88183c08b44SMarshall Clow { return !_VSTD::forward<_Tp>(__x); } 88225d3402cSMarshall Clow typedef void is_transparent; 88383c08b44SMarshall Clow}; 88483c08b44SMarshall Clow#endif 88583c08b44SMarshall Clow 88683c08b44SMarshall Clow 88783c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 88883c08b44SMarshall Clowtemplate <class _Tp = void> 88983c08b44SMarshall Clow#else 89083c08b44SMarshall Clowtemplate <class _Tp> 89183c08b44SMarshall Clow#endif 892e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS bit_and : binary_function<_Tp, _Tp, _Tp> 8933e519524SHoward Hinnant{ 8943d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 8953d5134ddSMarshall Clow _Tp operator()(const _Tp& __x, const _Tp& __y) const 8963e519524SHoward Hinnant {return __x & __y;} 8973e519524SHoward Hinnant}; 8983e519524SHoward Hinnant 89983c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 90083c08b44SMarshall Clowtemplate <> 901e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS bit_and<void> 90283c08b44SMarshall Clow{ 9033d5134ddSMarshall Clow template <class _T1, class _T2> 9043d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 90583c08b44SMarshall Clow auto operator()(_T1&& __t, _T2&& __u) const 906a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u))) 907a64f2fbcSMarshall Clow -> decltype (_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u)) 90883c08b44SMarshall Clow { return _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u); } 90925d3402cSMarshall Clow typedef void is_transparent; 91083c08b44SMarshall Clow}; 91183c08b44SMarshall Clow#endif 91283c08b44SMarshall Clow 91383c08b44SMarshall Clow 91483c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 91583c08b44SMarshall Clowtemplate <class _Tp = void> 91683c08b44SMarshall Clow#else 9173e519524SHoward Hinnanttemplate <class _Tp> 91883c08b44SMarshall Clow#endif 919e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS bit_or : binary_function<_Tp, _Tp, _Tp> 9203e519524SHoward Hinnant{ 9213d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 9223d5134ddSMarshall Clow _Tp operator()(const _Tp& __x, const _Tp& __y) const 9233e519524SHoward Hinnant {return __x | __y;} 9243e519524SHoward Hinnant}; 9253e519524SHoward Hinnant 92683c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 92783c08b44SMarshall Clowtemplate <> 928e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS bit_or<void> 92983c08b44SMarshall Clow{ 9303d5134ddSMarshall Clow template <class _T1, class _T2> 9313d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 93283c08b44SMarshall Clow auto operator()(_T1&& __t, _T2&& __u) const 933a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u))) 934a64f2fbcSMarshall Clow -> decltype (_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u)) 93583c08b44SMarshall Clow { return _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u); } 93625d3402cSMarshall Clow typedef void is_transparent; 93783c08b44SMarshall Clow}; 93883c08b44SMarshall Clow#endif 93983c08b44SMarshall Clow 94083c08b44SMarshall Clow 94183c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 94283c08b44SMarshall Clowtemplate <class _Tp = void> 94383c08b44SMarshall Clow#else 9443e519524SHoward Hinnanttemplate <class _Tp> 94583c08b44SMarshall Clow#endif 946e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS bit_xor : binary_function<_Tp, _Tp, _Tp> 9473e519524SHoward Hinnant{ 9483d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 9493d5134ddSMarshall Clow _Tp operator()(const _Tp& __x, const _Tp& __y) const 9503e519524SHoward Hinnant {return __x ^ __y;} 9513e519524SHoward Hinnant}; 9523e519524SHoward Hinnant 95383c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 95483c08b44SMarshall Clowtemplate <> 955e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS bit_xor<void> 95683c08b44SMarshall Clow{ 9573d5134ddSMarshall Clow template <class _T1, class _T2> 9583d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 95983c08b44SMarshall Clow auto operator()(_T1&& __t, _T2&& __u) const 960a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u))) 961a64f2fbcSMarshall Clow -> decltype (_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u)) 96283c08b44SMarshall Clow { return _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u); } 96325d3402cSMarshall Clow typedef void is_transparent; 96483c08b44SMarshall Clow}; 96583c08b44SMarshall Clow#endif 96683c08b44SMarshall Clow 96783c08b44SMarshall Clow 96883c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 96983c08b44SMarshall Clowtemplate <class _Tp = void> 970e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS bit_not : unary_function<_Tp, _Tp> 97183c08b44SMarshall Clow{ 9723d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 9733d5134ddSMarshall Clow _Tp operator()(const _Tp& __x) const 97483c08b44SMarshall Clow {return ~__x;} 97583c08b44SMarshall Clow}; 97683c08b44SMarshall Clow 97783c08b44SMarshall Clowtemplate <> 978e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS bit_not<void> 97983c08b44SMarshall Clow{ 98083c08b44SMarshall Clow template <class _Tp> 9813d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 9823d5134ddSMarshall Clow auto operator()(_Tp&& __x) const 983a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(~_VSTD::forward<_Tp>(__x))) 984a64f2fbcSMarshall Clow -> decltype (~_VSTD::forward<_Tp>(__x)) 98583c08b44SMarshall Clow { return ~_VSTD::forward<_Tp>(__x); } 98625d3402cSMarshall Clow typedef void is_transparent; 98783c08b44SMarshall Clow}; 98883c08b44SMarshall Clow#endif 98983c08b44SMarshall Clow 9903e519524SHoward Hinnanttemplate <class _Predicate> 991ea5cd3b4SLouis Dionneclass _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 unary_negate 9923e519524SHoward Hinnant : public unary_function<typename _Predicate::argument_type, bool> 9933e519524SHoward Hinnant{ 9943e519524SHoward Hinnant _Predicate __pred_; 9953e519524SHoward Hinnantpublic: 9963d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 9973d5134ddSMarshall Clow explicit unary_negate(const _Predicate& __pred) 9983e519524SHoward Hinnant : __pred_(__pred) {} 9993d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 10003d5134ddSMarshall Clow bool operator()(const typename _Predicate::argument_type& __x) const 10013e519524SHoward Hinnant {return !__pred_(__x);} 10023e519524SHoward Hinnant}; 10033e519524SHoward Hinnant 10043e519524SHoward Hinnanttemplate <class _Predicate> 1005ea5cd3b4SLouis Dionne_LIBCPP_DEPRECATED_IN_CXX17 inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 10063e519524SHoward Hinnantunary_negate<_Predicate> 10073e519524SHoward Hinnantnot1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);} 10083e519524SHoward Hinnant 10093e519524SHoward Hinnanttemplate <class _Predicate> 1010ea5cd3b4SLouis Dionneclass _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 binary_negate 10113e519524SHoward Hinnant : public binary_function<typename _Predicate::first_argument_type, 10123e519524SHoward Hinnant typename _Predicate::second_argument_type, 10133e519524SHoward Hinnant bool> 10143e519524SHoward Hinnant{ 10153e519524SHoward Hinnant _Predicate __pred_; 10163e519524SHoward Hinnantpublic: 10173d5134ddSMarshall Clow _LIBCPP_INLINE_VISIBILITY explicit _LIBCPP_CONSTEXPR_AFTER_CXX11 10183d5134ddSMarshall Clow binary_negate(const _Predicate& __pred) : __pred_(__pred) {} 10193d5134ddSMarshall Clow 10203d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 10213d5134ddSMarshall Clow bool operator()(const typename _Predicate::first_argument_type& __x, 10223e519524SHoward Hinnant const typename _Predicate::second_argument_type& __y) const 10233e519524SHoward Hinnant {return !__pred_(__x, __y);} 10243e519524SHoward Hinnant}; 10253e519524SHoward Hinnant 10263e519524SHoward Hinnanttemplate <class _Predicate> 1027ea5cd3b4SLouis Dionne_LIBCPP_DEPRECATED_IN_CXX17 inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 10283e519524SHoward Hinnantbinary_negate<_Predicate> 10293e519524SHoward Hinnantnot2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);} 10303e519524SHoward Hinnant 10317d210c78SMarshall Clow#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS) 10323e519524SHoward Hinnanttemplate <class __Operation> 1033ea5cd3b4SLouis Dionneclass _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 binder1st 10343e519524SHoward Hinnant : public unary_function<typename __Operation::second_argument_type, 10353e519524SHoward Hinnant typename __Operation::result_type> 10363e519524SHoward Hinnant{ 10373e519524SHoward Hinnantprotected: 10383e519524SHoward Hinnant __Operation op; 10393e519524SHoward Hinnant typename __Operation::first_argument_type value; 10403e519524SHoward Hinnantpublic: 10413e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x, 10423e519524SHoward Hinnant const typename __Operation::first_argument_type __y) 10433e519524SHoward Hinnant : op(__x), value(__y) {} 10443e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() 10453e519524SHoward Hinnant (typename __Operation::second_argument_type& __x) const 10463e519524SHoward Hinnant {return op(value, __x);} 10473e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() 10483e519524SHoward Hinnant (const typename __Operation::second_argument_type& __x) const 10493e519524SHoward Hinnant {return op(value, __x);} 10503e519524SHoward Hinnant}; 10513e519524SHoward Hinnant 10523e519524SHoward Hinnanttemplate <class __Operation, class _Tp> 1053ea5cd3b4SLouis Dionne_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY 10543e519524SHoward Hinnantbinder1st<__Operation> 10553e519524SHoward Hinnantbind1st(const __Operation& __op, const _Tp& __x) 10563e519524SHoward Hinnant {return binder1st<__Operation>(__op, __x);} 10573e519524SHoward Hinnant 10583e519524SHoward Hinnanttemplate <class __Operation> 1059ea5cd3b4SLouis Dionneclass _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 binder2nd 10603e519524SHoward Hinnant : public unary_function<typename __Operation::first_argument_type, 10613e519524SHoward Hinnant typename __Operation::result_type> 10623e519524SHoward Hinnant{ 10633e519524SHoward Hinnantprotected: 10643e519524SHoward Hinnant __Operation op; 10653e519524SHoward Hinnant typename __Operation::second_argument_type value; 10663e519524SHoward Hinnantpublic: 10670af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 10683e519524SHoward Hinnant binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y) 10693e519524SHoward Hinnant : op(__x), value(__y) {} 10703e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() 10713e519524SHoward Hinnant ( typename __Operation::first_argument_type& __x) const 10723e519524SHoward Hinnant {return op(__x, value);} 10733e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() 10743e519524SHoward Hinnant (const typename __Operation::first_argument_type& __x) const 10753e519524SHoward Hinnant {return op(__x, value);} 10763e519524SHoward Hinnant}; 10773e519524SHoward Hinnant 10783e519524SHoward Hinnanttemplate <class __Operation, class _Tp> 1079ea5cd3b4SLouis Dionne_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY 10803e519524SHoward Hinnantbinder2nd<__Operation> 10813e519524SHoward Hinnantbind2nd(const __Operation& __op, const _Tp& __x) 10823e519524SHoward Hinnant {return binder2nd<__Operation>(__op, __x);} 10833e519524SHoward Hinnant 10843e519524SHoward Hinnanttemplate <class _Arg, class _Result> 1085ea5cd3b4SLouis Dionneclass _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 pointer_to_unary_function 10860af133f9SHoward Hinnant : public unary_function<_Arg, _Result> 10873e519524SHoward Hinnant{ 10883e519524SHoward Hinnant _Result (*__f_)(_Arg); 10893e519524SHoward Hinnantpublic: 10903e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg)) 10913e519524SHoward Hinnant : __f_(__f) {} 10923e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const 10933e519524SHoward Hinnant {return __f_(__x);} 10943e519524SHoward Hinnant}; 10953e519524SHoward Hinnant 10963e519524SHoward Hinnanttemplate <class _Arg, class _Result> 1097ea5cd3b4SLouis Dionne_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY 10983e519524SHoward Hinnantpointer_to_unary_function<_Arg,_Result> 10993e519524SHoward Hinnantptr_fun(_Result (*__f)(_Arg)) 11003e519524SHoward Hinnant {return pointer_to_unary_function<_Arg,_Result>(__f);} 11013e519524SHoward Hinnant 11023e519524SHoward Hinnanttemplate <class _Arg1, class _Arg2, class _Result> 1103ea5cd3b4SLouis Dionneclass _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 pointer_to_binary_function 11040af133f9SHoward Hinnant : public binary_function<_Arg1, _Arg2, _Result> 11053e519524SHoward Hinnant{ 11063e519524SHoward Hinnant _Result (*__f_)(_Arg1, _Arg2); 11073e519524SHoward Hinnantpublic: 11083e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2)) 11093e519524SHoward Hinnant : __f_(__f) {} 11103e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const 11113e519524SHoward Hinnant {return __f_(__x, __y);} 11123e519524SHoward Hinnant}; 11133e519524SHoward Hinnant 11143e519524SHoward Hinnanttemplate <class _Arg1, class _Arg2, class _Result> 1115ea5cd3b4SLouis Dionne_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY 11163e519524SHoward Hinnantpointer_to_binary_function<_Arg1,_Arg2,_Result> 11173e519524SHoward Hinnantptr_fun(_Result (*__f)(_Arg1,_Arg2)) 11183e519524SHoward Hinnant {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);} 11193e519524SHoward Hinnant 11203e519524SHoward Hinnanttemplate<class _Sp, class _Tp> 1121ea5cd3b4SLouis Dionneclass _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun_t 1122ea5cd3b4SLouis Dionne : public unary_function<_Tp*, _Sp> 11233e519524SHoward Hinnant{ 11243e519524SHoward Hinnant _Sp (_Tp::*__p_)(); 11253e519524SHoward Hinnantpublic: 11263e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)()) 11273e519524SHoward Hinnant : __p_(__p) {} 11283e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const 11293e519524SHoward Hinnant {return (__p->*__p_)();} 11303e519524SHoward Hinnant}; 11313e519524SHoward Hinnant 11323e519524SHoward Hinnanttemplate<class _Sp, class _Tp, class _Ap> 1133ea5cd3b4SLouis Dionneclass _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun1_t 1134ea5cd3b4SLouis Dionne : public binary_function<_Tp*, _Ap, _Sp> 11353e519524SHoward Hinnant{ 11363e519524SHoward Hinnant _Sp (_Tp::*__p_)(_Ap); 11373e519524SHoward Hinnantpublic: 11383e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap)) 11393e519524SHoward Hinnant : __p_(__p) {} 11403e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const 11413e519524SHoward Hinnant {return (__p->*__p_)(__x);} 11423e519524SHoward Hinnant}; 11433e519524SHoward Hinnant 11443e519524SHoward Hinnanttemplate<class _Sp, class _Tp> 1145ea5cd3b4SLouis Dionne_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY 11463e519524SHoward Hinnantmem_fun_t<_Sp,_Tp> 11473e519524SHoward Hinnantmem_fun(_Sp (_Tp::*__f)()) 11483e519524SHoward Hinnant {return mem_fun_t<_Sp,_Tp>(__f);} 11493e519524SHoward Hinnant 11503e519524SHoward Hinnanttemplate<class _Sp, class _Tp, class _Ap> 1151ea5cd3b4SLouis Dionne_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY 11523e519524SHoward Hinnantmem_fun1_t<_Sp,_Tp,_Ap> 11533e519524SHoward Hinnantmem_fun(_Sp (_Tp::*__f)(_Ap)) 11543e519524SHoward Hinnant {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);} 11553e519524SHoward Hinnant 11563e519524SHoward Hinnanttemplate<class _Sp, class _Tp> 1157ea5cd3b4SLouis Dionneclass _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun_ref_t 1158ea5cd3b4SLouis Dionne : public unary_function<_Tp, _Sp> 11593e519524SHoward Hinnant{ 11603e519524SHoward Hinnant _Sp (_Tp::*__p_)(); 11613e519524SHoward Hinnantpublic: 11623e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)()) 11633e519524SHoward Hinnant : __p_(__p) {} 11643e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const 11653e519524SHoward Hinnant {return (__p.*__p_)();} 11663e519524SHoward Hinnant}; 11673e519524SHoward Hinnant 11683e519524SHoward Hinnanttemplate<class _Sp, class _Tp, class _Ap> 1169ea5cd3b4SLouis Dionneclass _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun1_ref_t 1170ea5cd3b4SLouis Dionne : public binary_function<_Tp, _Ap, _Sp> 11713e519524SHoward Hinnant{ 11723e519524SHoward Hinnant _Sp (_Tp::*__p_)(_Ap); 11733e519524SHoward Hinnantpublic: 11743e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap)) 11753e519524SHoward Hinnant : __p_(__p) {} 11763e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const 11773e519524SHoward Hinnant {return (__p.*__p_)(__x);} 11783e519524SHoward Hinnant}; 11793e519524SHoward Hinnant 11803e519524SHoward Hinnanttemplate<class _Sp, class _Tp> 1181ea5cd3b4SLouis Dionne_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY 11823e519524SHoward Hinnantmem_fun_ref_t<_Sp,_Tp> 11833e519524SHoward Hinnantmem_fun_ref(_Sp (_Tp::*__f)()) 11843e519524SHoward Hinnant {return mem_fun_ref_t<_Sp,_Tp>(__f);} 11853e519524SHoward Hinnant 11863e519524SHoward Hinnanttemplate<class _Sp, class _Tp, class _Ap> 1187ea5cd3b4SLouis Dionne_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY 11883e519524SHoward Hinnantmem_fun1_ref_t<_Sp,_Tp,_Ap> 11893e519524SHoward Hinnantmem_fun_ref(_Sp (_Tp::*__f)(_Ap)) 11903e519524SHoward Hinnant {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);} 11913e519524SHoward Hinnant 11923e519524SHoward Hinnanttemplate <class _Sp, class _Tp> 1193ea5cd3b4SLouis Dionneclass _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun_t 1194ea5cd3b4SLouis Dionne : public unary_function<const _Tp*, _Sp> 11953e519524SHoward Hinnant{ 11963e519524SHoward Hinnant _Sp (_Tp::*__p_)() const; 11973e519524SHoward Hinnantpublic: 11983e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const) 11993e519524SHoward Hinnant : __p_(__p) {} 12003e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const 12013e519524SHoward Hinnant {return (__p->*__p_)();} 12023e519524SHoward Hinnant}; 12033e519524SHoward Hinnant 12043e519524SHoward Hinnanttemplate <class _Sp, class _Tp, class _Ap> 1205ea5cd3b4SLouis Dionneclass _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun1_t 1206ea5cd3b4SLouis Dionne : public binary_function<const _Tp*, _Ap, _Sp> 12073e519524SHoward Hinnant{ 12083e519524SHoward Hinnant _Sp (_Tp::*__p_)(_Ap) const; 12093e519524SHoward Hinnantpublic: 12103e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const) 12113e519524SHoward Hinnant : __p_(__p) {} 12123e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const 12133e519524SHoward Hinnant {return (__p->*__p_)(__x);} 12143e519524SHoward Hinnant}; 12153e519524SHoward Hinnant 12163e519524SHoward Hinnanttemplate <class _Sp, class _Tp> 1217ea5cd3b4SLouis Dionne_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY 12183e519524SHoward Hinnantconst_mem_fun_t<_Sp,_Tp> 12193e519524SHoward Hinnantmem_fun(_Sp (_Tp::*__f)() const) 12203e519524SHoward Hinnant {return const_mem_fun_t<_Sp,_Tp>(__f);} 12213e519524SHoward Hinnant 12223e519524SHoward Hinnanttemplate <class _Sp, class _Tp, class _Ap> 1223ea5cd3b4SLouis Dionne_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY 12243e519524SHoward Hinnantconst_mem_fun1_t<_Sp,_Tp,_Ap> 12253e519524SHoward Hinnantmem_fun(_Sp (_Tp::*__f)(_Ap) const) 12263e519524SHoward Hinnant {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);} 12273e519524SHoward Hinnant 12283e519524SHoward Hinnanttemplate <class _Sp, class _Tp> 1229ea5cd3b4SLouis Dionneclass _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun_ref_t 1230ea5cd3b4SLouis Dionne : public unary_function<_Tp, _Sp> 12313e519524SHoward Hinnant{ 12323e519524SHoward Hinnant _Sp (_Tp::*__p_)() const; 12333e519524SHoward Hinnantpublic: 12343e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const) 12353e519524SHoward Hinnant : __p_(__p) {} 12363e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const 12373e519524SHoward Hinnant {return (__p.*__p_)();} 12383e519524SHoward Hinnant}; 12393e519524SHoward Hinnant 12403e519524SHoward Hinnanttemplate <class _Sp, class _Tp, class _Ap> 1241ea5cd3b4SLouis Dionneclass _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun1_ref_t 12420af133f9SHoward Hinnant : public binary_function<_Tp, _Ap, _Sp> 12433e519524SHoward Hinnant{ 12443e519524SHoward Hinnant _Sp (_Tp::*__p_)(_Ap) const; 12453e519524SHoward Hinnantpublic: 12463e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const) 12473e519524SHoward Hinnant : __p_(__p) {} 12483e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const 12493e519524SHoward Hinnant {return (__p.*__p_)(__x);} 12503e519524SHoward Hinnant}; 12513e519524SHoward Hinnant 12523e519524SHoward Hinnanttemplate <class _Sp, class _Tp> 1253ea5cd3b4SLouis Dionne_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY 12543e519524SHoward Hinnantconst_mem_fun_ref_t<_Sp,_Tp> 12553e519524SHoward Hinnantmem_fun_ref(_Sp (_Tp::*__f)() const) 12563e519524SHoward Hinnant {return const_mem_fun_ref_t<_Sp,_Tp>(__f);} 12573e519524SHoward Hinnant 12583e519524SHoward Hinnanttemplate <class _Sp, class _Tp, class _Ap> 1259ea5cd3b4SLouis Dionne_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY 12603e519524SHoward Hinnantconst_mem_fun1_ref_t<_Sp,_Tp,_Ap> 12613e519524SHoward Hinnantmem_fun_ref(_Sp (_Tp::*__f)(_Ap) const) 12623e519524SHoward Hinnant {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);} 12637d210c78SMarshall Clow#endif 12643e519524SHoward Hinnant 1265e5407178SEric Fiselier//////////////////////////////////////////////////////////////////////////////// 1266e5407178SEric Fiselier// MEMFUN 1267e5407178SEric Fiselier//============================================================================== 12683e519524SHoward Hinnant 12693e519524SHoward Hinnanttemplate <class _Tp> 12703e519524SHoward Hinnantclass __mem_fn 12713e519524SHoward Hinnant : public __weak_result_type<_Tp> 12723e519524SHoward Hinnant{ 12733e519524SHoward Hinnantpublic: 12743e519524SHoward Hinnant // types 12753e519524SHoward Hinnant typedef _Tp type; 12763e519524SHoward Hinnantprivate: 12773e519524SHoward Hinnant type __f_; 12783e519524SHoward Hinnant 12793e519524SHoward Hinnantpublic: 12803b72a6efSMarshall Clow _LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) _NOEXCEPT : __f_(__f) {} 12813e519524SHoward Hinnant 12827e23afcbSEric Fiselier#ifndef _LIBCPP_CXX03_LANG 12833e519524SHoward Hinnant // invoke 12843e519524SHoward Hinnant template <class... _ArgTypes> 12850af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 12863e519524SHoward Hinnant typename __invoke_return<type, _ArgTypes...>::type 128700f512ebSEric Fiselier operator() (_ArgTypes&&... __args) const { 1288ce48a113SHoward Hinnant return __invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...); 12893e519524SHoward Hinnant } 129000f512ebSEric Fiselier#else 129100f512ebSEric Fiselier 129200f512ebSEric Fiselier template <class _A0> 129370192a9eSEric Fiselier _LIBCPP_INLINE_VISIBILITY 129400f512ebSEric Fiselier typename __invoke_return0<type, _A0>::type 129500f512ebSEric Fiselier operator() (_A0& __a0) const { 129600f512ebSEric Fiselier return __invoke(__f_, __a0); 129700f512ebSEric Fiselier } 129800f512ebSEric Fiselier 129970192a9eSEric Fiselier template <class _A0> 130070192a9eSEric Fiselier _LIBCPP_INLINE_VISIBILITY 130170192a9eSEric Fiselier typename __invoke_return0<type, _A0 const>::type 130270192a9eSEric Fiselier operator() (_A0 const& __a0) const { 130370192a9eSEric Fiselier return __invoke(__f_, __a0); 130470192a9eSEric Fiselier } 130570192a9eSEric Fiselier 130600f512ebSEric Fiselier template <class _A0, class _A1> 130770192a9eSEric Fiselier _LIBCPP_INLINE_VISIBILITY 130800f512ebSEric Fiselier typename __invoke_return1<type, _A0, _A1>::type 130900f512ebSEric Fiselier operator() (_A0& __a0, _A1& __a1) const { 131000f512ebSEric Fiselier return __invoke(__f_, __a0, __a1); 131100f512ebSEric Fiselier } 131200f512ebSEric Fiselier 131370192a9eSEric Fiselier template <class _A0, class _A1> 131470192a9eSEric Fiselier _LIBCPP_INLINE_VISIBILITY 131570192a9eSEric Fiselier typename __invoke_return1<type, _A0 const, _A1>::type 131670192a9eSEric Fiselier operator() (_A0 const& __a0, _A1& __a1) const { 131770192a9eSEric Fiselier return __invoke(__f_, __a0, __a1); 131870192a9eSEric Fiselier } 131970192a9eSEric Fiselier 132070192a9eSEric Fiselier template <class _A0, class _A1> 132170192a9eSEric Fiselier _LIBCPP_INLINE_VISIBILITY 132270192a9eSEric Fiselier typename __invoke_return1<type, _A0, _A1 const>::type 132370192a9eSEric Fiselier operator() (_A0& __a0, _A1 const& __a1) const { 132470192a9eSEric Fiselier return __invoke(__f_, __a0, __a1); 132570192a9eSEric Fiselier } 132670192a9eSEric Fiselier 132770192a9eSEric Fiselier template <class _A0, class _A1> 132870192a9eSEric Fiselier _LIBCPP_INLINE_VISIBILITY 132970192a9eSEric Fiselier typename __invoke_return1<type, _A0 const, _A1 const>::type 133070192a9eSEric Fiselier operator() (_A0 const& __a0, _A1 const& __a1) const { 133170192a9eSEric Fiselier return __invoke(__f_, __a0, __a1); 133270192a9eSEric Fiselier } 133370192a9eSEric Fiselier 133400f512ebSEric Fiselier template <class _A0, class _A1, class _A2> 133570192a9eSEric Fiselier _LIBCPP_INLINE_VISIBILITY 133600f512ebSEric Fiselier typename __invoke_return2<type, _A0, _A1, _A2>::type 133700f512ebSEric Fiselier operator() (_A0& __a0, _A1& __a1, _A2& __a2) const { 133800f512ebSEric Fiselier return __invoke(__f_, __a0, __a1, __a2); 133900f512ebSEric Fiselier } 134070192a9eSEric Fiselier 134170192a9eSEric Fiselier template <class _A0, class _A1, class _A2> 134270192a9eSEric Fiselier _LIBCPP_INLINE_VISIBILITY 134370192a9eSEric Fiselier typename __invoke_return2<type, _A0 const, _A1, _A2>::type 134470192a9eSEric Fiselier operator() (_A0 const& __a0, _A1& __a1, _A2& __a2) const { 134570192a9eSEric Fiselier return __invoke(__f_, __a0, __a1, __a2); 134670192a9eSEric Fiselier } 134770192a9eSEric Fiselier 134870192a9eSEric Fiselier template <class _A0, class _A1, class _A2> 134970192a9eSEric Fiselier _LIBCPP_INLINE_VISIBILITY 135070192a9eSEric Fiselier typename __invoke_return2<type, _A0, _A1 const, _A2>::type 135170192a9eSEric Fiselier operator() (_A0& __a0, _A1 const& __a1, _A2& __a2) const { 135270192a9eSEric Fiselier return __invoke(__f_, __a0, __a1, __a2); 135370192a9eSEric Fiselier } 135470192a9eSEric Fiselier 135570192a9eSEric Fiselier template <class _A0, class _A1, class _A2> 135670192a9eSEric Fiselier _LIBCPP_INLINE_VISIBILITY 135770192a9eSEric Fiselier typename __invoke_return2<type, _A0, _A1, _A2 const>::type 135870192a9eSEric Fiselier operator() (_A0& __a0, _A1& __a1, _A2 const& __a2) const { 135970192a9eSEric Fiselier return __invoke(__f_, __a0, __a1, __a2); 136070192a9eSEric Fiselier } 136170192a9eSEric Fiselier 136270192a9eSEric Fiselier template <class _A0, class _A1, class _A2> 136370192a9eSEric Fiselier _LIBCPP_INLINE_VISIBILITY 136470192a9eSEric Fiselier typename __invoke_return2<type, _A0 const, _A1 const, _A2>::type 136570192a9eSEric Fiselier operator() (_A0 const& __a0, _A1 const& __a1, _A2& __a2) const { 136670192a9eSEric Fiselier return __invoke(__f_, __a0, __a1, __a2); 136770192a9eSEric Fiselier } 136870192a9eSEric Fiselier 136970192a9eSEric Fiselier template <class _A0, class _A1, class _A2> 137070192a9eSEric Fiselier _LIBCPP_INLINE_VISIBILITY 137170192a9eSEric Fiselier typename __invoke_return2<type, _A0 const, _A1, _A2 const>::type 137270192a9eSEric Fiselier operator() (_A0 const& __a0, _A1& __a1, _A2 const& __a2) const { 137370192a9eSEric Fiselier return __invoke(__f_, __a0, __a1, __a2); 137470192a9eSEric Fiselier } 137570192a9eSEric Fiselier 137670192a9eSEric Fiselier template <class _A0, class _A1, class _A2> 137770192a9eSEric Fiselier _LIBCPP_INLINE_VISIBILITY 137870192a9eSEric Fiselier typename __invoke_return2<type, _A0, _A1 const, _A2 const>::type 137970192a9eSEric Fiselier operator() (_A0& __a0, _A1 const& __a1, _A2 const& __a2) const { 138070192a9eSEric Fiselier return __invoke(__f_, __a0, __a1, __a2); 138170192a9eSEric Fiselier } 138270192a9eSEric Fiselier 138370192a9eSEric Fiselier template <class _A0, class _A1, class _A2> 138470192a9eSEric Fiselier _LIBCPP_INLINE_VISIBILITY 138570192a9eSEric Fiselier typename __invoke_return2<type, _A0 const, _A1 const, _A2 const>::type 138670192a9eSEric Fiselier operator() (_A0 const& __a0, _A1 const& __a1, _A2 const& __a2) const { 138770192a9eSEric Fiselier return __invoke(__f_, __a0, __a1, __a2); 138870192a9eSEric Fiselier } 138900f512ebSEric Fiselier#endif 13903e519524SHoward Hinnant}; 13913e519524SHoward Hinnant 1392c003db1fSHoward Hinnanttemplate<class _Rp, class _Tp> 13933e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 1394c003db1fSHoward Hinnant__mem_fn<_Rp _Tp::*> 13953b72a6efSMarshall Clowmem_fn(_Rp _Tp::* __pm) _NOEXCEPT 13963e519524SHoward Hinnant{ 1397c003db1fSHoward Hinnant return __mem_fn<_Rp _Tp::*>(__pm); 13983e519524SHoward Hinnant} 13993e519524SHoward Hinnant 1400e5407178SEric Fiselier//////////////////////////////////////////////////////////////////////////////// 1401e5407178SEric Fiselier// FUNCTION 1402e5407178SEric Fiselier//============================================================================== 1403e5407178SEric Fiselier 14043e519524SHoward Hinnant// bad_function_call 14053e519524SHoward Hinnant 14060af133f9SHoward Hinnantclass _LIBCPP_EXCEPTION_ABI bad_function_call 14073e519524SHoward Hinnant : public exception 14083e519524SHoward Hinnant{ 1409c7cd73e8SShoaib Meenai#ifdef _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION 1410c7cd73e8SShoaib Meenaipublic: 1411c7cd73e8SShoaib Meenai virtual ~bad_function_call() _NOEXCEPT; 1412c7cd73e8SShoaib Meenai 1413c7cd73e8SShoaib Meenai virtual const char* what() const _NOEXCEPT; 1414c7cd73e8SShoaib Meenai#endif 14153e519524SHoward Hinnant}; 14163e519524SHoward Hinnant 1417dc7200b4SLouis Dionne_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY 1418d437fa5cSMarshall Clowvoid __throw_bad_function_call() 1419d437fa5cSMarshall Clow{ 1420d437fa5cSMarshall Clow#ifndef _LIBCPP_NO_EXCEPTIONS 1421d437fa5cSMarshall Clow throw bad_function_call(); 1422d437fa5cSMarshall Clow#else 1423d437fa5cSMarshall Clow _VSTD::abort(); 1424d437fa5cSMarshall Clow#endif 1425d437fa5cSMarshall Clow} 1426d437fa5cSMarshall Clow 1427e2f2d1edSEric Fiseliertemplate<class _Fp> class _LIBCPP_TEMPLATE_VIS function; // undefined 14283e519524SHoward Hinnant 14293e519524SHoward Hinnantnamespace __function 14303e519524SHoward Hinnant{ 14313e519524SHoward Hinnant 1432e5407178SEric Fiseliertemplate<class _Rp> 14333e519524SHoward Hinnantstruct __maybe_derive_from_unary_function 14343e519524SHoward Hinnant{ 14353e519524SHoward Hinnant}; 14363e519524SHoward Hinnant 1437c003db1fSHoward Hinnanttemplate<class _Rp, class _A1> 1438c003db1fSHoward Hinnantstruct __maybe_derive_from_unary_function<_Rp(_A1)> 1439c003db1fSHoward Hinnant : public unary_function<_A1, _Rp> 14403e519524SHoward Hinnant{ 14413e519524SHoward Hinnant}; 14423e519524SHoward Hinnant 1443e5407178SEric Fiseliertemplate<class _Rp> 14443e519524SHoward Hinnantstruct __maybe_derive_from_binary_function 14453e519524SHoward Hinnant{ 14463e519524SHoward Hinnant}; 14473e519524SHoward Hinnant 1448c003db1fSHoward Hinnanttemplate<class _Rp, class _A1, class _A2> 1449c003db1fSHoward Hinnantstruct __maybe_derive_from_binary_function<_Rp(_A1, _A2)> 1450c003db1fSHoward Hinnant : public binary_function<_A1, _A2, _Rp> 14513e519524SHoward Hinnant{ 14523e519524SHoward Hinnant}; 14533e519524SHoward Hinnant 14540d28f784SEric Fiseliertemplate <class _Fp> 14550d28f784SEric Fiselier_LIBCPP_INLINE_VISIBILITY 14560d28f784SEric Fiselierbool __not_null(_Fp const&) { return true; } 14570d28f784SEric Fiselier 14580d28f784SEric Fiseliertemplate <class _Fp> 14590d28f784SEric Fiselier_LIBCPP_INLINE_VISIBILITY 14600d28f784SEric Fiselierbool __not_null(_Fp* __ptr) { return __ptr; } 14610d28f784SEric Fiselier 14620d28f784SEric Fiseliertemplate <class _Ret, class _Class> 14630d28f784SEric Fiselier_LIBCPP_INLINE_VISIBILITY 14640d28f784SEric Fiselierbool __not_null(_Ret _Class::*__ptr) { return __ptr; } 14650d28f784SEric Fiselier 14660d28f784SEric Fiseliertemplate <class _Fp> 14670d28f784SEric Fiselier_LIBCPP_INLINE_VISIBILITY 14680d28f784SEric Fiselierbool __not_null(function<_Fp> const& __f) { return !!__f; } 14690d28f784SEric Fiselier 1470e5407178SEric Fiselier} // namespace __function 1471e5407178SEric Fiselier 14727e23afcbSEric Fiselier#ifndef _LIBCPP_CXX03_LANG 1473e5407178SEric Fiselier 1474e5407178SEric Fiseliernamespace __function { 1475e5407178SEric Fiselier 14763e519524SHoward Hinnanttemplate<class _Fp> class __base; 14773e519524SHoward Hinnant 1478c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 1479c003db1fSHoward Hinnantclass __base<_Rp(_ArgTypes...)> 14803e519524SHoward Hinnant{ 14813e519524SHoward Hinnant __base(const __base&); 14823e519524SHoward Hinnant __base& operator=(const __base&); 14833e519524SHoward Hinnantpublic: 14840af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY __base() {} 14850af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY virtual ~__base() {} 14863e519524SHoward Hinnant virtual __base* __clone() const = 0; 14873e519524SHoward Hinnant virtual void __clone(__base*) const = 0; 14886a07d6f0SHoward Hinnant virtual void destroy() _NOEXCEPT = 0; 14896a07d6f0SHoward Hinnant virtual void destroy_deallocate() _NOEXCEPT = 0; 1490c003db1fSHoward Hinnant virtual _Rp operator()(_ArgTypes&& ...) = 0; 149154b409fdSHoward Hinnant#ifndef _LIBCPP_NO_RTTI 14926a07d6f0SHoward Hinnant virtual const void* target(const type_info&) const _NOEXCEPT = 0; 14936a07d6f0SHoward Hinnant virtual const std::type_info& target_type() const _NOEXCEPT = 0; 1494b3371f6fSHoward Hinnant#endif // _LIBCPP_NO_RTTI 14953e519524SHoward Hinnant}; 14963e519524SHoward Hinnant 14973e519524SHoward Hinnanttemplate<class _FD, class _Alloc, class _FB> class __func; 14983e519524SHoward Hinnant 1499c003db1fSHoward Hinnanttemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 1500c003db1fSHoward Hinnantclass __func<_Fp, _Alloc, _Rp(_ArgTypes...)> 1501c003db1fSHoward Hinnant : public __base<_Rp(_ArgTypes...)> 15023e519524SHoward Hinnant{ 1503c003db1fSHoward Hinnant __compressed_pair<_Fp, _Alloc> __f_; 15043e519524SHoward Hinnantpublic: 15050af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 15069bb1429fSHoward Hinnant explicit __func(_Fp&& __f) 15079bb1429fSHoward Hinnant : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)), 15089bb1429fSHoward Hinnant _VSTD::forward_as_tuple()) {} 15090af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 15109bb1429fSHoward Hinnant explicit __func(const _Fp& __f, const _Alloc& __a) 15119bb1429fSHoward Hinnant : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f), 15129bb1429fSHoward Hinnant _VSTD::forward_as_tuple(__a)) {} 15139bb1429fSHoward Hinnant 15149bb1429fSHoward Hinnant _LIBCPP_INLINE_VISIBILITY 15159bb1429fSHoward Hinnant explicit __func(const _Fp& __f, _Alloc&& __a) 15169bb1429fSHoward Hinnant : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f), 15179bb1429fSHoward Hinnant _VSTD::forward_as_tuple(_VSTD::move(__a))) {} 15189bb1429fSHoward Hinnant 15199bb1429fSHoward Hinnant _LIBCPP_INLINE_VISIBILITY 15209bb1429fSHoward Hinnant explicit __func(_Fp&& __f, _Alloc&& __a) 15219bb1429fSHoward Hinnant : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)), 15229bb1429fSHoward Hinnant _VSTD::forward_as_tuple(_VSTD::move(__a))) {} 1523c003db1fSHoward Hinnant virtual __base<_Rp(_ArgTypes...)>* __clone() const; 1524c003db1fSHoward Hinnant virtual void __clone(__base<_Rp(_ArgTypes...)>*) const; 15256a07d6f0SHoward Hinnant virtual void destroy() _NOEXCEPT; 15266a07d6f0SHoward Hinnant virtual void destroy_deallocate() _NOEXCEPT; 1527c003db1fSHoward Hinnant virtual _Rp operator()(_ArgTypes&& ... __arg); 152854b409fdSHoward Hinnant#ifndef _LIBCPP_NO_RTTI 15296a07d6f0SHoward Hinnant virtual const void* target(const type_info&) const _NOEXCEPT; 15306a07d6f0SHoward Hinnant virtual const std::type_info& target_type() const _NOEXCEPT; 1531b3371f6fSHoward Hinnant#endif // _LIBCPP_NO_RTTI 15323e519524SHoward Hinnant}; 15333e519524SHoward Hinnant 1534c003db1fSHoward Hinnanttemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 1535c003db1fSHoward Hinnant__base<_Rp(_ArgTypes...)>* 1536c003db1fSHoward Hinnant__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const 15373e519524SHoward Hinnant{ 15386d370568SEric Fiselier typedef allocator_traits<_Alloc> __alloc_traits; 15391f508014SMarshall Clow typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; 1540c003db1fSHoward Hinnant _Ap __a(__f_.second()); 1541c003db1fSHoward Hinnant typedef __allocator_destructor<_Ap> _Dp; 1542c003db1fSHoward Hinnant unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); 15433e519524SHoward Hinnant ::new (__hold.get()) __func(__f_.first(), _Alloc(__a)); 15443e519524SHoward Hinnant return __hold.release(); 15453e519524SHoward Hinnant} 15463e519524SHoward Hinnant 1547c003db1fSHoward Hinnanttemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 15483e519524SHoward Hinnantvoid 1549c003db1fSHoward Hinnant__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const 15503e519524SHoward Hinnant{ 15513e519524SHoward Hinnant ::new (__p) __func(__f_.first(), __f_.second()); 15523e519524SHoward Hinnant} 15533e519524SHoward Hinnant 1554c003db1fSHoward Hinnanttemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 15553e519524SHoward Hinnantvoid 1556c003db1fSHoward Hinnant__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPT 15573e519524SHoward Hinnant{ 1558c003db1fSHoward Hinnant __f_.~__compressed_pair<_Fp, _Alloc>(); 15593e519524SHoward Hinnant} 15603e519524SHoward Hinnant 1561c003db1fSHoward Hinnanttemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 15623e519524SHoward Hinnantvoid 1563c003db1fSHoward Hinnant__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT 15643e519524SHoward Hinnant{ 15656d370568SEric Fiselier typedef allocator_traits<_Alloc> __alloc_traits; 15661f508014SMarshall Clow typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; 1567c003db1fSHoward Hinnant _Ap __a(__f_.second()); 1568c003db1fSHoward Hinnant __f_.~__compressed_pair<_Fp, _Alloc>(); 15693e519524SHoward Hinnant __a.deallocate(this, 1); 15703e519524SHoward Hinnant} 15713e519524SHoward Hinnant 1572c003db1fSHoward Hinnanttemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 1573c003db1fSHoward Hinnant_Rp 1574c003db1fSHoward Hinnant__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg) 15753e519524SHoward Hinnant{ 157654519a6bSEric Fiselier typedef __invoke_void_return_wrapper<_Rp> _Invoker; 157754519a6bSEric Fiselier return _Invoker::__call(__f_.first(), _VSTD::forward<_ArgTypes>(__arg)...); 15783e519524SHoward Hinnant} 15793e519524SHoward Hinnant 158054b409fdSHoward Hinnant#ifndef _LIBCPP_NO_RTTI 158154b409fdSHoward Hinnant 1582c003db1fSHoward Hinnanttemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 15833e519524SHoward Hinnantconst void* 1584c003db1fSHoward Hinnant__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT 15853e519524SHoward Hinnant{ 1586c003db1fSHoward Hinnant if (__ti == typeid(_Fp)) 15873e519524SHoward Hinnant return &__f_.first(); 15883e519524SHoward Hinnant return (const void*)0; 15893e519524SHoward Hinnant} 15903e519524SHoward Hinnant 1591c003db1fSHoward Hinnanttemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 15923e519524SHoward Hinnantconst std::type_info& 1593c003db1fSHoward Hinnant__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT 15943e519524SHoward Hinnant{ 1595c003db1fSHoward Hinnant return typeid(_Fp); 15963e519524SHoward Hinnant} 15973e519524SHoward Hinnant 1598b3371f6fSHoward Hinnant#endif // _LIBCPP_NO_RTTI 159954b409fdSHoward Hinnant 16003e519524SHoward Hinnant} // __function 16013e519524SHoward Hinnant 1602c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 1603e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS function<_Rp(_ArgTypes...)> 1604c003db1fSHoward Hinnant : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>, 1605c003db1fSHoward Hinnant public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)> 16063e519524SHoward Hinnant{ 1607c003db1fSHoward Hinnant typedef __function::__base<_Rp(_ArgTypes...)> __base; 16088d3e7974SHoward Hinnant typename aligned_storage<3*sizeof(void*)>::type __buf_; 16093e519524SHoward Hinnant __base* __f_; 16103e519524SHoward Hinnant 16113e58a6a7SEvgeniy Stepanov _LIBCPP_NO_CFI static __base *__as_base(void *p) { 16123e58a6a7SEvgeniy Stepanov return reinterpret_cast<__base*>(p); 16133e58a6a7SEvgeniy Stepanov } 16143e58a6a7SEvgeniy Stepanov 161594d55511SEric Fiselier template <class _Fp, bool = __lazy_and< 161694d55511SEric Fiselier integral_constant<bool, !is_same<__uncvref_t<_Fp>, function>::value>, 161794d55511SEric Fiselier __invokable<_Fp&, _ArgTypes...> 161894d55511SEric Fiselier >::value> 1619542b2507SHoward Hinnant struct __callable; 1620c003db1fSHoward Hinnant template <class _Fp> 1621c003db1fSHoward Hinnant struct __callable<_Fp, true> 1622542b2507SHoward Hinnant { 162354519a6bSEric Fiselier static const bool value = is_same<void, _Rp>::value || 1624c003db1fSHoward Hinnant is_convertible<typename __invoke_of<_Fp&, _ArgTypes...>::type, 1625c003db1fSHoward Hinnant _Rp>::value; 1626542b2507SHoward Hinnant }; 1627c003db1fSHoward Hinnant template <class _Fp> 1628c003db1fSHoward Hinnant struct __callable<_Fp, false> 1629542b2507SHoward Hinnant { 1630542b2507SHoward Hinnant static const bool value = false; 1631542b2507SHoward Hinnant }; 163294d55511SEric Fiselier 163394d55511SEric Fiselier template <class _Fp> 163494d55511SEric Fiselier using _EnableIfCallable = typename enable_if<__callable<_Fp>::value>::type; 16353e519524SHoward Hinnantpublic: 1636c003db1fSHoward Hinnant typedef _Rp result_type; 16373e519524SHoward Hinnant 16389b0b6d45SHoward Hinnant // construct/copy/destroy: 16390af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 16406a07d6f0SHoward Hinnant function() _NOEXCEPT : __f_(0) {} 16410af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 16426a07d6f0SHoward Hinnant function(nullptr_t) _NOEXCEPT : __f_(0) {} 16433e519524SHoward Hinnant function(const function&); 16446a07d6f0SHoward Hinnant function(function&&) _NOEXCEPT; 164594d55511SEric Fiselier template<class _Fp, class = _EnableIfCallable<_Fp>> 1646fd32ab92SEric Fiselier function(_Fp); 16473e519524SHoward Hinnant 16486ecac730SMarshall Clow#if _LIBCPP_STD_VER <= 14 16499b0b6d45SHoward Hinnant template<class _Alloc> 16500af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 16516a07d6f0SHoward Hinnant function(allocator_arg_t, const _Alloc&) _NOEXCEPT : __f_(0) {} 16529b0b6d45SHoward Hinnant template<class _Alloc> 16530af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 16546a07d6f0SHoward Hinnant function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT : __f_(0) {} 16559b0b6d45SHoward Hinnant template<class _Alloc> 16569b0b6d45SHoward Hinnant function(allocator_arg_t, const _Alloc&, const function&); 16579b0b6d45SHoward Hinnant template<class _Alloc> 16589b0b6d45SHoward Hinnant function(allocator_arg_t, const _Alloc&, function&&); 165994d55511SEric Fiselier template<class _Fp, class _Alloc, class = _EnableIfCallable<_Fp>> 1660fd32ab92SEric Fiselier function(allocator_arg_t, const _Alloc& __a, _Fp __f); 16616ecac730SMarshall Clow#endif 16623e519524SHoward Hinnant 16633e519524SHoward Hinnant function& operator=(const function&); 16646a07d6f0SHoward Hinnant function& operator=(function&&) _NOEXCEPT; 16656a07d6f0SHoward Hinnant function& operator=(nullptr_t) _NOEXCEPT; 166694d55511SEric Fiselier template<class _Fp, class = _EnableIfCallable<_Fp>> 166794d55511SEric Fiselier function& operator=(_Fp&&); 16683e519524SHoward Hinnant 16693e519524SHoward Hinnant ~function(); 16703e519524SHoward Hinnant 16719b0b6d45SHoward Hinnant // function modifiers: 16726a07d6f0SHoward Hinnant void swap(function&) _NOEXCEPT; 16730aa1ccb0SMarshall Clow 16740aa1ccb0SMarshall Clow#if _LIBCPP_STD_VER <= 14 1675c003db1fSHoward Hinnant template<class _Fp, class _Alloc> 16760af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 1677c003db1fSHoward Hinnant void assign(_Fp&& __f, const _Alloc& __a) 1678c003db1fSHoward Hinnant {function(allocator_arg, __a, _VSTD::forward<_Fp>(__f)).swap(*this);} 16790aa1ccb0SMarshall Clow#endif 16803e519524SHoward Hinnant 16819b0b6d45SHoward Hinnant // function capacity: 16820af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 1683f2f2d8b9SHoward Hinnant _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return __f_;} 16843e519524SHoward Hinnant 16853e519524SHoward Hinnant // deleted overloads close possible hole in the type system 16863e519524SHoward Hinnant template<class _R2, class... _ArgTypes2> 168737030a77SHoward Hinnant bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete; 16883e519524SHoward Hinnant template<class _R2, class... _ArgTypes2> 168937030a77SHoward Hinnant bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete; 16903e519524SHoward Hinnantpublic: 16919b0b6d45SHoward Hinnant // function invocation: 1692c003db1fSHoward Hinnant _Rp operator()(_ArgTypes...) const; 16933e519524SHoward Hinnant 169454b409fdSHoward Hinnant#ifndef _LIBCPP_NO_RTTI 16959b0b6d45SHoward Hinnant // function target access: 16966a07d6f0SHoward Hinnant const std::type_info& target_type() const _NOEXCEPT; 1697c003db1fSHoward Hinnant template <typename _Tp> _Tp* target() _NOEXCEPT; 1698c003db1fSHoward Hinnant template <typename _Tp> const _Tp* target() const _NOEXCEPT; 1699b3371f6fSHoward Hinnant#endif // _LIBCPP_NO_RTTI 17003e519524SHoward Hinnant}; 17013e519524SHoward Hinnant 1702c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 1703c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::function(const function& __f) 17043e519524SHoward Hinnant{ 17053e519524SHoward Hinnant if (__f.__f_ == 0) 17063e519524SHoward Hinnant __f_ = 0; 17073e58a6a7SEvgeniy Stepanov else if ((void *)__f.__f_ == &__f.__buf_) 17083e519524SHoward Hinnant { 17093e58a6a7SEvgeniy Stepanov __f_ = __as_base(&__buf_); 17103e519524SHoward Hinnant __f.__f_->__clone(__f_); 17113e519524SHoward Hinnant } 17123e519524SHoward Hinnant else 17133e519524SHoward Hinnant __f_ = __f.__f_->__clone(); 17143e519524SHoward Hinnant} 17153e519524SHoward Hinnant 17166ecac730SMarshall Clow#if _LIBCPP_STD_VER <= 14 1717c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 17189b0b6d45SHoward Hinnanttemplate <class _Alloc> 1719c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, 17209b0b6d45SHoward Hinnant const function& __f) 17219b0b6d45SHoward Hinnant{ 17229b0b6d45SHoward Hinnant if (__f.__f_ == 0) 17239b0b6d45SHoward Hinnant __f_ = 0; 17243e58a6a7SEvgeniy Stepanov else if ((void *)__f.__f_ == &__f.__buf_) 17259b0b6d45SHoward Hinnant { 17263e58a6a7SEvgeniy Stepanov __f_ = __as_base(&__buf_); 17279b0b6d45SHoward Hinnant __f.__f_->__clone(__f_); 17289b0b6d45SHoward Hinnant } 17299b0b6d45SHoward Hinnant else 17309b0b6d45SHoward Hinnant __f_ = __f.__f_->__clone(); 17319b0b6d45SHoward Hinnant} 17326ecac730SMarshall Clow#endif 17339b0b6d45SHoward Hinnant 1734c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 1735c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT 17363e519524SHoward Hinnant{ 17373e519524SHoward Hinnant if (__f.__f_ == 0) 17383e519524SHoward Hinnant __f_ = 0; 17393e58a6a7SEvgeniy Stepanov else if ((void *)__f.__f_ == &__f.__buf_) 17403e519524SHoward Hinnant { 17413e58a6a7SEvgeniy Stepanov __f_ = __as_base(&__buf_); 17423e519524SHoward Hinnant __f.__f_->__clone(__f_); 17433e519524SHoward Hinnant } 17443e519524SHoward Hinnant else 17453e519524SHoward Hinnant { 17463e519524SHoward Hinnant __f_ = __f.__f_; 17473e519524SHoward Hinnant __f.__f_ = 0; 17483e519524SHoward Hinnant } 17493e519524SHoward Hinnant} 17503e519524SHoward Hinnant 17516ecac730SMarshall Clow#if _LIBCPP_STD_VER <= 14 1752c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 17539b0b6d45SHoward Hinnanttemplate <class _Alloc> 1754c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, 17559b0b6d45SHoward Hinnant function&& __f) 17569b0b6d45SHoward Hinnant{ 17579b0b6d45SHoward Hinnant if (__f.__f_ == 0) 17589b0b6d45SHoward Hinnant __f_ = 0; 17593e58a6a7SEvgeniy Stepanov else if ((void *)__f.__f_ == &__f.__buf_) 17609b0b6d45SHoward Hinnant { 17613e58a6a7SEvgeniy Stepanov __f_ = __as_base(&__buf_); 17629b0b6d45SHoward Hinnant __f.__f_->__clone(__f_); 17639b0b6d45SHoward Hinnant } 17649b0b6d45SHoward Hinnant else 17659b0b6d45SHoward Hinnant { 17669b0b6d45SHoward Hinnant __f_ = __f.__f_; 17679b0b6d45SHoward Hinnant __f.__f_ = 0; 17689b0b6d45SHoward Hinnant } 17699b0b6d45SHoward Hinnant} 17706ecac730SMarshall Clow#endif 17719b0b6d45SHoward Hinnant 1772c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 1773fd32ab92SEric Fiseliertemplate <class _Fp, class> 1774fd32ab92SEric Fiselierfunction<_Rp(_ArgTypes...)>::function(_Fp __f) 17753e519524SHoward Hinnant : __f_(0) 17763e519524SHoward Hinnant{ 17770d28f784SEric Fiselier if (__function::__not_null(__f)) 17783e519524SHoward Hinnant { 1779c003db1fSHoward Hinnant typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_ArgTypes...)> _FF; 1780c003db1fSHoward Hinnant if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value) 17813e519524SHoward Hinnant { 17823e58a6a7SEvgeniy Stepanov __f_ = ::new((void*)&__buf_) _FF(_VSTD::move(__f)); 17833e519524SHoward Hinnant } 17843e519524SHoward Hinnant else 17853e519524SHoward Hinnant { 1786c003db1fSHoward Hinnant typedef allocator<_FF> _Ap; 1787c003db1fSHoward Hinnant _Ap __a; 1788c003db1fSHoward Hinnant typedef __allocator_destructor<_Ap> _Dp; 1789c003db1fSHoward Hinnant unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); 1790c003db1fSHoward Hinnant ::new (__hold.get()) _FF(_VSTD::move(__f), allocator<_Fp>(__a)); 17913e519524SHoward Hinnant __f_ = __hold.release(); 17923e519524SHoward Hinnant } 17933e519524SHoward Hinnant } 17943e519524SHoward Hinnant} 17953e519524SHoward Hinnant 17966ecac730SMarshall Clow#if _LIBCPP_STD_VER <= 14 1797c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 1798fd32ab92SEric Fiseliertemplate <class _Fp, class _Alloc, class> 1799fd32ab92SEric Fiselierfunction<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f) 18009b0b6d45SHoward Hinnant : __f_(0) 18019b0b6d45SHoward Hinnant{ 18029b0b6d45SHoward Hinnant typedef allocator_traits<_Alloc> __alloc_traits; 18030d28f784SEric Fiselier if (__function::__not_null(__f)) 18049b0b6d45SHoward Hinnant { 1805c003db1fSHoward Hinnant typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _FF; 18061f508014SMarshall Clow typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap; 1807c003db1fSHoward Hinnant _Ap __a(__a0); 18085f7c2db2SMarshall Clow if (sizeof(_FF) <= sizeof(__buf_) && 18095f7c2db2SMarshall Clow is_nothrow_copy_constructible<_Fp>::value && is_nothrow_copy_constructible<_Ap>::value) 18105f7c2db2SMarshall Clow { 18113e58a6a7SEvgeniy Stepanov __f_ = ::new((void*)&__buf_) _FF(_VSTD::move(__f), _Alloc(__a)); 18125f7c2db2SMarshall Clow } 18135f7c2db2SMarshall Clow else 18145f7c2db2SMarshall Clow { 1815c003db1fSHoward Hinnant typedef __allocator_destructor<_Ap> _Dp; 1816c003db1fSHoward Hinnant unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); 1817ce48a113SHoward Hinnant ::new (__hold.get()) _FF(_VSTD::move(__f), _Alloc(__a)); 18189b0b6d45SHoward Hinnant __f_ = __hold.release(); 18199b0b6d45SHoward Hinnant } 18209b0b6d45SHoward Hinnant } 18219b0b6d45SHoward Hinnant} 18226ecac730SMarshall Clow#endif 18239b0b6d45SHoward Hinnant 1824c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 1825c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>& 1826c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::operator=(const function& __f) 18273e519524SHoward Hinnant{ 18283e519524SHoward Hinnant function(__f).swap(*this); 18293e519524SHoward Hinnant return *this; 18303e519524SHoward Hinnant} 18313e519524SHoward Hinnant 1832c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 1833c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>& 1834c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT 18353e519524SHoward Hinnant{ 1836aa208791SVolodymyr Sapsai *this = nullptr; 18373e519524SHoward Hinnant if (__f.__f_ == 0) 18383e519524SHoward Hinnant __f_ = 0; 18393e58a6a7SEvgeniy Stepanov else if ((void *)__f.__f_ == &__f.__buf_) 18403e519524SHoward Hinnant { 18413e58a6a7SEvgeniy Stepanov __f_ = __as_base(&__buf_); 18423e519524SHoward Hinnant __f.__f_->__clone(__f_); 18433e519524SHoward Hinnant } 18443e519524SHoward Hinnant else 18453e519524SHoward Hinnant { 18463e519524SHoward Hinnant __f_ = __f.__f_; 18473e519524SHoward Hinnant __f.__f_ = 0; 18483e519524SHoward Hinnant } 184988db3171SArgyrios Kyrtzidis return *this; 18503e519524SHoward Hinnant} 18513e519524SHoward Hinnant 1852c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 1853c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>& 1854c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT 18553e519524SHoward Hinnant{ 1856aa208791SVolodymyr Sapsai __base* __t = __f_; 18573e519524SHoward Hinnant __f_ = 0; 1858aa208791SVolodymyr Sapsai if ((void *)__t == &__buf_) 1859aa208791SVolodymyr Sapsai __t->destroy(); 1860aa208791SVolodymyr Sapsai else if (__t) 1861aa208791SVolodymyr Sapsai __t->destroy_deallocate(); 186288db3171SArgyrios Kyrtzidis return *this; 18633e519524SHoward Hinnant} 18643e519524SHoward Hinnant 1865c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 186694d55511SEric Fiseliertemplate <class _Fp, class> 1867c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>& 1868c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::operator=(_Fp&& __f) 18693e519524SHoward Hinnant{ 1870c003db1fSHoward Hinnant function(_VSTD::forward<_Fp>(__f)).swap(*this); 18713e519524SHoward Hinnant return *this; 18723e519524SHoward Hinnant} 18733e519524SHoward Hinnant 1874c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 1875c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::~function() 18763e519524SHoward Hinnant{ 18773e58a6a7SEvgeniy Stepanov if ((void *)__f_ == &__buf_) 18783e519524SHoward Hinnant __f_->destroy(); 18793e519524SHoward Hinnant else if (__f_) 18803e519524SHoward Hinnant __f_->destroy_deallocate(); 18813e519524SHoward Hinnant} 18823e519524SHoward Hinnant 1883c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 18843e519524SHoward Hinnantvoid 1885c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT 18863e519524SHoward Hinnant{ 1887d566c345SEric Fiselier if (_VSTD::addressof(__f) == this) 1888d566c345SEric Fiselier return; 18893e58a6a7SEvgeniy Stepanov if ((void *)__f_ == &__buf_ && (void *)__f.__f_ == &__f.__buf_) 18903e519524SHoward Hinnant { 18913e519524SHoward Hinnant typename aligned_storage<sizeof(__buf_)>::type __tempbuf; 18923e58a6a7SEvgeniy Stepanov __base* __t = __as_base(&__tempbuf); 18933e519524SHoward Hinnant __f_->__clone(__t); 18943e519524SHoward Hinnant __f_->destroy(); 18953e519524SHoward Hinnant __f_ = 0; 18963e58a6a7SEvgeniy Stepanov __f.__f_->__clone(__as_base(&__buf_)); 18973e519524SHoward Hinnant __f.__f_->destroy(); 18983e519524SHoward Hinnant __f.__f_ = 0; 18993e58a6a7SEvgeniy Stepanov __f_ = __as_base(&__buf_); 19003e58a6a7SEvgeniy Stepanov __t->__clone(__as_base(&__f.__buf_)); 19013e519524SHoward Hinnant __t->destroy(); 19023e58a6a7SEvgeniy Stepanov __f.__f_ = __as_base(&__f.__buf_); 19033e519524SHoward Hinnant } 19043e58a6a7SEvgeniy Stepanov else if ((void *)__f_ == &__buf_) 19053e519524SHoward Hinnant { 19063e58a6a7SEvgeniy Stepanov __f_->__clone(__as_base(&__f.__buf_)); 19073e519524SHoward Hinnant __f_->destroy(); 19083e519524SHoward Hinnant __f_ = __f.__f_; 19093e58a6a7SEvgeniy Stepanov __f.__f_ = __as_base(&__f.__buf_); 19103e519524SHoward Hinnant } 19113e58a6a7SEvgeniy Stepanov else if ((void *)__f.__f_ == &__f.__buf_) 19123e519524SHoward Hinnant { 19133e58a6a7SEvgeniy Stepanov __f.__f_->__clone(__as_base(&__buf_)); 19143e519524SHoward Hinnant __f.__f_->destroy(); 19153e519524SHoward Hinnant __f.__f_ = __f_; 19163e58a6a7SEvgeniy Stepanov __f_ = __as_base(&__buf_); 19173e519524SHoward Hinnant } 19183e519524SHoward Hinnant else 1919ce48a113SHoward Hinnant _VSTD::swap(__f_, __f.__f_); 19203e519524SHoward Hinnant} 19213e519524SHoward Hinnant 1922c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 1923c003db1fSHoward Hinnant_Rp 1924c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const 19253e519524SHoward Hinnant{ 19263e519524SHoward Hinnant if (__f_ == 0) 1927d437fa5cSMarshall Clow __throw_bad_function_call(); 1928ce48a113SHoward Hinnant return (*__f_)(_VSTD::forward<_ArgTypes>(__arg)...); 19293e519524SHoward Hinnant} 19303e519524SHoward Hinnant 193154b409fdSHoward Hinnant#ifndef _LIBCPP_NO_RTTI 193254b409fdSHoward Hinnant 1933c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 19343e519524SHoward Hinnantconst std::type_info& 1935c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT 19363e519524SHoward Hinnant{ 19373e519524SHoward Hinnant if (__f_ == 0) 19383e519524SHoward Hinnant return typeid(void); 19393e519524SHoward Hinnant return __f_->target_type(); 19403e519524SHoward Hinnant} 19413e519524SHoward Hinnant 1942c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 1943c003db1fSHoward Hinnanttemplate <typename _Tp> 1944c003db1fSHoward Hinnant_Tp* 1945c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::target() _NOEXCEPT 19463e519524SHoward Hinnant{ 19473e519524SHoward Hinnant if (__f_ == 0) 19488b086e38SMarshall Clow return nullptr; 19498b086e38SMarshall Clow return (_Tp*) const_cast<void *>(__f_->target(typeid(_Tp))); 19503e519524SHoward Hinnant} 19513e519524SHoward Hinnant 1952c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 1953c003db1fSHoward Hinnanttemplate <typename _Tp> 1954c003db1fSHoward Hinnantconst _Tp* 1955c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::target() const _NOEXCEPT 19563e519524SHoward Hinnant{ 19573e519524SHoward Hinnant if (__f_ == 0) 19588b086e38SMarshall Clow return nullptr; 1959c003db1fSHoward Hinnant return (const _Tp*)__f_->target(typeid(_Tp)); 19603e519524SHoward Hinnant} 19613e519524SHoward Hinnant 1962b3371f6fSHoward Hinnant#endif // _LIBCPP_NO_RTTI 196354b409fdSHoward Hinnant 1964c003db1fSHoward Hinnanttemplate <class _Rp, class... _ArgTypes> 19653e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 19663e519524SHoward Hinnantbool 1967c003db1fSHoward Hinnantoperator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;} 19683e519524SHoward Hinnant 1969c003db1fSHoward Hinnanttemplate <class _Rp, class... _ArgTypes> 19703e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 19713e519524SHoward Hinnantbool 1972c003db1fSHoward Hinnantoperator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;} 19733e519524SHoward Hinnant 1974c003db1fSHoward Hinnanttemplate <class _Rp, class... _ArgTypes> 19753e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 19763e519524SHoward Hinnantbool 1977c003db1fSHoward Hinnantoperator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;} 19783e519524SHoward Hinnant 1979c003db1fSHoward Hinnanttemplate <class _Rp, class... _ArgTypes> 19803e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 19813e519524SHoward Hinnantbool 1982c003db1fSHoward Hinnantoperator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;} 19833e519524SHoward Hinnant 1984c003db1fSHoward Hinnanttemplate <class _Rp, class... _ArgTypes> 19853e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 19863e519524SHoward Hinnantvoid 1987c003db1fSHoward Hinnantswap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT 19883e519524SHoward Hinnant{return __x.swap(__y);} 19893e519524SHoward Hinnant 19907e23afcbSEric Fiselier#else // _LIBCPP_CXX03_LANG 199100f512ebSEric Fiselier 199200f512ebSEric Fiselier#include <__functional_03> 199300f512ebSEric Fiselier 199400f512ebSEric Fiselier#endif 1995e5407178SEric Fiselier 1996e5407178SEric Fiselier//////////////////////////////////////////////////////////////////////////////// 1997e5407178SEric Fiselier// BIND 1998e5407178SEric Fiselier//============================================================================== 1999e5407178SEric Fiselier 20003e519524SHoward Hinnanttemplate<class _Tp> struct __is_bind_expression : public false_type {}; 2001e2f2d1edSEric Fiseliertemplate<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_bind_expression 20023e519524SHoward Hinnant : public __is_bind_expression<typename remove_cv<_Tp>::type> {}; 20033e519524SHoward Hinnant 2004a48055ceSMarshall Clow#if _LIBCPP_STD_VER > 14 2005a48055ceSMarshall Clowtemplate <class _Tp> 200640a01d53SMarshall Clow_LIBCPP_INLINE_VAR constexpr size_t is_bind_expression_v = is_bind_expression<_Tp>::value; 2007a48055ceSMarshall Clow#endif 2008a48055ceSMarshall Clow 20093e519524SHoward Hinnanttemplate<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {}; 2010e2f2d1edSEric Fiseliertemplate<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_placeholder 20113e519524SHoward Hinnant : public __is_placeholder<typename remove_cv<_Tp>::type> {}; 20123e519524SHoward Hinnant 2013a48055ceSMarshall Clow#if _LIBCPP_STD_VER > 14 2014a48055ceSMarshall Clowtemplate <class _Tp> 201540a01d53SMarshall Clow_LIBCPP_INLINE_VAR constexpr size_t is_placeholder_v = is_placeholder<_Tp>::value; 2016a48055ceSMarshall Clow#endif 2017a48055ceSMarshall Clow 20183e519524SHoward Hinnantnamespace placeholders 20193e519524SHoward Hinnant{ 20203e519524SHoward Hinnant 2021c003db1fSHoward Hinnanttemplate <int _Np> struct __ph {}; 20223e519524SHoward Hinnant 2023c8e84ff2SLouis Dionne#if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY) 202455533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<1> _1; 202555533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<2> _2; 202655533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<3> _3; 202755533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<4> _4; 202855533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<5> _5; 202955533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<6> _6; 203055533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<7> _7; 203155533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<8> _8; 203255533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<9> _9; 203355533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<10> _10; 203455533071SEric Fiselier#else 2035a911f39dSMarshall Clow/* _LIBCPP_INLINE_VAR */ constexpr __ph<1> _1{}; 2036a911f39dSMarshall Clow/* _LIBCPP_INLINE_VAR */ constexpr __ph<2> _2{}; 2037a911f39dSMarshall Clow/* _LIBCPP_INLINE_VAR */ constexpr __ph<3> _3{}; 2038a911f39dSMarshall Clow/* _LIBCPP_INLINE_VAR */ constexpr __ph<4> _4{}; 2039a911f39dSMarshall Clow/* _LIBCPP_INLINE_VAR */ constexpr __ph<5> _5{}; 2040a911f39dSMarshall Clow/* _LIBCPP_INLINE_VAR */ constexpr __ph<6> _6{}; 2041a911f39dSMarshall Clow/* _LIBCPP_INLINE_VAR */ constexpr __ph<7> _7{}; 2042a911f39dSMarshall Clow/* _LIBCPP_INLINE_VAR */ constexpr __ph<8> _8{}; 2043a911f39dSMarshall Clow/* _LIBCPP_INLINE_VAR */ constexpr __ph<9> _9{}; 2044a911f39dSMarshall Clow/* _LIBCPP_INLINE_VAR */ constexpr __ph<10> _10{}; 2045c8e84ff2SLouis Dionne#endif // defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY) 20463e519524SHoward Hinnant 20473e519524SHoward Hinnant} // placeholders 20483e519524SHoward Hinnant 2049c003db1fSHoward Hinnanttemplate<int _Np> 2050c003db1fSHoward Hinnantstruct __is_placeholder<placeholders::__ph<_Np> > 2051c003db1fSHoward Hinnant : public integral_constant<int, _Np> {}; 20523e519524SHoward Hinnant 2053e5407178SEric Fiselier 20547e23afcbSEric Fiselier#ifndef _LIBCPP_CXX03_LANG 2055e5407178SEric Fiselier 20563e519524SHoward Hinnanttemplate <class _Tp, class _Uj> 20573e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 20583e519524SHoward Hinnant_Tp& 20593e519524SHoward Hinnant__mu(reference_wrapper<_Tp> __t, _Uj&) 20603e519524SHoward Hinnant{ 20613e519524SHoward Hinnant return __t.get(); 20623e519524SHoward Hinnant} 20633e519524SHoward Hinnant 20643e519524SHoward Hinnanttemplate <class _Ti, class ..._Uj, size_t ..._Indx> 20653e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 20662344d6c1SHoward Hinnanttypename __invoke_of<_Ti&, _Uj...>::type 20672344d6c1SHoward Hinnant__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>) 20683e519524SHoward Hinnant{ 2069f9af6140SMarshall Clow return __ti(_VSTD::forward<_Uj>(_VSTD::get<_Indx>(__uj))...); 20703e519524SHoward Hinnant} 20713e519524SHoward Hinnant 20723e519524SHoward Hinnanttemplate <class _Ti, class ..._Uj> 20733e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 2074279663c1SEric Fiseliertypename __lazy_enable_if 20753e519524SHoward Hinnant< 20763e519524SHoward Hinnant is_bind_expression<_Ti>::value, 2077279663c1SEric Fiselier __invoke_of<_Ti&, _Uj...> 20783e519524SHoward Hinnant>::type 20793e519524SHoward Hinnant__mu(_Ti& __ti, tuple<_Uj...>& __uj) 20803e519524SHoward Hinnant{ 20813e519524SHoward Hinnant typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices; 20823e519524SHoward Hinnant return __mu_expand(__ti, __uj, __indices()); 20833e519524SHoward Hinnant} 20843e519524SHoward Hinnant 20853e519524SHoward Hinnanttemplate <bool IsPh, class _Ti, class _Uj> 20863e519524SHoward Hinnantstruct __mu_return2 {}; 20873e519524SHoward Hinnant 20883e519524SHoward Hinnanttemplate <class _Ti, class _Uj> 20893e519524SHoward Hinnantstruct __mu_return2<true, _Ti, _Uj> 20903e519524SHoward Hinnant{ 20913e519524SHoward Hinnant typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type; 20923e519524SHoward Hinnant}; 20933e519524SHoward Hinnant 20943e519524SHoward Hinnanttemplate <class _Ti, class _Uj> 20953e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 20963e519524SHoward Hinnanttypename enable_if 20973e519524SHoward Hinnant< 20983e519524SHoward Hinnant 0 < is_placeholder<_Ti>::value, 20993e519524SHoward Hinnant typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type 21003e519524SHoward Hinnant>::type 21013e519524SHoward Hinnant__mu(_Ti&, _Uj& __uj) 21023e519524SHoward Hinnant{ 21033e519524SHoward Hinnant const size_t _Indx = is_placeholder<_Ti>::value - 1; 2104f9af6140SMarshall Clow return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj)); 21053e519524SHoward Hinnant} 21063e519524SHoward Hinnant 21073e519524SHoward Hinnanttemplate <class _Ti, class _Uj> 21083e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 21093e519524SHoward Hinnanttypename enable_if 21103e519524SHoward Hinnant< 21113e519524SHoward Hinnant !is_bind_expression<_Ti>::value && 21123e519524SHoward Hinnant is_placeholder<_Ti>::value == 0 && 21133e519524SHoward Hinnant !__is_reference_wrapper<_Ti>::value, 21143e519524SHoward Hinnant _Ti& 21153e519524SHoward Hinnant>::type 2116c206366fSHoward Hinnant__mu(_Ti& __ti, _Uj&) 21173e519524SHoward Hinnant{ 21183e519524SHoward Hinnant return __ti; 21193e519524SHoward Hinnant} 21203e519524SHoward Hinnant 21212fa07ae9SHoward Hinnanttemplate <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh, 21222fa07ae9SHoward Hinnant class _TupleUj> 21230805a4faSLouis Dionnestruct __mu_return_impl; 21243e519524SHoward Hinnant 21259bf42533SHoward Hinnanttemplate <bool _Invokable, class _Ti, class ..._Uj> 21260805a4faSLouis Dionnestruct __mu_return_invokable // false 21279bf42533SHoward Hinnant{ 21289bf42533SHoward Hinnant typedef __nat type; 21299bf42533SHoward Hinnant}; 21309bf42533SHoward Hinnant 21313e519524SHoward Hinnanttemplate <class _Ti, class ..._Uj> 21320805a4faSLouis Dionnestruct __mu_return_invokable<true, _Ti, _Uj...> 21333e519524SHoward Hinnant{ 21342344d6c1SHoward Hinnant typedef typename __invoke_of<_Ti&, _Uj...>::type type; 21353e519524SHoward Hinnant}; 21363e519524SHoward Hinnant 21379bf42533SHoward Hinnanttemplate <class _Ti, class ..._Uj> 21380805a4faSLouis Dionnestruct __mu_return_impl<_Ti, false, true, false, tuple<_Uj...> > 21390805a4faSLouis Dionne : public __mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...> 21409bf42533SHoward Hinnant{ 21419bf42533SHoward Hinnant}; 21429bf42533SHoward Hinnant 21433e519524SHoward Hinnanttemplate <class _Ti, class _TupleUj> 21440805a4faSLouis Dionnestruct __mu_return_impl<_Ti, false, false, true, _TupleUj> 21453e519524SHoward Hinnant{ 21463e519524SHoward Hinnant typedef typename tuple_element<is_placeholder<_Ti>::value - 1, 21473e519524SHoward Hinnant _TupleUj>::type&& type; 21483e519524SHoward Hinnant}; 21493e519524SHoward Hinnant 21503e519524SHoward Hinnanttemplate <class _Ti, class _TupleUj> 21510805a4faSLouis Dionnestruct __mu_return_impl<_Ti, true, false, false, _TupleUj> 21522fa07ae9SHoward Hinnant{ 21532fa07ae9SHoward Hinnant typedef typename _Ti::type& type; 21542fa07ae9SHoward Hinnant}; 21552fa07ae9SHoward Hinnant 21562fa07ae9SHoward Hinnanttemplate <class _Ti, class _TupleUj> 21570805a4faSLouis Dionnestruct __mu_return_impl<_Ti, false, false, false, _TupleUj> 21583e519524SHoward Hinnant{ 21593e519524SHoward Hinnant typedef _Ti& type; 21603e519524SHoward Hinnant}; 21613e519524SHoward Hinnant 21623e519524SHoward Hinnanttemplate <class _Ti, class _TupleUj> 21633e519524SHoward Hinnantstruct __mu_return 21640805a4faSLouis Dionne : public __mu_return_impl<_Ti, 21652fa07ae9SHoward Hinnant __is_reference_wrapper<_Ti>::value, 21663e519524SHoward Hinnant is_bind_expression<_Ti>::value, 2167c0c9748cSHoward Hinnant 0 < is_placeholder<_Ti>::value && 2168c0c9748cSHoward Hinnant is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value, 21693e519524SHoward Hinnant _TupleUj> 21703e519524SHoward Hinnant{ 21713e519524SHoward Hinnant}; 21723e519524SHoward Hinnant 2173c003db1fSHoward Hinnanttemplate <class _Fp, class _BoundArgs, class _TupleUj> 217435cb2b28SEric Fiselierstruct __is_valid_bind_return 2175c0c9748cSHoward Hinnant{ 2176c0c9748cSHoward Hinnant static const bool value = false; 2177c0c9748cSHoward Hinnant}; 2178c0c9748cSHoward Hinnant 2179c0c9748cSHoward Hinnanttemplate <class _Fp, class ..._BoundArgs, class _TupleUj> 218035cb2b28SEric Fiselierstruct __is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj> 2181c0c9748cSHoward Hinnant{ 2182c0c9748cSHoward Hinnant static const bool value = __invokable<_Fp, 2183c0c9748cSHoward Hinnant typename __mu_return<_BoundArgs, _TupleUj>::type...>::value; 2184c0c9748cSHoward Hinnant}; 2185c0c9748cSHoward Hinnant 2186c0c9748cSHoward Hinnanttemplate <class _Fp, class ..._BoundArgs, class _TupleUj> 218735cb2b28SEric Fiselierstruct __is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj> 2188c0c9748cSHoward Hinnant{ 2189c0c9748cSHoward Hinnant static const bool value = __invokable<_Fp, 2190c0c9748cSHoward Hinnant typename __mu_return<const _BoundArgs, _TupleUj>::type...>::value; 2191c0c9748cSHoward Hinnant}; 2192c0c9748cSHoward Hinnant 2193c0c9748cSHoward Hinnanttemplate <class _Fp, class _BoundArgs, class _TupleUj, 219435cb2b28SEric Fiselier bool = __is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value> 21953e519524SHoward Hinnantstruct __bind_return; 21963e519524SHoward Hinnant 2197c003db1fSHoward Hinnanttemplate <class _Fp, class ..._BoundArgs, class _TupleUj> 2198c0c9748cSHoward Hinnantstruct __bind_return<_Fp, 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 _BoundArgs, 22063e519524SHoward Hinnant _TupleUj 22073e519524SHoward Hinnant >::type... 22083e519524SHoward Hinnant >::type type; 22093e519524SHoward Hinnant}; 22103e519524SHoward Hinnant 2211c003db1fSHoward Hinnanttemplate <class _Fp, class ..._BoundArgs, class _TupleUj> 2212c0c9748cSHoward Hinnantstruct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true> 22133e519524SHoward Hinnant{ 22142344d6c1SHoward Hinnant typedef typename __invoke_of 22153e519524SHoward Hinnant < 2216c003db1fSHoward Hinnant _Fp&, 22173e519524SHoward Hinnant typename __mu_return 22183e519524SHoward Hinnant < 22193e519524SHoward Hinnant const _BoundArgs, 22203e519524SHoward Hinnant _TupleUj 22213e519524SHoward Hinnant >::type... 22223e519524SHoward Hinnant >::type type; 22233e519524SHoward Hinnant}; 22243e519524SHoward Hinnant 2225c003db1fSHoward Hinnanttemplate <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args> 22263e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 2227c003db1fSHoward Hinnanttypename __bind_return<_Fp, _BoundArgs, _Args>::type 2228c003db1fSHoward Hinnant__apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>, 22293e519524SHoward Hinnant _Args&& __args) 22303e519524SHoward Hinnant{ 22311f8b73d1SEric Fiselier return _VSTD::__invoke(__f, _VSTD::__mu(_VSTD::get<_Indx>(__bound_args), __args)...); 22323e519524SHoward Hinnant} 22333e519524SHoward Hinnant 2234c003db1fSHoward Hinnanttemplate<class _Fp, class ..._BoundArgs> 22353e519524SHoward Hinnantclass __bind 2236c003db1fSHoward Hinnant : public __weak_result_type<typename decay<_Fp>::type> 22373e519524SHoward Hinnant{ 2238c0c9748cSHoward Hinnantprotected: 2239c003db1fSHoward Hinnant typedef typename decay<_Fp>::type _Fd; 22402344d6c1SHoward Hinnant typedef tuple<typename decay<_BoundArgs>::type...> _Td; 2241c0c9748cSHoward Hinnantprivate: 22422344d6c1SHoward Hinnant _Fd __f_; 22432344d6c1SHoward Hinnant _Td __bound_args_; 22443e519524SHoward Hinnant 22453e519524SHoward Hinnant typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices; 22463e519524SHoward Hinnantpublic: 2247df7aad41SHoward Hinnant template <class _Gp, class ..._BA, 2248df7aad41SHoward Hinnant class = typename enable_if 2249df7aad41SHoward Hinnant < 22509dbbf8deSHoward Hinnant is_constructible<_Fd, _Gp>::value && 22519dbbf8deSHoward Hinnant !is_same<typename remove_reference<_Gp>::type, 22529dbbf8deSHoward Hinnant __bind>::value 2253df7aad41SHoward Hinnant >::type> 22540af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 2255c003db1fSHoward Hinnant explicit __bind(_Gp&& __f, _BA&& ...__bound_args) 2256c003db1fSHoward Hinnant : __f_(_VSTD::forward<_Gp>(__f)), 2257ce48a113SHoward Hinnant __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {} 22583e519524SHoward Hinnant 22593e519524SHoward Hinnant template <class ..._Args> 22600af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 22612344d6c1SHoward Hinnant typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type 22623e519524SHoward Hinnant operator()(_Args&& ...__args) 22633e519524SHoward Hinnant { 22641f8b73d1SEric Fiselier return _VSTD::__apply_functor(__f_, __bound_args_, __indices(), 2265ce48a113SHoward Hinnant tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...)); 22663e519524SHoward Hinnant } 22673e519524SHoward Hinnant 22683e519524SHoward Hinnant template <class ..._Args> 22690af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 2270c0c9748cSHoward Hinnant typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type 22713e519524SHoward Hinnant operator()(_Args&& ...__args) const 22723e519524SHoward Hinnant { 22731f8b73d1SEric Fiselier return _VSTD::__apply_functor(__f_, __bound_args_, __indices(), 2274ce48a113SHoward Hinnant tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...)); 22753e519524SHoward Hinnant } 22763e519524SHoward Hinnant}; 22773e519524SHoward Hinnant 2278c003db1fSHoward Hinnanttemplate<class _Fp, class ..._BoundArgs> 2279c003db1fSHoward Hinnantstruct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {}; 22803e519524SHoward Hinnant 2281c003db1fSHoward Hinnanttemplate<class _Rp, class _Fp, class ..._BoundArgs> 22823e519524SHoward Hinnantclass __bind_r 2283c003db1fSHoward Hinnant : public __bind<_Fp, _BoundArgs...> 22843e519524SHoward Hinnant{ 2285c003db1fSHoward Hinnant typedef __bind<_Fp, _BoundArgs...> base; 2286c0c9748cSHoward Hinnant typedef typename base::_Fd _Fd; 2287c0c9748cSHoward Hinnant typedef typename base::_Td _Td; 22883e519524SHoward Hinnantpublic: 2289c003db1fSHoward Hinnant typedef _Rp result_type; 22903e519524SHoward Hinnant 2291086d0de1SHoward Hinnant 22929dbbf8deSHoward Hinnant template <class _Gp, class ..._BA, 22939dbbf8deSHoward Hinnant class = typename enable_if 22949dbbf8deSHoward Hinnant < 22959dbbf8deSHoward Hinnant is_constructible<_Fd, _Gp>::value && 22969dbbf8deSHoward Hinnant !is_same<typename remove_reference<_Gp>::type, 22979dbbf8deSHoward Hinnant __bind_r>::value 22989dbbf8deSHoward Hinnant >::type> 22990af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 2300c003db1fSHoward Hinnant explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args) 2301c003db1fSHoward Hinnant : base(_VSTD::forward<_Gp>(__f), 2302ce48a113SHoward Hinnant _VSTD::forward<_BA>(__bound_args)...) {} 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<_Fd, _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) 23133e519524SHoward Hinnant { 23142d15f15fSEric Fiselier typedef __invoke_void_return_wrapper<_Rp> _Invoker; 23152d15f15fSEric Fiselier return _Invoker::__call(static_cast<base&>(*this), _VSTD::forward<_Args>(__args)...); 23163e519524SHoward Hinnant } 23173e519524SHoward Hinnant 23183e519524SHoward Hinnant template <class ..._Args> 23190af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 2320c0c9748cSHoward Hinnant typename enable_if 2321c0c9748cSHoward Hinnant < 2322c0c9748cSHoward Hinnant is_convertible<typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type, 23232d15f15fSEric Fiselier result_type>::value || is_void<_Rp>::value, 23243e519524SHoward Hinnant result_type 2325c0c9748cSHoward Hinnant >::type 23263e519524SHoward Hinnant operator()(_Args&& ...__args) const 23273e519524SHoward Hinnant { 23282d15f15fSEric Fiselier typedef __invoke_void_return_wrapper<_Rp> _Invoker; 23292d15f15fSEric Fiselier return _Invoker::__call(static_cast<base const&>(*this), _VSTD::forward<_Args>(__args)...); 23303e519524SHoward Hinnant } 23313e519524SHoward Hinnant}; 23323e519524SHoward Hinnant 2333c003db1fSHoward Hinnanttemplate<class _Rp, class _Fp, class ..._BoundArgs> 2334c003db1fSHoward Hinnantstruct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {}; 23353e519524SHoward Hinnant 2336c003db1fSHoward Hinnanttemplate<class _Fp, class ..._BoundArgs> 23373e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 2338c003db1fSHoward Hinnant__bind<_Fp, _BoundArgs...> 2339c003db1fSHoward Hinnantbind(_Fp&& __f, _BoundArgs&&... __bound_args) 23403e519524SHoward Hinnant{ 2341c003db1fSHoward Hinnant typedef __bind<_Fp, _BoundArgs...> type; 2342c003db1fSHoward Hinnant return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...); 23433e519524SHoward Hinnant} 23443e519524SHoward Hinnant 2345c003db1fSHoward Hinnanttemplate<class _Rp, class _Fp, class ..._BoundArgs> 23463e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 2347c003db1fSHoward Hinnant__bind_r<_Rp, _Fp, _BoundArgs...> 2348c003db1fSHoward Hinnantbind(_Fp&& __f, _BoundArgs&&... __bound_args) 23493e519524SHoward Hinnant{ 2350c003db1fSHoward Hinnant typedef __bind_r<_Rp, _Fp, _BoundArgs...> type; 2351c003db1fSHoward Hinnant return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...); 23523e519524SHoward Hinnant} 23533e519524SHoward Hinnant 23547e23afcbSEric Fiselier#endif // _LIBCPP_CXX03_LANG 23553e519524SHoward Hinnant 23565be45129SEric Fiselier#if _LIBCPP_STD_VER > 14 235757257567SEric Fiselier 23585be45129SEric Fiseliertemplate <class _Fn, class ..._Args> 23595be45129SEric Fiselierresult_of_t<_Fn&&(_Args&&...)> 236057257567SEric Fiselierinvoke(_Fn&& __f, _Args&&... __args) 236157257567SEric Fiselier noexcept(noexcept(_VSTD::__invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...))) 236257257567SEric Fiselier{ 236357257567SEric Fiselier return _VSTD::__invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...); 23645be45129SEric Fiselier} 236557257567SEric Fiselier 236657257567SEric Fiseliertemplate <class _DecayFunc> 2367e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS __not_fn_imp { 236857257567SEric Fiselier _DecayFunc __fd; 236957257567SEric Fiselier 237057257567SEric Fiselierpublic: 237157257567SEric Fiselier __not_fn_imp() = delete; 237257257567SEric Fiselier 237357257567SEric Fiselier template <class ..._Args> 237457257567SEric Fiselier _LIBCPP_INLINE_VISIBILITY 23759372d8bcSEric Fiselier auto operator()(_Args&& ...__args) & 237657257567SEric Fiselier noexcept(noexcept(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...))) 237757257567SEric Fiselier -> decltype( !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)) 237857257567SEric Fiselier { return !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); } 237957257567SEric Fiselier 238057257567SEric Fiselier template <class ..._Args> 238157257567SEric Fiselier _LIBCPP_INLINE_VISIBILITY 23829372d8bcSEric Fiselier auto operator()(_Args&& ...__args) && 23839372d8bcSEric Fiselier noexcept(noexcept(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...))) 23849372d8bcSEric Fiselier -> decltype( !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)) 23859372d8bcSEric Fiselier { return !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); } 23869372d8bcSEric Fiselier 23879372d8bcSEric Fiselier template <class ..._Args> 23889372d8bcSEric Fiselier _LIBCPP_INLINE_VISIBILITY 23899372d8bcSEric Fiselier auto operator()(_Args&& ...__args) const& 239057257567SEric Fiselier noexcept(noexcept(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...))) 239157257567SEric Fiselier -> decltype( !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)) 239257257567SEric Fiselier { return !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); } 239357257567SEric Fiselier 23949372d8bcSEric Fiselier 23959372d8bcSEric Fiselier template <class ..._Args> 23969372d8bcSEric Fiselier _LIBCPP_INLINE_VISIBILITY 23979372d8bcSEric Fiselier auto operator()(_Args&& ...__args) const&& 23989372d8bcSEric Fiselier noexcept(noexcept(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...))) 23999372d8bcSEric Fiselier -> decltype( !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)) 24009372d8bcSEric Fiselier { return !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); } 24019372d8bcSEric Fiselier 240257257567SEric Fiselierprivate: 240357257567SEric Fiselier template <class _RawFunc, 240457257567SEric Fiselier class = enable_if_t<!is_same<decay_t<_RawFunc>, __not_fn_imp>::value>> 240557257567SEric Fiselier _LIBCPP_INLINE_VISIBILITY 240657257567SEric Fiselier explicit __not_fn_imp(_RawFunc&& __rf) 240757257567SEric Fiselier : __fd(_VSTD::forward<_RawFunc>(__rf)) {} 240857257567SEric Fiselier 240957257567SEric Fiselier template <class _RawFunc> 241057257567SEric Fiselier friend inline _LIBCPP_INLINE_VISIBILITY 241157257567SEric Fiselier __not_fn_imp<decay_t<_RawFunc>> not_fn(_RawFunc&&); 241257257567SEric Fiselier}; 241357257567SEric Fiselier 241457257567SEric Fiseliertemplate <class _RawFunc> 241557257567SEric Fiselierinline _LIBCPP_INLINE_VISIBILITY 241657257567SEric Fiselier__not_fn_imp<decay_t<_RawFunc>> not_fn(_RawFunc&& __fn) { 241757257567SEric Fiselier return __not_fn_imp<decay_t<_RawFunc>>(_VSTD::forward<_RawFunc>(__fn)); 241857257567SEric Fiselier} 241957257567SEric Fiselier 24205be45129SEric Fiselier#endif 24215be45129SEric Fiselier 2422d1803b6cSHoward Hinnant// struct hash<T*> in <memory> 24233e519524SHoward Hinnant 2424d835e592SMarshall Clowtemplate <class _BinaryPredicate, class _ForwardIterator1, class _ForwardIterator2> 242512f0a779SMarshall Clowpair<_ForwardIterator1, _ForwardIterator1> _LIBCPP_CONSTEXPR_AFTER_CXX11 2426d835e592SMarshall Clow__search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, 2427d835e592SMarshall Clow _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred, 2428d835e592SMarshall Clow forward_iterator_tag, forward_iterator_tag) 2429d835e592SMarshall Clow{ 2430d835e592SMarshall Clow if (__first2 == __last2) 2431d835e592SMarshall Clow return make_pair(__first1, __first1); // Everything matches an empty sequence 2432d835e592SMarshall Clow while (true) 2433d835e592SMarshall Clow { 2434d835e592SMarshall Clow // Find first element in sequence 1 that matchs *__first2, with a mininum of loop checks 2435d835e592SMarshall Clow while (true) 2436d835e592SMarshall Clow { 2437d835e592SMarshall Clow if (__first1 == __last1) // return __last1 if no element matches *__first2 2438d835e592SMarshall Clow return make_pair(__last1, __last1); 2439d835e592SMarshall Clow if (__pred(*__first1, *__first2)) 2440d835e592SMarshall Clow break; 2441d835e592SMarshall Clow ++__first1; 2442d835e592SMarshall Clow } 2443d835e592SMarshall Clow // *__first1 matches *__first2, now match elements after here 2444d835e592SMarshall Clow _ForwardIterator1 __m1 = __first1; 2445d835e592SMarshall Clow _ForwardIterator2 __m2 = __first2; 2446d835e592SMarshall Clow while (true) 2447d835e592SMarshall Clow { 2448d835e592SMarshall Clow if (++__m2 == __last2) // If pattern exhausted, __first1 is the answer (works for 1 element pattern) 2449d835e592SMarshall Clow return make_pair(__first1, __m1); 2450d835e592SMarshall Clow if (++__m1 == __last1) // Otherwise if source exhaused, pattern not found 2451d835e592SMarshall Clow return make_pair(__last1, __last1); 2452d835e592SMarshall Clow if (!__pred(*__m1, *__m2)) // if there is a mismatch, restart with a new __first1 2453d835e592SMarshall Clow { 2454d835e592SMarshall Clow ++__first1; 2455d835e592SMarshall Clow break; 2456d835e592SMarshall Clow } // else there is a match, check next elements 2457d835e592SMarshall Clow } 2458d835e592SMarshall Clow } 2459d835e592SMarshall Clow} 2460d835e592SMarshall Clow 2461d835e592SMarshall Clowtemplate <class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2> 2462d835e592SMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 2463d835e592SMarshall Clowpair<_RandomAccessIterator1, _RandomAccessIterator1> 2464d835e592SMarshall Clow__search(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, 2465d835e592SMarshall Clow _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __pred, 2466d835e592SMarshall Clow random_access_iterator_tag, random_access_iterator_tag) 2467d835e592SMarshall Clow{ 2468d835e592SMarshall Clow typedef typename iterator_traits<_RandomAccessIterator1>::difference_type _D1; 2469d835e592SMarshall Clow typedef typename iterator_traits<_RandomAccessIterator2>::difference_type _D2; 2470d835e592SMarshall Clow // Take advantage of knowing source and pattern lengths. Stop short when source is smaller than pattern 2471d835e592SMarshall Clow const _D2 __len2 = __last2 - __first2; 2472d835e592SMarshall Clow if (__len2 == 0) 2473d835e592SMarshall Clow return make_pair(__first1, __first1); 2474d835e592SMarshall Clow const _D1 __len1 = __last1 - __first1; 2475d835e592SMarshall Clow if (__len1 < __len2) 2476d835e592SMarshall Clow return make_pair(__last1, __last1); 2477d835e592SMarshall Clow const _RandomAccessIterator1 __s = __last1 - (__len2 - 1); // Start of pattern match can't go beyond here 2478d835e592SMarshall Clow 2479d835e592SMarshall Clow while (true) 2480d835e592SMarshall Clow { 2481d835e592SMarshall Clow while (true) 2482d835e592SMarshall Clow { 2483d835e592SMarshall Clow if (__first1 == __s) 2484d835e592SMarshall Clow return make_pair(__last1, __last1); 2485d835e592SMarshall Clow if (__pred(*__first1, *__first2)) 2486d835e592SMarshall Clow break; 2487d835e592SMarshall Clow ++__first1; 2488d835e592SMarshall Clow } 2489d835e592SMarshall Clow 2490d835e592SMarshall Clow _RandomAccessIterator1 __m1 = __first1; 2491d835e592SMarshall Clow _RandomAccessIterator2 __m2 = __first2; 2492d835e592SMarshall Clow while (true) 2493d835e592SMarshall Clow { 2494d835e592SMarshall Clow if (++__m2 == __last2) 2495d835e592SMarshall Clow return make_pair(__first1, __first1 + __len2); 2496d835e592SMarshall Clow ++__m1; // no need to check range on __m1 because __s guarantees we have enough source 2497d835e592SMarshall Clow if (!__pred(*__m1, *__m2)) 2498d835e592SMarshall Clow { 2499d835e592SMarshall Clow ++__first1; 2500d835e592SMarshall Clow break; 2501d835e592SMarshall Clow } 2502d835e592SMarshall Clow } 2503d835e592SMarshall Clow } 2504d835e592SMarshall Clow} 2505d835e592SMarshall Clow 2506d835e592SMarshall Clow#if _LIBCPP_STD_VER > 14 2507d835e592SMarshall Clow 2508d835e592SMarshall Clow// default searcher 2509d835e592SMarshall Clowtemplate<class _ForwardIterator, class _BinaryPredicate = equal_to<>> 25101b1b80f4SDimitry Andricclass _LIBCPP_TYPE_VIS default_searcher { 2511d835e592SMarshall Clowpublic: 2512d835e592SMarshall Clow _LIBCPP_INLINE_VISIBILITY 2513d835e592SMarshall Clow default_searcher(_ForwardIterator __f, _ForwardIterator __l, 2514d835e592SMarshall Clow _BinaryPredicate __p = _BinaryPredicate()) 2515d835e592SMarshall Clow : __first_(__f), __last_(__l), __pred_(__p) {} 2516d835e592SMarshall Clow 2517d835e592SMarshall Clow template <typename _ForwardIterator2> 2518d835e592SMarshall Clow _LIBCPP_INLINE_VISIBILITY 2519d835e592SMarshall Clow pair<_ForwardIterator2, _ForwardIterator2> 2520d835e592SMarshall Clow operator () (_ForwardIterator2 __f, _ForwardIterator2 __l) const 2521d835e592SMarshall Clow { 2522d835e592SMarshall Clow return _VSTD::__search(__f, __l, __first_, __last_, __pred_, 2523d835e592SMarshall Clow typename _VSTD::iterator_traits<_ForwardIterator>::iterator_category(), 2524d835e592SMarshall Clow typename _VSTD::iterator_traits<_ForwardIterator2>::iterator_category()); 2525d835e592SMarshall Clow } 2526d835e592SMarshall Clow 2527d835e592SMarshall Clowprivate: 2528d835e592SMarshall Clow _ForwardIterator __first_; 2529d835e592SMarshall Clow _ForwardIterator __last_; 2530d835e592SMarshall Clow _BinaryPredicate __pred_; 2531d835e592SMarshall Clow }; 2532d835e592SMarshall Clow 2533d835e592SMarshall Clow#endif // _LIBCPP_STD_VER > 14 2534d835e592SMarshall Clow 2535*bb9ca6d0SLouis Dionne#if _LIBCPP_STD_VER > 17 2536*bb9ca6d0SLouis Dionnetemplate <class _Tp> 2537*bb9ca6d0SLouis Dionneusing unwrap_reference_t = typename unwrap_reference<_Tp>::type; 2538*bb9ca6d0SLouis Dionne 2539*bb9ca6d0SLouis Dionnetemplate <class _Tp> 2540*bb9ca6d0SLouis Dionneusing unwrap_ref_decay_t = typename unwrap_ref_decay<_Tp>::type; 2541*bb9ca6d0SLouis Dionne#endif // > C++17 2542*bb9ca6d0SLouis Dionne 25433e519524SHoward Hinnant_LIBCPP_END_NAMESPACE_STD 25443e519524SHoward Hinnant 25453e519524SHoward Hinnant#endif // _LIBCPP_FUNCTIONAL 2546