10b57cec5SDimitry Andric// -*- C++ -*- 2*fe6060f1SDimitry Andric//===----------------------------------------------------------------------===// 30b57cec5SDimitry Andric// 40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 70b57cec5SDimitry Andric// 80b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 90b57cec5SDimitry Andric 100b57cec5SDimitry Andric#ifndef _LIBCPP_FUNCTIONAL 110b57cec5SDimitry Andric#define _LIBCPP_FUNCTIONAL 120b57cec5SDimitry Andric 130b57cec5SDimitry Andric/* 140b57cec5SDimitry Andric functional synopsis 150b57cec5SDimitry Andric 160b57cec5SDimitry Andricnamespace std 170b57cec5SDimitry Andric{ 180b57cec5SDimitry Andric 190b57cec5SDimitry Andrictemplate <class Arg, class Result> 200b57cec5SDimitry Andricstruct unary_function 210b57cec5SDimitry Andric{ 220b57cec5SDimitry Andric typedef Arg argument_type; 230b57cec5SDimitry Andric typedef Result result_type; 240b57cec5SDimitry Andric}; 250b57cec5SDimitry Andric 260b57cec5SDimitry Andrictemplate <class Arg1, class Arg2, class Result> 270b57cec5SDimitry Andricstruct binary_function 280b57cec5SDimitry Andric{ 290b57cec5SDimitry Andric typedef Arg1 first_argument_type; 300b57cec5SDimitry Andric typedef Arg2 second_argument_type; 310b57cec5SDimitry Andric typedef Result result_type; 320b57cec5SDimitry Andric}; 330b57cec5SDimitry Andric 340b57cec5SDimitry Andrictemplate <class T> 350b57cec5SDimitry Andricclass reference_wrapper 360b57cec5SDimitry Andric : public unary_function<T1, R> // if wrapping a unary functor 370b57cec5SDimitry Andric : public binary_function<T1, T2, R> // if wraping a binary functor 380b57cec5SDimitry Andric{ 390b57cec5SDimitry Andricpublic: 400b57cec5SDimitry Andric // types 410b57cec5SDimitry Andric typedef T type; 420b57cec5SDimitry Andric typedef see below result_type; // Not always defined 430b57cec5SDimitry Andric 440b57cec5SDimitry Andric // construct/copy/destroy 45*fe6060f1SDimitry Andric template<class U> 46*fe6060f1SDimitry Andric reference_wrapper(U&&); 470b57cec5SDimitry Andric reference_wrapper(const reference_wrapper<T>& x) noexcept; 480b57cec5SDimitry Andric 490b57cec5SDimitry Andric // assignment 500b57cec5SDimitry Andric reference_wrapper& operator=(const reference_wrapper<T>& x) noexcept; 510b57cec5SDimitry Andric 520b57cec5SDimitry Andric // access 530b57cec5SDimitry Andric operator T& () const noexcept; 540b57cec5SDimitry Andric T& get() const noexcept; 550b57cec5SDimitry Andric 560b57cec5SDimitry Andric // invoke 570b57cec5SDimitry Andric template <class... ArgTypes> 580b57cec5SDimitry Andric typename result_of<T&(ArgTypes&&...)>::type 590b57cec5SDimitry Andric operator() (ArgTypes&&...) const; 600b57cec5SDimitry Andric}; 610b57cec5SDimitry Andric 62*fe6060f1SDimitry Andrictemplate <class T> 63*fe6060f1SDimitry Andric reference_wrapper(T&) -> reference_wrapper<T>; 64*fe6060f1SDimitry Andric 650b57cec5SDimitry Andrictemplate <class T> reference_wrapper<T> ref(T& t) noexcept; 660b57cec5SDimitry Andrictemplate <class T> void ref(const T&& t) = delete; 670b57cec5SDimitry Andrictemplate <class T> reference_wrapper<T> ref(reference_wrapper<T>t) noexcept; 680b57cec5SDimitry Andric 690b57cec5SDimitry Andrictemplate <class T> reference_wrapper<const T> cref(const T& t) noexcept; 700b57cec5SDimitry Andrictemplate <class T> void cref(const T&& t) = delete; 710b57cec5SDimitry Andrictemplate <class T> reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept; 720b57cec5SDimitry Andric 730b57cec5SDimitry Andrictemplate <class T> struct unwrap_reference; // since C++20 740b57cec5SDimitry Andrictemplate <class T> struct unwrap_ref_decay : unwrap_reference<decay_t<T>> { }; // since C++20 750b57cec5SDimitry Andrictemplate <class T> using unwrap_reference_t = typename unwrap_reference<T>::type; // since C++20 760b57cec5SDimitry Andrictemplate <class T> using unwrap_ref_decay_t = typename unwrap_ref_decay<T>::type; // since C++20 770b57cec5SDimitry Andric 780b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 79*fe6060f1SDimitry Andricstruct plus { 800b57cec5SDimitry Andric T operator()(const T& x, const T& y) const; 810b57cec5SDimitry Andric}; 820b57cec5SDimitry Andric 830b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 84*fe6060f1SDimitry Andricstruct minus { 850b57cec5SDimitry Andric T operator()(const T& x, const T& y) const; 860b57cec5SDimitry Andric}; 870b57cec5SDimitry Andric 880b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 89*fe6060f1SDimitry Andricstruct multiplies { 900b57cec5SDimitry Andric T operator()(const T& x, const T& y) const; 910b57cec5SDimitry Andric}; 920b57cec5SDimitry Andric 930b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 94*fe6060f1SDimitry Andricstruct divides { 950b57cec5SDimitry Andric T operator()(const T& x, const T& y) const; 960b57cec5SDimitry Andric}; 970b57cec5SDimitry Andric 980b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 99*fe6060f1SDimitry Andricstruct modulus { 1000b57cec5SDimitry Andric T operator()(const T& x, const T& y) const; 1010b57cec5SDimitry Andric}; 1020b57cec5SDimitry Andric 1030b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 104*fe6060f1SDimitry Andricstruct negate { 1050b57cec5SDimitry Andric T operator()(const T& x) const; 1060b57cec5SDimitry Andric}; 1070b57cec5SDimitry Andric 1080b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 109*fe6060f1SDimitry Andricstruct equal_to { 1100b57cec5SDimitry Andric bool operator()(const T& x, const T& y) const; 1110b57cec5SDimitry Andric}; 1120b57cec5SDimitry Andric 1130b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 114*fe6060f1SDimitry Andricstruct not_equal_to { 1150b57cec5SDimitry Andric bool operator()(const T& x, const T& y) const; 1160b57cec5SDimitry Andric}; 1170b57cec5SDimitry Andric 1180b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 119*fe6060f1SDimitry Andricstruct greater { 1200b57cec5SDimitry Andric bool operator()(const T& x, const T& y) const; 1210b57cec5SDimitry Andric}; 1220b57cec5SDimitry Andric 1230b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 124*fe6060f1SDimitry Andricstruct less { 1250b57cec5SDimitry Andric bool operator()(const T& x, const T& y) const; 1260b57cec5SDimitry Andric}; 1270b57cec5SDimitry Andric 1280b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 129*fe6060f1SDimitry Andricstruct greater_equal { 1300b57cec5SDimitry Andric bool operator()(const T& x, const T& y) const; 1310b57cec5SDimitry Andric}; 1320b57cec5SDimitry Andric 1330b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 134*fe6060f1SDimitry Andricstruct less_equal { 1350b57cec5SDimitry Andric bool operator()(const T& x, const T& y) const; 1360b57cec5SDimitry Andric}; 1370b57cec5SDimitry Andric 1380b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 139*fe6060f1SDimitry Andricstruct logical_and { 1400b57cec5SDimitry Andric bool operator()(const T& x, const T& y) const; 1410b57cec5SDimitry Andric}; 1420b57cec5SDimitry Andric 1430b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 144*fe6060f1SDimitry Andricstruct logical_or { 1450b57cec5SDimitry Andric bool operator()(const T& x, const T& y) const; 1460b57cec5SDimitry Andric}; 1470b57cec5SDimitry Andric 1480b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 149*fe6060f1SDimitry Andricstruct logical_not { 1500b57cec5SDimitry Andric bool operator()(const T& x) const; 1510b57cec5SDimitry Andric}; 1520b57cec5SDimitry Andric 1530b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 154*fe6060f1SDimitry Andricstruct bit_and { 155*fe6060f1SDimitry Andric T operator()(const T& x, const T& y) const; 1560b57cec5SDimitry Andric}; 1570b57cec5SDimitry Andric 1580b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 159*fe6060f1SDimitry Andricstruct bit_or { 160*fe6060f1SDimitry Andric T operator()(const T& x, const T& y) const; 1610b57cec5SDimitry Andric}; 1620b57cec5SDimitry Andric 1630b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 164*fe6060f1SDimitry Andricstruct bit_xor { 165*fe6060f1SDimitry Andric T operator()(const T& x, const T& y) const; 1660b57cec5SDimitry Andric}; 1670b57cec5SDimitry Andric 1680b57cec5SDimitry Andrictemplate <class T=void> // C++14 169*fe6060f1SDimitry Andricstruct bit_not { 170*fe6060f1SDimitry Andric T operator()(const T& x) const; 1710b57cec5SDimitry Andric}; 1720b57cec5SDimitry Andric 173*fe6060f1SDimitry Andricstruct identity; // C++20 174*fe6060f1SDimitry Andric 1750b57cec5SDimitry Andrictemplate <class Predicate> 176*fe6060f1SDimitry Andricclass unary_negate // deprecated in C++17, removed in C++20 1770b57cec5SDimitry Andric : public unary_function<typename Predicate::argument_type, bool> 1780b57cec5SDimitry Andric{ 1790b57cec5SDimitry Andricpublic: 1800b57cec5SDimitry Andric explicit unary_negate(const Predicate& pred); 1810b57cec5SDimitry Andric bool operator()(const typename Predicate::argument_type& x) const; 1820b57cec5SDimitry Andric}; 1830b57cec5SDimitry Andric 184*fe6060f1SDimitry Andrictemplate <class Predicate> // deprecated in C++17, removed in C++20 1850b57cec5SDimitry Andricunary_negate<Predicate> not1(const Predicate& pred); 1860b57cec5SDimitry Andric 1870b57cec5SDimitry Andrictemplate <class Predicate> 188*fe6060f1SDimitry Andricclass binary_negate // deprecated in C++17, removed in C++20 1890b57cec5SDimitry Andric : public binary_function<typename Predicate::first_argument_type, 1900b57cec5SDimitry Andric typename Predicate::second_argument_type, 1910b57cec5SDimitry Andric bool> 1920b57cec5SDimitry Andric{ 1930b57cec5SDimitry Andricpublic: 1940b57cec5SDimitry Andric explicit binary_negate(const Predicate& pred); 1950b57cec5SDimitry Andric bool operator()(const typename Predicate::first_argument_type& x, 1960b57cec5SDimitry Andric const typename Predicate::second_argument_type& y) const; 1970b57cec5SDimitry Andric}; 1980b57cec5SDimitry Andric 199*fe6060f1SDimitry Andrictemplate <class Predicate> // deprecated in C++17, removed in C++20 2000b57cec5SDimitry Andricbinary_negate<Predicate> not2(const Predicate& pred); 2010b57cec5SDimitry Andric 202e8d8bef9SDimitry Andrictemplate <class F> 203e8d8bef9SDimitry Andricconstexpr unspecified not_fn(F&& f); // C++17, constexpr in C++20 2040b57cec5SDimitry Andric 2050b57cec5SDimitry Andrictemplate<class T> struct is_bind_expression; 2060b57cec5SDimitry Andrictemplate<class T> struct is_placeholder; 2070b57cec5SDimitry Andric 2080b57cec5SDimitry Andric // See C++14 20.9.9, Function object binders 2090b57cec5SDimitry Andrictemplate <class T> inline constexpr bool is_bind_expression_v 2100b57cec5SDimitry Andric = is_bind_expression<T>::value; // C++17 2110b57cec5SDimitry Andrictemplate <class T> inline constexpr int is_placeholder_v 2120b57cec5SDimitry Andric = is_placeholder<T>::value; // C++17 2130b57cec5SDimitry Andric 2140b57cec5SDimitry Andric 2150b57cec5SDimitry Andrictemplate<class Fn, class... BoundArgs> 216e8d8bef9SDimitry Andric constexpr unspecified bind(Fn&&, BoundArgs&&...); // constexpr in C++20 2170b57cec5SDimitry Andrictemplate<class R, class Fn, class... BoundArgs> 218e8d8bef9SDimitry Andric constexpr unspecified bind(Fn&&, BoundArgs&&...); // constexpr in C++20 2190b57cec5SDimitry Andric 2200b57cec5SDimitry Andrictemplate<class F, class... Args> 221e8d8bef9SDimitry Andric constexpr // constexpr in C++20 2220b57cec5SDimitry Andric invoke_result_t<F, Args...> invoke(F&& f, Args&&... args) // C++17 2230b57cec5SDimitry Andric noexcept(is_nothrow_invocable_v<F, Args...>); 2240b57cec5SDimitry Andric 2250b57cec5SDimitry Andricnamespace placeholders { 2260b57cec5SDimitry Andric // M is the implementation-defined number of placeholders 2270b57cec5SDimitry Andric extern unspecified _1; 2280b57cec5SDimitry Andric extern unspecified _2; 2290b57cec5SDimitry Andric . 2300b57cec5SDimitry Andric . 2310b57cec5SDimitry Andric . 2320b57cec5SDimitry Andric extern unspecified _Mp; 2330b57cec5SDimitry Andric} 2340b57cec5SDimitry Andric 2350b57cec5SDimitry Andrictemplate <class Operation> 2360b57cec5SDimitry Andricclass binder1st // deprecated in C++11, removed in C++17 2370b57cec5SDimitry Andric : public unary_function<typename Operation::second_argument_type, 2380b57cec5SDimitry Andric typename Operation::result_type> 2390b57cec5SDimitry Andric{ 2400b57cec5SDimitry Andricprotected: 2410b57cec5SDimitry Andric Operation op; 2420b57cec5SDimitry Andric typename Operation::first_argument_type value; 2430b57cec5SDimitry Andricpublic: 2440b57cec5SDimitry Andric binder1st(const Operation& x, const typename Operation::first_argument_type y); 2450b57cec5SDimitry Andric typename Operation::result_type operator()( typename Operation::second_argument_type& x) const; 2460b57cec5SDimitry Andric typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const; 2470b57cec5SDimitry Andric}; 2480b57cec5SDimitry Andric 2490b57cec5SDimitry Andrictemplate <class Operation, class T> 2500b57cec5SDimitry Andricbinder1st<Operation> bind1st(const Operation& op, const T& x); // deprecated in C++11, removed in C++17 2510b57cec5SDimitry Andric 2520b57cec5SDimitry Andrictemplate <class Operation> 2530b57cec5SDimitry Andricclass binder2nd // deprecated in C++11, removed in C++17 2540b57cec5SDimitry Andric : public unary_function<typename Operation::first_argument_type, 2550b57cec5SDimitry Andric typename Operation::result_type> 2560b57cec5SDimitry Andric{ 2570b57cec5SDimitry Andricprotected: 2580b57cec5SDimitry Andric Operation op; 2590b57cec5SDimitry Andric typename Operation::second_argument_type value; 2600b57cec5SDimitry Andricpublic: 2610b57cec5SDimitry Andric binder2nd(const Operation& x, const typename Operation::second_argument_type y); 2620b57cec5SDimitry Andric typename Operation::result_type operator()( typename Operation::first_argument_type& x) const; 2630b57cec5SDimitry Andric typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const; 2640b57cec5SDimitry Andric}; 2650b57cec5SDimitry Andric 2660b57cec5SDimitry Andrictemplate <class Operation, class T> 2670b57cec5SDimitry Andricbinder2nd<Operation> bind2nd(const Operation& op, const T& x); // deprecated in C++11, removed in C++17 2680b57cec5SDimitry Andric 2690b57cec5SDimitry Andrictemplate <class Arg, class Result> // deprecated in C++11, removed in C++17 2700b57cec5SDimitry Andricclass pointer_to_unary_function : public unary_function<Arg, Result> 2710b57cec5SDimitry Andric{ 2720b57cec5SDimitry Andricpublic: 2730b57cec5SDimitry Andric explicit pointer_to_unary_function(Result (*f)(Arg)); 2740b57cec5SDimitry Andric Result operator()(Arg x) const; 2750b57cec5SDimitry Andric}; 2760b57cec5SDimitry Andric 2770b57cec5SDimitry Andrictemplate <class Arg, class Result> 2780b57cec5SDimitry Andricpointer_to_unary_function<Arg,Result> ptr_fun(Result (*f)(Arg)); // deprecated in C++11, removed in C++17 2790b57cec5SDimitry Andric 2800b57cec5SDimitry Andrictemplate <class Arg1, class Arg2, class Result> // deprecated in C++11, removed in C++17 2810b57cec5SDimitry Andricclass pointer_to_binary_function : public binary_function<Arg1, Arg2, Result> 2820b57cec5SDimitry Andric{ 2830b57cec5SDimitry Andricpublic: 2840b57cec5SDimitry Andric explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2)); 2850b57cec5SDimitry Andric Result operator()(Arg1 x, Arg2 y) const; 2860b57cec5SDimitry Andric}; 2870b57cec5SDimitry Andric 2880b57cec5SDimitry Andrictemplate <class Arg1, class Arg2, class Result> 2890b57cec5SDimitry Andricpointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1,Arg2)); // deprecated in C++11, removed in C++17 2900b57cec5SDimitry Andric 2910b57cec5SDimitry Andrictemplate<class S, class T> // deprecated in C++11, removed in C++17 2920b57cec5SDimitry Andricclass mem_fun_t : public unary_function<T*, S> 2930b57cec5SDimitry Andric{ 2940b57cec5SDimitry Andricpublic: 2950b57cec5SDimitry Andric explicit mem_fun_t(S (T::*p)()); 2960b57cec5SDimitry Andric S operator()(T* p) const; 2970b57cec5SDimitry Andric}; 2980b57cec5SDimitry Andric 2990b57cec5SDimitry Andrictemplate<class S, class T, class A> 3000b57cec5SDimitry Andricclass mem_fun1_t : public binary_function<T*, A, S> // deprecated in C++11, removed in C++17 3010b57cec5SDimitry Andric{ 3020b57cec5SDimitry Andricpublic: 3030b57cec5SDimitry Andric explicit mem_fun1_t(S (T::*p)(A)); 3040b57cec5SDimitry Andric S operator()(T* p, A x) const; 3050b57cec5SDimitry Andric}; 3060b57cec5SDimitry Andric 3070b57cec5SDimitry Andrictemplate<class S, class T> mem_fun_t<S,T> mem_fun(S (T::*f)()); // deprecated in C++11, removed in C++17 3080b57cec5SDimitry Andrictemplate<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 3090b57cec5SDimitry Andric 3100b57cec5SDimitry Andrictemplate<class S, class T> 3110b57cec5SDimitry Andricclass mem_fun_ref_t : public unary_function<T, S> // deprecated in C++11, removed in C++17 3120b57cec5SDimitry Andric{ 3130b57cec5SDimitry Andricpublic: 3140b57cec5SDimitry Andric explicit mem_fun_ref_t(S (T::*p)()); 3150b57cec5SDimitry Andric S operator()(T& p) const; 3160b57cec5SDimitry Andric}; 3170b57cec5SDimitry Andric 3180b57cec5SDimitry Andrictemplate<class S, class T, class A> 3190b57cec5SDimitry Andricclass mem_fun1_ref_t : public binary_function<T, A, S> // deprecated in C++11, removed in C++17 3200b57cec5SDimitry Andric{ 3210b57cec5SDimitry Andricpublic: 3220b57cec5SDimitry Andric explicit mem_fun1_ref_t(S (T::*p)(A)); 3230b57cec5SDimitry Andric S operator()(T& p, A x) const; 3240b57cec5SDimitry Andric}; 3250b57cec5SDimitry Andric 3260b57cec5SDimitry Andrictemplate<class S, class T> mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)()); // deprecated in C++11, removed in C++17 3270b57cec5SDimitry Andrictemplate<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 3280b57cec5SDimitry Andric 3290b57cec5SDimitry Andrictemplate <class S, class T> 3300b57cec5SDimitry Andricclass const_mem_fun_t : public unary_function<const T*, S> // deprecated in C++11, removed in C++17 3310b57cec5SDimitry Andric{ 3320b57cec5SDimitry Andricpublic: 3330b57cec5SDimitry Andric explicit const_mem_fun_t(S (T::*p)() const); 3340b57cec5SDimitry Andric S operator()(const T* p) const; 3350b57cec5SDimitry Andric}; 3360b57cec5SDimitry Andric 3370b57cec5SDimitry Andrictemplate <class S, class T, class A> 3380b57cec5SDimitry Andricclass const_mem_fun1_t : public binary_function<const T*, A, S> // deprecated in C++11, removed in C++17 3390b57cec5SDimitry Andric{ 3400b57cec5SDimitry Andricpublic: 3410b57cec5SDimitry Andric explicit const_mem_fun1_t(S (T::*p)(A) const); 3420b57cec5SDimitry Andric S operator()(const T* p, A x) const; 3430b57cec5SDimitry Andric}; 3440b57cec5SDimitry Andric 3450b57cec5SDimitry Andrictemplate <class S, class T> const_mem_fun_t<S,T> mem_fun(S (T::*f)() const); // deprecated in C++11, removed in C++17 3460b57cec5SDimitry Andrictemplate <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 3470b57cec5SDimitry Andric 3480b57cec5SDimitry Andrictemplate <class S, class T> 3490b57cec5SDimitry Andricclass const_mem_fun_ref_t : public unary_function<T, S> // deprecated in C++11, removed in C++17 3500b57cec5SDimitry Andric{ 3510b57cec5SDimitry Andricpublic: 3520b57cec5SDimitry Andric explicit const_mem_fun_ref_t(S (T::*p)() const); 3530b57cec5SDimitry Andric S operator()(const T& p) const; 3540b57cec5SDimitry Andric}; 3550b57cec5SDimitry Andric 3560b57cec5SDimitry Andrictemplate <class S, class T, class A> 3570b57cec5SDimitry Andricclass const_mem_fun1_ref_t : public binary_function<T, A, S> // deprecated in C++11, removed in C++17 3580b57cec5SDimitry Andric{ 3590b57cec5SDimitry Andricpublic: 3600b57cec5SDimitry Andric explicit const_mem_fun1_ref_t(S (T::*p)(A) const); 3610b57cec5SDimitry Andric S operator()(const T& p, A x) const; 3620b57cec5SDimitry Andric}; 3630b57cec5SDimitry Andric 3640b57cec5SDimitry Andrictemplate <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 3650b57cec5SDimitry Andrictemplate <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 3660b57cec5SDimitry Andric 367e8d8bef9SDimitry Andrictemplate<class R, class T> 368e8d8bef9SDimitry Andricconstexpr unspecified mem_fn(R T::*); // constexpr in C++20 3690b57cec5SDimitry Andric 3700b57cec5SDimitry Andricclass bad_function_call 3710b57cec5SDimitry Andric : public exception 3720b57cec5SDimitry Andric{ 3730b57cec5SDimitry Andric}; 3740b57cec5SDimitry Andric 3750b57cec5SDimitry Andrictemplate<class> class function; // undefined 3760b57cec5SDimitry Andric 3770b57cec5SDimitry Andrictemplate<class R, class... ArgTypes> 3780b57cec5SDimitry Andricclass function<R(ArgTypes...)> 3790b57cec5SDimitry Andric : public unary_function<T1, R> // iff sizeof...(ArgTypes) == 1 and 3800b57cec5SDimitry Andric // ArgTypes contains T1 3810b57cec5SDimitry Andric : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and 3820b57cec5SDimitry Andric // ArgTypes contains T1 and T2 3830b57cec5SDimitry Andric{ 3840b57cec5SDimitry Andricpublic: 3850b57cec5SDimitry Andric typedef R result_type; 3860b57cec5SDimitry Andric 3870b57cec5SDimitry Andric // construct/copy/destroy: 3880b57cec5SDimitry Andric function() noexcept; 3890b57cec5SDimitry Andric function(nullptr_t) noexcept; 3900b57cec5SDimitry Andric function(const function&); 3910b57cec5SDimitry Andric function(function&&) noexcept; 3920b57cec5SDimitry Andric template<class F> 3930b57cec5SDimitry Andric function(F); 3940b57cec5SDimitry Andric template<Allocator Alloc> 3950b57cec5SDimitry Andric function(allocator_arg_t, const Alloc&) noexcept; // removed in C++17 3960b57cec5SDimitry Andric template<Allocator Alloc> 3970b57cec5SDimitry Andric function(allocator_arg_t, const Alloc&, nullptr_t) noexcept; // removed in C++17 3980b57cec5SDimitry Andric template<Allocator Alloc> 3990b57cec5SDimitry Andric function(allocator_arg_t, const Alloc&, const function&); // removed in C++17 4000b57cec5SDimitry Andric template<Allocator Alloc> 4010b57cec5SDimitry Andric function(allocator_arg_t, const Alloc&, function&&); // removed in C++17 4020b57cec5SDimitry Andric template<class F, Allocator Alloc> 4030b57cec5SDimitry Andric function(allocator_arg_t, const Alloc&, F); // removed in C++17 4040b57cec5SDimitry Andric 4050b57cec5SDimitry Andric function& operator=(const function&); 4060b57cec5SDimitry Andric function& operator=(function&&) noexcept; 4070b57cec5SDimitry Andric function& operator=(nullptr_t) noexcept; 4080b57cec5SDimitry Andric template<class F> 4090b57cec5SDimitry Andric function& operator=(F&&); 4100b57cec5SDimitry Andric template<class F> 4110b57cec5SDimitry Andric function& operator=(reference_wrapper<F>) noexcept; 4120b57cec5SDimitry Andric 4130b57cec5SDimitry Andric ~function(); 4140b57cec5SDimitry Andric 4150b57cec5SDimitry Andric // function modifiers: 4160b57cec5SDimitry Andric void swap(function&) noexcept; 4170b57cec5SDimitry Andric template<class F, class Alloc> 4180b57cec5SDimitry Andric void assign(F&&, const Alloc&); // Removed in C++17 4190b57cec5SDimitry Andric 4200b57cec5SDimitry Andric // function capacity: 4210b57cec5SDimitry Andric explicit operator bool() const noexcept; 4220b57cec5SDimitry Andric 4230b57cec5SDimitry Andric // function invocation: 4240b57cec5SDimitry Andric R operator()(ArgTypes...) const; 4250b57cec5SDimitry Andric 4260b57cec5SDimitry Andric // function target access: 4270b57cec5SDimitry Andric const std::type_info& target_type() const noexcept; 4280b57cec5SDimitry Andric template <typename T> T* target() noexcept; 4290b57cec5SDimitry Andric template <typename T> const T* target() const noexcept; 4300b57cec5SDimitry Andric}; 4310b57cec5SDimitry Andric 432e40139ffSDimitry Andric// Deduction guides 433e40139ffSDimitry Andrictemplate<class R, class ...Args> 434e40139ffSDimitry Andricfunction(R(*)(Args...)) -> function<R(Args...)>; // since C++17 435e40139ffSDimitry Andric 436e40139ffSDimitry Andrictemplate<class F> 437e40139ffSDimitry Andricfunction(F) -> function<see-below>; // since C++17 438e40139ffSDimitry Andric 4390b57cec5SDimitry Andric// Null pointer comparisons: 4400b57cec5SDimitry Andrictemplate <class R, class ... ArgTypes> 4410b57cec5SDimitry Andric bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept; 4420b57cec5SDimitry Andric 4430b57cec5SDimitry Andrictemplate <class R, class ... ArgTypes> 4440b57cec5SDimitry Andric bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept; 4450b57cec5SDimitry Andric 4460b57cec5SDimitry Andrictemplate <class R, class ... ArgTypes> 4470b57cec5SDimitry Andric bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept; 4480b57cec5SDimitry Andric 4490b57cec5SDimitry Andrictemplate <class R, class ... ArgTypes> 4500b57cec5SDimitry Andric bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept; 4510b57cec5SDimitry Andric 4520b57cec5SDimitry Andric// specialized algorithms: 4530b57cec5SDimitry Andrictemplate <class R, class ... ArgTypes> 4540b57cec5SDimitry Andric void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept; 4550b57cec5SDimitry Andric 4560b57cec5SDimitry Andrictemplate <class T> struct hash; 4570b57cec5SDimitry Andric 4580b57cec5SDimitry Andrictemplate <> struct hash<bool>; 4590b57cec5SDimitry Andrictemplate <> struct hash<char>; 4600b57cec5SDimitry Andrictemplate <> struct hash<signed char>; 4610b57cec5SDimitry Andrictemplate <> struct hash<unsigned char>; 462e8d8bef9SDimitry Andrictemplate <> struct hash<char8_t>; // since C++20 4630b57cec5SDimitry Andrictemplate <> struct hash<char16_t>; 4640b57cec5SDimitry Andrictemplate <> struct hash<char32_t>; 4650b57cec5SDimitry Andrictemplate <> struct hash<wchar_t>; 4660b57cec5SDimitry Andrictemplate <> struct hash<short>; 4670b57cec5SDimitry Andrictemplate <> struct hash<unsigned short>; 4680b57cec5SDimitry Andrictemplate <> struct hash<int>; 4690b57cec5SDimitry Andrictemplate <> struct hash<unsigned int>; 4700b57cec5SDimitry Andrictemplate <> struct hash<long>; 4710b57cec5SDimitry Andrictemplate <> struct hash<long long>; 4720b57cec5SDimitry Andrictemplate <> struct hash<unsigned long>; 4730b57cec5SDimitry Andrictemplate <> struct hash<unsigned long long>; 4740b57cec5SDimitry Andric 4750b57cec5SDimitry Andrictemplate <> struct hash<float>; 4760b57cec5SDimitry Andrictemplate <> struct hash<double>; 4770b57cec5SDimitry Andrictemplate <> struct hash<long double>; 4780b57cec5SDimitry Andric 4790b57cec5SDimitry Andrictemplate<class T> struct hash<T*>; 4800b57cec5SDimitry Andrictemplate <> struct hash<nullptr_t>; // C++17 4810b57cec5SDimitry Andric 4820b57cec5SDimitry Andric} // std 4830b57cec5SDimitry Andric 4840b57cec5SDimitry AndricPOLICY: For non-variadic implementations, the number of arguments is limited 4850b57cec5SDimitry Andric to 3. It is hoped that the need for non-variadic implementations 4860b57cec5SDimitry Andric will be minimal. 4870b57cec5SDimitry Andric 4880b57cec5SDimitry Andric*/ 4890b57cec5SDimitry Andric 490*fe6060f1SDimitry Andric#include <__algorithm/search.h> 4910b57cec5SDimitry Andric#include <__config> 492*fe6060f1SDimitry Andric#include <__debug> 493*fe6060f1SDimitry Andric#include <__functional/binary_function.h> // TODO: deprecate 494*fe6060f1SDimitry Andric#include <__functional/binary_negate.h> 495*fe6060f1SDimitry Andric#include <__functional/bind_front.h> 496*fe6060f1SDimitry Andric#include <__functional/bind.h> 497*fe6060f1SDimitry Andric#include <__functional/binder1st.h> 498*fe6060f1SDimitry Andric#include <__functional/binder2nd.h> 499*fe6060f1SDimitry Andric#include <__functional/default_searcher.h> 500*fe6060f1SDimitry Andric#include <__functional/function.h> 501*fe6060f1SDimitry Andric#include <__functional/hash.h> 502*fe6060f1SDimitry Andric#include <__functional/identity.h> 503*fe6060f1SDimitry Andric#include <__functional/invoke.h> 504*fe6060f1SDimitry Andric#include <__functional/mem_fn.h> // TODO: deprecate 505*fe6060f1SDimitry Andric#include <__functional/mem_fun_ref.h> 506*fe6060f1SDimitry Andric#include <__functional/not_fn.h> 507*fe6060f1SDimitry Andric#include <__functional/operations.h> 508*fe6060f1SDimitry Andric#include <__functional/pointer_to_binary_function.h> 509*fe6060f1SDimitry Andric#include <__functional/pointer_to_unary_function.h> 510*fe6060f1SDimitry Andric#include <__functional/ranges_operations.h> 511*fe6060f1SDimitry Andric#include <__functional/reference_wrapper.h> 512*fe6060f1SDimitry Andric#include <__functional/unary_function.h> // TODO: deprecate 513*fe6060f1SDimitry Andric#include <__functional/unary_negate.h> 514*fe6060f1SDimitry Andric#include <__functional/unwrap_ref.h> 515*fe6060f1SDimitry Andric#include <__utility/forward.h> 516*fe6060f1SDimitry Andric#include <concepts> 5170b57cec5SDimitry Andric#include <exception> 5180b57cec5SDimitry Andric#include <memory> 5190b57cec5SDimitry Andric#include <tuple> 520*fe6060f1SDimitry Andric#include <type_traits> 521*fe6060f1SDimitry Andric#include <typeinfo> 5220b57cec5SDimitry Andric#include <utility> 5230b57cec5SDimitry Andric#include <version> 5240b57cec5SDimitry Andric 5250b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 5260b57cec5SDimitry Andric#pragma GCC system_header 5270b57cec5SDimitry Andric#endif 5280b57cec5SDimitry Andric 5290b57cec5SDimitry Andric#endif // _LIBCPP_FUNCTIONAL 530