10b57cec5SDimitry Andric// -*- C++ -*- 2fe6060f1SDimitry 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 375f757f3fSDimitry Andric : public binary_function<T1, T2, R> // if wrapping 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 45fe6060f1SDimitry Andric template<class U> 4606c3fb27SDimitry Andric constexpr reference_wrapper(U&&); // constexpr since C++20 4706c3fb27SDimitry Andric constexpr reference_wrapper(const reference_wrapper<T>& x) noexcept; // constexpr since C++20 480b57cec5SDimitry Andric 490b57cec5SDimitry Andric // assignment 5006c3fb27SDimitry Andric constexpr reference_wrapper& 5106c3fb27SDimitry Andric operator=(const reference_wrapper<T>& x) noexcept; // constexpr since C++20 520b57cec5SDimitry Andric 530b57cec5SDimitry Andric // access 5406c3fb27SDimitry Andric constexpr operator T& () const noexcept; // constexpr since C++20 5506c3fb27SDimitry Andric constexpr T& get() const noexcept; // constexpr since C++20 560b57cec5SDimitry Andric 570b57cec5SDimitry Andric // invoke 580b57cec5SDimitry Andric template <class... ArgTypes> 5906c3fb27SDimitry Andric constexpr typename result_of<T&(ArgTypes&&...)>::type // constexpr since C++20 6006c3fb27SDimitry Andric operator() (ArgTypes&&...) const 6106c3fb27SDimitry Andric noexcept(is_nothrow_invocable_v<T&, ArgTypes...>); // noexcept since C++17 620b57cec5SDimitry Andric}; 630b57cec5SDimitry Andric 64fe6060f1SDimitry Andrictemplate <class T> 65fe6060f1SDimitry Andric reference_wrapper(T&) -> reference_wrapper<T>; 66fe6060f1SDimitry Andric 670b57cec5SDimitry Andrictemplate <class T> reference_wrapper<T> ref(T& t) noexcept; 680b57cec5SDimitry Andrictemplate <class T> void ref(const T&& t) = delete; 690b57cec5SDimitry Andrictemplate <class T> reference_wrapper<T> ref(reference_wrapper<T>t) noexcept; 700b57cec5SDimitry Andric 710b57cec5SDimitry Andrictemplate <class T> reference_wrapper<const T> cref(const T& t) noexcept; 720b57cec5SDimitry Andrictemplate <class T> void cref(const T&& t) = delete; 730b57cec5SDimitry Andrictemplate <class T> reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept; 740b57cec5SDimitry Andric 750b57cec5SDimitry Andrictemplate <class T> struct unwrap_reference; // since C++20 760b57cec5SDimitry Andrictemplate <class T> struct unwrap_ref_decay : unwrap_reference<decay_t<T>> { }; // since C++20 770b57cec5SDimitry Andrictemplate <class T> using unwrap_reference_t = typename unwrap_reference<T>::type; // since C++20 780b57cec5SDimitry Andrictemplate <class T> using unwrap_ref_decay_t = typename unwrap_ref_decay<T>::type; // since C++20 790b57cec5SDimitry Andric 80*0fca6ea1SDimitry Andric// [refwrap.comparisons], comparisons 81*0fca6ea1SDimitry Andricfriend constexpr bool operator==(reference_wrapper, reference_wrapper); // Since C++26 82*0fca6ea1SDimitry Andricfriend constexpr bool operator==(reference_wrapper, const T&); // Since C++26 83*0fca6ea1SDimitry Andricfriend constexpr bool operator==(reference_wrapper, reference_wrapper<const T>); // Since C++26 84*0fca6ea1SDimitry Andric 85*0fca6ea1SDimitry Andricfriend constexpr auto operator<=>(reference_wrapper, reference_wrapper); // Since C++26 86*0fca6ea1SDimitry Andricfriend constexpr auto operator<=>(reference_wrapper, const T&); // Since C++26 87*0fca6ea1SDimitry Andricfriend constexpr auto operator<=>(reference_wrapper, reference_wrapper<const T>); // Since C++26 88*0fca6ea1SDimitry Andric 890b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 90fe6060f1SDimitry Andricstruct plus { 910b57cec5SDimitry Andric T operator()(const T& x, const T& y) const; 920b57cec5SDimitry Andric}; 930b57cec5SDimitry Andric 940b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 95fe6060f1SDimitry Andricstruct minus { 960b57cec5SDimitry Andric T operator()(const T& x, const T& y) const; 970b57cec5SDimitry Andric}; 980b57cec5SDimitry Andric 990b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 100fe6060f1SDimitry Andricstruct multiplies { 1010b57cec5SDimitry Andric T operator()(const T& x, const T& y) const; 1020b57cec5SDimitry Andric}; 1030b57cec5SDimitry Andric 1040b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 105fe6060f1SDimitry Andricstruct divides { 1060b57cec5SDimitry Andric T operator()(const T& x, const T& y) const; 1070b57cec5SDimitry Andric}; 1080b57cec5SDimitry Andric 1090b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 110fe6060f1SDimitry Andricstruct modulus { 1110b57cec5SDimitry Andric T operator()(const T& x, const T& y) const; 1120b57cec5SDimitry Andric}; 1130b57cec5SDimitry Andric 1140b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 115fe6060f1SDimitry Andricstruct negate { 1160b57cec5SDimitry Andric T operator()(const T& x) const; 1170b57cec5SDimitry Andric}; 1180b57cec5SDimitry Andric 1190b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 120fe6060f1SDimitry Andricstruct equal_to { 1210b57cec5SDimitry Andric bool operator()(const T& x, const T& y) const; 1220b57cec5SDimitry Andric}; 1230b57cec5SDimitry Andric 1240b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 125fe6060f1SDimitry Andricstruct not_equal_to { 1260b57cec5SDimitry Andric bool operator()(const T& x, const T& y) const; 1270b57cec5SDimitry Andric}; 1280b57cec5SDimitry Andric 1290b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 130fe6060f1SDimitry Andricstruct greater { 1310b57cec5SDimitry Andric bool operator()(const T& x, const T& y) const; 1320b57cec5SDimitry Andric}; 1330b57cec5SDimitry Andric 1340b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 135fe6060f1SDimitry Andricstruct less { 1360b57cec5SDimitry Andric bool operator()(const T& x, const T& y) const; 1370b57cec5SDimitry Andric}; 1380b57cec5SDimitry Andric 1390b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 140fe6060f1SDimitry Andricstruct greater_equal { 1410b57cec5SDimitry Andric bool operator()(const T& x, const T& y) const; 1420b57cec5SDimitry Andric}; 1430b57cec5SDimitry Andric 1440b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 145fe6060f1SDimitry Andricstruct less_equal { 1460b57cec5SDimitry Andric bool operator()(const T& x, const T& y) const; 1470b57cec5SDimitry Andric}; 1480b57cec5SDimitry Andric 149349cc55cSDimitry Andric// [comparisons.three.way], class compare_three_way 150349cc55cSDimitry Andricstruct compare_three_way; 151349cc55cSDimitry Andric 1520b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 153fe6060f1SDimitry Andricstruct logical_and { 1540b57cec5SDimitry Andric bool operator()(const T& x, const T& y) const; 1550b57cec5SDimitry Andric}; 1560b57cec5SDimitry Andric 1570b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 158fe6060f1SDimitry Andricstruct logical_or { 1590b57cec5SDimitry Andric bool operator()(const T& x, const T& y) const; 1600b57cec5SDimitry Andric}; 1610b57cec5SDimitry Andric 1620b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 163fe6060f1SDimitry Andricstruct logical_not { 1640b57cec5SDimitry Andric bool operator()(const T& x) const; 1650b57cec5SDimitry Andric}; 1660b57cec5SDimitry Andric 1670b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 168fe6060f1SDimitry Andricstruct bit_and { 169fe6060f1SDimitry Andric T operator()(const T& x, const T& y) const; 1700b57cec5SDimitry Andric}; 1710b57cec5SDimitry Andric 1720b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 173fe6060f1SDimitry Andricstruct bit_or { 174fe6060f1SDimitry Andric T operator()(const T& x, const T& y) const; 1750b57cec5SDimitry Andric}; 1760b57cec5SDimitry Andric 1770b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14 178fe6060f1SDimitry Andricstruct bit_xor { 179fe6060f1SDimitry Andric T operator()(const T& x, const T& y) const; 1800b57cec5SDimitry Andric}; 1810b57cec5SDimitry Andric 1820b57cec5SDimitry Andrictemplate <class T=void> // C++14 183fe6060f1SDimitry Andricstruct bit_not { 184fe6060f1SDimitry Andric T operator()(const T& x) const; 1850b57cec5SDimitry Andric}; 1860b57cec5SDimitry Andric 187fe6060f1SDimitry Andricstruct identity; // C++20 188fe6060f1SDimitry Andric 1890b57cec5SDimitry Andrictemplate <class Predicate> 190fe6060f1SDimitry Andricclass unary_negate // deprecated in C++17, removed in C++20 1910b57cec5SDimitry Andric : public unary_function<typename Predicate::argument_type, bool> 1920b57cec5SDimitry Andric{ 1930b57cec5SDimitry Andricpublic: 1940b57cec5SDimitry Andric explicit unary_negate(const Predicate& pred); 1950b57cec5SDimitry Andric bool operator()(const typename Predicate::argument_type& x) const; 1960b57cec5SDimitry Andric}; 1970b57cec5SDimitry Andric 198fe6060f1SDimitry Andrictemplate <class Predicate> // deprecated in C++17, removed in C++20 1990b57cec5SDimitry Andricunary_negate<Predicate> not1(const Predicate& pred); 2000b57cec5SDimitry Andric 2010b57cec5SDimitry Andrictemplate <class Predicate> 202fe6060f1SDimitry Andricclass binary_negate // deprecated in C++17, removed in C++20 2030b57cec5SDimitry Andric : public binary_function<typename Predicate::first_argument_type, 2040b57cec5SDimitry Andric typename Predicate::second_argument_type, 2050b57cec5SDimitry Andric bool> 2060b57cec5SDimitry Andric{ 2070b57cec5SDimitry Andricpublic: 2080b57cec5SDimitry Andric explicit binary_negate(const Predicate& pred); 2090b57cec5SDimitry Andric bool operator()(const typename Predicate::first_argument_type& x, 2100b57cec5SDimitry Andric const typename Predicate::second_argument_type& y) const; 2110b57cec5SDimitry Andric}; 2120b57cec5SDimitry Andric 213fe6060f1SDimitry Andrictemplate <class Predicate> // deprecated in C++17, removed in C++20 2140b57cec5SDimitry Andricbinary_negate<Predicate> not2(const Predicate& pred); 2150b57cec5SDimitry Andric 216e8d8bef9SDimitry Andrictemplate <class F> 217e8d8bef9SDimitry Andricconstexpr unspecified not_fn(F&& f); // C++17, constexpr in C++20 2180b57cec5SDimitry Andric 219*0fca6ea1SDimitry Andric// [func.bind.partial], function templates bind_front and bind_back 220*0fca6ea1SDimitry Andrictemplate<class F, class... Args> 221*0fca6ea1SDimitry Andric constexpr unspecified bind_front(F&&, Args&&...); // C++20 222*0fca6ea1SDimitry Andrictemplate<class F, class... Args> 223*0fca6ea1SDimitry Andric constexpr unspecified bind_back(F&&, Args&&...); // C++23 224*0fca6ea1SDimitry Andric 2250b57cec5SDimitry Andrictemplate<class T> struct is_bind_expression; 2260b57cec5SDimitry Andrictemplate<class T> struct is_placeholder; 2270b57cec5SDimitry Andric 2280b57cec5SDimitry Andric // See C++14 20.9.9, Function object binders 2290b57cec5SDimitry Andrictemplate <class T> inline constexpr bool is_bind_expression_v 2300b57cec5SDimitry Andric = is_bind_expression<T>::value; // C++17 2310b57cec5SDimitry Andrictemplate <class T> inline constexpr int is_placeholder_v 2320b57cec5SDimitry Andric = is_placeholder<T>::value; // C++17 2330b57cec5SDimitry Andric 2340b57cec5SDimitry Andric 2350b57cec5SDimitry Andrictemplate<class Fn, class... BoundArgs> 236e8d8bef9SDimitry Andric constexpr unspecified bind(Fn&&, BoundArgs&&...); // constexpr in C++20 2370b57cec5SDimitry Andrictemplate<class R, class Fn, class... BoundArgs> 238e8d8bef9SDimitry Andric constexpr unspecified bind(Fn&&, BoundArgs&&...); // constexpr in C++20 2390b57cec5SDimitry Andric 24006c3fb27SDimitry Andric// [func.invoke] 2410b57cec5SDimitry Andrictemplate<class F, class... Args> 242e8d8bef9SDimitry Andric constexpr // constexpr in C++20 2430b57cec5SDimitry Andric invoke_result_t<F, Args...> invoke(F&& f, Args&&... args) // C++17 2440b57cec5SDimitry Andric noexcept(is_nothrow_invocable_v<F, Args...>); 2450b57cec5SDimitry Andric 24606c3fb27SDimitry Andrictemplate<class R, class F, class... Args> 24706c3fb27SDimitry Andric constexpr R invoke_r(F&& f, Args&&... args) // C++23 24806c3fb27SDimitry Andric noexcept(is_nothrow_invocable_r_v<R, F, Args...>); 24906c3fb27SDimitry Andric 2500b57cec5SDimitry Andricnamespace placeholders { 2510b57cec5SDimitry Andric // M is the implementation-defined number of placeholders 2520b57cec5SDimitry Andric extern unspecified _1; 2530b57cec5SDimitry Andric extern unspecified _2; 2540b57cec5SDimitry Andric . 2550b57cec5SDimitry Andric . 2560b57cec5SDimitry Andric . 2570b57cec5SDimitry Andric extern unspecified _Mp; 2580b57cec5SDimitry Andric} 2590b57cec5SDimitry Andric 2600b57cec5SDimitry Andrictemplate <class Operation> 2610b57cec5SDimitry Andricclass binder1st // deprecated in C++11, removed in C++17 2620b57cec5SDimitry Andric : public unary_function<typename Operation::second_argument_type, 2630b57cec5SDimitry Andric typename Operation::result_type> 2640b57cec5SDimitry Andric{ 2650b57cec5SDimitry Andricprotected: 2660b57cec5SDimitry Andric Operation op; 2670b57cec5SDimitry Andric typename Operation::first_argument_type value; 2680b57cec5SDimitry Andricpublic: 2690b57cec5SDimitry Andric binder1st(const Operation& x, const typename Operation::first_argument_type y); 2700b57cec5SDimitry Andric typename Operation::result_type operator()( typename Operation::second_argument_type& x) const; 2710b57cec5SDimitry Andric typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const; 2720b57cec5SDimitry Andric}; 2730b57cec5SDimitry Andric 2740b57cec5SDimitry Andrictemplate <class Operation, class T> 2750b57cec5SDimitry Andricbinder1st<Operation> bind1st(const Operation& op, const T& x); // deprecated in C++11, removed in C++17 2760b57cec5SDimitry Andric 2770b57cec5SDimitry Andrictemplate <class Operation> 2780b57cec5SDimitry Andricclass binder2nd // deprecated in C++11, removed in C++17 2790b57cec5SDimitry Andric : public unary_function<typename Operation::first_argument_type, 2800b57cec5SDimitry Andric typename Operation::result_type> 2810b57cec5SDimitry Andric{ 2820b57cec5SDimitry Andricprotected: 2830b57cec5SDimitry Andric Operation op; 2840b57cec5SDimitry Andric typename Operation::second_argument_type value; 2850b57cec5SDimitry Andricpublic: 2860b57cec5SDimitry Andric binder2nd(const Operation& x, const typename Operation::second_argument_type y); 2870b57cec5SDimitry Andric typename Operation::result_type operator()( typename Operation::first_argument_type& x) const; 2880b57cec5SDimitry Andric typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const; 2890b57cec5SDimitry Andric}; 2900b57cec5SDimitry Andric 2910b57cec5SDimitry Andrictemplate <class Operation, class T> 2920b57cec5SDimitry Andricbinder2nd<Operation> bind2nd(const Operation& op, const T& x); // deprecated in C++11, removed in C++17 2930b57cec5SDimitry Andric 2940b57cec5SDimitry Andrictemplate <class Arg, class Result> // deprecated in C++11, removed in C++17 2950b57cec5SDimitry Andricclass pointer_to_unary_function : public unary_function<Arg, Result> 2960b57cec5SDimitry Andric{ 2970b57cec5SDimitry Andricpublic: 2980b57cec5SDimitry Andric explicit pointer_to_unary_function(Result (*f)(Arg)); 2990b57cec5SDimitry Andric Result operator()(Arg x) const; 3000b57cec5SDimitry Andric}; 3010b57cec5SDimitry Andric 3020b57cec5SDimitry Andrictemplate <class Arg, class Result> 3030b57cec5SDimitry Andricpointer_to_unary_function<Arg,Result> ptr_fun(Result (*f)(Arg)); // deprecated in C++11, removed in C++17 3040b57cec5SDimitry Andric 3050b57cec5SDimitry Andrictemplate <class Arg1, class Arg2, class Result> // deprecated in C++11, removed in C++17 3060b57cec5SDimitry Andricclass pointer_to_binary_function : public binary_function<Arg1, Arg2, Result> 3070b57cec5SDimitry Andric{ 3080b57cec5SDimitry Andricpublic: 3090b57cec5SDimitry Andric explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2)); 3100b57cec5SDimitry Andric Result operator()(Arg1 x, Arg2 y) const; 3110b57cec5SDimitry Andric}; 3120b57cec5SDimitry Andric 3130b57cec5SDimitry Andrictemplate <class Arg1, class Arg2, class Result> 3140b57cec5SDimitry Andricpointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1,Arg2)); // deprecated in C++11, removed in C++17 3150b57cec5SDimitry Andric 3160b57cec5SDimitry Andrictemplate<class S, class T> // deprecated in C++11, removed in C++17 3170b57cec5SDimitry Andricclass mem_fun_t : public unary_function<T*, S> 3180b57cec5SDimitry Andric{ 3190b57cec5SDimitry Andricpublic: 3200b57cec5SDimitry Andric explicit mem_fun_t(S (T::*p)()); 3210b57cec5SDimitry Andric S operator()(T* p) const; 3220b57cec5SDimitry Andric}; 3230b57cec5SDimitry Andric 3240b57cec5SDimitry Andrictemplate<class S, class T, class A> 3250b57cec5SDimitry Andricclass mem_fun1_t : public binary_function<T*, A, S> // deprecated in C++11, removed in C++17 3260b57cec5SDimitry Andric{ 3270b57cec5SDimitry Andricpublic: 3280b57cec5SDimitry Andric explicit mem_fun1_t(S (T::*p)(A)); 3290b57cec5SDimitry Andric S operator()(T* p, A x) const; 3300b57cec5SDimitry Andric}; 3310b57cec5SDimitry Andric 3320b57cec5SDimitry Andrictemplate<class S, class T> mem_fun_t<S,T> mem_fun(S (T::*f)()); // deprecated in C++11, removed in C++17 3330b57cec5SDimitry 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 3340b57cec5SDimitry Andric 3350b57cec5SDimitry Andrictemplate<class S, class T> 3360b57cec5SDimitry Andricclass mem_fun_ref_t : public unary_function<T, S> // deprecated in C++11, removed in C++17 3370b57cec5SDimitry Andric{ 3380b57cec5SDimitry Andricpublic: 3390b57cec5SDimitry Andric explicit mem_fun_ref_t(S (T::*p)()); 3400b57cec5SDimitry Andric S operator()(T& p) const; 3410b57cec5SDimitry Andric}; 3420b57cec5SDimitry Andric 3430b57cec5SDimitry Andrictemplate<class S, class T, class A> 3440b57cec5SDimitry Andricclass mem_fun1_ref_t : public binary_function<T, A, S> // deprecated in C++11, removed in C++17 3450b57cec5SDimitry Andric{ 3460b57cec5SDimitry Andricpublic: 3470b57cec5SDimitry Andric explicit mem_fun1_ref_t(S (T::*p)(A)); 3480b57cec5SDimitry Andric S operator()(T& p, A x) const; 3490b57cec5SDimitry Andric}; 3500b57cec5SDimitry Andric 35106c3fb27SDimitry Andrictemplate<class S, class T> 35206c3fb27SDimitry Andricmem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)()); // deprecated in C++11, removed in C++17 35306c3fb27SDimitry Andrictemplate<class S, class T, class A> 35406c3fb27SDimitry Andricmem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A)); // deprecated in C++11, removed in C++17 3550b57cec5SDimitry Andric 3560b57cec5SDimitry Andrictemplate <class S, class T> 3570b57cec5SDimitry Andricclass const_mem_fun_t : public unary_function<const T*, S> // deprecated in C++11, removed in C++17 3580b57cec5SDimitry Andric{ 3590b57cec5SDimitry Andricpublic: 3600b57cec5SDimitry Andric explicit const_mem_fun_t(S (T::*p)() const); 3610b57cec5SDimitry Andric S operator()(const T* p) const; 3620b57cec5SDimitry Andric}; 3630b57cec5SDimitry Andric 3640b57cec5SDimitry Andrictemplate <class S, class T, class A> 3650b57cec5SDimitry Andricclass const_mem_fun1_t : public binary_function<const T*, A, S> // deprecated in C++11, removed in C++17 3660b57cec5SDimitry Andric{ 3670b57cec5SDimitry Andricpublic: 3680b57cec5SDimitry Andric explicit const_mem_fun1_t(S (T::*p)(A) const); 3690b57cec5SDimitry Andric S operator()(const T* p, A x) const; 3700b57cec5SDimitry Andric}; 3710b57cec5SDimitry Andric 37206c3fb27SDimitry Andrictemplate <class S, class T> 37306c3fb27SDimitry Andricconst_mem_fun_t<S,T> mem_fun(S (T::*f)() const); // deprecated in C++11, removed in C++17 37406c3fb27SDimitry Andrictemplate <class S, class T, class A> 37506c3fb27SDimitry Andricconst_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const); // deprecated in C++11, removed in C++17 3760b57cec5SDimitry Andric 3770b57cec5SDimitry Andrictemplate <class S, class T> 3780b57cec5SDimitry Andricclass const_mem_fun_ref_t : public unary_function<T, S> // deprecated in C++11, removed in C++17 3790b57cec5SDimitry Andric{ 3800b57cec5SDimitry Andricpublic: 3810b57cec5SDimitry Andric explicit const_mem_fun_ref_t(S (T::*p)() const); 3820b57cec5SDimitry Andric S operator()(const T& p) const; 3830b57cec5SDimitry Andric}; 3840b57cec5SDimitry Andric 3850b57cec5SDimitry Andrictemplate <class S, class T, class A> 3860b57cec5SDimitry Andricclass const_mem_fun1_ref_t : public binary_function<T, A, S> // deprecated in C++11, removed in C++17 3870b57cec5SDimitry Andric{ 3880b57cec5SDimitry Andricpublic: 3890b57cec5SDimitry Andric explicit const_mem_fun1_ref_t(S (T::*p)(A) const); 3900b57cec5SDimitry Andric S operator()(const T& p, A x) const; 3910b57cec5SDimitry Andric}; 3920b57cec5SDimitry Andric 39306c3fb27SDimitry Andrictemplate <class S, class T> 39406c3fb27SDimitry Andricconst_mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)() const); // deprecated in C++11, removed in C++17 39506c3fb27SDimitry Andrictemplate <class S, class T, class A> 39606c3fb27SDimitry Andricconst_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const); // deprecated in C++11, removed in C++17 3970b57cec5SDimitry Andric 39806c3fb27SDimitry Andrictemplate<class R, class T> constexpr unspecified mem_fn(R T::*); // constexpr in C++20 3990b57cec5SDimitry Andric 4000b57cec5SDimitry Andricclass bad_function_call 4010b57cec5SDimitry Andric : public exception 4020b57cec5SDimitry Andric{ 4030b57cec5SDimitry Andric}; 4040b57cec5SDimitry Andric 4050b57cec5SDimitry Andrictemplate<class> class function; // undefined 4060b57cec5SDimitry Andric 4070b57cec5SDimitry Andrictemplate<class R, class... ArgTypes> 4080b57cec5SDimitry Andricclass function<R(ArgTypes...)> 4090b57cec5SDimitry Andric : public unary_function<T1, R> // iff sizeof...(ArgTypes) == 1 and 4100b57cec5SDimitry Andric // ArgTypes contains T1 4110b57cec5SDimitry Andric : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and 4120b57cec5SDimitry Andric // ArgTypes contains T1 and T2 4130b57cec5SDimitry Andric{ 4140b57cec5SDimitry Andricpublic: 4150b57cec5SDimitry Andric typedef R result_type; 4160b57cec5SDimitry Andric 4170b57cec5SDimitry Andric // construct/copy/destroy: 4180b57cec5SDimitry Andric function() noexcept; 4190b57cec5SDimitry Andric function(nullptr_t) noexcept; 4200b57cec5SDimitry Andric function(const function&); 4210b57cec5SDimitry Andric function(function&&) noexcept; 4220b57cec5SDimitry Andric template<class F> 4230b57cec5SDimitry Andric function(F); 4240b57cec5SDimitry Andric template<Allocator Alloc> 4250b57cec5SDimitry Andric function(allocator_arg_t, const Alloc&) noexcept; // removed in C++17 4260b57cec5SDimitry Andric template<Allocator Alloc> 4270b57cec5SDimitry Andric function(allocator_arg_t, const Alloc&, nullptr_t) noexcept; // removed in C++17 4280b57cec5SDimitry Andric template<Allocator Alloc> 4290b57cec5SDimitry Andric function(allocator_arg_t, const Alloc&, const function&); // removed in C++17 4300b57cec5SDimitry Andric template<Allocator Alloc> 4310b57cec5SDimitry Andric function(allocator_arg_t, const Alloc&, function&&); // removed in C++17 4320b57cec5SDimitry Andric template<class F, Allocator Alloc> 4330b57cec5SDimitry Andric function(allocator_arg_t, const Alloc&, F); // removed in C++17 4340b57cec5SDimitry Andric 4350b57cec5SDimitry Andric function& operator=(const function&); 4360b57cec5SDimitry Andric function& operator=(function&&) noexcept; 4370b57cec5SDimitry Andric function& operator=(nullptr_t) noexcept; 4380b57cec5SDimitry Andric template<class F> 4390b57cec5SDimitry Andric function& operator=(F&&); 4400b57cec5SDimitry Andric template<class F> 4410b57cec5SDimitry Andric function& operator=(reference_wrapper<F>) noexcept; 4420b57cec5SDimitry Andric 4430b57cec5SDimitry Andric ~function(); 4440b57cec5SDimitry Andric 4450b57cec5SDimitry Andric // function modifiers: 4460b57cec5SDimitry Andric void swap(function&) noexcept; 4470b57cec5SDimitry Andric template<class F, class Alloc> 4480b57cec5SDimitry Andric void assign(F&&, const Alloc&); // Removed in C++17 4490b57cec5SDimitry Andric 4500b57cec5SDimitry Andric // function capacity: 4510b57cec5SDimitry Andric explicit operator bool() const noexcept; 4520b57cec5SDimitry Andric 4530b57cec5SDimitry Andric // function invocation: 4540b57cec5SDimitry Andric R operator()(ArgTypes...) const; 4550b57cec5SDimitry Andric 4560b57cec5SDimitry Andric // function target access: 4570b57cec5SDimitry Andric const std::type_info& target_type() const noexcept; 4580b57cec5SDimitry Andric template <typename T> T* target() noexcept; 4590b57cec5SDimitry Andric template <typename T> const T* target() const noexcept; 4600b57cec5SDimitry Andric}; 4610b57cec5SDimitry Andric 462e40139ffSDimitry Andric// Deduction guides 463e40139ffSDimitry Andrictemplate<class R, class ...Args> 464e40139ffSDimitry Andricfunction(R(*)(Args...)) -> function<R(Args...)>; // since C++17 465e40139ffSDimitry Andric 466e40139ffSDimitry Andrictemplate<class F> 467e40139ffSDimitry Andricfunction(F) -> function<see-below>; // since C++17 468e40139ffSDimitry Andric 4690b57cec5SDimitry Andric// Null pointer comparisons: 4700b57cec5SDimitry Andrictemplate <class R, class ... ArgTypes> 4710b57cec5SDimitry Andric bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept; 4720b57cec5SDimitry Andric 4730b57cec5SDimitry Andrictemplate <class R, class ... ArgTypes> 47406c3fb27SDimitry Andric bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept; // removed in C++20 4750b57cec5SDimitry Andric 4760b57cec5SDimitry Andrictemplate <class R, class ... ArgTypes> 47706c3fb27SDimitry Andric bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept; // removed in C++20 4780b57cec5SDimitry Andric 4790b57cec5SDimitry Andrictemplate <class R, class ... ArgTypes> 48006c3fb27SDimitry Andric bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept; // removed in C++20 4810b57cec5SDimitry Andric 4820b57cec5SDimitry Andric// specialized algorithms: 4830b57cec5SDimitry Andrictemplate <class R, class ... ArgTypes> 4840b57cec5SDimitry Andric void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept; 4850b57cec5SDimitry Andric 4860b57cec5SDimitry Andrictemplate <class T> struct hash; 4870b57cec5SDimitry Andric 4880b57cec5SDimitry Andrictemplate <> struct hash<bool>; 4890b57cec5SDimitry Andrictemplate <> struct hash<char>; 4900b57cec5SDimitry Andrictemplate <> struct hash<signed char>; 4910b57cec5SDimitry Andrictemplate <> struct hash<unsigned char>; 492e8d8bef9SDimitry Andrictemplate <> struct hash<char8_t>; // since C++20 4930b57cec5SDimitry Andrictemplate <> struct hash<char16_t>; 4940b57cec5SDimitry Andrictemplate <> struct hash<char32_t>; 4950b57cec5SDimitry Andrictemplate <> struct hash<wchar_t>; 4960b57cec5SDimitry Andrictemplate <> struct hash<short>; 4970b57cec5SDimitry Andrictemplate <> struct hash<unsigned short>; 4980b57cec5SDimitry Andrictemplate <> struct hash<int>; 4990b57cec5SDimitry Andrictemplate <> struct hash<unsigned int>; 5000b57cec5SDimitry Andrictemplate <> struct hash<long>; 5010b57cec5SDimitry Andrictemplate <> struct hash<long long>; 5020b57cec5SDimitry Andrictemplate <> struct hash<unsigned long>; 5030b57cec5SDimitry Andrictemplate <> struct hash<unsigned long long>; 5040b57cec5SDimitry Andric 5050b57cec5SDimitry Andrictemplate <> struct hash<float>; 5060b57cec5SDimitry Andrictemplate <> struct hash<double>; 5070b57cec5SDimitry Andrictemplate <> struct hash<long double>; 5080b57cec5SDimitry Andric 5090b57cec5SDimitry Andrictemplate<class T> struct hash<T*>; 5100b57cec5SDimitry Andrictemplate <> struct hash<nullptr_t>; // C++17 5110b57cec5SDimitry Andric 51281ad6265SDimitry Andricnamespace ranges { 51381ad6265SDimitry Andric // [range.cmp], concept-constrained comparisons 51481ad6265SDimitry Andric struct equal_to; 51581ad6265SDimitry Andric struct not_equal_to; 51681ad6265SDimitry Andric struct greater; 51781ad6265SDimitry Andric struct less; 51881ad6265SDimitry Andric struct greater_equal; 51981ad6265SDimitry Andric struct less_equal; 52081ad6265SDimitry Andric} 52181ad6265SDimitry Andric 5220b57cec5SDimitry Andric} // std 5230b57cec5SDimitry Andric 5240b57cec5SDimitry AndricPOLICY: For non-variadic implementations, the number of arguments is limited 5250b57cec5SDimitry Andric to 3. It is hoped that the need for non-variadic implementations 5260b57cec5SDimitry Andric will be minimal. 5270b57cec5SDimitry Andric 5280b57cec5SDimitry Andric*/ 5290b57cec5SDimitry Andric 5300b57cec5SDimitry Andric#include <__config> 531*0fca6ea1SDimitry Andric 53206c3fb27SDimitry Andric#include <__functional/binary_function.h> 533fe6060f1SDimitry Andric#include <__functional/binary_negate.h> 53404eeddc0SDimitry Andric#include <__functional/bind.h> 535fe6060f1SDimitry Andric#include <__functional/binder1st.h> 536fe6060f1SDimitry Andric#include <__functional/binder2nd.h> 537fe6060f1SDimitry Andric#include <__functional/hash.h> 538fe6060f1SDimitry Andric#include <__functional/mem_fn.h> // TODO: deprecate 539fe6060f1SDimitry Andric#include <__functional/mem_fun_ref.h> 540fe6060f1SDimitry Andric#include <__functional/operations.h> 541fe6060f1SDimitry Andric#include <__functional/pointer_to_binary_function.h> 542fe6060f1SDimitry Andric#include <__functional/pointer_to_unary_function.h> 543fe6060f1SDimitry Andric#include <__functional/reference_wrapper.h> 54406c3fb27SDimitry Andric#include <__functional/unary_function.h> 545fe6060f1SDimitry Andric#include <__functional/unary_negate.h> 546*0fca6ea1SDimitry Andric 547*0fca6ea1SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 548*0fca6ea1SDimitry Andric# include <__functional/function.h> 549*0fca6ea1SDimitry Andric#endif 550*0fca6ea1SDimitry Andric 551*0fca6ea1SDimitry Andric#if _LIBCPP_STD_VER >= 17 552*0fca6ea1SDimitry Andric# include <__functional/boyer_moore_searcher.h> 553*0fca6ea1SDimitry Andric# include <__functional/default_searcher.h> 554*0fca6ea1SDimitry Andric# include <__functional/invoke.h> 555*0fca6ea1SDimitry Andric# include <__functional/not_fn.h> 556*0fca6ea1SDimitry Andric#endif 557*0fca6ea1SDimitry Andric 558*0fca6ea1SDimitry Andric#if _LIBCPP_STD_VER >= 20 559*0fca6ea1SDimitry Andric# include <__functional/bind_back.h> 560*0fca6ea1SDimitry Andric# include <__functional/bind_front.h> 561*0fca6ea1SDimitry Andric# include <__functional/identity.h> 562*0fca6ea1SDimitry Andric# include <__functional/ranges_operations.h> 56306c3fb27SDimitry Andric# include <__type_traits/unwrap_ref.h> 564*0fca6ea1SDimitry Andric#endif 565*0fca6ea1SDimitry Andric 5660b57cec5SDimitry Andric#include <version> 5670b57cec5SDimitry Andric 5680b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 5690b57cec5SDimitry Andric# pragma GCC system_header 5700b57cec5SDimitry Andric#endif 5710b57cec5SDimitry Andric 572*0fca6ea1SDimitry Andric#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && defined(_LIBCPP_CXX03_LANG) 573*0fca6ea1SDimitry Andric# include <limits> 574*0fca6ea1SDimitry Andric# include <new> 575*0fca6ea1SDimitry Andric#endif 576*0fca6ea1SDimitry Andric 577*0fca6ea1SDimitry Andric#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 14 578*0fca6ea1SDimitry Andric# include <array> 579*0fca6ea1SDimitry Andric# include <initializer_list> 580*0fca6ea1SDimitry Andric# include <unordered_map> 581*0fca6ea1SDimitry Andric# include <vector> 582*0fca6ea1SDimitry Andric#endif 583*0fca6ea1SDimitry Andric 584bdd1243dSDimitry Andric#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 58506c3fb27SDimitry Andric# include <atomic> 586bdd1243dSDimitry Andric# include <concepts> 58706c3fb27SDimitry Andric# include <cstdlib> 58806c3fb27SDimitry Andric# include <exception> 5895f757f3fSDimitry Andric# include <iosfwd> 5905f757f3fSDimitry Andric# include <memory> 5915f757f3fSDimitry Andric# include <stdexcept> 592bdd1243dSDimitry Andric# include <tuple> 59306c3fb27SDimitry Andric# include <type_traits> 5945f757f3fSDimitry Andric# include <typeinfo> 595bdd1243dSDimitry Andric# include <utility> 596bdd1243dSDimitry Andric#endif 597bdd1243dSDimitry Andric 5980b57cec5SDimitry Andric#endif // _LIBCPP_FUNCTIONAL 599