xref: /freebsd/contrib/llvm-project/libcxx/include/functional (revision 06c3fb2749bda94cb5201f81ffdb8fa6c3161b2e)
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>
46*06c3fb27SDimitry Andric      constexpr reference_wrapper(U&&);                                   // constexpr since C++20
47*06c3fb27SDimitry Andric    constexpr reference_wrapper(const reference_wrapper<T>& x) noexcept;  // constexpr since C++20
480b57cec5SDimitry Andric
490b57cec5SDimitry Andric    // assignment
50*06c3fb27SDimitry Andric    constexpr reference_wrapper&
51*06c3fb27SDimitry Andric    operator=(const reference_wrapper<T>& x) noexcept;                    // constexpr since C++20
520b57cec5SDimitry Andric
530b57cec5SDimitry Andric    // access
54*06c3fb27SDimitry Andric    constexpr operator T& () const noexcept;                              // constexpr since C++20
55*06c3fb27SDimitry Andric    constexpr T& get() const noexcept;                                    // constexpr since C++20
560b57cec5SDimitry Andric
570b57cec5SDimitry Andric    // invoke
580b57cec5SDimitry Andric    template <class... ArgTypes>
59*06c3fb27SDimitry Andric      constexpr typename result_of<T&(ArgTypes&&...)>::type               // constexpr since C++20
60*06c3fb27SDimitry Andric          operator() (ArgTypes&&...) const
61*06c3fb27SDimitry 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
800b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14
81fe6060f1SDimitry Andricstruct plus {
820b57cec5SDimitry Andric    T operator()(const T& x, const T& y) const;
830b57cec5SDimitry Andric};
840b57cec5SDimitry Andric
850b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14
86fe6060f1SDimitry Andricstruct minus {
870b57cec5SDimitry Andric    T operator()(const T& x, const T& y) const;
880b57cec5SDimitry Andric};
890b57cec5SDimitry Andric
900b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14
91fe6060f1SDimitry Andricstruct multiplies {
920b57cec5SDimitry Andric    T operator()(const T& x, const T& y) const;
930b57cec5SDimitry Andric};
940b57cec5SDimitry Andric
950b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14
96fe6060f1SDimitry Andricstruct divides {
970b57cec5SDimitry Andric    T operator()(const T& x, const T& y) const;
980b57cec5SDimitry Andric};
990b57cec5SDimitry Andric
1000b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14
101fe6060f1SDimitry Andricstruct modulus {
1020b57cec5SDimitry Andric    T operator()(const T& x, const T& y) const;
1030b57cec5SDimitry Andric};
1040b57cec5SDimitry Andric
1050b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14
106fe6060f1SDimitry Andricstruct negate {
1070b57cec5SDimitry Andric    T operator()(const T& x) const;
1080b57cec5SDimitry Andric};
1090b57cec5SDimitry Andric
1100b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14
111fe6060f1SDimitry Andricstruct equal_to {
1120b57cec5SDimitry Andric    bool operator()(const T& x, const T& y) const;
1130b57cec5SDimitry Andric};
1140b57cec5SDimitry Andric
1150b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14
116fe6060f1SDimitry Andricstruct not_equal_to {
1170b57cec5SDimitry Andric    bool operator()(const T& x, const T& y) const;
1180b57cec5SDimitry Andric};
1190b57cec5SDimitry Andric
1200b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14
121fe6060f1SDimitry Andricstruct greater {
1220b57cec5SDimitry Andric    bool operator()(const T& x, const T& y) const;
1230b57cec5SDimitry Andric};
1240b57cec5SDimitry Andric
1250b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14
126fe6060f1SDimitry Andricstruct less {
1270b57cec5SDimitry Andric    bool operator()(const T& x, const T& y) const;
1280b57cec5SDimitry Andric};
1290b57cec5SDimitry Andric
1300b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14
131fe6060f1SDimitry Andricstruct greater_equal {
1320b57cec5SDimitry Andric    bool operator()(const T& x, const T& y) const;
1330b57cec5SDimitry Andric};
1340b57cec5SDimitry Andric
1350b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14
136fe6060f1SDimitry Andricstruct less_equal {
1370b57cec5SDimitry Andric    bool operator()(const T& x, const T& y) const;
1380b57cec5SDimitry Andric};
1390b57cec5SDimitry Andric
140349cc55cSDimitry Andric// [comparisons.three.way], class compare_three_way
141349cc55cSDimitry Andricstruct compare_three_way;
142349cc55cSDimitry Andric
1430b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14
144fe6060f1SDimitry Andricstruct logical_and {
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
149fe6060f1SDimitry Andricstruct logical_or {
1500b57cec5SDimitry Andric    bool operator()(const T& x, const T& y) const;
1510b57cec5SDimitry Andric};
1520b57cec5SDimitry Andric
1530b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14
154fe6060f1SDimitry Andricstruct logical_not {
1550b57cec5SDimitry Andric    bool operator()(const T& x) const;
1560b57cec5SDimitry Andric};
1570b57cec5SDimitry Andric
1580b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14
159fe6060f1SDimitry Andricstruct bit_and {
160fe6060f1SDimitry Andric    T operator()(const T& x, const T& y) const;
1610b57cec5SDimitry Andric};
1620b57cec5SDimitry Andric
1630b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14
164fe6060f1SDimitry Andricstruct bit_or {
165fe6060f1SDimitry Andric    T operator()(const T& x, const T& y) const;
1660b57cec5SDimitry Andric};
1670b57cec5SDimitry Andric
1680b57cec5SDimitry Andrictemplate <class T> // <class T=void> in C++14
169fe6060f1SDimitry Andricstruct bit_xor {
170fe6060f1SDimitry Andric    T operator()(const T& x, const T& y) const;
1710b57cec5SDimitry Andric};
1720b57cec5SDimitry Andric
1730b57cec5SDimitry Andrictemplate <class T=void> // C++14
174fe6060f1SDimitry Andricstruct bit_not {
175fe6060f1SDimitry Andric    T operator()(const T& x) const;
1760b57cec5SDimitry Andric};
1770b57cec5SDimitry Andric
178fe6060f1SDimitry Andricstruct identity; // C++20
179fe6060f1SDimitry Andric
1800b57cec5SDimitry Andrictemplate <class Predicate>
181fe6060f1SDimitry Andricclass unary_negate // deprecated in C++17, removed in C++20
1820b57cec5SDimitry Andric    : public unary_function<typename Predicate::argument_type, bool>
1830b57cec5SDimitry Andric{
1840b57cec5SDimitry Andricpublic:
1850b57cec5SDimitry Andric    explicit unary_negate(const Predicate& pred);
1860b57cec5SDimitry Andric    bool operator()(const typename Predicate::argument_type& x) const;
1870b57cec5SDimitry Andric};
1880b57cec5SDimitry Andric
189fe6060f1SDimitry Andrictemplate <class Predicate> // deprecated in C++17, removed in C++20
1900b57cec5SDimitry Andricunary_negate<Predicate> not1(const Predicate& pred);
1910b57cec5SDimitry Andric
1920b57cec5SDimitry Andrictemplate <class Predicate>
193fe6060f1SDimitry Andricclass binary_negate // deprecated in C++17, removed in C++20
1940b57cec5SDimitry Andric    : public binary_function<typename Predicate::first_argument_type,
1950b57cec5SDimitry Andric                             typename Predicate::second_argument_type,
1960b57cec5SDimitry Andric                             bool>
1970b57cec5SDimitry Andric{
1980b57cec5SDimitry Andricpublic:
1990b57cec5SDimitry Andric    explicit binary_negate(const Predicate& pred);
2000b57cec5SDimitry Andric    bool operator()(const typename Predicate::first_argument_type& x,
2010b57cec5SDimitry Andric                    const typename Predicate::second_argument_type& y) const;
2020b57cec5SDimitry Andric};
2030b57cec5SDimitry Andric
204fe6060f1SDimitry Andrictemplate <class Predicate> // deprecated in C++17, removed in C++20
2050b57cec5SDimitry Andricbinary_negate<Predicate> not2(const Predicate& pred);
2060b57cec5SDimitry Andric
207e8d8bef9SDimitry Andrictemplate <class F>
208e8d8bef9SDimitry Andricconstexpr unspecified not_fn(F&& f); // C++17, constexpr in C++20
2090b57cec5SDimitry Andric
2100b57cec5SDimitry Andrictemplate<class T> struct is_bind_expression;
2110b57cec5SDimitry Andrictemplate<class T> struct is_placeholder;
2120b57cec5SDimitry Andric
2130b57cec5SDimitry Andric    // See C++14 20.9.9, Function object binders
2140b57cec5SDimitry Andrictemplate <class T> inline constexpr bool is_bind_expression_v
2150b57cec5SDimitry Andric  = is_bind_expression<T>::value; // C++17
2160b57cec5SDimitry Andrictemplate <class T> inline constexpr int is_placeholder_v
2170b57cec5SDimitry Andric  = is_placeholder<T>::value; // C++17
2180b57cec5SDimitry Andric
2190b57cec5SDimitry Andric
2200b57cec5SDimitry Andrictemplate<class Fn, class... BoundArgs>
221e8d8bef9SDimitry Andric  constexpr unspecified bind(Fn&&, BoundArgs&&...);  // constexpr in C++20
2220b57cec5SDimitry Andrictemplate<class R, class Fn, class... BoundArgs>
223e8d8bef9SDimitry Andric  constexpr unspecified bind(Fn&&, BoundArgs&&...);  // constexpr in C++20
2240b57cec5SDimitry Andric
225*06c3fb27SDimitry Andric// [func.invoke]
2260b57cec5SDimitry Andrictemplate<class F, class... Args>
227e8d8bef9SDimitry Andric constexpr // constexpr in C++20
2280b57cec5SDimitry Andric invoke_result_t<F, Args...> invoke(F&& f, Args&&... args) // C++17
2290b57cec5SDimitry Andric    noexcept(is_nothrow_invocable_v<F, Args...>);
2300b57cec5SDimitry Andric
231*06c3fb27SDimitry Andrictemplate<class R, class F, class... Args>
232*06c3fb27SDimitry Andric  constexpr R invoke_r(F&& f, Args&&... args)              // C++23
233*06c3fb27SDimitry Andric    noexcept(is_nothrow_invocable_r_v<R, F, Args...>);
234*06c3fb27SDimitry Andric
2350b57cec5SDimitry Andricnamespace placeholders {
2360b57cec5SDimitry Andric  // M is the implementation-defined number of placeholders
2370b57cec5SDimitry Andric  extern unspecified _1;
2380b57cec5SDimitry Andric  extern unspecified _2;
2390b57cec5SDimitry Andric  .
2400b57cec5SDimitry Andric  .
2410b57cec5SDimitry Andric  .
2420b57cec5SDimitry Andric  extern unspecified _Mp;
2430b57cec5SDimitry Andric}
2440b57cec5SDimitry Andric
2450b57cec5SDimitry Andrictemplate <class Operation>
2460b57cec5SDimitry Andricclass binder1st     // deprecated in C++11, removed in C++17
2470b57cec5SDimitry Andric    : public unary_function<typename Operation::second_argument_type,
2480b57cec5SDimitry Andric                            typename Operation::result_type>
2490b57cec5SDimitry Andric{
2500b57cec5SDimitry Andricprotected:
2510b57cec5SDimitry Andric    Operation                               op;
2520b57cec5SDimitry Andric    typename Operation::first_argument_type value;
2530b57cec5SDimitry Andricpublic:
2540b57cec5SDimitry Andric    binder1st(const Operation& x, const typename Operation::first_argument_type y);
2550b57cec5SDimitry Andric    typename Operation::result_type operator()(      typename Operation::second_argument_type& x) const;
2560b57cec5SDimitry Andric    typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const;
2570b57cec5SDimitry Andric};
2580b57cec5SDimitry Andric
2590b57cec5SDimitry Andrictemplate <class Operation, class T>
2600b57cec5SDimitry Andricbinder1st<Operation> bind1st(const Operation& op, const T& x);                  // deprecated in C++11, removed in C++17
2610b57cec5SDimitry Andric
2620b57cec5SDimitry Andrictemplate <class Operation>
2630b57cec5SDimitry Andricclass binder2nd                                                                 // deprecated in C++11, removed in C++17
2640b57cec5SDimitry Andric    : public unary_function<typename Operation::first_argument_type,
2650b57cec5SDimitry Andric                            typename Operation::result_type>
2660b57cec5SDimitry Andric{
2670b57cec5SDimitry Andricprotected:
2680b57cec5SDimitry Andric    Operation                                op;
2690b57cec5SDimitry Andric    typename Operation::second_argument_type value;
2700b57cec5SDimitry Andricpublic:
2710b57cec5SDimitry Andric    binder2nd(const Operation& x, const typename Operation::second_argument_type y);
2720b57cec5SDimitry Andric    typename Operation::result_type operator()(      typename Operation::first_argument_type& x) const;
2730b57cec5SDimitry Andric    typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const;
2740b57cec5SDimitry Andric};
2750b57cec5SDimitry Andric
2760b57cec5SDimitry Andrictemplate <class Operation, class T>
2770b57cec5SDimitry Andricbinder2nd<Operation> bind2nd(const Operation& op, const T& x);                  // deprecated in C++11, removed in C++17
2780b57cec5SDimitry Andric
2790b57cec5SDimitry Andrictemplate <class Arg, class Result>                                              // deprecated in C++11, removed in C++17
2800b57cec5SDimitry Andricclass pointer_to_unary_function : public unary_function<Arg, Result>
2810b57cec5SDimitry Andric{
2820b57cec5SDimitry Andricpublic:
2830b57cec5SDimitry Andric    explicit pointer_to_unary_function(Result (*f)(Arg));
2840b57cec5SDimitry Andric    Result operator()(Arg x) const;
2850b57cec5SDimitry Andric};
2860b57cec5SDimitry Andric
2870b57cec5SDimitry Andrictemplate <class Arg, class Result>
2880b57cec5SDimitry Andricpointer_to_unary_function<Arg,Result> ptr_fun(Result (*f)(Arg));                // deprecated in C++11, removed in C++17
2890b57cec5SDimitry Andric
2900b57cec5SDimitry Andrictemplate <class Arg1, class Arg2, class Result>                                 // deprecated in C++11, removed in C++17
2910b57cec5SDimitry Andricclass pointer_to_binary_function : public binary_function<Arg1, Arg2, Result>
2920b57cec5SDimitry Andric{
2930b57cec5SDimitry Andricpublic:
2940b57cec5SDimitry Andric    explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2));
2950b57cec5SDimitry Andric    Result operator()(Arg1 x, Arg2 y) const;
2960b57cec5SDimitry Andric};
2970b57cec5SDimitry Andric
2980b57cec5SDimitry Andrictemplate <class Arg1, class Arg2, class Result>
2990b57cec5SDimitry Andricpointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1,Arg2));   // deprecated in C++11, removed in C++17
3000b57cec5SDimitry Andric
3010b57cec5SDimitry Andrictemplate<class S, class T>                                                      // deprecated in C++11, removed in C++17
3020b57cec5SDimitry Andricclass mem_fun_t : public unary_function<T*, S>
3030b57cec5SDimitry Andric{
3040b57cec5SDimitry Andricpublic:
3050b57cec5SDimitry Andric    explicit mem_fun_t(S (T::*p)());
3060b57cec5SDimitry Andric    S operator()(T* p) const;
3070b57cec5SDimitry Andric};
3080b57cec5SDimitry Andric
3090b57cec5SDimitry Andrictemplate<class S, class T, class A>
3100b57cec5SDimitry Andricclass mem_fun1_t : public binary_function<T*, A, S>                             // deprecated in C++11, removed in C++17
3110b57cec5SDimitry Andric{
3120b57cec5SDimitry Andricpublic:
3130b57cec5SDimitry Andric    explicit mem_fun1_t(S (T::*p)(A));
3140b57cec5SDimitry Andric    S operator()(T* p, A x) const;
3150b57cec5SDimitry Andric};
3160b57cec5SDimitry Andric
3170b57cec5SDimitry Andrictemplate<class S, class T>          mem_fun_t<S,T>    mem_fun(S (T::*f)());     // deprecated in C++11, removed in C++17
3180b57cec5SDimitry 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
3190b57cec5SDimitry Andric
3200b57cec5SDimitry Andrictemplate<class S, class T>
3210b57cec5SDimitry Andricclass mem_fun_ref_t : public unary_function<T, S>                               // deprecated in C++11, removed in C++17
3220b57cec5SDimitry Andric{
3230b57cec5SDimitry Andricpublic:
3240b57cec5SDimitry Andric    explicit mem_fun_ref_t(S (T::*p)());
3250b57cec5SDimitry Andric    S operator()(T& p) const;
3260b57cec5SDimitry Andric};
3270b57cec5SDimitry Andric
3280b57cec5SDimitry Andrictemplate<class S, class T, class A>
3290b57cec5SDimitry Andricclass mem_fun1_ref_t : public binary_function<T, A, S>                          // deprecated in C++11, removed in C++17
3300b57cec5SDimitry Andric{
3310b57cec5SDimitry Andricpublic:
3320b57cec5SDimitry Andric    explicit mem_fun1_ref_t(S (T::*p)(A));
3330b57cec5SDimitry Andric    S operator()(T& p, A x) const;
3340b57cec5SDimitry Andric};
3350b57cec5SDimitry Andric
336*06c3fb27SDimitry Andrictemplate<class S, class T>
337*06c3fb27SDimitry Andricmem_fun_ref_t<S,T>    mem_fun_ref(S (T::*f)());                                 // deprecated in C++11, removed in C++17
338*06c3fb27SDimitry Andrictemplate<class S, class T, class A>
339*06c3fb27SDimitry Andricmem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A));                                // deprecated in C++11, removed in C++17
3400b57cec5SDimitry Andric
3410b57cec5SDimitry Andrictemplate <class S, class T>
3420b57cec5SDimitry Andricclass const_mem_fun_t : public unary_function<const T*, S>                      // deprecated in C++11, removed in C++17
3430b57cec5SDimitry Andric{
3440b57cec5SDimitry Andricpublic:
3450b57cec5SDimitry Andric    explicit const_mem_fun_t(S (T::*p)() const);
3460b57cec5SDimitry Andric    S operator()(const T* p) const;
3470b57cec5SDimitry Andric};
3480b57cec5SDimitry Andric
3490b57cec5SDimitry Andrictemplate <class S, class T, class A>
3500b57cec5SDimitry Andricclass const_mem_fun1_t : public binary_function<const T*, A, S>                 // deprecated in C++11, removed in C++17
3510b57cec5SDimitry Andric{
3520b57cec5SDimitry Andricpublic:
3530b57cec5SDimitry Andric    explicit const_mem_fun1_t(S (T::*p)(A) const);
3540b57cec5SDimitry Andric    S operator()(const T* p, A x) const;
3550b57cec5SDimitry Andric};
3560b57cec5SDimitry Andric
357*06c3fb27SDimitry Andrictemplate <class S, class T>
358*06c3fb27SDimitry Andricconst_mem_fun_t<S,T>    mem_fun(S (T::*f)() const);                             // deprecated in C++11, removed in C++17
359*06c3fb27SDimitry Andrictemplate <class S, class T, class A>
360*06c3fb27SDimitry Andricconst_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const);                            // deprecated in C++11, removed in C++17
3610b57cec5SDimitry Andric
3620b57cec5SDimitry Andrictemplate <class S, class T>
3630b57cec5SDimitry Andricclass const_mem_fun_ref_t : public unary_function<T, S>                         // deprecated in C++11, removed in C++17
3640b57cec5SDimitry Andric{
3650b57cec5SDimitry Andricpublic:
3660b57cec5SDimitry Andric    explicit const_mem_fun_ref_t(S (T::*p)() const);
3670b57cec5SDimitry Andric    S operator()(const T& p) const;
3680b57cec5SDimitry Andric};
3690b57cec5SDimitry Andric
3700b57cec5SDimitry Andrictemplate <class S, class T, class A>
3710b57cec5SDimitry Andricclass const_mem_fun1_ref_t : public binary_function<T, A, S>                    // deprecated in C++11, removed in C++17
3720b57cec5SDimitry Andric{
3730b57cec5SDimitry Andricpublic:
3740b57cec5SDimitry Andric    explicit const_mem_fun1_ref_t(S (T::*p)(A) const);
3750b57cec5SDimitry Andric    S operator()(const T& p, A x) const;
3760b57cec5SDimitry Andric};
3770b57cec5SDimitry Andric
378*06c3fb27SDimitry Andrictemplate <class S, class T>
379*06c3fb27SDimitry Andricconst_mem_fun_ref_t<S,T>    mem_fun_ref(S (T::*f)() const);                     // deprecated in C++11, removed in C++17
380*06c3fb27SDimitry Andrictemplate <class S, class T, class A>
381*06c3fb27SDimitry Andricconst_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const);                    // deprecated in C++11, removed in C++17
3820b57cec5SDimitry Andric
383*06c3fb27SDimitry Andrictemplate<class R, class T> constexpr unspecified mem_fn(R T::*);                // constexpr in C++20
3840b57cec5SDimitry Andric
3850b57cec5SDimitry Andricclass bad_function_call
3860b57cec5SDimitry Andric    : public exception
3870b57cec5SDimitry Andric{
3880b57cec5SDimitry Andric};
3890b57cec5SDimitry Andric
3900b57cec5SDimitry Andrictemplate<class> class function; // undefined
3910b57cec5SDimitry Andric
3920b57cec5SDimitry Andrictemplate<class R, class... ArgTypes>
3930b57cec5SDimitry Andricclass function<R(ArgTypes...)>
3940b57cec5SDimitry Andric  : public unary_function<T1, R>      // iff sizeof...(ArgTypes) == 1 and
3950b57cec5SDimitry Andric                                      // ArgTypes contains T1
3960b57cec5SDimitry Andric  : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and
3970b57cec5SDimitry Andric                                      // ArgTypes contains T1 and T2
3980b57cec5SDimitry Andric{
3990b57cec5SDimitry Andricpublic:
4000b57cec5SDimitry Andric    typedef R result_type;
4010b57cec5SDimitry Andric
4020b57cec5SDimitry Andric    // construct/copy/destroy:
4030b57cec5SDimitry Andric    function() noexcept;
4040b57cec5SDimitry Andric    function(nullptr_t) noexcept;
4050b57cec5SDimitry Andric    function(const function&);
4060b57cec5SDimitry Andric    function(function&&) noexcept;
4070b57cec5SDimitry Andric    template<class F>
4080b57cec5SDimitry Andric      function(F);
4090b57cec5SDimitry Andric    template<Allocator Alloc>
4100b57cec5SDimitry Andric      function(allocator_arg_t, const Alloc&) noexcept;            // removed in C++17
4110b57cec5SDimitry Andric    template<Allocator Alloc>
4120b57cec5SDimitry Andric      function(allocator_arg_t, const Alloc&, nullptr_t) noexcept; // removed in C++17
4130b57cec5SDimitry Andric    template<Allocator Alloc>
4140b57cec5SDimitry Andric      function(allocator_arg_t, const Alloc&, const function&);    // removed in C++17
4150b57cec5SDimitry Andric    template<Allocator Alloc>
4160b57cec5SDimitry Andric      function(allocator_arg_t, const Alloc&, function&&);         // removed in C++17
4170b57cec5SDimitry Andric    template<class F, Allocator Alloc>
4180b57cec5SDimitry Andric      function(allocator_arg_t, const Alloc&, F);                  // removed in C++17
4190b57cec5SDimitry Andric
4200b57cec5SDimitry Andric    function& operator=(const function&);
4210b57cec5SDimitry Andric    function& operator=(function&&) noexcept;
4220b57cec5SDimitry Andric    function& operator=(nullptr_t) noexcept;
4230b57cec5SDimitry Andric    template<class F>
4240b57cec5SDimitry Andric      function& operator=(F&&);
4250b57cec5SDimitry Andric    template<class F>
4260b57cec5SDimitry Andric      function& operator=(reference_wrapper<F>) noexcept;
4270b57cec5SDimitry Andric
4280b57cec5SDimitry Andric    ~function();
4290b57cec5SDimitry Andric
4300b57cec5SDimitry Andric    // function modifiers:
4310b57cec5SDimitry Andric    void swap(function&) noexcept;
4320b57cec5SDimitry Andric    template<class F, class Alloc>
4330b57cec5SDimitry Andric      void assign(F&&, const Alloc&);                 // Removed in C++17
4340b57cec5SDimitry Andric
4350b57cec5SDimitry Andric    // function capacity:
4360b57cec5SDimitry Andric    explicit operator bool() const noexcept;
4370b57cec5SDimitry Andric
4380b57cec5SDimitry Andric    // function invocation:
4390b57cec5SDimitry Andric    R operator()(ArgTypes...) const;
4400b57cec5SDimitry Andric
4410b57cec5SDimitry Andric    // function target access:
4420b57cec5SDimitry Andric    const std::type_info& target_type() const noexcept;
4430b57cec5SDimitry Andric    template <typename T>       T* target() noexcept;
4440b57cec5SDimitry Andric    template <typename T> const T* target() const noexcept;
4450b57cec5SDimitry Andric};
4460b57cec5SDimitry Andric
447e40139ffSDimitry Andric// Deduction guides
448e40139ffSDimitry Andrictemplate<class R, class ...Args>
449e40139ffSDimitry Andricfunction(R(*)(Args...)) -> function<R(Args...)>; // since C++17
450e40139ffSDimitry Andric
451e40139ffSDimitry Andrictemplate<class F>
452e40139ffSDimitry Andricfunction(F) -> function<see-below>; // since C++17
453e40139ffSDimitry Andric
4540b57cec5SDimitry Andric// Null pointer comparisons:
4550b57cec5SDimitry Andrictemplate <class R, class ... ArgTypes>
4560b57cec5SDimitry Andric  bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
4570b57cec5SDimitry Andric
4580b57cec5SDimitry Andrictemplate <class R, class ... ArgTypes>
459*06c3fb27SDimitry Andric  bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept; // removed in C++20
4600b57cec5SDimitry Andric
4610b57cec5SDimitry Andrictemplate <class R, class ... ArgTypes>
462*06c3fb27SDimitry Andric  bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept; // removed in C++20
4630b57cec5SDimitry Andric
4640b57cec5SDimitry Andrictemplate <class  R, class ... ArgTypes>
465*06c3fb27SDimitry Andric  bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept; // removed in C++20
4660b57cec5SDimitry Andric
4670b57cec5SDimitry Andric// specialized algorithms:
4680b57cec5SDimitry Andrictemplate <class  R, class ... ArgTypes>
4690b57cec5SDimitry Andric  void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
4700b57cec5SDimitry Andric
4710b57cec5SDimitry Andrictemplate <class T> struct hash;
4720b57cec5SDimitry Andric
4730b57cec5SDimitry Andrictemplate <> struct hash<bool>;
4740b57cec5SDimitry Andrictemplate <> struct hash<char>;
4750b57cec5SDimitry Andrictemplate <> struct hash<signed char>;
4760b57cec5SDimitry Andrictemplate <> struct hash<unsigned char>;
477e8d8bef9SDimitry Andrictemplate <> struct hash<char8_t>; // since C++20
4780b57cec5SDimitry Andrictemplate <> struct hash<char16_t>;
4790b57cec5SDimitry Andrictemplate <> struct hash<char32_t>;
4800b57cec5SDimitry Andrictemplate <> struct hash<wchar_t>;
4810b57cec5SDimitry Andrictemplate <> struct hash<short>;
4820b57cec5SDimitry Andrictemplate <> struct hash<unsigned short>;
4830b57cec5SDimitry Andrictemplate <> struct hash<int>;
4840b57cec5SDimitry Andrictemplate <> struct hash<unsigned int>;
4850b57cec5SDimitry Andrictemplate <> struct hash<long>;
4860b57cec5SDimitry Andrictemplate <> struct hash<long long>;
4870b57cec5SDimitry Andrictemplate <> struct hash<unsigned long>;
4880b57cec5SDimitry Andrictemplate <> struct hash<unsigned long long>;
4890b57cec5SDimitry Andric
4900b57cec5SDimitry Andrictemplate <> struct hash<float>;
4910b57cec5SDimitry Andrictemplate <> struct hash<double>;
4920b57cec5SDimitry Andrictemplate <> struct hash<long double>;
4930b57cec5SDimitry Andric
4940b57cec5SDimitry Andrictemplate<class T> struct hash<T*>;
4950b57cec5SDimitry Andrictemplate <> struct hash<nullptr_t>;  // C++17
4960b57cec5SDimitry Andric
49781ad6265SDimitry Andricnamespace ranges {
49881ad6265SDimitry Andric  // [range.cmp], concept-constrained comparisons
49981ad6265SDimitry Andric  struct equal_to;
50081ad6265SDimitry Andric  struct not_equal_to;
50181ad6265SDimitry Andric  struct greater;
50281ad6265SDimitry Andric  struct less;
50381ad6265SDimitry Andric  struct greater_equal;
50481ad6265SDimitry Andric  struct less_equal;
50581ad6265SDimitry Andric}
50681ad6265SDimitry Andric
5070b57cec5SDimitry Andric}  // std
5080b57cec5SDimitry Andric
5090b57cec5SDimitry AndricPOLICY:  For non-variadic implementations, the number of arguments is limited
5100b57cec5SDimitry Andric         to 3.  It is hoped that the need for non-variadic implementations
5110b57cec5SDimitry Andric         will be minimal.
5120b57cec5SDimitry Andric
5130b57cec5SDimitry Andric*/
5140b57cec5SDimitry Andric
515fe6060f1SDimitry Andric#include <__algorithm/search.h>
51681ad6265SDimitry Andric#include <__assert> // all public C++ headers provide the assertion handler
517349cc55cSDimitry Andric#include <__compare/compare_three_way.h>
5180b57cec5SDimitry Andric#include <__config>
519*06c3fb27SDimitry Andric#include <__functional/binary_function.h>
520fe6060f1SDimitry Andric#include <__functional/binary_negate.h>
52104eeddc0SDimitry Andric#include <__functional/bind.h>
522349cc55cSDimitry Andric#include <__functional/bind_back.h>
523fe6060f1SDimitry Andric#include <__functional/bind_front.h>
524fe6060f1SDimitry Andric#include <__functional/binder1st.h>
525fe6060f1SDimitry Andric#include <__functional/binder2nd.h>
52681ad6265SDimitry Andric#include <__functional/boyer_moore_searcher.h>
527349cc55cSDimitry Andric#include <__functional/compose.h>
528fe6060f1SDimitry Andric#include <__functional/default_searcher.h>
529fe6060f1SDimitry Andric#include <__functional/function.h>
530fe6060f1SDimitry Andric#include <__functional/hash.h>
531fe6060f1SDimitry Andric#include <__functional/identity.h>
532fe6060f1SDimitry Andric#include <__functional/invoke.h>
533fe6060f1SDimitry Andric#include <__functional/mem_fn.h> // TODO: deprecate
534fe6060f1SDimitry Andric#include <__functional/mem_fun_ref.h>
535fe6060f1SDimitry Andric#include <__functional/not_fn.h>
536fe6060f1SDimitry Andric#include <__functional/operations.h>
537fe6060f1SDimitry Andric#include <__functional/pointer_to_binary_function.h>
538fe6060f1SDimitry Andric#include <__functional/pointer_to_unary_function.h>
539fe6060f1SDimitry Andric#include <__functional/ranges_operations.h>
540fe6060f1SDimitry Andric#include <__functional/reference_wrapper.h>
541*06c3fb27SDimitry Andric#include <__functional/unary_function.h>
542fe6060f1SDimitry Andric#include <__functional/unary_negate.h>
543*06c3fb27SDimitry Andric#include <__type_traits/unwrap_ref.h>
544fe6060f1SDimitry Andric#include <__utility/forward.h>
545bdd1243dSDimitry Andric#include <memory> // TODO: find out why removing this breaks the modules build
546fe6060f1SDimitry Andric#include <typeinfo>
5470b57cec5SDimitry Andric#include <version>
5480b57cec5SDimitry Andric
5490b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
5500b57cec5SDimitry Andric#  pragma GCC system_header
5510b57cec5SDimitry Andric#endif
5520b57cec5SDimitry Andric
553bdd1243dSDimitry Andric#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
554*06c3fb27SDimitry Andric#  include <atomic>
555bdd1243dSDimitry Andric#  include <concepts>
556*06c3fb27SDimitry Andric#  include <cstdlib>
557*06c3fb27SDimitry Andric#  include <exception>
558bdd1243dSDimitry Andric#  include <tuple>
559*06c3fb27SDimitry Andric#  include <type_traits>
560bdd1243dSDimitry Andric#  include <utility>
561bdd1243dSDimitry Andric#endif
562bdd1243dSDimitry Andric
5630b57cec5SDimitry Andric#endif // _LIBCPP_FUNCTIONAL
564