13e519524SHoward Hinnant// -*- C++ -*- 23e519524SHoward Hinnant//===------------------------ functional ----------------------------------===// 33e519524SHoward Hinnant// 45b08a8a4SHoward Hinnant// The LLVM Compiler Infrastructure 53e519524SHoward Hinnant// 6412dbebeSHoward Hinnant// This file is dual licensed under the MIT and the University of Illinois Open 7412dbebeSHoward Hinnant// Source Licenses. See LICENSE.TXT for details. 83e519524SHoward Hinnant// 93e519524SHoward Hinnant//===----------------------------------------------------------------------===// 103e519524SHoward Hinnant 113e519524SHoward Hinnant#ifndef _LIBCPP_FUNCTIONAL 123e519524SHoward Hinnant#define _LIBCPP_FUNCTIONAL 133e519524SHoward Hinnant 143e519524SHoward Hinnant/* 153e519524SHoward Hinnant functional synopsis 163e519524SHoward Hinnant 173e519524SHoward Hinnantnamespace std 183e519524SHoward Hinnant{ 193e519524SHoward Hinnant 203e519524SHoward Hinnanttemplate <class Arg, class Result> 213e519524SHoward Hinnantstruct unary_function 223e519524SHoward Hinnant{ 233e519524SHoward Hinnant typedef Arg argument_type; 243e519524SHoward Hinnant typedef Result result_type; 253e519524SHoward Hinnant}; 263e519524SHoward Hinnant 273e519524SHoward Hinnanttemplate <class Arg1, class Arg2, class Result> 283e519524SHoward Hinnantstruct binary_function 293e519524SHoward Hinnant{ 303e519524SHoward Hinnant typedef Arg1 first_argument_type; 313e519524SHoward Hinnant typedef Arg2 second_argument_type; 323e519524SHoward Hinnant typedef Result result_type; 333e519524SHoward Hinnant}; 343e519524SHoward Hinnant 359b0b6d45SHoward Hinnanttemplate <class T> 363e519524SHoward Hinnantclass reference_wrapper 373e519524SHoward Hinnant : public unary_function<T1, R> // if wrapping a unary functor 383e519524SHoward Hinnant : public binary_function<T1, T2, R> // if wraping a binary functor 393e519524SHoward Hinnant{ 403e519524SHoward Hinnantpublic: 413e519524SHoward Hinnant // types 423e519524SHoward Hinnant typedef T type; 433e519524SHoward Hinnant typedef see below result_type; // Not always defined 443e519524SHoward Hinnant 453e519524SHoward Hinnant // construct/copy/destroy 466a07d6f0SHoward Hinnant reference_wrapper(T&) noexcept; 473e519524SHoward Hinnant reference_wrapper(T&&) = delete; // do not bind to temps 486a07d6f0SHoward Hinnant reference_wrapper(const reference_wrapper<T>& x) noexcept; 493e519524SHoward Hinnant 503e519524SHoward Hinnant // assignment 516a07d6f0SHoward Hinnant reference_wrapper& operator=(const reference_wrapper<T>& x) noexcept; 523e519524SHoward Hinnant 533e519524SHoward Hinnant // access 546a07d6f0SHoward Hinnant operator T& () const noexcept; 556a07d6f0SHoward Hinnant T& get() const noexcept; 563e519524SHoward Hinnant 573e519524SHoward Hinnant // invoke 583e519524SHoward Hinnant template <class... ArgTypes> 59b76e6a95SHoward Hinnant typename result_of<T&(ArgTypes&&...)>::type 603e519524SHoward Hinnant operator() (ArgTypes&&...) const; 613e519524SHoward Hinnant}; 623e519524SHoward Hinnant 636a07d6f0SHoward Hinnanttemplate <class T> reference_wrapper<T> ref(T& t) noexcept; 649b0b6d45SHoward Hinnanttemplate <class T> void ref(const T&& t) = delete; 656a07d6f0SHoward Hinnanttemplate <class T> reference_wrapper<T> ref(reference_wrapper<T>t) noexcept; 663e519524SHoward Hinnant 676a07d6f0SHoward Hinnanttemplate <class T> reference_wrapper<const T> cref(const T& t) noexcept; 689b0b6d45SHoward Hinnanttemplate <class T> void cref(const T&& t) = delete; 696a07d6f0SHoward Hinnanttemplate <class T> reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept; 703e519524SHoward Hinnant 7183c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14 723e519524SHoward Hinnantstruct plus : binary_function<T, T, T> 733e519524SHoward Hinnant{ 743e519524SHoward Hinnant T operator()(const T& x, const T& y) const; 753e519524SHoward Hinnant}; 763e519524SHoward Hinnant 7783c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14 783e519524SHoward Hinnantstruct minus : binary_function<T, T, T> 793e519524SHoward Hinnant{ 803e519524SHoward Hinnant T operator()(const T& x, const T& y) const; 813e519524SHoward Hinnant}; 823e519524SHoward Hinnant 8383c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14 843e519524SHoward Hinnantstruct multiplies : binary_function<T, T, T> 853e519524SHoward Hinnant{ 863e519524SHoward Hinnant T operator()(const T& x, const T& y) const; 873e519524SHoward Hinnant}; 883e519524SHoward Hinnant 8983c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14 903e519524SHoward Hinnantstruct divides : binary_function<T, T, T> 913e519524SHoward Hinnant{ 923e519524SHoward Hinnant T operator()(const T& x, const T& y) const; 933e519524SHoward Hinnant}; 943e519524SHoward Hinnant 9583c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14 963e519524SHoward Hinnantstruct modulus : binary_function<T, T, T> 973e519524SHoward Hinnant{ 983e519524SHoward Hinnant T operator()(const T& x, const T& y) const; 993e519524SHoward Hinnant}; 1003e519524SHoward Hinnant 10183c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14 1023e519524SHoward Hinnantstruct negate : unary_function<T, T> 1033e519524SHoward Hinnant{ 1043e519524SHoward Hinnant T operator()(const T& x) const; 1053e519524SHoward Hinnant}; 1063e519524SHoward Hinnant 10783c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14 1083e519524SHoward Hinnantstruct equal_to : binary_function<T, T, bool> 1093e519524SHoward Hinnant{ 1103e519524SHoward Hinnant bool operator()(const T& x, const T& y) const; 1113e519524SHoward Hinnant}; 1123e519524SHoward Hinnant 11383c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14 1143e519524SHoward Hinnantstruct not_equal_to : binary_function<T, T, bool> 1153e519524SHoward Hinnant{ 1163e519524SHoward Hinnant bool operator()(const T& x, const T& y) const; 1173e519524SHoward Hinnant}; 1183e519524SHoward Hinnant 11983c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14 1203e519524SHoward Hinnantstruct greater : binary_function<T, T, bool> 1213e519524SHoward Hinnant{ 1223e519524SHoward Hinnant bool operator()(const T& x, const T& y) const; 1233e519524SHoward Hinnant}; 1243e519524SHoward Hinnant 12583c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14 1263e519524SHoward Hinnantstruct less : binary_function<T, T, bool> 1273e519524SHoward Hinnant{ 1283e519524SHoward Hinnant bool operator()(const T& x, const T& y) const; 1293e519524SHoward Hinnant}; 1303e519524SHoward Hinnant 13183c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14 1323e519524SHoward Hinnantstruct greater_equal : binary_function<T, T, bool> 1333e519524SHoward Hinnant{ 1343e519524SHoward Hinnant bool operator()(const T& x, const T& y) const; 1353e519524SHoward Hinnant}; 1363e519524SHoward Hinnant 13783c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14 1383e519524SHoward Hinnantstruct less_equal : binary_function<T, T, bool> 1393e519524SHoward Hinnant{ 1403e519524SHoward Hinnant bool operator()(const T& x, const T& y) const; 1413e519524SHoward Hinnant}; 1423e519524SHoward Hinnant 14383c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14 1443e519524SHoward Hinnantstruct logical_and : binary_function<T, T, bool> 1453e519524SHoward Hinnant{ 1463e519524SHoward Hinnant bool operator()(const T& x, const T& y) const; 1473e519524SHoward Hinnant}; 1483e519524SHoward Hinnant 14983c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14 1503e519524SHoward Hinnantstruct logical_or : binary_function<T, T, bool> 1513e519524SHoward Hinnant{ 1523e519524SHoward Hinnant bool operator()(const T& x, const T& y) const; 1533e519524SHoward Hinnant}; 1543e519524SHoward Hinnant 15583c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14 1563e519524SHoward Hinnantstruct logical_not : unary_function<T, bool> 1573e519524SHoward Hinnant{ 1583e519524SHoward Hinnant bool operator()(const T& x) const; 1593e519524SHoward Hinnant}; 1603e519524SHoward Hinnant 16183c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14 16283c08b44SMarshall Clowstruct bit_and : unary_function<T, bool> 16383c08b44SMarshall Clow{ 16483c08b44SMarshall Clow bool operator()(const T& x, const T& y) const; 16583c08b44SMarshall Clow}; 16683c08b44SMarshall Clow 16783c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14 16883c08b44SMarshall Clowstruct bit_or : unary_function<T, bool> 16983c08b44SMarshall Clow{ 17083c08b44SMarshall Clow bool operator()(const T& x, const T& y) const; 17183c08b44SMarshall Clow}; 17283c08b44SMarshall Clow 17383c08b44SMarshall Clowtemplate <class T> // <class T=void> in C++14 17483c08b44SMarshall Clowstruct bit_xor : unary_function<T, bool> 17583c08b44SMarshall Clow{ 17683c08b44SMarshall Clow bool operator()(const T& x, const T& y) const; 17783c08b44SMarshall Clow}; 17883c08b44SMarshall Clow 17983c08b44SMarshall Clowtemplate <class T=void> // C++14 18083c08b44SMarshall Clowstruct bit_xor : unary_function<T, bool> 18183c08b44SMarshall Clow{ 18283c08b44SMarshall Clow bool operator()(const T& x) const; 18383c08b44SMarshall Clow}; 18483c08b44SMarshall Clow 1853e519524SHoward Hinnanttemplate <class Predicate> 1863e519524SHoward Hinnantclass unary_negate 1873e519524SHoward Hinnant : public unary_function<typename Predicate::argument_type, bool> 1883e519524SHoward Hinnant{ 1893e519524SHoward Hinnantpublic: 1903e519524SHoward Hinnant explicit unary_negate(const Predicate& pred); 1913e519524SHoward Hinnant bool operator()(const typename Predicate::argument_type& x) const; 1923e519524SHoward Hinnant}; 1933e519524SHoward Hinnant 1943e519524SHoward Hinnanttemplate <class Predicate> unary_negate<Predicate> not1(const Predicate& pred); 1953e519524SHoward Hinnant 1963e519524SHoward Hinnanttemplate <class Predicate> 1973e519524SHoward Hinnantclass binary_negate 1983e519524SHoward Hinnant : public binary_function<typename Predicate::first_argument_type, 1993e519524SHoward Hinnant typename Predicate::second_argument_type, 2003e519524SHoward Hinnant bool> 2013e519524SHoward Hinnant{ 2023e519524SHoward Hinnantpublic: 2033e519524SHoward Hinnant explicit binary_negate(const Predicate& pred); 2043e519524SHoward Hinnant bool operator()(const typename Predicate::first_argument_type& x, 2053e519524SHoward Hinnant const typename Predicate::second_argument_type& y) const; 2063e519524SHoward Hinnant}; 2073e519524SHoward Hinnant 2083e519524SHoward Hinnanttemplate <class Predicate> binary_negate<Predicate> not2(const Predicate& pred); 2093e519524SHoward Hinnant 21057257567SEric Fiseliertemplate <class F> unspecified not_fn(F&& f); // C++17 21157257567SEric Fiselier 2123e519524SHoward Hinnanttemplate<class T> struct is_bind_expression; 2133e519524SHoward Hinnanttemplate<class T> struct is_placeholder; 2143e519524SHoward Hinnant 215a48055ceSMarshall Clow // See C++14 20.9.9, Function object binders 21640a01d53SMarshall Clowtemplate <class T> inline constexpr bool is_bind_expression_v 217a48055ceSMarshall Clow = is_bind_expression<T>::value; // C++17 21840a01d53SMarshall Clowtemplate <class T> inline constexpr int is_placeholder_v 219a48055ceSMarshall Clow = is_placeholder<T>::value; // C++17 220a48055ceSMarshall Clow 221a48055ceSMarshall Clow 2229b0b6d45SHoward Hinnanttemplate<class Fn, class... BoundArgs> 2239b0b6d45SHoward Hinnant unspecified bind(Fn&&, BoundArgs&&...); 2249b0b6d45SHoward Hinnanttemplate<class R, class Fn, class... BoundArgs> 2259b0b6d45SHoward Hinnant unspecified bind(Fn&&, BoundArgs&&...); 2263e519524SHoward Hinnant 2273e519524SHoward Hinnantnamespace placeholders { 2283e519524SHoward Hinnant // M is the implementation-defined number of placeholders 2293e519524SHoward Hinnant extern unspecified _1; 2303e519524SHoward Hinnant extern unspecified _2; 2313e519524SHoward Hinnant . 2323e519524SHoward Hinnant . 2333e519524SHoward Hinnant . 234c003db1fSHoward Hinnant extern unspecified _Mp; 2353e519524SHoward Hinnant} 2363e519524SHoward Hinnant 2373e519524SHoward Hinnanttemplate <class Operation> 2387d210c78SMarshall Clowclass binder1st // deprecated in C++11, removed in C++17 2393e519524SHoward Hinnant : public unary_function<typename Operation::second_argument_type, 2403e519524SHoward Hinnant typename Operation::result_type> 2413e519524SHoward Hinnant{ 2423e519524SHoward Hinnantprotected: 2433e519524SHoward Hinnant Operation op; 2443e519524SHoward Hinnant typename Operation::first_argument_type value; 2453e519524SHoward Hinnantpublic: 2463e519524SHoward Hinnant binder1st(const Operation& x, const typename Operation::first_argument_type y); 2473e519524SHoward Hinnant typename Operation::result_type operator()( typename Operation::second_argument_type& x) const; 2483e519524SHoward Hinnant typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const; 2493e519524SHoward Hinnant}; 2503e519524SHoward Hinnant 2513e519524SHoward Hinnanttemplate <class Operation, class T> 2527d210c78SMarshall Clowbinder1st<Operation> bind1st(const Operation& op, const T& x); // deprecated in C++11, removed in C++17 2533e519524SHoward Hinnant 2543e519524SHoward Hinnanttemplate <class Operation> 2557d210c78SMarshall Clowclass binder2nd // deprecated in C++11, removed in C++17 2563e519524SHoward Hinnant : public unary_function<typename Operation::first_argument_type, 2573e519524SHoward Hinnant typename Operation::result_type> 2583e519524SHoward Hinnant{ 2593e519524SHoward Hinnantprotected: 2603e519524SHoward Hinnant Operation op; 2613e519524SHoward Hinnant typename Operation::second_argument_type value; 2623e519524SHoward Hinnantpublic: 2633e519524SHoward Hinnant binder2nd(const Operation& x, const typename Operation::second_argument_type y); 2643e519524SHoward Hinnant typename Operation::result_type operator()( typename Operation::first_argument_type& x) const; 2653e519524SHoward Hinnant typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const; 2663e519524SHoward Hinnant}; 2673e519524SHoward Hinnant 2683e519524SHoward Hinnanttemplate <class Operation, class T> 2697d210c78SMarshall Clowbinder2nd<Operation> bind2nd(const Operation& op, const T& x); // deprecated in C++11, removed in C++17 2703e519524SHoward Hinnant 2717d210c78SMarshall Clowtemplate <class Arg, class Result> // deprecated in C++11, removed in C++17 2723e519524SHoward Hinnantclass pointer_to_unary_function : public unary_function<Arg, Result> 2733e519524SHoward Hinnant{ 2743e519524SHoward Hinnantpublic: 2753e519524SHoward Hinnant explicit pointer_to_unary_function(Result (*f)(Arg)); 2763e519524SHoward Hinnant Result operator()(Arg x) const; 2773e519524SHoward Hinnant}; 2783e519524SHoward Hinnant 2793e519524SHoward Hinnanttemplate <class Arg, class Result> 2807d210c78SMarshall Clowpointer_to_unary_function<Arg,Result> ptr_fun(Result (*f)(Arg)); // deprecated in C++11, removed in C++17 2813e519524SHoward Hinnant 2827d210c78SMarshall Clowtemplate <class Arg1, class Arg2, class Result> // deprecated in C++11, removed in C++17 2833e519524SHoward Hinnantclass pointer_to_binary_function : public binary_function<Arg1, Arg2, Result> 2843e519524SHoward Hinnant{ 2853e519524SHoward Hinnantpublic: 2863e519524SHoward Hinnant explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2)); 2873e519524SHoward Hinnant Result operator()(Arg1 x, Arg2 y) const; 2883e519524SHoward Hinnant}; 2893e519524SHoward Hinnant 2903e519524SHoward Hinnanttemplate <class Arg1, class Arg2, class Result> 2917d210c78SMarshall Clowpointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1,Arg2)); // deprecated in C++11, removed in C++17 2923e519524SHoward Hinnant 2937d210c78SMarshall Clowtemplate<class S, class T> // deprecated in C++11, removed in C++17 2943e519524SHoward Hinnantclass mem_fun_t : public unary_function<T*, S> 2953e519524SHoward Hinnant{ 2963e519524SHoward Hinnantpublic: 2973e519524SHoward Hinnant explicit mem_fun_t(S (T::*p)()); 2983e519524SHoward Hinnant S operator()(T* p) const; 2993e519524SHoward Hinnant}; 3003e519524SHoward Hinnant 3013e519524SHoward Hinnanttemplate<class S, class T, class A> 3027d210c78SMarshall Clowclass mem_fun1_t : public binary_function<T*, A, S> // deprecated in C++11, removed in C++17 3033e519524SHoward Hinnant{ 3043e519524SHoward Hinnantpublic: 3053e519524SHoward Hinnant explicit mem_fun1_t(S (T::*p)(A)); 3063e519524SHoward Hinnant S operator()(T* p, A x) const; 3073e519524SHoward Hinnant}; 3083e519524SHoward Hinnant 3097d210c78SMarshall Clowtemplate<class S, class T> mem_fun_t<S,T> mem_fun(S (T::*f)()); // deprecated in C++11, removed in C++17 3107d210c78SMarshall Clowtemplate<class S, class T, class A> mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A)); // deprecated in C++11, removed in C++17 3113e519524SHoward Hinnant 3123e519524SHoward Hinnanttemplate<class S, class T> 3137d210c78SMarshall Clowclass mem_fun_ref_t : public unary_function<T, S> // deprecated in C++11, removed in C++17 3143e519524SHoward Hinnant{ 3153e519524SHoward Hinnantpublic: 3163e519524SHoward Hinnant explicit mem_fun_ref_t(S (T::*p)()); 3173e519524SHoward Hinnant S operator()(T& p) const; 3183e519524SHoward Hinnant}; 3193e519524SHoward Hinnant 3203e519524SHoward Hinnanttemplate<class S, class T, class A> 3217d210c78SMarshall Clowclass mem_fun1_ref_t : public binary_function<T, A, S> // deprecated in C++11, removed in C++17 3223e519524SHoward Hinnant{ 3233e519524SHoward Hinnantpublic: 3243e519524SHoward Hinnant explicit mem_fun1_ref_t(S (T::*p)(A)); 3253e519524SHoward Hinnant S operator()(T& p, A x) const; 3263e519524SHoward Hinnant}; 3273e519524SHoward Hinnant 3287d210c78SMarshall Clowtemplate<class S, class T> mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)()); // deprecated in C++11, removed in C++17 3297d210c78SMarshall Clowtemplate<class S, class T, class A> mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A)); // deprecated in C++11, removed in C++17 3303e519524SHoward Hinnant 3313e519524SHoward Hinnanttemplate <class S, class T> 3327d210c78SMarshall Clowclass const_mem_fun_t : public unary_function<const T*, S> // deprecated in C++11, removed in C++17 3333e519524SHoward Hinnant{ 3343e519524SHoward Hinnantpublic: 3353e519524SHoward Hinnant explicit const_mem_fun_t(S (T::*p)() const); 3363e519524SHoward Hinnant S operator()(const T* p) const; 3373e519524SHoward Hinnant}; 3383e519524SHoward Hinnant 3393e519524SHoward Hinnanttemplate <class S, class T, class A> 3407d210c78SMarshall Clowclass const_mem_fun1_t : public binary_function<const T*, A, S> // deprecated in C++11, removed in C++17 3413e519524SHoward Hinnant{ 3423e519524SHoward Hinnantpublic: 3433e519524SHoward Hinnant explicit const_mem_fun1_t(S (T::*p)(A) const); 3443e519524SHoward Hinnant S operator()(const T* p, A x) const; 3453e519524SHoward Hinnant}; 3463e519524SHoward Hinnant 3477d210c78SMarshall Clowtemplate <class S, class T> const_mem_fun_t<S,T> mem_fun(S (T::*f)() const); // deprecated in C++11, removed in C++17 3487d210c78SMarshall Clowtemplate <class S, class T, class A> const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const); // deprecated in C++11, removed in C++17 3493e519524SHoward Hinnant 3503e519524SHoward Hinnanttemplate <class S, class T> 3517d210c78SMarshall Clowclass const_mem_fun_ref_t : public unary_function<T, S> // deprecated in C++11, removed in C++17 3523e519524SHoward Hinnant{ 3533e519524SHoward Hinnantpublic: 3543e519524SHoward Hinnant explicit const_mem_fun_ref_t(S (T::*p)() const); 3553e519524SHoward Hinnant S operator()(const T& p) const; 3563e519524SHoward Hinnant}; 3573e519524SHoward Hinnant 3583e519524SHoward Hinnanttemplate <class S, class T, class A> 3597d210c78SMarshall Clowclass const_mem_fun1_ref_t : public binary_function<T, A, S> // deprecated in C++11, removed in C++17 3603e519524SHoward Hinnant{ 3613e519524SHoward Hinnantpublic: 3623e519524SHoward Hinnant explicit const_mem_fun1_ref_t(S (T::*p)(A) const); 3633e519524SHoward Hinnant S operator()(const T& p, A x) const; 3643e519524SHoward Hinnant}; 3653e519524SHoward Hinnant 3667d210c78SMarshall Clowtemplate <class S, class T> const_mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)() const); // deprecated in C++11, removed in C++17 3677d210c78SMarshall Clowtemplate <class S, class T, class A> const_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const); // deprecated in C++11, removed in C++17 3683e519524SHoward Hinnant 3699b0b6d45SHoward Hinnanttemplate<class R, class T> unspecified mem_fn(R T::*); 3709b0b6d45SHoward Hinnant 3713e519524SHoward Hinnantclass bad_function_call 3723e519524SHoward Hinnant : public exception 3733e519524SHoward Hinnant{ 3743e519524SHoward Hinnant}; 3753e519524SHoward Hinnant 3769b0b6d45SHoward Hinnanttemplate<class> class function; // undefined 3773e519524SHoward Hinnant 3789b0b6d45SHoward Hinnanttemplate<class R, class... ArgTypes> 3793e519524SHoward Hinnantclass function<R(ArgTypes...)> 3803e519524SHoward Hinnant : public unary_function<T1, R> // iff sizeof...(ArgTypes) == 1 and 3813e519524SHoward Hinnant // ArgTypes contains T1 3823e519524SHoward Hinnant : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and 3833e519524SHoward Hinnant // ArgTypes contains T1 and T2 3843e519524SHoward Hinnant{ 3853e519524SHoward Hinnantpublic: 3863e519524SHoward Hinnant typedef R result_type; 3873e519524SHoward Hinnant 3889b0b6d45SHoward Hinnant // construct/copy/destroy: 3896a07d6f0SHoward Hinnant function() noexcept; 3906a07d6f0SHoward Hinnant function(nullptr_t) noexcept; 3913e519524SHoward Hinnant function(const function&); 3926a07d6f0SHoward Hinnant function(function&&) noexcept; 3933e519524SHoward Hinnant template<class F> 3943e519524SHoward Hinnant function(F); 3953e519524SHoward Hinnant template<Allocator Alloc> 3966ecac730SMarshall Clow function(allocator_arg_t, const Alloc&) noexcept; // removed in C++17 3973e519524SHoward Hinnant template<Allocator Alloc> 3986ecac730SMarshall Clow function(allocator_arg_t, const Alloc&, nullptr_t) noexcept; // removed in C++17 3993e519524SHoward Hinnant template<Allocator Alloc> 4006ecac730SMarshall Clow function(allocator_arg_t, const Alloc&, const function&); // removed in C++17 4013e519524SHoward Hinnant template<Allocator Alloc> 4026ecac730SMarshall Clow function(allocator_arg_t, const Alloc&, function&&); // removed in C++17 4033e519524SHoward Hinnant template<class F, Allocator Alloc> 4046ecac730SMarshall Clow function(allocator_arg_t, const Alloc&, F); // removed in C++17 4053e519524SHoward Hinnant 4063e519524SHoward Hinnant function& operator=(const function&); 4076a07d6f0SHoward Hinnant function& operator=(function&&) noexcept; 408af152c84SHoward Hinnant function& operator=(nullptr_t) noexcept; 4093e519524SHoward Hinnant template<class F> 4109b0b6d45SHoward Hinnant function& operator=(F&&); 4113e519524SHoward Hinnant template<class F> 4126a07d6f0SHoward Hinnant function& operator=(reference_wrapper<F>) noexcept; 4133e519524SHoward Hinnant 4143e519524SHoward Hinnant ~function(); 4153e519524SHoward Hinnant 4169b0b6d45SHoward Hinnant // function modifiers: 4176a07d6f0SHoward Hinnant void swap(function&) noexcept; 4189b0b6d45SHoward Hinnant template<class F, class Alloc> 4190aa1ccb0SMarshall Clow void assign(F&&, const Alloc&); // Removed in C++17 4203e519524SHoward Hinnant 4219b0b6d45SHoward Hinnant // function capacity: 4226a07d6f0SHoward Hinnant explicit operator bool() const noexcept; 4233e519524SHoward Hinnant 4249b0b6d45SHoward Hinnant // function invocation: 4253e519524SHoward Hinnant R operator()(ArgTypes...) const; 4263e519524SHoward Hinnant 4279b0b6d45SHoward Hinnant // function target access: 4286a07d6f0SHoward Hinnant const std::type_info& target_type() const noexcept; 4296a07d6f0SHoward Hinnant template <typename T> T* target() noexcept; 4306a07d6f0SHoward Hinnant template <typename T> const T* target() const noexcept; 4313e519524SHoward Hinnant}; 4323e519524SHoward Hinnant 4339b0b6d45SHoward Hinnant// Null pointer comparisons: 4349b0b6d45SHoward Hinnanttemplate <class R, class ... ArgTypes> 4356a07d6f0SHoward Hinnant bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept; 4363e519524SHoward Hinnant 4379b0b6d45SHoward Hinnanttemplate <class R, class ... ArgTypes> 4386a07d6f0SHoward Hinnant bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept; 4393e519524SHoward Hinnant 4409b0b6d45SHoward Hinnanttemplate <class R, class ... ArgTypes> 4416a07d6f0SHoward Hinnant bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept; 4423e519524SHoward Hinnant 4439b0b6d45SHoward Hinnanttemplate <class R, class ... ArgTypes> 4446a07d6f0SHoward Hinnant bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept; 4453e519524SHoward Hinnant 4469b0b6d45SHoward Hinnant// specialized algorithms: 4479b0b6d45SHoward Hinnanttemplate <class R, class ... ArgTypes> 4486a07d6f0SHoward Hinnant void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept; 4493e519524SHoward Hinnant 4503e519524SHoward Hinnanttemplate <class T> struct hash; 4513e519524SHoward Hinnant 4523e519524SHoward Hinnanttemplate <> struct hash<bool>; 4533e519524SHoward Hinnanttemplate <> struct hash<char>; 4543e519524SHoward Hinnanttemplate <> struct hash<signed char>; 4553e519524SHoward Hinnanttemplate <> struct hash<unsigned char>; 4563e519524SHoward Hinnanttemplate <> struct hash<char16_t>; 4573e519524SHoward Hinnanttemplate <> struct hash<char32_t>; 4583e519524SHoward Hinnanttemplate <> struct hash<wchar_t>; 4593e519524SHoward Hinnanttemplate <> struct hash<short>; 4603e519524SHoward Hinnanttemplate <> struct hash<unsigned short>; 4613e519524SHoward Hinnanttemplate <> struct hash<int>; 4623e519524SHoward Hinnanttemplate <> struct hash<unsigned int>; 4633e519524SHoward Hinnanttemplate <> struct hash<long>; 4643e519524SHoward Hinnanttemplate <> struct hash<long long>; 4653e519524SHoward Hinnanttemplate <> struct hash<unsigned long>; 4663e519524SHoward Hinnanttemplate <> struct hash<unsigned long long>; 4673e519524SHoward Hinnant 4683e519524SHoward Hinnanttemplate <> struct hash<float>; 4693e519524SHoward Hinnanttemplate <> struct hash<double>; 4703e519524SHoward Hinnanttemplate <> struct hash<long double>; 4713e519524SHoward Hinnant 4723e519524SHoward Hinnanttemplate<class T> struct hash<T*>; 473d8323168SMarshall Clowtemplate <> struct hash<nullptr_t>; // C++17 4743e519524SHoward Hinnant 4753e519524SHoward Hinnant} // std 4763e519524SHoward Hinnant 4773e519524SHoward HinnantPOLICY: For non-variadic implementations, the number of arguments is limited 4783e519524SHoward Hinnant to 3. It is hoped that the need for non-variadic implementations 4793e519524SHoward Hinnant will be minimal. 4803e519524SHoward Hinnant 4813e519524SHoward Hinnant*/ 4823e519524SHoward Hinnant 4833e519524SHoward Hinnant#include <__config> 4843e519524SHoward Hinnant#include <type_traits> 4853e519524SHoward Hinnant#include <typeinfo> 4863e519524SHoward Hinnant#include <exception> 4873e519524SHoward Hinnant#include <memory> 4883e519524SHoward Hinnant#include <tuple> 489f9127593SEric Fiselier#include <utility> 4903e519524SHoward Hinnant 4913e519524SHoward Hinnant#include <__functional_base> 4923e519524SHoward Hinnant 493073458b1SHoward Hinnant#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 4943e519524SHoward Hinnant#pragma GCC system_header 495073458b1SHoward Hinnant#endif 4963e519524SHoward Hinnant 4973e519524SHoward Hinnant_LIBCPP_BEGIN_NAMESPACE_STD 4983e519524SHoward Hinnant 49983c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 50083c08b44SMarshall Clowtemplate <class _Tp = void> 50183c08b44SMarshall Clow#else 5023e519524SHoward Hinnanttemplate <class _Tp> 50383c08b44SMarshall Clow#endif 504e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS plus : binary_function<_Tp, _Tp, _Tp> 5053e519524SHoward Hinnant{ 5063d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 5073d5134ddSMarshall Clow _Tp operator()(const _Tp& __x, const _Tp& __y) const 5083e519524SHoward Hinnant {return __x + __y;} 5093e519524SHoward Hinnant}; 5103e519524SHoward Hinnant 51183c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 51283c08b44SMarshall Clowtemplate <> 513e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS plus<void> 51483c08b44SMarshall Clow{ 51583c08b44SMarshall Clow template <class _T1, class _T2> 5163d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 5173d5134ddSMarshall Clow auto operator()(_T1&& __t, _T2&& __u) const 518a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))) 519a64f2fbcSMarshall Clow -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)) 52083c08b44SMarshall Clow { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); } 52125d3402cSMarshall Clow typedef void is_transparent; 52283c08b44SMarshall Clow}; 52383c08b44SMarshall Clow#endif 52483c08b44SMarshall Clow 52583c08b44SMarshall Clow 52683c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 52783c08b44SMarshall Clowtemplate <class _Tp = void> 52883c08b44SMarshall Clow#else 5293e519524SHoward Hinnanttemplate <class _Tp> 53083c08b44SMarshall Clow#endif 531e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS minus : binary_function<_Tp, _Tp, _Tp> 5323e519524SHoward Hinnant{ 5333d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 5343d5134ddSMarshall Clow _Tp operator()(const _Tp& __x, const _Tp& __y) const 5353e519524SHoward Hinnant {return __x - __y;} 5363e519524SHoward Hinnant}; 5373e519524SHoward Hinnant 53883c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 53983c08b44SMarshall Clowtemplate <> 540e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS minus<void> 54183c08b44SMarshall Clow{ 54283c08b44SMarshall Clow template <class _T1, class _T2> 5433d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 5443d5134ddSMarshall Clow auto operator()(_T1&& __t, _T2&& __u) const 545a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u))) 546a64f2fbcSMarshall Clow -> decltype (_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u)) 54783c08b44SMarshall Clow { return _VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u); } 54825d3402cSMarshall Clow typedef void is_transparent; 54983c08b44SMarshall Clow}; 55083c08b44SMarshall Clow#endif 55183c08b44SMarshall Clow 55283c08b44SMarshall Clow 55383c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 55483c08b44SMarshall Clowtemplate <class _Tp = void> 55583c08b44SMarshall Clow#else 5563e519524SHoward Hinnanttemplate <class _Tp> 55783c08b44SMarshall Clow#endif 558e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS multiplies : binary_function<_Tp, _Tp, _Tp> 5593e519524SHoward Hinnant{ 5603d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 5613d5134ddSMarshall Clow _Tp operator()(const _Tp& __x, const _Tp& __y) const 5623e519524SHoward Hinnant {return __x * __y;} 5633e519524SHoward Hinnant}; 5643e519524SHoward Hinnant 56583c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 56683c08b44SMarshall Clowtemplate <> 567e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS multiplies<void> 56883c08b44SMarshall Clow{ 56983c08b44SMarshall Clow template <class _T1, class _T2> 5703d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 5713d5134ddSMarshall Clow auto operator()(_T1&& __t, _T2&& __u) const 572a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u))) 573a64f2fbcSMarshall Clow -> decltype (_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u)) 57483c08b44SMarshall Clow { return _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u); } 57525d3402cSMarshall Clow typedef void is_transparent; 57683c08b44SMarshall Clow}; 57783c08b44SMarshall Clow#endif 57883c08b44SMarshall Clow 57983c08b44SMarshall Clow 58083c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 58183c08b44SMarshall Clowtemplate <class _Tp = void> 58283c08b44SMarshall Clow#else 5833e519524SHoward Hinnanttemplate <class _Tp> 58483c08b44SMarshall Clow#endif 585e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS divides : binary_function<_Tp, _Tp, _Tp> 5863e519524SHoward Hinnant{ 5873d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 5883d5134ddSMarshall Clow _Tp operator()(const _Tp& __x, const _Tp& __y) const 5893e519524SHoward Hinnant {return __x / __y;} 5903e519524SHoward Hinnant}; 5913e519524SHoward Hinnant 59283c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 59383c08b44SMarshall Clowtemplate <> 594e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS divides<void> 59583c08b44SMarshall Clow{ 59683c08b44SMarshall Clow template <class _T1, class _T2> 5973d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 5983d5134ddSMarshall Clow auto operator()(_T1&& __t, _T2&& __u) const 599a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u))) 600a64f2fbcSMarshall Clow -> decltype (_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u)) 60183c08b44SMarshall Clow { return _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u); } 60225d3402cSMarshall Clow typedef void is_transparent; 60383c08b44SMarshall Clow}; 60483c08b44SMarshall Clow#endif 60583c08b44SMarshall Clow 60683c08b44SMarshall Clow 60783c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 60883c08b44SMarshall Clowtemplate <class _Tp = void> 60983c08b44SMarshall Clow#else 6103e519524SHoward Hinnanttemplate <class _Tp> 61183c08b44SMarshall Clow#endif 612e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS modulus : binary_function<_Tp, _Tp, _Tp> 6133e519524SHoward Hinnant{ 6143d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 6153d5134ddSMarshall Clow _Tp operator()(const _Tp& __x, const _Tp& __y) const 6163e519524SHoward Hinnant {return __x % __y;} 6173e519524SHoward Hinnant}; 6183e519524SHoward Hinnant 61983c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 62083c08b44SMarshall Clowtemplate <> 621e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS modulus<void> 62283c08b44SMarshall Clow{ 62383c08b44SMarshall Clow template <class _T1, class _T2> 6243d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 6253d5134ddSMarshall Clow auto operator()(_T1&& __t, _T2&& __u) const 626a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u))) 627a64f2fbcSMarshall Clow -> decltype (_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u)) 62883c08b44SMarshall Clow { return _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u); } 62925d3402cSMarshall Clow typedef void is_transparent; 63083c08b44SMarshall Clow}; 63183c08b44SMarshall Clow#endif 63283c08b44SMarshall Clow 63383c08b44SMarshall Clow 63483c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 63583c08b44SMarshall Clowtemplate <class _Tp = void> 63683c08b44SMarshall Clow#else 6373e519524SHoward Hinnanttemplate <class _Tp> 63883c08b44SMarshall Clow#endif 639e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS negate : unary_function<_Tp, _Tp> 6403e519524SHoward Hinnant{ 6413d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 6423d5134ddSMarshall Clow _Tp operator()(const _Tp& __x) const 6433e519524SHoward Hinnant {return -__x;} 6443e519524SHoward Hinnant}; 6453e519524SHoward Hinnant 64683c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 64783c08b44SMarshall Clowtemplate <> 648e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS negate<void> 64983c08b44SMarshall Clow{ 6503e519524SHoward Hinnant template <class _Tp> 6513d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 6523d5134ddSMarshall Clow auto operator()(_Tp&& __x) const 653a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(- _VSTD::forward<_Tp>(__x))) 654a64f2fbcSMarshall Clow -> decltype (- _VSTD::forward<_Tp>(__x)) 65583c08b44SMarshall Clow { return - _VSTD::forward<_Tp>(__x); } 65625d3402cSMarshall Clow typedef void is_transparent; 65783c08b44SMarshall Clow}; 65883c08b44SMarshall Clow#endif 65983c08b44SMarshall Clow 66083c08b44SMarshall Clow 66183c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 66283c08b44SMarshall Clowtemplate <class _Tp = void> 66383c08b44SMarshall Clow#else 66483c08b44SMarshall Clowtemplate <class _Tp> 66583c08b44SMarshall Clow#endif 666e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS equal_to : binary_function<_Tp, _Tp, bool> 6673e519524SHoward Hinnant{ 6683d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 6693d5134ddSMarshall Clow bool operator()(const _Tp& __x, const _Tp& __y) const 6703e519524SHoward Hinnant {return __x == __y;} 6713e519524SHoward Hinnant}; 6723e519524SHoward Hinnant 67383c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 67483c08b44SMarshall Clowtemplate <> 675e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS equal_to<void> 67683c08b44SMarshall Clow{ 6773d5134ddSMarshall Clow template <class _T1, class _T2> 6783d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 67983c08b44SMarshall Clow auto operator()(_T1&& __t, _T2&& __u) const 680a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u))) 681a64f2fbcSMarshall Clow -> decltype (_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u)) 68283c08b44SMarshall Clow { return _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u); } 68325d3402cSMarshall Clow typedef void is_transparent; 68483c08b44SMarshall Clow}; 68583c08b44SMarshall Clow#endif 68683c08b44SMarshall Clow 68783c08b44SMarshall Clow 68883c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 68983c08b44SMarshall Clowtemplate <class _Tp = void> 69083c08b44SMarshall Clow#else 6913e519524SHoward Hinnanttemplate <class _Tp> 69283c08b44SMarshall Clow#endif 693e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS not_equal_to : binary_function<_Tp, _Tp, bool> 6943e519524SHoward Hinnant{ 6953d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 6963d5134ddSMarshall Clow bool operator()(const _Tp& __x, const _Tp& __y) const 6973e519524SHoward Hinnant {return __x != __y;} 6983e519524SHoward Hinnant}; 6993e519524SHoward Hinnant 70083c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 70183c08b44SMarshall Clowtemplate <> 702e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS not_equal_to<void> 70383c08b44SMarshall Clow{ 7043d5134ddSMarshall Clow template <class _T1, class _T2> 7053d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 70683c08b44SMarshall Clow auto operator()(_T1&& __t, _T2&& __u) const 707a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u))) 708a64f2fbcSMarshall Clow -> decltype (_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u)) 70983c08b44SMarshall Clow { return _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u); } 71025d3402cSMarshall Clow typedef void is_transparent; 71183c08b44SMarshall Clow}; 71283c08b44SMarshall Clow#endif 71383c08b44SMarshall Clow 71483c08b44SMarshall Clow 71583c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 71683c08b44SMarshall Clowtemplate <class _Tp = void> 71783c08b44SMarshall Clow#else 7183e519524SHoward Hinnanttemplate <class _Tp> 71983c08b44SMarshall Clow#endif 720e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS greater : binary_function<_Tp, _Tp, bool> 7213e519524SHoward Hinnant{ 7223d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 7233d5134ddSMarshall Clow bool operator()(const _Tp& __x, const _Tp& __y) const 7243e519524SHoward Hinnant {return __x > __y;} 7253e519524SHoward Hinnant}; 7263e519524SHoward Hinnant 72783c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 72883c08b44SMarshall Clowtemplate <> 729e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS greater<void> 73083c08b44SMarshall Clow{ 7313d5134ddSMarshall Clow template <class _T1, class _T2> 7323d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 73383c08b44SMarshall Clow auto operator()(_T1&& __t, _T2&& __u) const 734a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u))) 735a64f2fbcSMarshall Clow -> decltype (_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u)) 73683c08b44SMarshall Clow { return _VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u); } 73725d3402cSMarshall Clow typedef void is_transparent; 73883c08b44SMarshall Clow}; 73983c08b44SMarshall Clow#endif 74083c08b44SMarshall Clow 74183c08b44SMarshall Clow 74267f39647SHoward Hinnant// less in <__functional_base> 7433e519524SHoward Hinnant 74483c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 74583c08b44SMarshall Clowtemplate <class _Tp = void> 74683c08b44SMarshall Clow#else 7473e519524SHoward Hinnanttemplate <class _Tp> 74883c08b44SMarshall Clow#endif 749e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS greater_equal : binary_function<_Tp, _Tp, bool> 7503e519524SHoward Hinnant{ 7513d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 7523d5134ddSMarshall Clow bool operator()(const _Tp& __x, const _Tp& __y) const 7533e519524SHoward Hinnant {return __x >= __y;} 7543e519524SHoward Hinnant}; 7553e519524SHoward Hinnant 75683c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 75783c08b44SMarshall Clowtemplate <> 758e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS greater_equal<void> 75983c08b44SMarshall Clow{ 7603d5134ddSMarshall Clow template <class _T1, class _T2> 7613d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 76283c08b44SMarshall Clow auto operator()(_T1&& __t, _T2&& __u) const 763a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u))) 764a64f2fbcSMarshall Clow -> decltype (_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u)) 76583c08b44SMarshall Clow { return _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u); } 76625d3402cSMarshall Clow typedef void is_transparent; 76783c08b44SMarshall Clow}; 76883c08b44SMarshall Clow#endif 76983c08b44SMarshall Clow 77083c08b44SMarshall Clow 77183c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 77283c08b44SMarshall Clowtemplate <class _Tp = void> 77383c08b44SMarshall Clow#else 7743e519524SHoward Hinnanttemplate <class _Tp> 77583c08b44SMarshall Clow#endif 776e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS less_equal : binary_function<_Tp, _Tp, bool> 7773e519524SHoward Hinnant{ 7783d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 7793d5134ddSMarshall Clow bool operator()(const _Tp& __x, const _Tp& __y) const 7803e519524SHoward Hinnant {return __x <= __y;} 7813e519524SHoward Hinnant}; 7823e519524SHoward Hinnant 78383c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 78483c08b44SMarshall Clowtemplate <> 785e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS less_equal<void> 78683c08b44SMarshall Clow{ 7873d5134ddSMarshall Clow template <class _T1, class _T2> 7883d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 78983c08b44SMarshall Clow auto operator()(_T1&& __t, _T2&& __u) const 790a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u))) 791a64f2fbcSMarshall Clow -> decltype (_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u)) 79283c08b44SMarshall Clow { return _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u); } 79325d3402cSMarshall Clow typedef void is_transparent; 79483c08b44SMarshall Clow}; 79583c08b44SMarshall Clow#endif 79683c08b44SMarshall Clow 79783c08b44SMarshall Clow 79883c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 79983c08b44SMarshall Clowtemplate <class _Tp = void> 80083c08b44SMarshall Clow#else 8013e519524SHoward Hinnanttemplate <class _Tp> 80283c08b44SMarshall Clow#endif 803e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS logical_and : binary_function<_Tp, _Tp, bool> 8043e519524SHoward Hinnant{ 8053d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 8063d5134ddSMarshall Clow bool operator()(const _Tp& __x, const _Tp& __y) const 8073e519524SHoward Hinnant {return __x && __y;} 8083e519524SHoward Hinnant}; 8093e519524SHoward Hinnant 81083c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 81183c08b44SMarshall Clowtemplate <> 812e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS logical_and<void> 81383c08b44SMarshall Clow{ 8143d5134ddSMarshall Clow template <class _T1, class _T2> 8153d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 81683c08b44SMarshall Clow auto operator()(_T1&& __t, _T2&& __u) const 817a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u))) 818a64f2fbcSMarshall Clow -> decltype (_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u)) 81983c08b44SMarshall Clow { return _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u); } 82025d3402cSMarshall Clow typedef void is_transparent; 82183c08b44SMarshall Clow}; 82283c08b44SMarshall Clow#endif 82383c08b44SMarshall Clow 82483c08b44SMarshall Clow 82583c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 82683c08b44SMarshall Clowtemplate <class _Tp = void> 82783c08b44SMarshall Clow#else 8283e519524SHoward Hinnanttemplate <class _Tp> 82983c08b44SMarshall Clow#endif 830e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS logical_or : binary_function<_Tp, _Tp, bool> 8313e519524SHoward Hinnant{ 8323d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 8333d5134ddSMarshall Clow bool operator()(const _Tp& __x, const _Tp& __y) const 8343e519524SHoward Hinnant {return __x || __y;} 8353e519524SHoward Hinnant}; 8363e519524SHoward Hinnant 83783c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 83883c08b44SMarshall Clowtemplate <> 839e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS logical_or<void> 84083c08b44SMarshall Clow{ 8413d5134ddSMarshall Clow template <class _T1, class _T2> 8423d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 84383c08b44SMarshall Clow auto operator()(_T1&& __t, _T2&& __u) const 844a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u))) 845a64f2fbcSMarshall Clow -> decltype (_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u)) 84683c08b44SMarshall Clow { return _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u); } 84725d3402cSMarshall Clow typedef void is_transparent; 84883c08b44SMarshall Clow}; 84983c08b44SMarshall Clow#endif 85083c08b44SMarshall Clow 85183c08b44SMarshall Clow 85283c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 85383c08b44SMarshall Clowtemplate <class _Tp = void> 85483c08b44SMarshall Clow#else 8553e519524SHoward Hinnanttemplate <class _Tp> 85683c08b44SMarshall Clow#endif 857e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS logical_not : unary_function<_Tp, bool> 8583e519524SHoward Hinnant{ 8593d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 8603d5134ddSMarshall Clow bool operator()(const _Tp& __x) const 8613e519524SHoward Hinnant {return !__x;} 8623e519524SHoward Hinnant}; 8633e519524SHoward Hinnant 86483c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 86583c08b44SMarshall Clowtemplate <> 866e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS logical_not<void> 86783c08b44SMarshall Clow{ 8683e519524SHoward Hinnant template <class _Tp> 8693d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 8703d5134ddSMarshall Clow auto operator()(_Tp&& __x) const 871a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(!_VSTD::forward<_Tp>(__x))) 872a64f2fbcSMarshall Clow -> decltype (!_VSTD::forward<_Tp>(__x)) 87383c08b44SMarshall Clow { return !_VSTD::forward<_Tp>(__x); } 87425d3402cSMarshall Clow typedef void is_transparent; 87583c08b44SMarshall Clow}; 87683c08b44SMarshall Clow#endif 87783c08b44SMarshall Clow 87883c08b44SMarshall Clow 87983c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 88083c08b44SMarshall Clowtemplate <class _Tp = void> 88183c08b44SMarshall Clow#else 88283c08b44SMarshall Clowtemplate <class _Tp> 88383c08b44SMarshall Clow#endif 884e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS bit_and : binary_function<_Tp, _Tp, _Tp> 8853e519524SHoward Hinnant{ 8863d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 8873d5134ddSMarshall Clow _Tp operator()(const _Tp& __x, const _Tp& __y) const 8883e519524SHoward Hinnant {return __x & __y;} 8893e519524SHoward Hinnant}; 8903e519524SHoward Hinnant 89183c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 89283c08b44SMarshall Clowtemplate <> 893e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS bit_and<void> 89483c08b44SMarshall Clow{ 8953d5134ddSMarshall Clow template <class _T1, class _T2> 8963d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 89783c08b44SMarshall Clow auto operator()(_T1&& __t, _T2&& __u) const 898a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u))) 899a64f2fbcSMarshall Clow -> decltype (_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u)) 90083c08b44SMarshall Clow { return _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u); } 90125d3402cSMarshall Clow typedef void is_transparent; 90283c08b44SMarshall Clow}; 90383c08b44SMarshall Clow#endif 90483c08b44SMarshall Clow 90583c08b44SMarshall Clow 90683c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 90783c08b44SMarshall Clowtemplate <class _Tp = void> 90883c08b44SMarshall Clow#else 9093e519524SHoward Hinnanttemplate <class _Tp> 91083c08b44SMarshall Clow#endif 911e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS bit_or : binary_function<_Tp, _Tp, _Tp> 9123e519524SHoward Hinnant{ 9133d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 9143d5134ddSMarshall Clow _Tp operator()(const _Tp& __x, const _Tp& __y) const 9153e519524SHoward Hinnant {return __x | __y;} 9163e519524SHoward Hinnant}; 9173e519524SHoward Hinnant 91883c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 91983c08b44SMarshall Clowtemplate <> 920e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS bit_or<void> 92183c08b44SMarshall Clow{ 9223d5134ddSMarshall Clow template <class _T1, class _T2> 9233d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 92483c08b44SMarshall Clow auto operator()(_T1&& __t, _T2&& __u) const 925a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u))) 926a64f2fbcSMarshall Clow -> decltype (_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u)) 92783c08b44SMarshall Clow { return _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u); } 92825d3402cSMarshall Clow typedef void is_transparent; 92983c08b44SMarshall Clow}; 93083c08b44SMarshall Clow#endif 93183c08b44SMarshall Clow 93283c08b44SMarshall Clow 93383c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 93483c08b44SMarshall Clowtemplate <class _Tp = void> 93583c08b44SMarshall Clow#else 9363e519524SHoward Hinnanttemplate <class _Tp> 93783c08b44SMarshall Clow#endif 938e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS bit_xor : binary_function<_Tp, _Tp, _Tp> 9393e519524SHoward Hinnant{ 9403d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 9413d5134ddSMarshall Clow _Tp operator()(const _Tp& __x, const _Tp& __y) const 9423e519524SHoward Hinnant {return __x ^ __y;} 9433e519524SHoward Hinnant}; 9443e519524SHoward Hinnant 94583c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 94683c08b44SMarshall Clowtemplate <> 947e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS bit_xor<void> 94883c08b44SMarshall Clow{ 9493d5134ddSMarshall Clow template <class _T1, class _T2> 9503d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 95183c08b44SMarshall Clow auto operator()(_T1&& __t, _T2&& __u) const 952a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u))) 953a64f2fbcSMarshall Clow -> decltype (_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u)) 95483c08b44SMarshall Clow { return _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u); } 95525d3402cSMarshall Clow typedef void is_transparent; 95683c08b44SMarshall Clow}; 95783c08b44SMarshall Clow#endif 95883c08b44SMarshall Clow 95983c08b44SMarshall Clow 96083c08b44SMarshall Clow#if _LIBCPP_STD_VER > 11 96183c08b44SMarshall Clowtemplate <class _Tp = void> 962e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS bit_not : unary_function<_Tp, _Tp> 96383c08b44SMarshall Clow{ 9643d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 9653d5134ddSMarshall Clow _Tp operator()(const _Tp& __x) const 96683c08b44SMarshall Clow {return ~__x;} 96783c08b44SMarshall Clow}; 96883c08b44SMarshall Clow 96983c08b44SMarshall Clowtemplate <> 970e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS bit_not<void> 97183c08b44SMarshall Clow{ 97283c08b44SMarshall Clow template <class _Tp> 9733d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 9743d5134ddSMarshall Clow auto operator()(_Tp&& __x) const 975a64f2fbcSMarshall Clow _NOEXCEPT_(noexcept(~_VSTD::forward<_Tp>(__x))) 976a64f2fbcSMarshall Clow -> decltype (~_VSTD::forward<_Tp>(__x)) 97783c08b44SMarshall Clow { return ~_VSTD::forward<_Tp>(__x); } 97825d3402cSMarshall Clow typedef void is_transparent; 97983c08b44SMarshall Clow}; 98083c08b44SMarshall Clow#endif 98183c08b44SMarshall Clow 9823e519524SHoward Hinnanttemplate <class _Predicate> 983e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS unary_negate 9843e519524SHoward Hinnant : public unary_function<typename _Predicate::argument_type, bool> 9853e519524SHoward Hinnant{ 9863e519524SHoward Hinnant _Predicate __pred_; 9873e519524SHoward Hinnantpublic: 9883d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 9893d5134ddSMarshall Clow explicit unary_negate(const _Predicate& __pred) 9903e519524SHoward Hinnant : __pred_(__pred) {} 9913d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 9923d5134ddSMarshall Clow bool operator()(const typename _Predicate::argument_type& __x) const 9933e519524SHoward Hinnant {return !__pred_(__x);} 9943e519524SHoward Hinnant}; 9953e519524SHoward Hinnant 9963e519524SHoward Hinnanttemplate <class _Predicate> 9973d5134ddSMarshall Clowinline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 9983e519524SHoward Hinnantunary_negate<_Predicate> 9993e519524SHoward Hinnantnot1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);} 10003e519524SHoward Hinnant 10013e519524SHoward Hinnanttemplate <class _Predicate> 1002e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS binary_negate 10033e519524SHoward Hinnant : public binary_function<typename _Predicate::first_argument_type, 10043e519524SHoward Hinnant typename _Predicate::second_argument_type, 10053e519524SHoward Hinnant bool> 10063e519524SHoward Hinnant{ 10073e519524SHoward Hinnant _Predicate __pred_; 10083e519524SHoward Hinnantpublic: 10093d5134ddSMarshall Clow _LIBCPP_INLINE_VISIBILITY explicit _LIBCPP_CONSTEXPR_AFTER_CXX11 10103d5134ddSMarshall Clow binary_negate(const _Predicate& __pred) : __pred_(__pred) {} 10113d5134ddSMarshall Clow 10123d5134ddSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 10133d5134ddSMarshall Clow bool operator()(const typename _Predicate::first_argument_type& __x, 10143e519524SHoward Hinnant const typename _Predicate::second_argument_type& __y) const 10153e519524SHoward Hinnant {return !__pred_(__x, __y);} 10163e519524SHoward Hinnant}; 10173e519524SHoward Hinnant 10183e519524SHoward Hinnanttemplate <class _Predicate> 10193d5134ddSMarshall Clowinline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 10203e519524SHoward Hinnantbinary_negate<_Predicate> 10213e519524SHoward Hinnantnot2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);} 10223e519524SHoward Hinnant 10237d210c78SMarshall Clow#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS) 10243e519524SHoward Hinnanttemplate <class __Operation> 1025e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS binder1st 10263e519524SHoward Hinnant : public unary_function<typename __Operation::second_argument_type, 10273e519524SHoward Hinnant typename __Operation::result_type> 10283e519524SHoward Hinnant{ 10293e519524SHoward Hinnantprotected: 10303e519524SHoward Hinnant __Operation op; 10313e519524SHoward Hinnant typename __Operation::first_argument_type value; 10323e519524SHoward Hinnantpublic: 10333e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x, 10343e519524SHoward Hinnant const typename __Operation::first_argument_type __y) 10353e519524SHoward Hinnant : op(__x), value(__y) {} 10363e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() 10373e519524SHoward Hinnant (typename __Operation::second_argument_type& __x) const 10383e519524SHoward Hinnant {return op(value, __x);} 10393e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() 10403e519524SHoward Hinnant (const typename __Operation::second_argument_type& __x) const 10413e519524SHoward Hinnant {return op(value, __x);} 10423e519524SHoward Hinnant}; 10433e519524SHoward Hinnant 10443e519524SHoward Hinnanttemplate <class __Operation, class _Tp> 10453e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 10463e519524SHoward Hinnantbinder1st<__Operation> 10473e519524SHoward Hinnantbind1st(const __Operation& __op, const _Tp& __x) 10483e519524SHoward Hinnant {return binder1st<__Operation>(__op, __x);} 10493e519524SHoward Hinnant 10503e519524SHoward Hinnanttemplate <class __Operation> 1051e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS binder2nd 10523e519524SHoward Hinnant : public unary_function<typename __Operation::first_argument_type, 10533e519524SHoward Hinnant typename __Operation::result_type> 10543e519524SHoward Hinnant{ 10553e519524SHoward Hinnantprotected: 10563e519524SHoward Hinnant __Operation op; 10573e519524SHoward Hinnant typename __Operation::second_argument_type value; 10583e519524SHoward Hinnantpublic: 10590af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 10603e519524SHoward Hinnant binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y) 10613e519524SHoward Hinnant : op(__x), value(__y) {} 10623e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() 10633e519524SHoward Hinnant ( typename __Operation::first_argument_type& __x) const 10643e519524SHoward Hinnant {return op(__x, value);} 10653e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() 10663e519524SHoward Hinnant (const typename __Operation::first_argument_type& __x) const 10673e519524SHoward Hinnant {return op(__x, value);} 10683e519524SHoward Hinnant}; 10693e519524SHoward Hinnant 10703e519524SHoward Hinnanttemplate <class __Operation, class _Tp> 10713e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 10723e519524SHoward Hinnantbinder2nd<__Operation> 10733e519524SHoward Hinnantbind2nd(const __Operation& __op, const _Tp& __x) 10743e519524SHoward Hinnant {return binder2nd<__Operation>(__op, __x);} 10753e519524SHoward Hinnant 10763e519524SHoward Hinnanttemplate <class _Arg, class _Result> 1077e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS pointer_to_unary_function 10780af133f9SHoward Hinnant : public unary_function<_Arg, _Result> 10793e519524SHoward Hinnant{ 10803e519524SHoward Hinnant _Result (*__f_)(_Arg); 10813e519524SHoward Hinnantpublic: 10823e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg)) 10833e519524SHoward Hinnant : __f_(__f) {} 10843e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const 10853e519524SHoward Hinnant {return __f_(__x);} 10863e519524SHoward Hinnant}; 10873e519524SHoward Hinnant 10883e519524SHoward Hinnanttemplate <class _Arg, class _Result> 10893e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 10903e519524SHoward Hinnantpointer_to_unary_function<_Arg,_Result> 10913e519524SHoward Hinnantptr_fun(_Result (*__f)(_Arg)) 10923e519524SHoward Hinnant {return pointer_to_unary_function<_Arg,_Result>(__f);} 10933e519524SHoward Hinnant 10943e519524SHoward Hinnanttemplate <class _Arg1, class _Arg2, class _Result> 1095e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS pointer_to_binary_function 10960af133f9SHoward Hinnant : public binary_function<_Arg1, _Arg2, _Result> 10973e519524SHoward Hinnant{ 10983e519524SHoward Hinnant _Result (*__f_)(_Arg1, _Arg2); 10993e519524SHoward Hinnantpublic: 11003e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2)) 11013e519524SHoward Hinnant : __f_(__f) {} 11023e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const 11033e519524SHoward Hinnant {return __f_(__x, __y);} 11043e519524SHoward Hinnant}; 11053e519524SHoward Hinnant 11063e519524SHoward Hinnanttemplate <class _Arg1, class _Arg2, class _Result> 11073e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 11083e519524SHoward Hinnantpointer_to_binary_function<_Arg1,_Arg2,_Result> 11093e519524SHoward Hinnantptr_fun(_Result (*__f)(_Arg1,_Arg2)) 11103e519524SHoward Hinnant {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);} 11113e519524SHoward Hinnant 11123e519524SHoward Hinnanttemplate<class _Sp, class _Tp> 1113e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS mem_fun_t : public unary_function<_Tp*, _Sp> 11143e519524SHoward Hinnant{ 11153e519524SHoward Hinnant _Sp (_Tp::*__p_)(); 11163e519524SHoward Hinnantpublic: 11173e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)()) 11183e519524SHoward Hinnant : __p_(__p) {} 11193e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const 11203e519524SHoward Hinnant {return (__p->*__p_)();} 11213e519524SHoward Hinnant}; 11223e519524SHoward Hinnant 11233e519524SHoward Hinnanttemplate<class _Sp, class _Tp, class _Ap> 1124e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS mem_fun1_t : public binary_function<_Tp*, _Ap, _Sp> 11253e519524SHoward Hinnant{ 11263e519524SHoward Hinnant _Sp (_Tp::*__p_)(_Ap); 11273e519524SHoward Hinnantpublic: 11283e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap)) 11293e519524SHoward Hinnant : __p_(__p) {} 11303e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const 11313e519524SHoward Hinnant {return (__p->*__p_)(__x);} 11323e519524SHoward Hinnant}; 11333e519524SHoward Hinnant 11343e519524SHoward Hinnanttemplate<class _Sp, class _Tp> 11353e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 11363e519524SHoward Hinnantmem_fun_t<_Sp,_Tp> 11373e519524SHoward Hinnantmem_fun(_Sp (_Tp::*__f)()) 11383e519524SHoward Hinnant {return mem_fun_t<_Sp,_Tp>(__f);} 11393e519524SHoward Hinnant 11403e519524SHoward Hinnanttemplate<class _Sp, class _Tp, class _Ap> 11413e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 11423e519524SHoward Hinnantmem_fun1_t<_Sp,_Tp,_Ap> 11433e519524SHoward Hinnantmem_fun(_Sp (_Tp::*__f)(_Ap)) 11443e519524SHoward Hinnant {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);} 11453e519524SHoward Hinnant 11463e519524SHoward Hinnanttemplate<class _Sp, class _Tp> 1147e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS mem_fun_ref_t : public unary_function<_Tp, _Sp> 11483e519524SHoward Hinnant{ 11493e519524SHoward Hinnant _Sp (_Tp::*__p_)(); 11503e519524SHoward Hinnantpublic: 11513e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)()) 11523e519524SHoward Hinnant : __p_(__p) {} 11533e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const 11543e519524SHoward Hinnant {return (__p.*__p_)();} 11553e519524SHoward Hinnant}; 11563e519524SHoward Hinnant 11573e519524SHoward Hinnanttemplate<class _Sp, class _Tp, class _Ap> 1158e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS mem_fun1_ref_t : public binary_function<_Tp, _Ap, _Sp> 11593e519524SHoward Hinnant{ 11603e519524SHoward Hinnant _Sp (_Tp::*__p_)(_Ap); 11613e519524SHoward Hinnantpublic: 11623e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap)) 11633e519524SHoward Hinnant : __p_(__p) {} 11643e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const 11653e519524SHoward Hinnant {return (__p.*__p_)(__x);} 11663e519524SHoward Hinnant}; 11673e519524SHoward Hinnant 11683e519524SHoward Hinnanttemplate<class _Sp, class _Tp> 11693e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 11703e519524SHoward Hinnantmem_fun_ref_t<_Sp,_Tp> 11713e519524SHoward Hinnantmem_fun_ref(_Sp (_Tp::*__f)()) 11723e519524SHoward Hinnant {return mem_fun_ref_t<_Sp,_Tp>(__f);} 11733e519524SHoward Hinnant 11743e519524SHoward Hinnanttemplate<class _Sp, class _Tp, class _Ap> 11753e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 11763e519524SHoward Hinnantmem_fun1_ref_t<_Sp,_Tp,_Ap> 11773e519524SHoward Hinnantmem_fun_ref(_Sp (_Tp::*__f)(_Ap)) 11783e519524SHoward Hinnant {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);} 11793e519524SHoward Hinnant 11803e519524SHoward Hinnanttemplate <class _Sp, class _Tp> 1181e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS const_mem_fun_t : public unary_function<const _Tp*, _Sp> 11823e519524SHoward Hinnant{ 11833e519524SHoward Hinnant _Sp (_Tp::*__p_)() const; 11843e519524SHoward Hinnantpublic: 11853e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const) 11863e519524SHoward Hinnant : __p_(__p) {} 11873e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const 11883e519524SHoward Hinnant {return (__p->*__p_)();} 11893e519524SHoward Hinnant}; 11903e519524SHoward Hinnant 11913e519524SHoward Hinnanttemplate <class _Sp, class _Tp, class _Ap> 1192e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS const_mem_fun1_t : public binary_function<const _Tp*, _Ap, _Sp> 11933e519524SHoward Hinnant{ 11943e519524SHoward Hinnant _Sp (_Tp::*__p_)(_Ap) const; 11953e519524SHoward Hinnantpublic: 11963e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const) 11973e519524SHoward Hinnant : __p_(__p) {} 11983e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const 11993e519524SHoward Hinnant {return (__p->*__p_)(__x);} 12003e519524SHoward Hinnant}; 12013e519524SHoward Hinnant 12023e519524SHoward Hinnanttemplate <class _Sp, class _Tp> 12033e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 12043e519524SHoward Hinnantconst_mem_fun_t<_Sp,_Tp> 12053e519524SHoward Hinnantmem_fun(_Sp (_Tp::*__f)() const) 12063e519524SHoward Hinnant {return const_mem_fun_t<_Sp,_Tp>(__f);} 12073e519524SHoward Hinnant 12083e519524SHoward Hinnanttemplate <class _Sp, class _Tp, class _Ap> 12093e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 12103e519524SHoward Hinnantconst_mem_fun1_t<_Sp,_Tp,_Ap> 12113e519524SHoward Hinnantmem_fun(_Sp (_Tp::*__f)(_Ap) const) 12123e519524SHoward Hinnant {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);} 12133e519524SHoward Hinnant 12143e519524SHoward Hinnanttemplate <class _Sp, class _Tp> 1215e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS const_mem_fun_ref_t : public unary_function<_Tp, _Sp> 12163e519524SHoward Hinnant{ 12173e519524SHoward Hinnant _Sp (_Tp::*__p_)() const; 12183e519524SHoward Hinnantpublic: 12193e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const) 12203e519524SHoward Hinnant : __p_(__p) {} 12213e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const 12223e519524SHoward Hinnant {return (__p.*__p_)();} 12233e519524SHoward Hinnant}; 12243e519524SHoward Hinnant 12253e519524SHoward Hinnanttemplate <class _Sp, class _Tp, class _Ap> 1226e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS const_mem_fun1_ref_t 12270af133f9SHoward Hinnant : public binary_function<_Tp, _Ap, _Sp> 12283e519524SHoward Hinnant{ 12293e519524SHoward Hinnant _Sp (_Tp::*__p_)(_Ap) const; 12303e519524SHoward Hinnantpublic: 12313e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const) 12323e519524SHoward Hinnant : __p_(__p) {} 12333e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const 12343e519524SHoward Hinnant {return (__p.*__p_)(__x);} 12353e519524SHoward Hinnant}; 12363e519524SHoward Hinnant 12373e519524SHoward Hinnanttemplate <class _Sp, class _Tp> 12383e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 12393e519524SHoward Hinnantconst_mem_fun_ref_t<_Sp,_Tp> 12403e519524SHoward Hinnantmem_fun_ref(_Sp (_Tp::*__f)() const) 12413e519524SHoward Hinnant {return const_mem_fun_ref_t<_Sp,_Tp>(__f);} 12423e519524SHoward Hinnant 12433e519524SHoward Hinnanttemplate <class _Sp, class _Tp, class _Ap> 12443e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 12453e519524SHoward Hinnantconst_mem_fun1_ref_t<_Sp,_Tp,_Ap> 12463e519524SHoward Hinnantmem_fun_ref(_Sp (_Tp::*__f)(_Ap) const) 12473e519524SHoward Hinnant {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);} 12487d210c78SMarshall Clow#endif 12493e519524SHoward Hinnant 1250e5407178SEric Fiselier//////////////////////////////////////////////////////////////////////////////// 1251e5407178SEric Fiselier// MEMFUN 1252e5407178SEric Fiselier//============================================================================== 12533e519524SHoward Hinnant 12543e519524SHoward Hinnanttemplate <class _Tp> 12553e519524SHoward Hinnantclass __mem_fn 12563e519524SHoward Hinnant : public __weak_result_type<_Tp> 12573e519524SHoward Hinnant{ 12583e519524SHoward Hinnantpublic: 12593e519524SHoward Hinnant // types 12603e519524SHoward Hinnant typedef _Tp type; 12613e519524SHoward Hinnantprivate: 12623e519524SHoward Hinnant type __f_; 12633e519524SHoward Hinnant 12643e519524SHoward Hinnantpublic: 12653b72a6efSMarshall Clow _LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) _NOEXCEPT : __f_(__f) {} 12663e519524SHoward Hinnant 12677e23afcbSEric Fiselier#ifndef _LIBCPP_CXX03_LANG 12683e519524SHoward Hinnant // invoke 12693e519524SHoward Hinnant template <class... _ArgTypes> 12700af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 12713e519524SHoward Hinnant typename __invoke_return<type, _ArgTypes...>::type 127200f512ebSEric Fiselier operator() (_ArgTypes&&... __args) const { 1273ce48a113SHoward Hinnant return __invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...); 12743e519524SHoward Hinnant } 127500f512ebSEric Fiselier#else 127600f512ebSEric Fiselier 127700f512ebSEric Fiselier template <class _A0> 127870192a9eSEric Fiselier _LIBCPP_INLINE_VISIBILITY 127900f512ebSEric Fiselier typename __invoke_return0<type, _A0>::type 128000f512ebSEric Fiselier operator() (_A0& __a0) const { 128100f512ebSEric Fiselier return __invoke(__f_, __a0); 128200f512ebSEric Fiselier } 128300f512ebSEric Fiselier 128470192a9eSEric Fiselier template <class _A0> 128570192a9eSEric Fiselier _LIBCPP_INLINE_VISIBILITY 128670192a9eSEric Fiselier typename __invoke_return0<type, _A0 const>::type 128770192a9eSEric Fiselier operator() (_A0 const& __a0) const { 128870192a9eSEric Fiselier return __invoke(__f_, __a0); 128970192a9eSEric Fiselier } 129070192a9eSEric Fiselier 129100f512ebSEric Fiselier template <class _A0, class _A1> 129270192a9eSEric Fiselier _LIBCPP_INLINE_VISIBILITY 129300f512ebSEric Fiselier typename __invoke_return1<type, _A0, _A1>::type 129400f512ebSEric Fiselier operator() (_A0& __a0, _A1& __a1) const { 129500f512ebSEric Fiselier return __invoke(__f_, __a0, __a1); 129600f512ebSEric Fiselier } 129700f512ebSEric Fiselier 129870192a9eSEric Fiselier template <class _A0, class _A1> 129970192a9eSEric Fiselier _LIBCPP_INLINE_VISIBILITY 130070192a9eSEric Fiselier typename __invoke_return1<type, _A0 const, _A1>::type 130170192a9eSEric Fiselier operator() (_A0 const& __a0, _A1& __a1) const { 130270192a9eSEric Fiselier return __invoke(__f_, __a0, __a1); 130370192a9eSEric Fiselier } 130470192a9eSEric Fiselier 130570192a9eSEric Fiselier template <class _A0, class _A1> 130670192a9eSEric Fiselier _LIBCPP_INLINE_VISIBILITY 130770192a9eSEric Fiselier typename __invoke_return1<type, _A0, _A1 const>::type 130870192a9eSEric Fiselier operator() (_A0& __a0, _A1 const& __a1) const { 130970192a9eSEric Fiselier return __invoke(__f_, __a0, __a1); 131070192a9eSEric Fiselier } 131170192a9eSEric Fiselier 131270192a9eSEric Fiselier template <class _A0, class _A1> 131370192a9eSEric Fiselier _LIBCPP_INLINE_VISIBILITY 131470192a9eSEric Fiselier typename __invoke_return1<type, _A0 const, _A1 const>::type 131570192a9eSEric Fiselier operator() (_A0 const& __a0, _A1 const& __a1) const { 131670192a9eSEric Fiselier return __invoke(__f_, __a0, __a1); 131770192a9eSEric Fiselier } 131870192a9eSEric Fiselier 131900f512ebSEric Fiselier template <class _A0, class _A1, class _A2> 132070192a9eSEric Fiselier _LIBCPP_INLINE_VISIBILITY 132100f512ebSEric Fiselier typename __invoke_return2<type, _A0, _A1, _A2>::type 132200f512ebSEric Fiselier operator() (_A0& __a0, _A1& __a1, _A2& __a2) const { 132300f512ebSEric Fiselier return __invoke(__f_, __a0, __a1, __a2); 132400f512ebSEric Fiselier } 132570192a9eSEric Fiselier 132670192a9eSEric Fiselier template <class _A0, class _A1, class _A2> 132770192a9eSEric Fiselier _LIBCPP_INLINE_VISIBILITY 132870192a9eSEric Fiselier typename __invoke_return2<type, _A0 const, _A1, _A2>::type 132970192a9eSEric Fiselier operator() (_A0 const& __a0, _A1& __a1, _A2& __a2) const { 133070192a9eSEric Fiselier return __invoke(__f_, __a0, __a1, __a2); 133170192a9eSEric Fiselier } 133270192a9eSEric Fiselier 133370192a9eSEric Fiselier template <class _A0, class _A1, class _A2> 133470192a9eSEric Fiselier _LIBCPP_INLINE_VISIBILITY 133570192a9eSEric Fiselier typename __invoke_return2<type, _A0, _A1 const, _A2>::type 133670192a9eSEric Fiselier operator() (_A0& __a0, _A1 const& __a1, _A2& __a2) const { 133770192a9eSEric Fiselier return __invoke(__f_, __a0, __a1, __a2); 133870192a9eSEric Fiselier } 133970192a9eSEric Fiselier 134070192a9eSEric Fiselier template <class _A0, class _A1, class _A2> 134170192a9eSEric Fiselier _LIBCPP_INLINE_VISIBILITY 134270192a9eSEric Fiselier typename __invoke_return2<type, _A0, _A1, _A2 const>::type 134370192a9eSEric Fiselier operator() (_A0& __a0, _A1& __a1, _A2 const& __a2) const { 134470192a9eSEric Fiselier return __invoke(__f_, __a0, __a1, __a2); 134570192a9eSEric Fiselier } 134670192a9eSEric Fiselier 134770192a9eSEric Fiselier template <class _A0, class _A1, class _A2> 134870192a9eSEric Fiselier _LIBCPP_INLINE_VISIBILITY 134970192a9eSEric Fiselier typename __invoke_return2<type, _A0 const, _A1 const, _A2>::type 135070192a9eSEric Fiselier operator() (_A0 const& __a0, _A1 const& __a1, _A2& __a2) const { 135170192a9eSEric Fiselier return __invoke(__f_, __a0, __a1, __a2); 135270192a9eSEric Fiselier } 135370192a9eSEric Fiselier 135470192a9eSEric Fiselier template <class _A0, class _A1, class _A2> 135570192a9eSEric Fiselier _LIBCPP_INLINE_VISIBILITY 135670192a9eSEric Fiselier typename __invoke_return2<type, _A0 const, _A1, _A2 const>::type 135770192a9eSEric Fiselier operator() (_A0 const& __a0, _A1& __a1, _A2 const& __a2) const { 135870192a9eSEric Fiselier return __invoke(__f_, __a0, __a1, __a2); 135970192a9eSEric Fiselier } 136070192a9eSEric Fiselier 136170192a9eSEric Fiselier template <class _A0, class _A1, class _A2> 136270192a9eSEric Fiselier _LIBCPP_INLINE_VISIBILITY 136370192a9eSEric Fiselier typename __invoke_return2<type, _A0, _A1 const, _A2 const>::type 136470192a9eSEric Fiselier operator() (_A0& __a0, _A1 const& __a1, _A2 const& __a2) const { 136570192a9eSEric Fiselier return __invoke(__f_, __a0, __a1, __a2); 136670192a9eSEric Fiselier } 136770192a9eSEric Fiselier 136870192a9eSEric Fiselier template <class _A0, class _A1, class _A2> 136970192a9eSEric Fiselier _LIBCPP_INLINE_VISIBILITY 137070192a9eSEric Fiselier typename __invoke_return2<type, _A0 const, _A1 const, _A2 const>::type 137170192a9eSEric Fiselier operator() (_A0 const& __a0, _A1 const& __a1, _A2 const& __a2) const { 137270192a9eSEric Fiselier return __invoke(__f_, __a0, __a1, __a2); 137370192a9eSEric Fiselier } 137400f512ebSEric Fiselier#endif 13753e519524SHoward Hinnant}; 13763e519524SHoward Hinnant 1377c003db1fSHoward Hinnanttemplate<class _Rp, class _Tp> 13783e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 1379c003db1fSHoward Hinnant__mem_fn<_Rp _Tp::*> 13803b72a6efSMarshall Clowmem_fn(_Rp _Tp::* __pm) _NOEXCEPT 13813e519524SHoward Hinnant{ 1382c003db1fSHoward Hinnant return __mem_fn<_Rp _Tp::*>(__pm); 13833e519524SHoward Hinnant} 13843e519524SHoward Hinnant 1385e5407178SEric Fiselier//////////////////////////////////////////////////////////////////////////////// 1386e5407178SEric Fiselier// FUNCTION 1387e5407178SEric Fiselier//============================================================================== 1388e5407178SEric Fiselier 13893e519524SHoward Hinnant// bad_function_call 13903e519524SHoward Hinnant 13910af133f9SHoward Hinnantclass _LIBCPP_EXCEPTION_ABI bad_function_call 13923e519524SHoward Hinnant : public exception 13933e519524SHoward Hinnant{ 1394c7cd73e8SShoaib Meenai#ifdef _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION 1395c7cd73e8SShoaib Meenaipublic: 1396c7cd73e8SShoaib Meenai virtual ~bad_function_call() _NOEXCEPT; 1397c7cd73e8SShoaib Meenai 1398c7cd73e8SShoaib Meenai virtual const char* what() const _NOEXCEPT; 1399c7cd73e8SShoaib Meenai#endif 14003e519524SHoward Hinnant}; 14013e519524SHoward Hinnant 1402dc7200b4SLouis Dionne_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY 1403d437fa5cSMarshall Clowvoid __throw_bad_function_call() 1404d437fa5cSMarshall Clow{ 1405d437fa5cSMarshall Clow#ifndef _LIBCPP_NO_EXCEPTIONS 1406d437fa5cSMarshall Clow throw bad_function_call(); 1407d437fa5cSMarshall Clow#else 1408d437fa5cSMarshall Clow _VSTD::abort(); 1409d437fa5cSMarshall Clow#endif 1410d437fa5cSMarshall Clow} 1411d437fa5cSMarshall Clow 1412e2f2d1edSEric Fiseliertemplate<class _Fp> class _LIBCPP_TEMPLATE_VIS function; // undefined 14133e519524SHoward Hinnant 14143e519524SHoward Hinnantnamespace __function 14153e519524SHoward Hinnant{ 14163e519524SHoward Hinnant 1417e5407178SEric Fiseliertemplate<class _Rp> 14183e519524SHoward Hinnantstruct __maybe_derive_from_unary_function 14193e519524SHoward Hinnant{ 14203e519524SHoward Hinnant}; 14213e519524SHoward Hinnant 1422c003db1fSHoward Hinnanttemplate<class _Rp, class _A1> 1423c003db1fSHoward Hinnantstruct __maybe_derive_from_unary_function<_Rp(_A1)> 1424c003db1fSHoward Hinnant : public unary_function<_A1, _Rp> 14253e519524SHoward Hinnant{ 14263e519524SHoward Hinnant}; 14273e519524SHoward Hinnant 1428e5407178SEric Fiseliertemplate<class _Rp> 14293e519524SHoward Hinnantstruct __maybe_derive_from_binary_function 14303e519524SHoward Hinnant{ 14313e519524SHoward Hinnant}; 14323e519524SHoward Hinnant 1433c003db1fSHoward Hinnanttemplate<class _Rp, class _A1, class _A2> 1434c003db1fSHoward Hinnantstruct __maybe_derive_from_binary_function<_Rp(_A1, _A2)> 1435c003db1fSHoward Hinnant : public binary_function<_A1, _A2, _Rp> 14363e519524SHoward Hinnant{ 14373e519524SHoward Hinnant}; 14383e519524SHoward Hinnant 14390d28f784SEric Fiseliertemplate <class _Fp> 14400d28f784SEric Fiselier_LIBCPP_INLINE_VISIBILITY 14410d28f784SEric Fiselierbool __not_null(_Fp const&) { return true; } 14420d28f784SEric Fiselier 14430d28f784SEric Fiseliertemplate <class _Fp> 14440d28f784SEric Fiselier_LIBCPP_INLINE_VISIBILITY 14450d28f784SEric Fiselierbool __not_null(_Fp* __ptr) { return __ptr; } 14460d28f784SEric Fiselier 14470d28f784SEric Fiseliertemplate <class _Ret, class _Class> 14480d28f784SEric Fiselier_LIBCPP_INLINE_VISIBILITY 14490d28f784SEric Fiselierbool __not_null(_Ret _Class::*__ptr) { return __ptr; } 14500d28f784SEric Fiselier 14510d28f784SEric Fiseliertemplate <class _Fp> 14520d28f784SEric Fiselier_LIBCPP_INLINE_VISIBILITY 14530d28f784SEric Fiselierbool __not_null(function<_Fp> const& __f) { return !!__f; } 14540d28f784SEric Fiselier 1455e5407178SEric Fiselier} // namespace __function 1456e5407178SEric Fiselier 14577e23afcbSEric Fiselier#ifndef _LIBCPP_CXX03_LANG 1458e5407178SEric Fiselier 1459e5407178SEric Fiseliernamespace __function { 1460e5407178SEric Fiselier 14613e519524SHoward Hinnanttemplate<class _Fp> class __base; 14623e519524SHoward Hinnant 1463c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 1464c003db1fSHoward Hinnantclass __base<_Rp(_ArgTypes...)> 14653e519524SHoward Hinnant{ 14663e519524SHoward Hinnant __base(const __base&); 14673e519524SHoward Hinnant __base& operator=(const __base&); 14683e519524SHoward Hinnantpublic: 14690af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY __base() {} 14700af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY virtual ~__base() {} 14713e519524SHoward Hinnant virtual __base* __clone() const = 0; 14723e519524SHoward Hinnant virtual void __clone(__base*) const = 0; 14736a07d6f0SHoward Hinnant virtual void destroy() _NOEXCEPT = 0; 14746a07d6f0SHoward Hinnant virtual void destroy_deallocate() _NOEXCEPT = 0; 1475c003db1fSHoward Hinnant virtual _Rp operator()(_ArgTypes&& ...) = 0; 147654b409fdSHoward Hinnant#ifndef _LIBCPP_NO_RTTI 14776a07d6f0SHoward Hinnant virtual const void* target(const type_info&) const _NOEXCEPT = 0; 14786a07d6f0SHoward Hinnant virtual const std::type_info& target_type() const _NOEXCEPT = 0; 1479b3371f6fSHoward Hinnant#endif // _LIBCPP_NO_RTTI 14803e519524SHoward Hinnant}; 14813e519524SHoward Hinnant 14823e519524SHoward Hinnanttemplate<class _FD, class _Alloc, class _FB> class __func; 14833e519524SHoward Hinnant 1484c003db1fSHoward Hinnanttemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 1485c003db1fSHoward Hinnantclass __func<_Fp, _Alloc, _Rp(_ArgTypes...)> 1486c003db1fSHoward Hinnant : public __base<_Rp(_ArgTypes...)> 14873e519524SHoward Hinnant{ 1488c003db1fSHoward Hinnant __compressed_pair<_Fp, _Alloc> __f_; 14893e519524SHoward Hinnantpublic: 14900af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 14919bb1429fSHoward Hinnant explicit __func(_Fp&& __f) 14929bb1429fSHoward Hinnant : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)), 14939bb1429fSHoward Hinnant _VSTD::forward_as_tuple()) {} 14940af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 14959bb1429fSHoward Hinnant explicit __func(const _Fp& __f, const _Alloc& __a) 14969bb1429fSHoward Hinnant : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f), 14979bb1429fSHoward Hinnant _VSTD::forward_as_tuple(__a)) {} 14989bb1429fSHoward Hinnant 14999bb1429fSHoward Hinnant _LIBCPP_INLINE_VISIBILITY 15009bb1429fSHoward Hinnant explicit __func(const _Fp& __f, _Alloc&& __a) 15019bb1429fSHoward Hinnant : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f), 15029bb1429fSHoward Hinnant _VSTD::forward_as_tuple(_VSTD::move(__a))) {} 15039bb1429fSHoward Hinnant 15049bb1429fSHoward Hinnant _LIBCPP_INLINE_VISIBILITY 15059bb1429fSHoward Hinnant explicit __func(_Fp&& __f, _Alloc&& __a) 15069bb1429fSHoward Hinnant : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)), 15079bb1429fSHoward Hinnant _VSTD::forward_as_tuple(_VSTD::move(__a))) {} 1508c003db1fSHoward Hinnant virtual __base<_Rp(_ArgTypes...)>* __clone() const; 1509c003db1fSHoward Hinnant virtual void __clone(__base<_Rp(_ArgTypes...)>*) const; 15106a07d6f0SHoward Hinnant virtual void destroy() _NOEXCEPT; 15116a07d6f0SHoward Hinnant virtual void destroy_deallocate() _NOEXCEPT; 1512c003db1fSHoward Hinnant virtual _Rp operator()(_ArgTypes&& ... __arg); 151354b409fdSHoward Hinnant#ifndef _LIBCPP_NO_RTTI 15146a07d6f0SHoward Hinnant virtual const void* target(const type_info&) const _NOEXCEPT; 15156a07d6f0SHoward Hinnant virtual const std::type_info& target_type() const _NOEXCEPT; 1516b3371f6fSHoward Hinnant#endif // _LIBCPP_NO_RTTI 15173e519524SHoward Hinnant}; 15183e519524SHoward Hinnant 1519c003db1fSHoward Hinnanttemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 1520c003db1fSHoward Hinnant__base<_Rp(_ArgTypes...)>* 1521c003db1fSHoward Hinnant__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const 15223e519524SHoward Hinnant{ 15236d370568SEric Fiselier typedef allocator_traits<_Alloc> __alloc_traits; 15241f508014SMarshall Clow typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; 1525c003db1fSHoward Hinnant _Ap __a(__f_.second()); 1526c003db1fSHoward Hinnant typedef __allocator_destructor<_Ap> _Dp; 1527c003db1fSHoward Hinnant unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); 15283e519524SHoward Hinnant ::new (__hold.get()) __func(__f_.first(), _Alloc(__a)); 15293e519524SHoward Hinnant return __hold.release(); 15303e519524SHoward Hinnant} 15313e519524SHoward Hinnant 1532c003db1fSHoward Hinnanttemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 15333e519524SHoward Hinnantvoid 1534c003db1fSHoward Hinnant__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const 15353e519524SHoward Hinnant{ 15363e519524SHoward Hinnant ::new (__p) __func(__f_.first(), __f_.second()); 15373e519524SHoward Hinnant} 15383e519524SHoward Hinnant 1539c003db1fSHoward Hinnanttemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 15403e519524SHoward Hinnantvoid 1541c003db1fSHoward Hinnant__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPT 15423e519524SHoward Hinnant{ 1543c003db1fSHoward Hinnant __f_.~__compressed_pair<_Fp, _Alloc>(); 15443e519524SHoward Hinnant} 15453e519524SHoward Hinnant 1546c003db1fSHoward Hinnanttemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 15473e519524SHoward Hinnantvoid 1548c003db1fSHoward Hinnant__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT 15493e519524SHoward Hinnant{ 15506d370568SEric Fiselier typedef allocator_traits<_Alloc> __alloc_traits; 15511f508014SMarshall Clow typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; 1552c003db1fSHoward Hinnant _Ap __a(__f_.second()); 1553c003db1fSHoward Hinnant __f_.~__compressed_pair<_Fp, _Alloc>(); 15543e519524SHoward Hinnant __a.deallocate(this, 1); 15553e519524SHoward Hinnant} 15563e519524SHoward Hinnant 1557c003db1fSHoward Hinnanttemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 1558c003db1fSHoward Hinnant_Rp 1559c003db1fSHoward Hinnant__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg) 15603e519524SHoward Hinnant{ 156154519a6bSEric Fiselier typedef __invoke_void_return_wrapper<_Rp> _Invoker; 156254519a6bSEric Fiselier return _Invoker::__call(__f_.first(), _VSTD::forward<_ArgTypes>(__arg)...); 15633e519524SHoward Hinnant} 15643e519524SHoward Hinnant 156554b409fdSHoward Hinnant#ifndef _LIBCPP_NO_RTTI 156654b409fdSHoward Hinnant 1567c003db1fSHoward Hinnanttemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 15683e519524SHoward Hinnantconst void* 1569c003db1fSHoward Hinnant__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT 15703e519524SHoward Hinnant{ 1571c003db1fSHoward Hinnant if (__ti == typeid(_Fp)) 15723e519524SHoward Hinnant return &__f_.first(); 15733e519524SHoward Hinnant return (const void*)0; 15743e519524SHoward Hinnant} 15753e519524SHoward Hinnant 1576c003db1fSHoward Hinnanttemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 15773e519524SHoward Hinnantconst std::type_info& 1578c003db1fSHoward Hinnant__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT 15793e519524SHoward Hinnant{ 1580c003db1fSHoward Hinnant return typeid(_Fp); 15813e519524SHoward Hinnant} 15823e519524SHoward Hinnant 1583b3371f6fSHoward Hinnant#endif // _LIBCPP_NO_RTTI 158454b409fdSHoward Hinnant 15853e519524SHoward Hinnant} // __function 15863e519524SHoward Hinnant 1587c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 1588e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS function<_Rp(_ArgTypes...)> 1589c003db1fSHoward Hinnant : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>, 1590c003db1fSHoward Hinnant public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)> 15913e519524SHoward Hinnant{ 1592c003db1fSHoward Hinnant typedef __function::__base<_Rp(_ArgTypes...)> __base; 15938d3e7974SHoward Hinnant typename aligned_storage<3*sizeof(void*)>::type __buf_; 15943e519524SHoward Hinnant __base* __f_; 15953e519524SHoward Hinnant 15963e58a6a7SEvgeniy Stepanov _LIBCPP_NO_CFI static __base *__as_base(void *p) { 15973e58a6a7SEvgeniy Stepanov return reinterpret_cast<__base*>(p); 15983e58a6a7SEvgeniy Stepanov } 15993e58a6a7SEvgeniy Stepanov 160094d55511SEric Fiselier template <class _Fp, bool = __lazy_and< 160194d55511SEric Fiselier integral_constant<bool, !is_same<__uncvref_t<_Fp>, function>::value>, 160294d55511SEric Fiselier __invokable<_Fp&, _ArgTypes...> 160394d55511SEric Fiselier >::value> 1604542b2507SHoward Hinnant struct __callable; 1605c003db1fSHoward Hinnant template <class _Fp> 1606c003db1fSHoward Hinnant struct __callable<_Fp, true> 1607542b2507SHoward Hinnant { 160854519a6bSEric Fiselier static const bool value = is_same<void, _Rp>::value || 1609c003db1fSHoward Hinnant is_convertible<typename __invoke_of<_Fp&, _ArgTypes...>::type, 1610c003db1fSHoward Hinnant _Rp>::value; 1611542b2507SHoward Hinnant }; 1612c003db1fSHoward Hinnant template <class _Fp> 1613c003db1fSHoward Hinnant struct __callable<_Fp, false> 1614542b2507SHoward Hinnant { 1615542b2507SHoward Hinnant static const bool value = false; 1616542b2507SHoward Hinnant }; 161794d55511SEric Fiselier 161894d55511SEric Fiselier template <class _Fp> 161994d55511SEric Fiselier using _EnableIfCallable = typename enable_if<__callable<_Fp>::value>::type; 16203e519524SHoward Hinnantpublic: 1621c003db1fSHoward Hinnant typedef _Rp result_type; 16223e519524SHoward Hinnant 16239b0b6d45SHoward Hinnant // construct/copy/destroy: 16240af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 16256a07d6f0SHoward Hinnant function() _NOEXCEPT : __f_(0) {} 16260af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 16276a07d6f0SHoward Hinnant function(nullptr_t) _NOEXCEPT : __f_(0) {} 16283e519524SHoward Hinnant function(const function&); 16296a07d6f0SHoward Hinnant function(function&&) _NOEXCEPT; 163094d55511SEric Fiselier template<class _Fp, class = _EnableIfCallable<_Fp>> 1631fd32ab92SEric Fiselier function(_Fp); 16323e519524SHoward Hinnant 16336ecac730SMarshall Clow#if _LIBCPP_STD_VER <= 14 16349b0b6d45SHoward Hinnant template<class _Alloc> 16350af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 16366a07d6f0SHoward Hinnant function(allocator_arg_t, const _Alloc&) _NOEXCEPT : __f_(0) {} 16379b0b6d45SHoward Hinnant template<class _Alloc> 16380af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 16396a07d6f0SHoward Hinnant function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT : __f_(0) {} 16409b0b6d45SHoward Hinnant template<class _Alloc> 16419b0b6d45SHoward Hinnant function(allocator_arg_t, const _Alloc&, const function&); 16429b0b6d45SHoward Hinnant template<class _Alloc> 16439b0b6d45SHoward Hinnant function(allocator_arg_t, const _Alloc&, function&&); 164494d55511SEric Fiselier template<class _Fp, class _Alloc, class = _EnableIfCallable<_Fp>> 1645fd32ab92SEric Fiselier function(allocator_arg_t, const _Alloc& __a, _Fp __f); 16466ecac730SMarshall Clow#endif 16473e519524SHoward Hinnant 16483e519524SHoward Hinnant function& operator=(const function&); 16496a07d6f0SHoward Hinnant function& operator=(function&&) _NOEXCEPT; 16506a07d6f0SHoward Hinnant function& operator=(nullptr_t) _NOEXCEPT; 165194d55511SEric Fiselier template<class _Fp, class = _EnableIfCallable<_Fp>> 165294d55511SEric Fiselier function& operator=(_Fp&&); 16533e519524SHoward Hinnant 16543e519524SHoward Hinnant ~function(); 16553e519524SHoward Hinnant 16569b0b6d45SHoward Hinnant // function modifiers: 16576a07d6f0SHoward Hinnant void swap(function&) _NOEXCEPT; 16580aa1ccb0SMarshall Clow 16590aa1ccb0SMarshall Clow#if _LIBCPP_STD_VER <= 14 1660c003db1fSHoward Hinnant template<class _Fp, class _Alloc> 16610af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 1662c003db1fSHoward Hinnant void assign(_Fp&& __f, const _Alloc& __a) 1663c003db1fSHoward Hinnant {function(allocator_arg, __a, _VSTD::forward<_Fp>(__f)).swap(*this);} 16640aa1ccb0SMarshall Clow#endif 16653e519524SHoward Hinnant 16669b0b6d45SHoward Hinnant // function capacity: 16670af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 1668f2f2d8b9SHoward Hinnant _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return __f_;} 16693e519524SHoward Hinnant 16703e519524SHoward Hinnant // deleted overloads close possible hole in the type system 16713e519524SHoward Hinnant template<class _R2, class... _ArgTypes2> 167237030a77SHoward Hinnant bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete; 16733e519524SHoward Hinnant template<class _R2, class... _ArgTypes2> 167437030a77SHoward Hinnant bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete; 16753e519524SHoward Hinnantpublic: 16769b0b6d45SHoward Hinnant // function invocation: 1677c003db1fSHoward Hinnant _Rp operator()(_ArgTypes...) const; 16783e519524SHoward Hinnant 167954b409fdSHoward Hinnant#ifndef _LIBCPP_NO_RTTI 16809b0b6d45SHoward Hinnant // function target access: 16816a07d6f0SHoward Hinnant const std::type_info& target_type() const _NOEXCEPT; 1682c003db1fSHoward Hinnant template <typename _Tp> _Tp* target() _NOEXCEPT; 1683c003db1fSHoward Hinnant template <typename _Tp> const _Tp* target() const _NOEXCEPT; 1684b3371f6fSHoward Hinnant#endif // _LIBCPP_NO_RTTI 16853e519524SHoward Hinnant}; 16863e519524SHoward Hinnant 1687c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 1688c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::function(const function& __f) 16893e519524SHoward Hinnant{ 16903e519524SHoward Hinnant if (__f.__f_ == 0) 16913e519524SHoward Hinnant __f_ = 0; 16923e58a6a7SEvgeniy Stepanov else if ((void *)__f.__f_ == &__f.__buf_) 16933e519524SHoward Hinnant { 16943e58a6a7SEvgeniy Stepanov __f_ = __as_base(&__buf_); 16953e519524SHoward Hinnant __f.__f_->__clone(__f_); 16963e519524SHoward Hinnant } 16973e519524SHoward Hinnant else 16983e519524SHoward Hinnant __f_ = __f.__f_->__clone(); 16993e519524SHoward Hinnant} 17003e519524SHoward Hinnant 17016ecac730SMarshall Clow#if _LIBCPP_STD_VER <= 14 1702c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 17039b0b6d45SHoward Hinnanttemplate <class _Alloc> 1704c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, 17059b0b6d45SHoward Hinnant const function& __f) 17069b0b6d45SHoward Hinnant{ 17079b0b6d45SHoward Hinnant if (__f.__f_ == 0) 17089b0b6d45SHoward Hinnant __f_ = 0; 17093e58a6a7SEvgeniy Stepanov else if ((void *)__f.__f_ == &__f.__buf_) 17109b0b6d45SHoward Hinnant { 17113e58a6a7SEvgeniy Stepanov __f_ = __as_base(&__buf_); 17129b0b6d45SHoward Hinnant __f.__f_->__clone(__f_); 17139b0b6d45SHoward Hinnant } 17149b0b6d45SHoward Hinnant else 17159b0b6d45SHoward Hinnant __f_ = __f.__f_->__clone(); 17169b0b6d45SHoward Hinnant} 17176ecac730SMarshall Clow#endif 17189b0b6d45SHoward Hinnant 1719c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 1720c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT 17213e519524SHoward Hinnant{ 17223e519524SHoward Hinnant if (__f.__f_ == 0) 17233e519524SHoward Hinnant __f_ = 0; 17243e58a6a7SEvgeniy Stepanov else if ((void *)__f.__f_ == &__f.__buf_) 17253e519524SHoward Hinnant { 17263e58a6a7SEvgeniy Stepanov __f_ = __as_base(&__buf_); 17273e519524SHoward Hinnant __f.__f_->__clone(__f_); 17283e519524SHoward Hinnant } 17293e519524SHoward Hinnant else 17303e519524SHoward Hinnant { 17313e519524SHoward Hinnant __f_ = __f.__f_; 17323e519524SHoward Hinnant __f.__f_ = 0; 17333e519524SHoward Hinnant } 17343e519524SHoward Hinnant} 17353e519524SHoward Hinnant 17366ecac730SMarshall Clow#if _LIBCPP_STD_VER <= 14 1737c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 17389b0b6d45SHoward Hinnanttemplate <class _Alloc> 1739c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, 17409b0b6d45SHoward Hinnant function&& __f) 17419b0b6d45SHoward Hinnant{ 17429b0b6d45SHoward Hinnant if (__f.__f_ == 0) 17439b0b6d45SHoward Hinnant __f_ = 0; 17443e58a6a7SEvgeniy Stepanov else if ((void *)__f.__f_ == &__f.__buf_) 17459b0b6d45SHoward Hinnant { 17463e58a6a7SEvgeniy Stepanov __f_ = __as_base(&__buf_); 17479b0b6d45SHoward Hinnant __f.__f_->__clone(__f_); 17489b0b6d45SHoward Hinnant } 17499b0b6d45SHoward Hinnant else 17509b0b6d45SHoward Hinnant { 17519b0b6d45SHoward Hinnant __f_ = __f.__f_; 17529b0b6d45SHoward Hinnant __f.__f_ = 0; 17539b0b6d45SHoward Hinnant } 17549b0b6d45SHoward Hinnant} 17556ecac730SMarshall Clow#endif 17569b0b6d45SHoward Hinnant 1757c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 1758fd32ab92SEric Fiseliertemplate <class _Fp, class> 1759fd32ab92SEric Fiselierfunction<_Rp(_ArgTypes...)>::function(_Fp __f) 17603e519524SHoward Hinnant : __f_(0) 17613e519524SHoward Hinnant{ 17620d28f784SEric Fiselier if (__function::__not_null(__f)) 17633e519524SHoward Hinnant { 1764c003db1fSHoward Hinnant typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_ArgTypes...)> _FF; 1765c003db1fSHoward Hinnant if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value) 17663e519524SHoward Hinnant { 17673e58a6a7SEvgeniy Stepanov __f_ = ::new((void*)&__buf_) _FF(_VSTD::move(__f)); 17683e519524SHoward Hinnant } 17693e519524SHoward Hinnant else 17703e519524SHoward Hinnant { 1771c003db1fSHoward Hinnant typedef allocator<_FF> _Ap; 1772c003db1fSHoward Hinnant _Ap __a; 1773c003db1fSHoward Hinnant typedef __allocator_destructor<_Ap> _Dp; 1774c003db1fSHoward Hinnant unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); 1775c003db1fSHoward Hinnant ::new (__hold.get()) _FF(_VSTD::move(__f), allocator<_Fp>(__a)); 17763e519524SHoward Hinnant __f_ = __hold.release(); 17773e519524SHoward Hinnant } 17783e519524SHoward Hinnant } 17793e519524SHoward Hinnant} 17803e519524SHoward Hinnant 17816ecac730SMarshall Clow#if _LIBCPP_STD_VER <= 14 1782c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 1783fd32ab92SEric Fiseliertemplate <class _Fp, class _Alloc, class> 1784fd32ab92SEric Fiselierfunction<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f) 17859b0b6d45SHoward Hinnant : __f_(0) 17869b0b6d45SHoward Hinnant{ 17879b0b6d45SHoward Hinnant typedef allocator_traits<_Alloc> __alloc_traits; 17880d28f784SEric Fiselier if (__function::__not_null(__f)) 17899b0b6d45SHoward Hinnant { 1790c003db1fSHoward Hinnant typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _FF; 17911f508014SMarshall Clow typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap; 1792c003db1fSHoward Hinnant _Ap __a(__a0); 17935f7c2db2SMarshall Clow if (sizeof(_FF) <= sizeof(__buf_) && 17945f7c2db2SMarshall Clow is_nothrow_copy_constructible<_Fp>::value && is_nothrow_copy_constructible<_Ap>::value) 17955f7c2db2SMarshall Clow { 17963e58a6a7SEvgeniy Stepanov __f_ = ::new((void*)&__buf_) _FF(_VSTD::move(__f), _Alloc(__a)); 17975f7c2db2SMarshall Clow } 17985f7c2db2SMarshall Clow else 17995f7c2db2SMarshall Clow { 1800c003db1fSHoward Hinnant typedef __allocator_destructor<_Ap> _Dp; 1801c003db1fSHoward Hinnant unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); 1802ce48a113SHoward Hinnant ::new (__hold.get()) _FF(_VSTD::move(__f), _Alloc(__a)); 18039b0b6d45SHoward Hinnant __f_ = __hold.release(); 18049b0b6d45SHoward Hinnant } 18059b0b6d45SHoward Hinnant } 18069b0b6d45SHoward Hinnant} 18076ecac730SMarshall Clow#endif 18089b0b6d45SHoward Hinnant 1809c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 1810c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>& 1811c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::operator=(const function& __f) 18123e519524SHoward Hinnant{ 18133e519524SHoward Hinnant function(__f).swap(*this); 18143e519524SHoward Hinnant return *this; 18153e519524SHoward Hinnant} 18163e519524SHoward Hinnant 1817c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 1818c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>& 1819c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT 18203e519524SHoward Hinnant{ 1821aa208791SVolodymyr Sapsai *this = nullptr; 18223e519524SHoward Hinnant if (__f.__f_ == 0) 18233e519524SHoward Hinnant __f_ = 0; 18243e58a6a7SEvgeniy Stepanov else if ((void *)__f.__f_ == &__f.__buf_) 18253e519524SHoward Hinnant { 18263e58a6a7SEvgeniy Stepanov __f_ = __as_base(&__buf_); 18273e519524SHoward Hinnant __f.__f_->__clone(__f_); 18283e519524SHoward Hinnant } 18293e519524SHoward Hinnant else 18303e519524SHoward Hinnant { 18313e519524SHoward Hinnant __f_ = __f.__f_; 18323e519524SHoward Hinnant __f.__f_ = 0; 18333e519524SHoward Hinnant } 183488db3171SArgyrios Kyrtzidis return *this; 18353e519524SHoward Hinnant} 18363e519524SHoward Hinnant 1837c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 1838c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>& 1839c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT 18403e519524SHoward Hinnant{ 1841aa208791SVolodymyr Sapsai __base* __t = __f_; 18423e519524SHoward Hinnant __f_ = 0; 1843aa208791SVolodymyr Sapsai if ((void *)__t == &__buf_) 1844aa208791SVolodymyr Sapsai __t->destroy(); 1845aa208791SVolodymyr Sapsai else if (__t) 1846aa208791SVolodymyr Sapsai __t->destroy_deallocate(); 184788db3171SArgyrios Kyrtzidis return *this; 18483e519524SHoward Hinnant} 18493e519524SHoward Hinnant 1850c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 185194d55511SEric Fiseliertemplate <class _Fp, class> 1852c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>& 1853c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::operator=(_Fp&& __f) 18543e519524SHoward Hinnant{ 1855c003db1fSHoward Hinnant function(_VSTD::forward<_Fp>(__f)).swap(*this); 18563e519524SHoward Hinnant return *this; 18573e519524SHoward Hinnant} 18583e519524SHoward Hinnant 1859c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 1860c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::~function() 18613e519524SHoward Hinnant{ 18623e58a6a7SEvgeniy Stepanov if ((void *)__f_ == &__buf_) 18633e519524SHoward Hinnant __f_->destroy(); 18643e519524SHoward Hinnant else if (__f_) 18653e519524SHoward Hinnant __f_->destroy_deallocate(); 18663e519524SHoward Hinnant} 18673e519524SHoward Hinnant 1868c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 18693e519524SHoward Hinnantvoid 1870c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT 18713e519524SHoward Hinnant{ 1872d566c345SEric Fiselier if (_VSTD::addressof(__f) == this) 1873d566c345SEric Fiselier return; 18743e58a6a7SEvgeniy Stepanov if ((void *)__f_ == &__buf_ && (void *)__f.__f_ == &__f.__buf_) 18753e519524SHoward Hinnant { 18763e519524SHoward Hinnant typename aligned_storage<sizeof(__buf_)>::type __tempbuf; 18773e58a6a7SEvgeniy Stepanov __base* __t = __as_base(&__tempbuf); 18783e519524SHoward Hinnant __f_->__clone(__t); 18793e519524SHoward Hinnant __f_->destroy(); 18803e519524SHoward Hinnant __f_ = 0; 18813e58a6a7SEvgeniy Stepanov __f.__f_->__clone(__as_base(&__buf_)); 18823e519524SHoward Hinnant __f.__f_->destroy(); 18833e519524SHoward Hinnant __f.__f_ = 0; 18843e58a6a7SEvgeniy Stepanov __f_ = __as_base(&__buf_); 18853e58a6a7SEvgeniy Stepanov __t->__clone(__as_base(&__f.__buf_)); 18863e519524SHoward Hinnant __t->destroy(); 18873e58a6a7SEvgeniy Stepanov __f.__f_ = __as_base(&__f.__buf_); 18883e519524SHoward Hinnant } 18893e58a6a7SEvgeniy Stepanov else if ((void *)__f_ == &__buf_) 18903e519524SHoward Hinnant { 18913e58a6a7SEvgeniy Stepanov __f_->__clone(__as_base(&__f.__buf_)); 18923e519524SHoward Hinnant __f_->destroy(); 18933e519524SHoward Hinnant __f_ = __f.__f_; 18943e58a6a7SEvgeniy Stepanov __f.__f_ = __as_base(&__f.__buf_); 18953e519524SHoward Hinnant } 18963e58a6a7SEvgeniy Stepanov else if ((void *)__f.__f_ == &__f.__buf_) 18973e519524SHoward Hinnant { 18983e58a6a7SEvgeniy Stepanov __f.__f_->__clone(__as_base(&__buf_)); 18993e519524SHoward Hinnant __f.__f_->destroy(); 19003e519524SHoward Hinnant __f.__f_ = __f_; 19013e58a6a7SEvgeniy Stepanov __f_ = __as_base(&__buf_); 19023e519524SHoward Hinnant } 19033e519524SHoward Hinnant else 1904ce48a113SHoward Hinnant _VSTD::swap(__f_, __f.__f_); 19053e519524SHoward Hinnant} 19063e519524SHoward Hinnant 1907c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 1908c003db1fSHoward Hinnant_Rp 1909c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const 19103e519524SHoward Hinnant{ 19113e519524SHoward Hinnant if (__f_ == 0) 1912d437fa5cSMarshall Clow __throw_bad_function_call(); 1913ce48a113SHoward Hinnant return (*__f_)(_VSTD::forward<_ArgTypes>(__arg)...); 19143e519524SHoward Hinnant} 19153e519524SHoward Hinnant 191654b409fdSHoward Hinnant#ifndef _LIBCPP_NO_RTTI 191754b409fdSHoward Hinnant 1918c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 19193e519524SHoward Hinnantconst std::type_info& 1920c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT 19213e519524SHoward Hinnant{ 19223e519524SHoward Hinnant if (__f_ == 0) 19233e519524SHoward Hinnant return typeid(void); 19243e519524SHoward Hinnant return __f_->target_type(); 19253e519524SHoward Hinnant} 19263e519524SHoward Hinnant 1927c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 1928c003db1fSHoward Hinnanttemplate <typename _Tp> 1929c003db1fSHoward Hinnant_Tp* 1930c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::target() _NOEXCEPT 19313e519524SHoward Hinnant{ 19323e519524SHoward Hinnant if (__f_ == 0) 19338b086e38SMarshall Clow return nullptr; 19348b086e38SMarshall Clow return (_Tp*) const_cast<void *>(__f_->target(typeid(_Tp))); 19353e519524SHoward Hinnant} 19363e519524SHoward Hinnant 1937c003db1fSHoward Hinnanttemplate<class _Rp, class ..._ArgTypes> 1938c003db1fSHoward Hinnanttemplate <typename _Tp> 1939c003db1fSHoward Hinnantconst _Tp* 1940c003db1fSHoward Hinnantfunction<_Rp(_ArgTypes...)>::target() const _NOEXCEPT 19413e519524SHoward Hinnant{ 19423e519524SHoward Hinnant if (__f_ == 0) 19438b086e38SMarshall Clow return nullptr; 1944c003db1fSHoward Hinnant return (const _Tp*)__f_->target(typeid(_Tp)); 19453e519524SHoward Hinnant} 19463e519524SHoward Hinnant 1947b3371f6fSHoward Hinnant#endif // _LIBCPP_NO_RTTI 194854b409fdSHoward Hinnant 1949c003db1fSHoward Hinnanttemplate <class _Rp, class... _ArgTypes> 19503e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 19513e519524SHoward Hinnantbool 1952c003db1fSHoward Hinnantoperator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;} 19533e519524SHoward Hinnant 1954c003db1fSHoward Hinnanttemplate <class _Rp, class... _ArgTypes> 19553e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 19563e519524SHoward Hinnantbool 1957c003db1fSHoward Hinnantoperator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;} 19583e519524SHoward Hinnant 1959c003db1fSHoward Hinnanttemplate <class _Rp, class... _ArgTypes> 19603e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 19613e519524SHoward Hinnantbool 1962c003db1fSHoward Hinnantoperator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;} 19633e519524SHoward Hinnant 1964c003db1fSHoward Hinnanttemplate <class _Rp, class... _ArgTypes> 19653e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 19663e519524SHoward Hinnantbool 1967c003db1fSHoward Hinnantoperator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;} 19683e519524SHoward Hinnant 1969c003db1fSHoward Hinnanttemplate <class _Rp, class... _ArgTypes> 19703e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 19713e519524SHoward Hinnantvoid 1972c003db1fSHoward Hinnantswap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT 19733e519524SHoward Hinnant{return __x.swap(__y);} 19743e519524SHoward Hinnant 19757e23afcbSEric Fiselier#else // _LIBCPP_CXX03_LANG 197600f512ebSEric Fiselier 197700f512ebSEric Fiselier#include <__functional_03> 197800f512ebSEric Fiselier 197900f512ebSEric Fiselier#endif 1980e5407178SEric Fiselier 1981e5407178SEric Fiselier//////////////////////////////////////////////////////////////////////////////// 1982e5407178SEric Fiselier// BIND 1983e5407178SEric Fiselier//============================================================================== 1984e5407178SEric Fiselier 19853e519524SHoward Hinnanttemplate<class _Tp> struct __is_bind_expression : public false_type {}; 1986e2f2d1edSEric Fiseliertemplate<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_bind_expression 19873e519524SHoward Hinnant : public __is_bind_expression<typename remove_cv<_Tp>::type> {}; 19883e519524SHoward Hinnant 1989a48055ceSMarshall Clow#if _LIBCPP_STD_VER > 14 1990a48055ceSMarshall Clowtemplate <class _Tp> 199140a01d53SMarshall Clow_LIBCPP_INLINE_VAR constexpr size_t is_bind_expression_v = is_bind_expression<_Tp>::value; 1992a48055ceSMarshall Clow#endif 1993a48055ceSMarshall Clow 19943e519524SHoward Hinnanttemplate<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {}; 1995e2f2d1edSEric Fiseliertemplate<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_placeholder 19963e519524SHoward Hinnant : public __is_placeholder<typename remove_cv<_Tp>::type> {}; 19973e519524SHoward Hinnant 1998a48055ceSMarshall Clow#if _LIBCPP_STD_VER > 14 1999a48055ceSMarshall Clowtemplate <class _Tp> 200040a01d53SMarshall Clow_LIBCPP_INLINE_VAR constexpr size_t is_placeholder_v = is_placeholder<_Tp>::value; 2001a48055ceSMarshall Clow#endif 2002a48055ceSMarshall Clow 20033e519524SHoward Hinnantnamespace placeholders 20043e519524SHoward Hinnant{ 20053e519524SHoward Hinnant 2006c003db1fSHoward Hinnanttemplate <int _Np> struct __ph {}; 20073e519524SHoward Hinnant 2008*c8e84ff2SLouis Dionne#if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY) 200955533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<1> _1; 201055533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<2> _2; 201155533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<3> _3; 201255533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<4> _4; 201355533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<5> _5; 201455533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<6> _6; 201555533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<7> _7; 201655533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<8> _8; 201755533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<9> _9; 201855533071SEric Fiselier_LIBCPP_FUNC_VIS extern const __ph<10> _10; 201955533071SEric Fiselier#else 2020a911f39dSMarshall Clow/* _LIBCPP_INLINE_VAR */ constexpr __ph<1> _1{}; 2021a911f39dSMarshall Clow/* _LIBCPP_INLINE_VAR */ constexpr __ph<2> _2{}; 2022a911f39dSMarshall Clow/* _LIBCPP_INLINE_VAR */ constexpr __ph<3> _3{}; 2023a911f39dSMarshall Clow/* _LIBCPP_INLINE_VAR */ constexpr __ph<4> _4{}; 2024a911f39dSMarshall Clow/* _LIBCPP_INLINE_VAR */ constexpr __ph<5> _5{}; 2025a911f39dSMarshall Clow/* _LIBCPP_INLINE_VAR */ constexpr __ph<6> _6{}; 2026a911f39dSMarshall Clow/* _LIBCPP_INLINE_VAR */ constexpr __ph<7> _7{}; 2027a911f39dSMarshall Clow/* _LIBCPP_INLINE_VAR */ constexpr __ph<8> _8{}; 2028a911f39dSMarshall Clow/* _LIBCPP_INLINE_VAR */ constexpr __ph<9> _9{}; 2029a911f39dSMarshall Clow/* _LIBCPP_INLINE_VAR */ constexpr __ph<10> _10{}; 2030*c8e84ff2SLouis Dionne#endif // defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY) 20313e519524SHoward Hinnant 20323e519524SHoward Hinnant} // placeholders 20333e519524SHoward Hinnant 2034c003db1fSHoward Hinnanttemplate<int _Np> 2035c003db1fSHoward Hinnantstruct __is_placeholder<placeholders::__ph<_Np> > 2036c003db1fSHoward Hinnant : public integral_constant<int, _Np> {}; 20373e519524SHoward Hinnant 2038e5407178SEric Fiselier 20397e23afcbSEric Fiselier#ifndef _LIBCPP_CXX03_LANG 2040e5407178SEric Fiselier 20413e519524SHoward Hinnanttemplate <class _Tp, class _Uj> 20423e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 20433e519524SHoward Hinnant_Tp& 20443e519524SHoward Hinnant__mu(reference_wrapper<_Tp> __t, _Uj&) 20453e519524SHoward Hinnant{ 20463e519524SHoward Hinnant return __t.get(); 20473e519524SHoward Hinnant} 20483e519524SHoward Hinnant 20493e519524SHoward Hinnanttemplate <class _Ti, class ..._Uj, size_t ..._Indx> 20503e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 20512344d6c1SHoward Hinnanttypename __invoke_of<_Ti&, _Uj...>::type 20522344d6c1SHoward Hinnant__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>) 20533e519524SHoward Hinnant{ 2054f9af6140SMarshall Clow return __ti(_VSTD::forward<_Uj>(_VSTD::get<_Indx>(__uj))...); 20553e519524SHoward Hinnant} 20563e519524SHoward Hinnant 20573e519524SHoward Hinnanttemplate <class _Ti, class ..._Uj> 20583e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 2059279663c1SEric Fiseliertypename __lazy_enable_if 20603e519524SHoward Hinnant< 20613e519524SHoward Hinnant is_bind_expression<_Ti>::value, 2062279663c1SEric Fiselier __invoke_of<_Ti&, _Uj...> 20633e519524SHoward Hinnant>::type 20643e519524SHoward Hinnant__mu(_Ti& __ti, tuple<_Uj...>& __uj) 20653e519524SHoward Hinnant{ 20663e519524SHoward Hinnant typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices; 20673e519524SHoward Hinnant return __mu_expand(__ti, __uj, __indices()); 20683e519524SHoward Hinnant} 20693e519524SHoward Hinnant 20703e519524SHoward Hinnanttemplate <bool IsPh, class _Ti, class _Uj> 20713e519524SHoward Hinnantstruct __mu_return2 {}; 20723e519524SHoward Hinnant 20733e519524SHoward Hinnanttemplate <class _Ti, class _Uj> 20743e519524SHoward Hinnantstruct __mu_return2<true, _Ti, _Uj> 20753e519524SHoward Hinnant{ 20763e519524SHoward Hinnant typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type; 20773e519524SHoward Hinnant}; 20783e519524SHoward Hinnant 20793e519524SHoward Hinnanttemplate <class _Ti, class _Uj> 20803e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 20813e519524SHoward Hinnanttypename enable_if 20823e519524SHoward Hinnant< 20833e519524SHoward Hinnant 0 < is_placeholder<_Ti>::value, 20843e519524SHoward Hinnant typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type 20853e519524SHoward Hinnant>::type 20863e519524SHoward Hinnant__mu(_Ti&, _Uj& __uj) 20873e519524SHoward Hinnant{ 20883e519524SHoward Hinnant const size_t _Indx = is_placeholder<_Ti>::value - 1; 2089f9af6140SMarshall Clow return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj)); 20903e519524SHoward Hinnant} 20913e519524SHoward Hinnant 20923e519524SHoward Hinnanttemplate <class _Ti, class _Uj> 20933e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 20943e519524SHoward Hinnanttypename enable_if 20953e519524SHoward Hinnant< 20963e519524SHoward Hinnant !is_bind_expression<_Ti>::value && 20973e519524SHoward Hinnant is_placeholder<_Ti>::value == 0 && 20983e519524SHoward Hinnant !__is_reference_wrapper<_Ti>::value, 20993e519524SHoward Hinnant _Ti& 21003e519524SHoward Hinnant>::type 2101c206366fSHoward Hinnant__mu(_Ti& __ti, _Uj&) 21023e519524SHoward Hinnant{ 21033e519524SHoward Hinnant return __ti; 21043e519524SHoward Hinnant} 21053e519524SHoward Hinnant 21062fa07ae9SHoward Hinnanttemplate <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh, 21072fa07ae9SHoward Hinnant class _TupleUj> 21083e519524SHoward Hinnantstruct ____mu_return; 21093e519524SHoward Hinnant 21109bf42533SHoward Hinnanttemplate <bool _Invokable, class _Ti, class ..._Uj> 21119bf42533SHoward Hinnantstruct ____mu_return_invokable // false 21129bf42533SHoward Hinnant{ 21139bf42533SHoward Hinnant typedef __nat type; 21149bf42533SHoward Hinnant}; 21159bf42533SHoward Hinnant 21163e519524SHoward Hinnanttemplate <class _Ti, class ..._Uj> 21179bf42533SHoward Hinnantstruct ____mu_return_invokable<true, _Ti, _Uj...> 21183e519524SHoward Hinnant{ 21192344d6c1SHoward Hinnant typedef typename __invoke_of<_Ti&, _Uj...>::type type; 21203e519524SHoward Hinnant}; 21213e519524SHoward Hinnant 21229bf42533SHoward Hinnanttemplate <class _Ti, class ..._Uj> 21239bf42533SHoward Hinnantstruct ____mu_return<_Ti, false, true, false, tuple<_Uj...> > 21249bf42533SHoward Hinnant : public ____mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...> 21259bf42533SHoward Hinnant{ 21269bf42533SHoward Hinnant}; 21279bf42533SHoward Hinnant 21283e519524SHoward Hinnanttemplate <class _Ti, class _TupleUj> 21292fa07ae9SHoward Hinnantstruct ____mu_return<_Ti, false, false, true, _TupleUj> 21303e519524SHoward Hinnant{ 21313e519524SHoward Hinnant typedef typename tuple_element<is_placeholder<_Ti>::value - 1, 21323e519524SHoward Hinnant _TupleUj>::type&& type; 21333e519524SHoward Hinnant}; 21343e519524SHoward Hinnant 21353e519524SHoward Hinnanttemplate <class _Ti, class _TupleUj> 21362fa07ae9SHoward Hinnantstruct ____mu_return<_Ti, true, false, false, _TupleUj> 21372fa07ae9SHoward Hinnant{ 21382fa07ae9SHoward Hinnant typedef typename _Ti::type& type; 21392fa07ae9SHoward Hinnant}; 21402fa07ae9SHoward Hinnant 21412fa07ae9SHoward Hinnanttemplate <class _Ti, class _TupleUj> 21422fa07ae9SHoward Hinnantstruct ____mu_return<_Ti, false, false, false, _TupleUj> 21433e519524SHoward Hinnant{ 21443e519524SHoward Hinnant typedef _Ti& type; 21453e519524SHoward Hinnant}; 21463e519524SHoward Hinnant 21473e519524SHoward Hinnanttemplate <class _Ti, class _TupleUj> 21483e519524SHoward Hinnantstruct __mu_return 21493e519524SHoward Hinnant : public ____mu_return<_Ti, 21502fa07ae9SHoward Hinnant __is_reference_wrapper<_Ti>::value, 21513e519524SHoward Hinnant is_bind_expression<_Ti>::value, 2152c0c9748cSHoward Hinnant 0 < is_placeholder<_Ti>::value && 2153c0c9748cSHoward Hinnant is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value, 21543e519524SHoward Hinnant _TupleUj> 21553e519524SHoward Hinnant{ 21563e519524SHoward Hinnant}; 21573e519524SHoward Hinnant 2158c003db1fSHoward Hinnanttemplate <class _Fp, class _BoundArgs, class _TupleUj> 215935cb2b28SEric Fiselierstruct __is_valid_bind_return 2160c0c9748cSHoward Hinnant{ 2161c0c9748cSHoward Hinnant static const bool value = false; 2162c0c9748cSHoward Hinnant}; 2163c0c9748cSHoward Hinnant 2164c0c9748cSHoward Hinnanttemplate <class _Fp, class ..._BoundArgs, class _TupleUj> 216535cb2b28SEric Fiselierstruct __is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj> 2166c0c9748cSHoward Hinnant{ 2167c0c9748cSHoward Hinnant static const bool value = __invokable<_Fp, 2168c0c9748cSHoward Hinnant typename __mu_return<_BoundArgs, _TupleUj>::type...>::value; 2169c0c9748cSHoward Hinnant}; 2170c0c9748cSHoward Hinnant 2171c0c9748cSHoward Hinnanttemplate <class _Fp, class ..._BoundArgs, class _TupleUj> 217235cb2b28SEric Fiselierstruct __is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj> 2173c0c9748cSHoward Hinnant{ 2174c0c9748cSHoward Hinnant static const bool value = __invokable<_Fp, 2175c0c9748cSHoward Hinnant typename __mu_return<const _BoundArgs, _TupleUj>::type...>::value; 2176c0c9748cSHoward Hinnant}; 2177c0c9748cSHoward Hinnant 2178c0c9748cSHoward Hinnanttemplate <class _Fp, class _BoundArgs, class _TupleUj, 217935cb2b28SEric Fiselier bool = __is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value> 21803e519524SHoward Hinnantstruct __bind_return; 21813e519524SHoward Hinnant 2182c003db1fSHoward Hinnanttemplate <class _Fp, class ..._BoundArgs, class _TupleUj> 2183c0c9748cSHoward Hinnantstruct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true> 21843e519524SHoward Hinnant{ 21852344d6c1SHoward Hinnant typedef typename __invoke_of 21863e519524SHoward Hinnant < 2187c003db1fSHoward Hinnant _Fp&, 21883e519524SHoward Hinnant typename __mu_return 21893e519524SHoward Hinnant < 21903e519524SHoward Hinnant _BoundArgs, 21913e519524SHoward Hinnant _TupleUj 21923e519524SHoward Hinnant >::type... 21933e519524SHoward Hinnant >::type type; 21943e519524SHoward Hinnant}; 21953e519524SHoward Hinnant 2196c003db1fSHoward Hinnanttemplate <class _Fp, class ..._BoundArgs, class _TupleUj> 2197c0c9748cSHoward Hinnantstruct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true> 21983e519524SHoward Hinnant{ 21992344d6c1SHoward Hinnant typedef typename __invoke_of 22003e519524SHoward Hinnant < 2201c003db1fSHoward Hinnant _Fp&, 22023e519524SHoward Hinnant typename __mu_return 22033e519524SHoward Hinnant < 22043e519524SHoward Hinnant const _BoundArgs, 22053e519524SHoward Hinnant _TupleUj 22063e519524SHoward Hinnant >::type... 22073e519524SHoward Hinnant >::type type; 22083e519524SHoward Hinnant}; 22093e519524SHoward Hinnant 2210c003db1fSHoward Hinnanttemplate <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args> 22113e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 2212c003db1fSHoward Hinnanttypename __bind_return<_Fp, _BoundArgs, _Args>::type 2213c003db1fSHoward Hinnant__apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>, 22143e519524SHoward Hinnant _Args&& __args) 22153e519524SHoward Hinnant{ 22161f8b73d1SEric Fiselier return _VSTD::__invoke(__f, _VSTD::__mu(_VSTD::get<_Indx>(__bound_args), __args)...); 22173e519524SHoward Hinnant} 22183e519524SHoward Hinnant 2219c003db1fSHoward Hinnanttemplate<class _Fp, class ..._BoundArgs> 22203e519524SHoward Hinnantclass __bind 2221c003db1fSHoward Hinnant : public __weak_result_type<typename decay<_Fp>::type> 22223e519524SHoward Hinnant{ 2223c0c9748cSHoward Hinnantprotected: 2224c003db1fSHoward Hinnant typedef typename decay<_Fp>::type _Fd; 22252344d6c1SHoward Hinnant typedef tuple<typename decay<_BoundArgs>::type...> _Td; 2226c0c9748cSHoward Hinnantprivate: 22272344d6c1SHoward Hinnant _Fd __f_; 22282344d6c1SHoward Hinnant _Td __bound_args_; 22293e519524SHoward Hinnant 22303e519524SHoward Hinnant typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices; 22313e519524SHoward Hinnantpublic: 2232df7aad41SHoward Hinnant template <class _Gp, class ..._BA, 2233df7aad41SHoward Hinnant class = typename enable_if 2234df7aad41SHoward Hinnant < 22359dbbf8deSHoward Hinnant is_constructible<_Fd, _Gp>::value && 22369dbbf8deSHoward Hinnant !is_same<typename remove_reference<_Gp>::type, 22379dbbf8deSHoward Hinnant __bind>::value 2238df7aad41SHoward Hinnant >::type> 22390af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 2240c003db1fSHoward Hinnant explicit __bind(_Gp&& __f, _BA&& ...__bound_args) 2241c003db1fSHoward Hinnant : __f_(_VSTD::forward<_Gp>(__f)), 2242ce48a113SHoward Hinnant __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {} 22433e519524SHoward Hinnant 22443e519524SHoward Hinnant template <class ..._Args> 22450af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 22462344d6c1SHoward Hinnant typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type 22473e519524SHoward Hinnant operator()(_Args&& ...__args) 22483e519524SHoward Hinnant { 22491f8b73d1SEric Fiselier return _VSTD::__apply_functor(__f_, __bound_args_, __indices(), 2250ce48a113SHoward Hinnant tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...)); 22513e519524SHoward Hinnant } 22523e519524SHoward Hinnant 22533e519524SHoward Hinnant template <class ..._Args> 22540af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 2255c0c9748cSHoward Hinnant typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type 22563e519524SHoward Hinnant operator()(_Args&& ...__args) const 22573e519524SHoward Hinnant { 22581f8b73d1SEric Fiselier return _VSTD::__apply_functor(__f_, __bound_args_, __indices(), 2259ce48a113SHoward Hinnant tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...)); 22603e519524SHoward Hinnant } 22613e519524SHoward Hinnant}; 22623e519524SHoward Hinnant 2263c003db1fSHoward Hinnanttemplate<class _Fp, class ..._BoundArgs> 2264c003db1fSHoward Hinnantstruct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {}; 22653e519524SHoward Hinnant 2266c003db1fSHoward Hinnanttemplate<class _Rp, class _Fp, class ..._BoundArgs> 22673e519524SHoward Hinnantclass __bind_r 2268c003db1fSHoward Hinnant : public __bind<_Fp, _BoundArgs...> 22693e519524SHoward Hinnant{ 2270c003db1fSHoward Hinnant typedef __bind<_Fp, _BoundArgs...> base; 2271c0c9748cSHoward Hinnant typedef typename base::_Fd _Fd; 2272c0c9748cSHoward Hinnant typedef typename base::_Td _Td; 22733e519524SHoward Hinnantpublic: 2274c003db1fSHoward Hinnant typedef _Rp result_type; 22753e519524SHoward Hinnant 2276086d0de1SHoward Hinnant 22779dbbf8deSHoward Hinnant template <class _Gp, class ..._BA, 22789dbbf8deSHoward Hinnant class = typename enable_if 22799dbbf8deSHoward Hinnant < 22809dbbf8deSHoward Hinnant is_constructible<_Fd, _Gp>::value && 22819dbbf8deSHoward Hinnant !is_same<typename remove_reference<_Gp>::type, 22829dbbf8deSHoward Hinnant __bind_r>::value 22839dbbf8deSHoward Hinnant >::type> 22840af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 2285c003db1fSHoward Hinnant explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args) 2286c003db1fSHoward Hinnant : base(_VSTD::forward<_Gp>(__f), 2287ce48a113SHoward Hinnant _VSTD::forward<_BA>(__bound_args)...) {} 22883e519524SHoward Hinnant 22893e519524SHoward Hinnant template <class ..._Args> 22900af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 2291c0c9748cSHoward Hinnant typename enable_if 2292c0c9748cSHoward Hinnant < 2293c0c9748cSHoward Hinnant is_convertible<typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type, 22942d15f15fSEric Fiselier result_type>::value || is_void<_Rp>::value, 22953e519524SHoward Hinnant result_type 2296c0c9748cSHoward Hinnant >::type 22973e519524SHoward Hinnant operator()(_Args&& ...__args) 22983e519524SHoward Hinnant { 22992d15f15fSEric Fiselier typedef __invoke_void_return_wrapper<_Rp> _Invoker; 23002d15f15fSEric Fiselier return _Invoker::__call(static_cast<base&>(*this), _VSTD::forward<_Args>(__args)...); 23013e519524SHoward Hinnant } 23023e519524SHoward Hinnant 23033e519524SHoward Hinnant template <class ..._Args> 23040af133f9SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 2305c0c9748cSHoward Hinnant typename enable_if 2306c0c9748cSHoward Hinnant < 2307c0c9748cSHoward Hinnant is_convertible<typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type, 23082d15f15fSEric Fiselier result_type>::value || is_void<_Rp>::value, 23093e519524SHoward Hinnant result_type 2310c0c9748cSHoward Hinnant >::type 23113e519524SHoward Hinnant operator()(_Args&& ...__args) const 23123e519524SHoward Hinnant { 23132d15f15fSEric Fiselier typedef __invoke_void_return_wrapper<_Rp> _Invoker; 23142d15f15fSEric Fiselier return _Invoker::__call(static_cast<base const&>(*this), _VSTD::forward<_Args>(__args)...); 23153e519524SHoward Hinnant } 23163e519524SHoward Hinnant}; 23173e519524SHoward Hinnant 2318c003db1fSHoward Hinnanttemplate<class _Rp, class _Fp, class ..._BoundArgs> 2319c003db1fSHoward Hinnantstruct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {}; 23203e519524SHoward Hinnant 2321c003db1fSHoward Hinnanttemplate<class _Fp, class ..._BoundArgs> 23223e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 2323c003db1fSHoward Hinnant__bind<_Fp, _BoundArgs...> 2324c003db1fSHoward Hinnantbind(_Fp&& __f, _BoundArgs&&... __bound_args) 23253e519524SHoward Hinnant{ 2326c003db1fSHoward Hinnant typedef __bind<_Fp, _BoundArgs...> type; 2327c003db1fSHoward Hinnant return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...); 23283e519524SHoward Hinnant} 23293e519524SHoward Hinnant 2330c003db1fSHoward Hinnanttemplate<class _Rp, class _Fp, class ..._BoundArgs> 23313e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 2332c003db1fSHoward Hinnant__bind_r<_Rp, _Fp, _BoundArgs...> 2333c003db1fSHoward Hinnantbind(_Fp&& __f, _BoundArgs&&... __bound_args) 23343e519524SHoward Hinnant{ 2335c003db1fSHoward Hinnant typedef __bind_r<_Rp, _Fp, _BoundArgs...> type; 2336c003db1fSHoward Hinnant return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...); 23373e519524SHoward Hinnant} 23383e519524SHoward Hinnant 23397e23afcbSEric Fiselier#endif // _LIBCPP_CXX03_LANG 23403e519524SHoward Hinnant 23415be45129SEric Fiselier#if _LIBCPP_STD_VER > 14 234257257567SEric Fiselier 2343498ee00aSEric Fiselier#define __cpp_lib_invoke 201411 2344498ee00aSEric Fiselier 23455be45129SEric Fiseliertemplate <class _Fn, class ..._Args> 23465be45129SEric Fiselierresult_of_t<_Fn&&(_Args&&...)> 234757257567SEric Fiselierinvoke(_Fn&& __f, _Args&&... __args) 234857257567SEric Fiselier noexcept(noexcept(_VSTD::__invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...))) 234957257567SEric Fiselier{ 235057257567SEric Fiselier return _VSTD::__invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...); 23515be45129SEric Fiselier} 235257257567SEric Fiselier 235357257567SEric Fiseliertemplate <class _DecayFunc> 2354e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS __not_fn_imp { 235557257567SEric Fiselier _DecayFunc __fd; 235657257567SEric Fiselier 235757257567SEric Fiselierpublic: 235857257567SEric Fiselier __not_fn_imp() = delete; 235957257567SEric Fiselier 236057257567SEric Fiselier template <class ..._Args> 236157257567SEric Fiselier _LIBCPP_INLINE_VISIBILITY 23629372d8bcSEric Fiselier auto operator()(_Args&& ...__args) & 236357257567SEric Fiselier noexcept(noexcept(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...))) 236457257567SEric Fiselier -> decltype( !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)) 236557257567SEric Fiselier { return !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); } 236657257567SEric Fiselier 236757257567SEric Fiselier template <class ..._Args> 236857257567SEric Fiselier _LIBCPP_INLINE_VISIBILITY 23699372d8bcSEric Fiselier auto operator()(_Args&& ...__args) && 23709372d8bcSEric Fiselier noexcept(noexcept(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...))) 23719372d8bcSEric Fiselier -> decltype( !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)) 23729372d8bcSEric Fiselier { return !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); } 23739372d8bcSEric Fiselier 23749372d8bcSEric Fiselier template <class ..._Args> 23759372d8bcSEric Fiselier _LIBCPP_INLINE_VISIBILITY 23769372d8bcSEric Fiselier auto operator()(_Args&& ...__args) const& 237757257567SEric Fiselier noexcept(noexcept(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...))) 237857257567SEric Fiselier -> decltype( !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)) 237957257567SEric Fiselier { return !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); } 238057257567SEric Fiselier 23819372d8bcSEric Fiselier 23829372d8bcSEric Fiselier template <class ..._Args> 23839372d8bcSEric Fiselier _LIBCPP_INLINE_VISIBILITY 23849372d8bcSEric Fiselier auto operator()(_Args&& ...__args) const&& 23859372d8bcSEric Fiselier noexcept(noexcept(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...))) 23869372d8bcSEric Fiselier -> decltype( !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)) 23879372d8bcSEric Fiselier { return !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); } 23889372d8bcSEric Fiselier 238957257567SEric Fiselierprivate: 239057257567SEric Fiselier template <class _RawFunc, 239157257567SEric Fiselier class = enable_if_t<!is_same<decay_t<_RawFunc>, __not_fn_imp>::value>> 239257257567SEric Fiselier _LIBCPP_INLINE_VISIBILITY 239357257567SEric Fiselier explicit __not_fn_imp(_RawFunc&& __rf) 239457257567SEric Fiselier : __fd(_VSTD::forward<_RawFunc>(__rf)) {} 239557257567SEric Fiselier 239657257567SEric Fiselier template <class _RawFunc> 239757257567SEric Fiselier friend inline _LIBCPP_INLINE_VISIBILITY 239857257567SEric Fiselier __not_fn_imp<decay_t<_RawFunc>> not_fn(_RawFunc&&); 239957257567SEric Fiselier}; 240057257567SEric Fiselier 240157257567SEric Fiseliertemplate <class _RawFunc> 240257257567SEric Fiselierinline _LIBCPP_INLINE_VISIBILITY 240357257567SEric Fiselier__not_fn_imp<decay_t<_RawFunc>> not_fn(_RawFunc&& __fn) { 240457257567SEric Fiselier return __not_fn_imp<decay_t<_RawFunc>>(_VSTD::forward<_RawFunc>(__fn)); 240557257567SEric Fiselier} 240657257567SEric Fiselier 24075be45129SEric Fiselier#endif 24085be45129SEric Fiselier 2409d1803b6cSHoward Hinnant// struct hash<T*> in <memory> 24103e519524SHoward Hinnant 2411d835e592SMarshall Clowtemplate <class _BinaryPredicate, class _ForwardIterator1, class _ForwardIterator2> 241212f0a779SMarshall Clowpair<_ForwardIterator1, _ForwardIterator1> _LIBCPP_CONSTEXPR_AFTER_CXX11 2413d835e592SMarshall Clow__search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, 2414d835e592SMarshall Clow _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred, 2415d835e592SMarshall Clow forward_iterator_tag, forward_iterator_tag) 2416d835e592SMarshall Clow{ 2417d835e592SMarshall Clow if (__first2 == __last2) 2418d835e592SMarshall Clow return make_pair(__first1, __first1); // Everything matches an empty sequence 2419d835e592SMarshall Clow while (true) 2420d835e592SMarshall Clow { 2421d835e592SMarshall Clow // Find first element in sequence 1 that matchs *__first2, with a mininum of loop checks 2422d835e592SMarshall Clow while (true) 2423d835e592SMarshall Clow { 2424d835e592SMarshall Clow if (__first1 == __last1) // return __last1 if no element matches *__first2 2425d835e592SMarshall Clow return make_pair(__last1, __last1); 2426d835e592SMarshall Clow if (__pred(*__first1, *__first2)) 2427d835e592SMarshall Clow break; 2428d835e592SMarshall Clow ++__first1; 2429d835e592SMarshall Clow } 2430d835e592SMarshall Clow // *__first1 matches *__first2, now match elements after here 2431d835e592SMarshall Clow _ForwardIterator1 __m1 = __first1; 2432d835e592SMarshall Clow _ForwardIterator2 __m2 = __first2; 2433d835e592SMarshall Clow while (true) 2434d835e592SMarshall Clow { 2435d835e592SMarshall Clow if (++__m2 == __last2) // If pattern exhausted, __first1 is the answer (works for 1 element pattern) 2436d835e592SMarshall Clow return make_pair(__first1, __m1); 2437d835e592SMarshall Clow if (++__m1 == __last1) // Otherwise if source exhaused, pattern not found 2438d835e592SMarshall Clow return make_pair(__last1, __last1); 2439d835e592SMarshall Clow if (!__pred(*__m1, *__m2)) // if there is a mismatch, restart with a new __first1 2440d835e592SMarshall Clow { 2441d835e592SMarshall Clow ++__first1; 2442d835e592SMarshall Clow break; 2443d835e592SMarshall Clow } // else there is a match, check next elements 2444d835e592SMarshall Clow } 2445d835e592SMarshall Clow } 2446d835e592SMarshall Clow} 2447d835e592SMarshall Clow 2448d835e592SMarshall Clowtemplate <class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2> 2449d835e592SMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 2450d835e592SMarshall Clowpair<_RandomAccessIterator1, _RandomAccessIterator1> 2451d835e592SMarshall Clow__search(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, 2452d835e592SMarshall Clow _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __pred, 2453d835e592SMarshall Clow random_access_iterator_tag, random_access_iterator_tag) 2454d835e592SMarshall Clow{ 2455d835e592SMarshall Clow typedef typename iterator_traits<_RandomAccessIterator1>::difference_type _D1; 2456d835e592SMarshall Clow typedef typename iterator_traits<_RandomAccessIterator2>::difference_type _D2; 2457d835e592SMarshall Clow // Take advantage of knowing source and pattern lengths. Stop short when source is smaller than pattern 2458d835e592SMarshall Clow const _D2 __len2 = __last2 - __first2; 2459d835e592SMarshall Clow if (__len2 == 0) 2460d835e592SMarshall Clow return make_pair(__first1, __first1); 2461d835e592SMarshall Clow const _D1 __len1 = __last1 - __first1; 2462d835e592SMarshall Clow if (__len1 < __len2) 2463d835e592SMarshall Clow return make_pair(__last1, __last1); 2464d835e592SMarshall Clow const _RandomAccessIterator1 __s = __last1 - (__len2 - 1); // Start of pattern match can't go beyond here 2465d835e592SMarshall Clow 2466d835e592SMarshall Clow while (true) 2467d835e592SMarshall Clow { 2468d835e592SMarshall Clow while (true) 2469d835e592SMarshall Clow { 2470d835e592SMarshall Clow if (__first1 == __s) 2471d835e592SMarshall Clow return make_pair(__last1, __last1); 2472d835e592SMarshall Clow if (__pred(*__first1, *__first2)) 2473d835e592SMarshall Clow break; 2474d835e592SMarshall Clow ++__first1; 2475d835e592SMarshall Clow } 2476d835e592SMarshall Clow 2477d835e592SMarshall Clow _RandomAccessIterator1 __m1 = __first1; 2478d835e592SMarshall Clow _RandomAccessIterator2 __m2 = __first2; 2479d835e592SMarshall Clow while (true) 2480d835e592SMarshall Clow { 2481d835e592SMarshall Clow if (++__m2 == __last2) 2482d835e592SMarshall Clow return make_pair(__first1, __first1 + __len2); 2483d835e592SMarshall Clow ++__m1; // no need to check range on __m1 because __s guarantees we have enough source 2484d835e592SMarshall Clow if (!__pred(*__m1, *__m2)) 2485d835e592SMarshall Clow { 2486d835e592SMarshall Clow ++__first1; 2487d835e592SMarshall Clow break; 2488d835e592SMarshall Clow } 2489d835e592SMarshall Clow } 2490d835e592SMarshall Clow } 2491d835e592SMarshall Clow} 2492d835e592SMarshall Clow 2493d835e592SMarshall Clow#if _LIBCPP_STD_VER > 14 2494d835e592SMarshall Clow 2495d835e592SMarshall Clow// default searcher 2496d835e592SMarshall Clowtemplate<class _ForwardIterator, class _BinaryPredicate = equal_to<>> 24971b1b80f4SDimitry Andricclass _LIBCPP_TYPE_VIS default_searcher { 2498d835e592SMarshall Clowpublic: 2499d835e592SMarshall Clow _LIBCPP_INLINE_VISIBILITY 2500d835e592SMarshall Clow default_searcher(_ForwardIterator __f, _ForwardIterator __l, 2501d835e592SMarshall Clow _BinaryPredicate __p = _BinaryPredicate()) 2502d835e592SMarshall Clow : __first_(__f), __last_(__l), __pred_(__p) {} 2503d835e592SMarshall Clow 2504d835e592SMarshall Clow template <typename _ForwardIterator2> 2505d835e592SMarshall Clow _LIBCPP_INLINE_VISIBILITY 2506d835e592SMarshall Clow pair<_ForwardIterator2, _ForwardIterator2> 2507d835e592SMarshall Clow operator () (_ForwardIterator2 __f, _ForwardIterator2 __l) const 2508d835e592SMarshall Clow { 2509d835e592SMarshall Clow return _VSTD::__search(__f, __l, __first_, __last_, __pred_, 2510d835e592SMarshall Clow typename _VSTD::iterator_traits<_ForwardIterator>::iterator_category(), 2511d835e592SMarshall Clow typename _VSTD::iterator_traits<_ForwardIterator2>::iterator_category()); 2512d835e592SMarshall Clow } 2513d835e592SMarshall Clow 2514d835e592SMarshall Clowprivate: 2515d835e592SMarshall Clow _ForwardIterator __first_; 2516d835e592SMarshall Clow _ForwardIterator __last_; 2517d835e592SMarshall Clow _BinaryPredicate __pred_; 2518d835e592SMarshall Clow }; 2519d835e592SMarshall Clow 2520d835e592SMarshall Clow#endif // _LIBCPP_STD_VER > 14 2521d835e592SMarshall Clow 25223e519524SHoward Hinnant_LIBCPP_END_NAMESPACE_STD 25233e519524SHoward Hinnant 25243e519524SHoward Hinnant#endif // _LIBCPP_FUNCTIONAL 2525