xref: /freebsd/contrib/llvm-project/libcxx/include/functional (revision bdd1243df58e60e85101c09001d9812a789b6bc4)
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
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
45fe6060f1SDimitry Andric    template<class U>
46fe6060f1SDimitry 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
62fe6060f1SDimitry Andrictemplate <class T>
63fe6060f1SDimitry Andric  reference_wrapper(T&) -> reference_wrapper<T>;
64fe6060f1SDimitry 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
79fe6060f1SDimitry 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
84fe6060f1SDimitry 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
89fe6060f1SDimitry 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
94fe6060f1SDimitry 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
99fe6060f1SDimitry 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
104fe6060f1SDimitry Andricstruct negate {
1050b57cec5SDimitry Andric    T operator()(const T& x) const;
1060b57cec5SDimitry Andric};
1070b57cec5SDimitry Andric
1080b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14
109fe6060f1SDimitry 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
114fe6060f1SDimitry 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
119fe6060f1SDimitry 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
124fe6060f1SDimitry 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
129fe6060f1SDimitry 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
134fe6060f1SDimitry Andricstruct less_equal {
1350b57cec5SDimitry Andric    bool operator()(const T& x, const T& y) const;
1360b57cec5SDimitry Andric};
1370b57cec5SDimitry Andric
138349cc55cSDimitry Andric// [comparisons.three.way], class compare_three_way
139349cc55cSDimitry Andricstruct compare_three_way;
140349cc55cSDimitry Andric
1410b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14
142fe6060f1SDimitry Andricstruct logical_and {
1430b57cec5SDimitry Andric    bool operator()(const T& x, const T& y) const;
1440b57cec5SDimitry Andric};
1450b57cec5SDimitry Andric
1460b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14
147fe6060f1SDimitry Andricstruct logical_or {
1480b57cec5SDimitry Andric    bool operator()(const T& x, const T& y) const;
1490b57cec5SDimitry Andric};
1500b57cec5SDimitry Andric
1510b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14
152fe6060f1SDimitry Andricstruct logical_not {
1530b57cec5SDimitry Andric    bool operator()(const T& x) const;
1540b57cec5SDimitry Andric};
1550b57cec5SDimitry Andric
1560b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14
157fe6060f1SDimitry Andricstruct bit_and {
158fe6060f1SDimitry Andric    T operator()(const T& x, const T& y) const;
1590b57cec5SDimitry Andric};
1600b57cec5SDimitry Andric
1610b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14
162fe6060f1SDimitry Andricstruct bit_or {
163fe6060f1SDimitry Andric    T operator()(const T& x, const T& y) const;
1640b57cec5SDimitry Andric};
1650b57cec5SDimitry Andric
1660b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14
167fe6060f1SDimitry Andricstruct bit_xor {
168fe6060f1SDimitry Andric    T operator()(const T& x, const T& y) const;
1690b57cec5SDimitry Andric};
1700b57cec5SDimitry Andric
1710b57cec5SDimitry Andrictemplate <class T=void> // C++14
172fe6060f1SDimitry Andricstruct bit_not {
173fe6060f1SDimitry Andric    T operator()(const T& x) const;
1740b57cec5SDimitry Andric};
1750b57cec5SDimitry Andric
176fe6060f1SDimitry Andricstruct identity; // C++20
177fe6060f1SDimitry Andric
1780b57cec5SDimitry Andrictemplate <class Predicate>
179fe6060f1SDimitry Andricclass unary_negate // deprecated in C++17, removed in C++20
1800b57cec5SDimitry Andric    : public unary_function<typename Predicate::argument_type, bool>
1810b57cec5SDimitry Andric{
1820b57cec5SDimitry Andricpublic:
1830b57cec5SDimitry Andric    explicit unary_negate(const Predicate& pred);
1840b57cec5SDimitry Andric    bool operator()(const typename Predicate::argument_type& x) const;
1850b57cec5SDimitry Andric};
1860b57cec5SDimitry Andric
187fe6060f1SDimitry Andrictemplate <class Predicate> // deprecated in C++17, removed in C++20
1880b57cec5SDimitry Andricunary_negate<Predicate> not1(const Predicate& pred);
1890b57cec5SDimitry Andric
1900b57cec5SDimitry Andrictemplate <class Predicate>
191fe6060f1SDimitry Andricclass binary_negate // deprecated in C++17, removed in C++20
1920b57cec5SDimitry Andric    : public binary_function<typename Predicate::first_argument_type,
1930b57cec5SDimitry Andric                             typename Predicate::second_argument_type,
1940b57cec5SDimitry Andric                             bool>
1950b57cec5SDimitry Andric{
1960b57cec5SDimitry Andricpublic:
1970b57cec5SDimitry Andric    explicit binary_negate(const Predicate& pred);
1980b57cec5SDimitry Andric    bool operator()(const typename Predicate::first_argument_type& x,
1990b57cec5SDimitry Andric                    const typename Predicate::second_argument_type& y) const;
2000b57cec5SDimitry Andric};
2010b57cec5SDimitry Andric
202fe6060f1SDimitry Andrictemplate <class Predicate> // deprecated in C++17, removed in C++20
2030b57cec5SDimitry Andricbinary_negate<Predicate> not2(const Predicate& pred);
2040b57cec5SDimitry Andric
205e8d8bef9SDimitry Andrictemplate <class F>
206e8d8bef9SDimitry Andricconstexpr unspecified not_fn(F&& f); // C++17, constexpr in C++20
2070b57cec5SDimitry Andric
2080b57cec5SDimitry Andrictemplate<class T> struct is_bind_expression;
2090b57cec5SDimitry Andrictemplate<class T> struct is_placeholder;
2100b57cec5SDimitry Andric
2110b57cec5SDimitry Andric    // See C++14 20.9.9, Function object binders
2120b57cec5SDimitry Andrictemplate <class T> inline constexpr bool is_bind_expression_v
2130b57cec5SDimitry Andric  = is_bind_expression<T>::value; // C++17
2140b57cec5SDimitry Andrictemplate <class T> inline constexpr int is_placeholder_v
2150b57cec5SDimitry Andric  = is_placeholder<T>::value; // C++17
2160b57cec5SDimitry Andric
2170b57cec5SDimitry Andric
2180b57cec5SDimitry Andrictemplate<class Fn, class... BoundArgs>
219e8d8bef9SDimitry Andric  constexpr unspecified bind(Fn&&, BoundArgs&&...);  // constexpr in C++20
2200b57cec5SDimitry Andrictemplate<class R, class Fn, class... BoundArgs>
221e8d8bef9SDimitry Andric  constexpr unspecified bind(Fn&&, BoundArgs&&...);  // constexpr in C++20
2220b57cec5SDimitry Andric
2230b57cec5SDimitry Andrictemplate<class F, class... Args>
224e8d8bef9SDimitry Andric constexpr // constexpr in C++20
2250b57cec5SDimitry Andric invoke_result_t<F, Args...> invoke(F&& f, Args&&... args) // C++17
2260b57cec5SDimitry Andric    noexcept(is_nothrow_invocable_v<F, Args...>);
2270b57cec5SDimitry Andric
2280b57cec5SDimitry Andricnamespace placeholders {
2290b57cec5SDimitry Andric  // M is the implementation-defined number of placeholders
2300b57cec5SDimitry Andric  extern unspecified _1;
2310b57cec5SDimitry Andric  extern unspecified _2;
2320b57cec5SDimitry Andric  .
2330b57cec5SDimitry Andric  .
2340b57cec5SDimitry Andric  .
2350b57cec5SDimitry Andric  extern unspecified _Mp;
2360b57cec5SDimitry Andric}
2370b57cec5SDimitry Andric
2380b57cec5SDimitry Andrictemplate <class Operation>
2390b57cec5SDimitry Andricclass binder1st     // deprecated in C++11, removed in C++17
2400b57cec5SDimitry Andric    : public unary_function<typename Operation::second_argument_type,
2410b57cec5SDimitry Andric                            typename Operation::result_type>
2420b57cec5SDimitry Andric{
2430b57cec5SDimitry Andricprotected:
2440b57cec5SDimitry Andric    Operation                               op;
2450b57cec5SDimitry Andric    typename Operation::first_argument_type value;
2460b57cec5SDimitry Andricpublic:
2470b57cec5SDimitry Andric    binder1st(const Operation& x, const typename Operation::first_argument_type y);
2480b57cec5SDimitry Andric    typename Operation::result_type operator()(      typename Operation::second_argument_type& x) const;
2490b57cec5SDimitry Andric    typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const;
2500b57cec5SDimitry Andric};
2510b57cec5SDimitry Andric
2520b57cec5SDimitry Andrictemplate <class Operation, class T>
2530b57cec5SDimitry Andricbinder1st<Operation> bind1st(const Operation& op, const T& x);  // deprecated in C++11, removed in C++17
2540b57cec5SDimitry Andric
2550b57cec5SDimitry Andrictemplate <class Operation>
2560b57cec5SDimitry Andricclass binder2nd     // deprecated in C++11, removed in C++17
2570b57cec5SDimitry Andric    : public unary_function<typename Operation::first_argument_type,
2580b57cec5SDimitry Andric                            typename Operation::result_type>
2590b57cec5SDimitry Andric{
2600b57cec5SDimitry Andricprotected:
2610b57cec5SDimitry Andric    Operation                                op;
2620b57cec5SDimitry Andric    typename Operation::second_argument_type value;
2630b57cec5SDimitry Andricpublic:
2640b57cec5SDimitry Andric    binder2nd(const Operation& x, const typename Operation::second_argument_type y);
2650b57cec5SDimitry Andric    typename Operation::result_type operator()(      typename Operation::first_argument_type& x) const;
2660b57cec5SDimitry Andric    typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const;
2670b57cec5SDimitry Andric};
2680b57cec5SDimitry Andric
2690b57cec5SDimitry Andrictemplate <class Operation, class T>
2700b57cec5SDimitry Andricbinder2nd<Operation> bind2nd(const Operation& op, const T& x);  // deprecated in C++11, removed in C++17
2710b57cec5SDimitry Andric
2720b57cec5SDimitry Andrictemplate <class Arg, class Result>      // deprecated in C++11, removed in C++17
2730b57cec5SDimitry Andricclass pointer_to_unary_function : public unary_function<Arg, Result>
2740b57cec5SDimitry Andric{
2750b57cec5SDimitry Andricpublic:
2760b57cec5SDimitry Andric    explicit pointer_to_unary_function(Result (*f)(Arg));
2770b57cec5SDimitry Andric    Result operator()(Arg x) const;
2780b57cec5SDimitry Andric};
2790b57cec5SDimitry Andric
2800b57cec5SDimitry Andrictemplate <class Arg, class Result>
2810b57cec5SDimitry Andricpointer_to_unary_function<Arg,Result> ptr_fun(Result (*f)(Arg));      // deprecated in C++11, removed in C++17
2820b57cec5SDimitry Andric
2830b57cec5SDimitry Andrictemplate <class Arg1, class Arg2, class Result>      // deprecated in C++11, removed in C++17
2840b57cec5SDimitry Andricclass pointer_to_binary_function : public binary_function<Arg1, Arg2, Result>
2850b57cec5SDimitry Andric{
2860b57cec5SDimitry Andricpublic:
2870b57cec5SDimitry Andric    explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2));
2880b57cec5SDimitry Andric    Result operator()(Arg1 x, Arg2 y) const;
2890b57cec5SDimitry Andric};
2900b57cec5SDimitry Andric
2910b57cec5SDimitry Andrictemplate <class Arg1, class Arg2, class Result>
2920b57cec5SDimitry Andricpointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1,Arg2));      // deprecated in C++11, removed in C++17
2930b57cec5SDimitry Andric
2940b57cec5SDimitry Andrictemplate<class S, class T>      // deprecated in C++11, removed in C++17
2950b57cec5SDimitry Andricclass mem_fun_t : public unary_function<T*, S>
2960b57cec5SDimitry Andric{
2970b57cec5SDimitry Andricpublic:
2980b57cec5SDimitry Andric    explicit mem_fun_t(S (T::*p)());
2990b57cec5SDimitry Andric    S operator()(T* p) const;
3000b57cec5SDimitry Andric};
3010b57cec5SDimitry Andric
3020b57cec5SDimitry Andrictemplate<class S, class T, class A>
3030b57cec5SDimitry Andricclass mem_fun1_t : public binary_function<T*, A, S>      // deprecated in C++11, removed in C++17
3040b57cec5SDimitry Andric{
3050b57cec5SDimitry Andricpublic:
3060b57cec5SDimitry Andric    explicit mem_fun1_t(S (T::*p)(A));
3070b57cec5SDimitry Andric    S operator()(T* p, A x) const;
3080b57cec5SDimitry Andric};
3090b57cec5SDimitry Andric
3100b57cec5SDimitry Andrictemplate<class S, class T>          mem_fun_t<S,T>    mem_fun(S (T::*f)());      // deprecated in C++11, removed in C++17
3110b57cec5SDimitry 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
3120b57cec5SDimitry Andric
3130b57cec5SDimitry Andrictemplate<class S, class T>
3140b57cec5SDimitry Andricclass mem_fun_ref_t : public unary_function<T, S>      // deprecated in C++11, removed in C++17
3150b57cec5SDimitry Andric{
3160b57cec5SDimitry Andricpublic:
3170b57cec5SDimitry Andric    explicit mem_fun_ref_t(S (T::*p)());
3180b57cec5SDimitry Andric    S operator()(T& p) const;
3190b57cec5SDimitry Andric};
3200b57cec5SDimitry Andric
3210b57cec5SDimitry Andrictemplate<class S, class T, class A>
3220b57cec5SDimitry Andricclass mem_fun1_ref_t : public binary_function<T, A, S>      // deprecated in C++11, removed in C++17
3230b57cec5SDimitry Andric{
3240b57cec5SDimitry Andricpublic:
3250b57cec5SDimitry Andric    explicit mem_fun1_ref_t(S (T::*p)(A));
3260b57cec5SDimitry Andric    S operator()(T& p, A x) const;
3270b57cec5SDimitry Andric};
3280b57cec5SDimitry Andric
3290b57cec5SDimitry 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
3300b57cec5SDimitry 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
3310b57cec5SDimitry Andric
3320b57cec5SDimitry Andrictemplate <class S, class T>
3330b57cec5SDimitry Andricclass const_mem_fun_t : public unary_function<const T*, S>      // deprecated in C++11, removed in C++17
3340b57cec5SDimitry Andric{
3350b57cec5SDimitry Andricpublic:
3360b57cec5SDimitry Andric    explicit const_mem_fun_t(S (T::*p)() const);
3370b57cec5SDimitry Andric    S operator()(const T* p) const;
3380b57cec5SDimitry Andric};
3390b57cec5SDimitry Andric
3400b57cec5SDimitry Andrictemplate <class S, class T, class A>
3410b57cec5SDimitry Andricclass const_mem_fun1_t : public binary_function<const T*, A, S>      // deprecated in C++11, removed in C++17
3420b57cec5SDimitry Andric{
3430b57cec5SDimitry Andricpublic:
3440b57cec5SDimitry Andric    explicit const_mem_fun1_t(S (T::*p)(A) const);
3450b57cec5SDimitry Andric    S operator()(const T* p, A x) const;
3460b57cec5SDimitry Andric};
3470b57cec5SDimitry Andric
3480b57cec5SDimitry 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
3490b57cec5SDimitry 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
3500b57cec5SDimitry Andric
3510b57cec5SDimitry Andrictemplate <class S, class T>
3520b57cec5SDimitry Andricclass const_mem_fun_ref_t : public unary_function<T, S>      // deprecated in C++11, removed in C++17
3530b57cec5SDimitry Andric{
3540b57cec5SDimitry Andricpublic:
3550b57cec5SDimitry Andric    explicit const_mem_fun_ref_t(S (T::*p)() const);
3560b57cec5SDimitry Andric    S operator()(const T& p) const;
3570b57cec5SDimitry Andric};
3580b57cec5SDimitry Andric
3590b57cec5SDimitry Andrictemplate <class S, class T, class A>
3600b57cec5SDimitry Andricclass const_mem_fun1_ref_t : public binary_function<T, A, S>      // deprecated in C++11, removed in C++17
3610b57cec5SDimitry Andric{
3620b57cec5SDimitry Andricpublic:
3630b57cec5SDimitry Andric    explicit const_mem_fun1_ref_t(S (T::*p)(A) const);
3640b57cec5SDimitry Andric    S operator()(const T& p, A x) const;
3650b57cec5SDimitry Andric};
3660b57cec5SDimitry Andric
3670b57cec5SDimitry 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
3680b57cec5SDimitry 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
3690b57cec5SDimitry Andric
370e8d8bef9SDimitry Andrictemplate<class R, class T>
371e8d8bef9SDimitry Andricconstexpr unspecified mem_fn(R T::*); // constexpr in C++20
3720b57cec5SDimitry Andric
3730b57cec5SDimitry Andricclass bad_function_call
3740b57cec5SDimitry Andric    : public exception
3750b57cec5SDimitry Andric{
3760b57cec5SDimitry Andric};
3770b57cec5SDimitry Andric
3780b57cec5SDimitry Andrictemplate<class> class function; // undefined
3790b57cec5SDimitry Andric
3800b57cec5SDimitry Andrictemplate<class R, class... ArgTypes>
3810b57cec5SDimitry Andricclass function<R(ArgTypes...)>
3820b57cec5SDimitry Andric  : public unary_function<T1, R>      // iff sizeof...(ArgTypes) == 1 and
3830b57cec5SDimitry Andric                                      // ArgTypes contains T1
3840b57cec5SDimitry Andric  : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and
3850b57cec5SDimitry Andric                                      // ArgTypes contains T1 and T2
3860b57cec5SDimitry Andric{
3870b57cec5SDimitry Andricpublic:
3880b57cec5SDimitry Andric    typedef R result_type;
3890b57cec5SDimitry Andric
3900b57cec5SDimitry Andric    // construct/copy/destroy:
3910b57cec5SDimitry Andric    function() noexcept;
3920b57cec5SDimitry Andric    function(nullptr_t) noexcept;
3930b57cec5SDimitry Andric    function(const function&);
3940b57cec5SDimitry Andric    function(function&&) noexcept;
3950b57cec5SDimitry Andric    template<class F>
3960b57cec5SDimitry Andric      function(F);
3970b57cec5SDimitry Andric    template<Allocator Alloc>
3980b57cec5SDimitry Andric      function(allocator_arg_t, const Alloc&) noexcept;            // removed in C++17
3990b57cec5SDimitry Andric    template<Allocator Alloc>
4000b57cec5SDimitry Andric      function(allocator_arg_t, const Alloc&, nullptr_t) noexcept; // removed in C++17
4010b57cec5SDimitry Andric    template<Allocator Alloc>
4020b57cec5SDimitry Andric      function(allocator_arg_t, const Alloc&, const function&);    // removed in C++17
4030b57cec5SDimitry Andric    template<Allocator Alloc>
4040b57cec5SDimitry Andric      function(allocator_arg_t, const Alloc&, function&&);         // removed in C++17
4050b57cec5SDimitry Andric    template<class F, Allocator Alloc>
4060b57cec5SDimitry Andric      function(allocator_arg_t, const Alloc&, F);                  // removed in C++17
4070b57cec5SDimitry Andric
4080b57cec5SDimitry Andric    function& operator=(const function&);
4090b57cec5SDimitry Andric    function& operator=(function&&) noexcept;
4100b57cec5SDimitry Andric    function& operator=(nullptr_t) noexcept;
4110b57cec5SDimitry Andric    template<class F>
4120b57cec5SDimitry Andric      function& operator=(F&&);
4130b57cec5SDimitry Andric    template<class F>
4140b57cec5SDimitry Andric      function& operator=(reference_wrapper<F>) noexcept;
4150b57cec5SDimitry Andric
4160b57cec5SDimitry Andric    ~function();
4170b57cec5SDimitry Andric
4180b57cec5SDimitry Andric    // function modifiers:
4190b57cec5SDimitry Andric    void swap(function&) noexcept;
4200b57cec5SDimitry Andric    template<class F, class Alloc>
4210b57cec5SDimitry Andric      void assign(F&&, const Alloc&);                 // Removed in C++17
4220b57cec5SDimitry Andric
4230b57cec5SDimitry Andric    // function capacity:
4240b57cec5SDimitry Andric    explicit operator bool() const noexcept;
4250b57cec5SDimitry Andric
4260b57cec5SDimitry Andric    // function invocation:
4270b57cec5SDimitry Andric    R operator()(ArgTypes...) const;
4280b57cec5SDimitry Andric
4290b57cec5SDimitry Andric    // function target access:
4300b57cec5SDimitry Andric    const std::type_info& target_type() const noexcept;
4310b57cec5SDimitry Andric    template <typename T>       T* target() noexcept;
4320b57cec5SDimitry Andric    template <typename T> const T* target() const noexcept;
4330b57cec5SDimitry Andric};
4340b57cec5SDimitry Andric
435e40139ffSDimitry Andric// Deduction guides
436e40139ffSDimitry Andrictemplate<class R, class ...Args>
437e40139ffSDimitry Andricfunction(R(*)(Args...)) -> function<R(Args...)>; // since C++17
438e40139ffSDimitry Andric
439e40139ffSDimitry Andrictemplate<class F>
440e40139ffSDimitry Andricfunction(F) -> function<see-below>; // since C++17
441e40139ffSDimitry Andric
4420b57cec5SDimitry Andric// Null pointer comparisons:
4430b57cec5SDimitry Andrictemplate <class R, class ... ArgTypes>
4440b57cec5SDimitry Andric  bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
4450b57cec5SDimitry Andric
4460b57cec5SDimitry Andrictemplate <class R, class ... ArgTypes>
4470b57cec5SDimitry Andric  bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
4480b57cec5SDimitry Andric
4490b57cec5SDimitry Andrictemplate <class R, class ... ArgTypes>
4500b57cec5SDimitry Andric  bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
4510b57cec5SDimitry Andric
4520b57cec5SDimitry Andrictemplate <class  R, class ... ArgTypes>
4530b57cec5SDimitry Andric  bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
4540b57cec5SDimitry Andric
4550b57cec5SDimitry Andric// specialized algorithms:
4560b57cec5SDimitry Andrictemplate <class  R, class ... ArgTypes>
4570b57cec5SDimitry Andric  void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
4580b57cec5SDimitry Andric
4590b57cec5SDimitry Andrictemplate <class T> struct hash;
4600b57cec5SDimitry Andric
4610b57cec5SDimitry Andrictemplate <> struct hash<bool>;
4620b57cec5SDimitry Andrictemplate <> struct hash<char>;
4630b57cec5SDimitry Andrictemplate <> struct hash<signed char>;
4640b57cec5SDimitry Andrictemplate <> struct hash<unsigned char>;
465e8d8bef9SDimitry Andrictemplate <> struct hash<char8_t>; // since C++20
4660b57cec5SDimitry Andrictemplate <> struct hash<char16_t>;
4670b57cec5SDimitry Andrictemplate <> struct hash<char32_t>;
4680b57cec5SDimitry Andrictemplate <> struct hash<wchar_t>;
4690b57cec5SDimitry Andrictemplate <> struct hash<short>;
4700b57cec5SDimitry Andrictemplate <> struct hash<unsigned short>;
4710b57cec5SDimitry Andrictemplate <> struct hash<int>;
4720b57cec5SDimitry Andrictemplate <> struct hash<unsigned int>;
4730b57cec5SDimitry Andrictemplate <> struct hash<long>;
4740b57cec5SDimitry Andrictemplate <> struct hash<long long>;
4750b57cec5SDimitry Andrictemplate <> struct hash<unsigned long>;
4760b57cec5SDimitry Andrictemplate <> struct hash<unsigned long long>;
4770b57cec5SDimitry Andric
4780b57cec5SDimitry Andrictemplate <> struct hash<float>;
4790b57cec5SDimitry Andrictemplate <> struct hash<double>;
4800b57cec5SDimitry Andrictemplate <> struct hash<long double>;
4810b57cec5SDimitry Andric
4820b57cec5SDimitry Andrictemplate<class T> struct hash<T*>;
4830b57cec5SDimitry Andrictemplate <> struct hash<nullptr_t>;  // C++17
4840b57cec5SDimitry Andric
48581ad6265SDimitry Andricnamespace ranges {
48681ad6265SDimitry Andric  // [range.cmp], concept-constrained comparisons
48781ad6265SDimitry Andric  struct equal_to;
48881ad6265SDimitry Andric  struct not_equal_to;
48981ad6265SDimitry Andric  struct greater;
49081ad6265SDimitry Andric  struct less;
49181ad6265SDimitry Andric  struct greater_equal;
49281ad6265SDimitry Andric  struct less_equal;
49381ad6265SDimitry Andric}
49481ad6265SDimitry Andric
4950b57cec5SDimitry Andric}  // std
4960b57cec5SDimitry Andric
4970b57cec5SDimitry AndricPOLICY:  For non-variadic implementations, the number of arguments is limited
4980b57cec5SDimitry Andric         to 3.  It is hoped that the need for non-variadic implementations
4990b57cec5SDimitry Andric         will be minimal.
5000b57cec5SDimitry Andric
5010b57cec5SDimitry Andric*/
5020b57cec5SDimitry Andric
503fe6060f1SDimitry Andric#include <__algorithm/search.h>
50481ad6265SDimitry Andric#include <__assert> // all public C++ headers provide the assertion handler
505349cc55cSDimitry Andric#include <__compare/compare_three_way.h>
5060b57cec5SDimitry Andric#include <__config>
507fe6060f1SDimitry Andric#include <__debug>
508fe6060f1SDimitry Andric#include <__functional/binary_function.h> // TODO: deprecate
509fe6060f1SDimitry Andric#include <__functional/binary_negate.h>
51004eeddc0SDimitry Andric#include <__functional/bind.h>
511349cc55cSDimitry Andric#include <__functional/bind_back.h>
512fe6060f1SDimitry Andric#include <__functional/bind_front.h>
513fe6060f1SDimitry Andric#include <__functional/binder1st.h>
514fe6060f1SDimitry Andric#include <__functional/binder2nd.h>
51581ad6265SDimitry Andric#include <__functional/boyer_moore_searcher.h>
516349cc55cSDimitry Andric#include <__functional/compose.h>
517fe6060f1SDimitry Andric#include <__functional/default_searcher.h>
518fe6060f1SDimitry Andric#include <__functional/function.h>
519fe6060f1SDimitry Andric#include <__functional/hash.h>
520fe6060f1SDimitry Andric#include <__functional/identity.h>
521fe6060f1SDimitry Andric#include <__functional/invoke.h>
522fe6060f1SDimitry Andric#include <__functional/mem_fn.h> // TODO: deprecate
523fe6060f1SDimitry Andric#include <__functional/mem_fun_ref.h>
524fe6060f1SDimitry Andric#include <__functional/not_fn.h>
525fe6060f1SDimitry Andric#include <__functional/operations.h>
526fe6060f1SDimitry Andric#include <__functional/pointer_to_binary_function.h>
527fe6060f1SDimitry Andric#include <__functional/pointer_to_unary_function.h>
528fe6060f1SDimitry Andric#include <__functional/ranges_operations.h>
529fe6060f1SDimitry Andric#include <__functional/reference_wrapper.h>
530fe6060f1SDimitry Andric#include <__functional/unary_function.h> // TODO: deprecate
531fe6060f1SDimitry Andric#include <__functional/unary_negate.h>
532fe6060f1SDimitry Andric#include <__functional/unwrap_ref.h>
533fe6060f1SDimitry Andric#include <__utility/forward.h>
5340b57cec5SDimitry Andric#include <exception>
535*bdd1243dSDimitry Andric#include <memory> // TODO: find out why removing this breaks the modules build
536fe6060f1SDimitry Andric#include <type_traits>
537fe6060f1SDimitry Andric#include <typeinfo>
5380b57cec5SDimitry Andric#include <version>
5390b57cec5SDimitry Andric
5400b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
5410b57cec5SDimitry Andric#  pragma GCC system_header
5420b57cec5SDimitry Andric#endif
5430b57cec5SDimitry Andric
544*bdd1243dSDimitry Andric#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
545*bdd1243dSDimitry Andric#  include <concepts>
546*bdd1243dSDimitry Andric#  include <tuple>
547*bdd1243dSDimitry Andric#  include <utility>
548*bdd1243dSDimitry Andric#endif
549*bdd1243dSDimitry Andric
5500b57cec5SDimitry Andric#endif // _LIBCPP_FUNCTIONAL
551