// -*- C++ -*- //===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #ifndef _LIBCPP_FUNCTIONAL #define _LIBCPP_FUNCTIONAL /* functional synopsis namespace std { template struct unary_function { typedef Arg argument_type; typedef Result result_type; }; template struct binary_function { typedef Arg1 first_argument_type; typedef Arg2 second_argument_type; typedef Result result_type; }; template class reference_wrapper : public unary_function // if wrapping a unary functor : public binary_function // if wraping a binary functor { public: // types typedef T type; typedef see below result_type; // Not always defined // construct/copy/destroy template constexpr reference_wrapper(U&&); // constexpr since C++20 constexpr reference_wrapper(const reference_wrapper& x) noexcept; // constexpr since C++20 // assignment constexpr reference_wrapper& operator=(const reference_wrapper& x) noexcept; // constexpr since C++20 // access constexpr operator T& () const noexcept; // constexpr since C++20 constexpr T& get() const noexcept; // constexpr since C++20 // invoke template constexpr typename result_of::type // constexpr since C++20 operator() (ArgTypes&&...) const noexcept(is_nothrow_invocable_v); // noexcept since C++17 }; template reference_wrapper(T&) -> reference_wrapper; template reference_wrapper ref(T& t) noexcept; template void ref(const T&& t) = delete; template reference_wrapper ref(reference_wrappert) noexcept; template reference_wrapper cref(const T& t) noexcept; template void cref(const T&& t) = delete; template reference_wrapper cref(reference_wrapper t) noexcept; template struct unwrap_reference; // since C++20 template struct unwrap_ref_decay : unwrap_reference> { }; // since C++20 template using unwrap_reference_t = typename unwrap_reference::type; // since C++20 template using unwrap_ref_decay_t = typename unwrap_ref_decay::type; // since C++20 template // in C++14 struct plus { T operator()(const T& x, const T& y) const; }; template // in C++14 struct minus { T operator()(const T& x, const T& y) const; }; template // in C++14 struct multiplies { T operator()(const T& x, const T& y) const; }; template // in C++14 struct divides { T operator()(const T& x, const T& y) const; }; template // in C++14 struct modulus { T operator()(const T& x, const T& y) const; }; template // in C++14 struct negate { T operator()(const T& x) const; }; template // in C++14 struct equal_to { bool operator()(const T& x, const T& y) const; }; template // in C++14 struct not_equal_to { bool operator()(const T& x, const T& y) const; }; template // in C++14 struct greater { bool operator()(const T& x, const T& y) const; }; template // in C++14 struct less { bool operator()(const T& x, const T& y) const; }; template // in C++14 struct greater_equal { bool operator()(const T& x, const T& y) const; }; template // in C++14 struct less_equal { bool operator()(const T& x, const T& y) const; }; // [comparisons.three.way], class compare_three_way struct compare_three_way; template // in C++14 struct logical_and { bool operator()(const T& x, const T& y) const; }; template // in C++14 struct logical_or { bool operator()(const T& x, const T& y) const; }; template // in C++14 struct logical_not { bool operator()(const T& x) const; }; template // in C++14 struct bit_and { T operator()(const T& x, const T& y) const; }; template // in C++14 struct bit_or { T operator()(const T& x, const T& y) const; }; template // in C++14 struct bit_xor { T operator()(const T& x, const T& y) const; }; template // C++14 struct bit_not { T operator()(const T& x) const; }; struct identity; // C++20 template class unary_negate // deprecated in C++17, removed in C++20 : public unary_function { public: explicit unary_negate(const Predicate& pred); bool operator()(const typename Predicate::argument_type& x) const; }; template // deprecated in C++17, removed in C++20 unary_negate not1(const Predicate& pred); template class binary_negate // deprecated in C++17, removed in C++20 : public binary_function { public: explicit binary_negate(const Predicate& pred); bool operator()(const typename Predicate::first_argument_type& x, const typename Predicate::second_argument_type& y) const; }; template // deprecated in C++17, removed in C++20 binary_negate not2(const Predicate& pred); template constexpr unspecified not_fn(F&& f); // C++17, constexpr in C++20 template struct is_bind_expression; template struct is_placeholder; // See C++14 20.9.9, Function object binders template inline constexpr bool is_bind_expression_v = is_bind_expression::value; // C++17 template inline constexpr int is_placeholder_v = is_placeholder::value; // C++17 template constexpr unspecified bind(Fn&&, BoundArgs&&...); // constexpr in C++20 template constexpr unspecified bind(Fn&&, BoundArgs&&...); // constexpr in C++20 // [func.invoke] template constexpr // constexpr in C++20 invoke_result_t invoke(F&& f, Args&&... args) // C++17 noexcept(is_nothrow_invocable_v); template constexpr R invoke_r(F&& f, Args&&... args) // C++23 noexcept(is_nothrow_invocable_r_v); namespace placeholders { // M is the implementation-defined number of placeholders extern unspecified _1; extern unspecified _2; . . . extern unspecified _Mp; } template class binder1st // deprecated in C++11, removed in C++17 : public unary_function { protected: Operation op; typename Operation::first_argument_type value; public: binder1st(const Operation& x, const typename Operation::first_argument_type y); typename Operation::result_type operator()( typename Operation::second_argument_type& x) const; typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const; }; template binder1st bind1st(const Operation& op, const T& x); // deprecated in C++11, removed in C++17 template class binder2nd // deprecated in C++11, removed in C++17 : public unary_function { protected: Operation op; typename Operation::second_argument_type value; public: binder2nd(const Operation& x, const typename Operation::second_argument_type y); typename Operation::result_type operator()( typename Operation::first_argument_type& x) const; typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const; }; template binder2nd bind2nd(const Operation& op, const T& x); // deprecated in C++11, removed in C++17 template // deprecated in C++11, removed in C++17 class pointer_to_unary_function : public unary_function { public: explicit pointer_to_unary_function(Result (*f)(Arg)); Result operator()(Arg x) const; }; template pointer_to_unary_function ptr_fun(Result (*f)(Arg)); // deprecated in C++11, removed in C++17 template // deprecated in C++11, removed in C++17 class pointer_to_binary_function : public binary_function { public: explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2)); Result operator()(Arg1 x, Arg2 y) const; }; template pointer_to_binary_function ptr_fun(Result (*f)(Arg1,Arg2)); // deprecated in C++11, removed in C++17 template // deprecated in C++11, removed in C++17 class mem_fun_t : public unary_function { public: explicit mem_fun_t(S (T::*p)()); S operator()(T* p) const; }; template class mem_fun1_t : public binary_function // deprecated in C++11, removed in C++17 { public: explicit mem_fun1_t(S (T::*p)(A)); S operator()(T* p, A x) const; }; template mem_fun_t mem_fun(S (T::*f)()); // deprecated in C++11, removed in C++17 template mem_fun1_t mem_fun(S (T::*f)(A)); // deprecated in C++11, removed in C++17 template class mem_fun_ref_t : public unary_function // deprecated in C++11, removed in C++17 { public: explicit mem_fun_ref_t(S (T::*p)()); S operator()(T& p) const; }; template class mem_fun1_ref_t : public binary_function // deprecated in C++11, removed in C++17 { public: explicit mem_fun1_ref_t(S (T::*p)(A)); S operator()(T& p, A x) const; }; template mem_fun_ref_t mem_fun_ref(S (T::*f)()); // deprecated in C++11, removed in C++17 template mem_fun1_ref_t mem_fun_ref(S (T::*f)(A)); // deprecated in C++11, removed in C++17 template class const_mem_fun_t : public unary_function // deprecated in C++11, removed in C++17 { public: explicit const_mem_fun_t(S (T::*p)() const); S operator()(const T* p) const; }; template class const_mem_fun1_t : public binary_function // deprecated in C++11, removed in C++17 { public: explicit const_mem_fun1_t(S (T::*p)(A) const); S operator()(const T* p, A x) const; }; template const_mem_fun_t mem_fun(S (T::*f)() const); // deprecated in C++11, removed in C++17 template const_mem_fun1_t mem_fun(S (T::*f)(A) const); // deprecated in C++11, removed in C++17 template class const_mem_fun_ref_t : public unary_function // deprecated in C++11, removed in C++17 { public: explicit const_mem_fun_ref_t(S (T::*p)() const); S operator()(const T& p) const; }; template class const_mem_fun1_ref_t : public binary_function // deprecated in C++11, removed in C++17 { public: explicit const_mem_fun1_ref_t(S (T::*p)(A) const); S operator()(const T& p, A x) const; }; template const_mem_fun_ref_t mem_fun_ref(S (T::*f)() const); // deprecated in C++11, removed in C++17 template const_mem_fun1_ref_t mem_fun_ref(S (T::*f)(A) const); // deprecated in C++11, removed in C++17 template constexpr unspecified mem_fn(R T::*); // constexpr in C++20 class bad_function_call : public exception { }; template class function; // undefined template class function : public unary_function // iff sizeof...(ArgTypes) == 1 and // ArgTypes contains T1 : public binary_function // iff sizeof...(ArgTypes) == 2 and // ArgTypes contains T1 and T2 { public: typedef R result_type; // construct/copy/destroy: function() noexcept; function(nullptr_t) noexcept; function(const function&); function(function&&) noexcept; template function(F); template function(allocator_arg_t, const Alloc&) noexcept; // removed in C++17 template function(allocator_arg_t, const Alloc&, nullptr_t) noexcept; // removed in C++17 template function(allocator_arg_t, const Alloc&, const function&); // removed in C++17 template function(allocator_arg_t, const Alloc&, function&&); // removed in C++17 template function(allocator_arg_t, const Alloc&, F); // removed in C++17 function& operator=(const function&); function& operator=(function&&) noexcept; function& operator=(nullptr_t) noexcept; template function& operator=(F&&); template function& operator=(reference_wrapper) noexcept; ~function(); // function modifiers: void swap(function&) noexcept; template void assign(F&&, const Alloc&); // Removed in C++17 // function capacity: explicit operator bool() const noexcept; // function invocation: R operator()(ArgTypes...) const; // function target access: const std::type_info& target_type() const noexcept; template T* target() noexcept; template const T* target() const noexcept; }; // Deduction guides template function(R(*)(Args...)) -> function; // since C++17 template function(F) -> function; // since C++17 // Null pointer comparisons: template bool operator==(const function&, nullptr_t) noexcept; template bool operator==(nullptr_t, const function&) noexcept; // removed in C++20 template bool operator!=(const function&, nullptr_t) noexcept; // removed in C++20 template bool operator!=(nullptr_t, const function&) noexcept; // removed in C++20 // specialized algorithms: template void swap(function&, function&) noexcept; template struct hash; template <> struct hash; template <> struct hash; template <> struct hash; template <> struct hash; template <> struct hash; // since C++20 template <> struct hash; template <> struct hash; template <> struct hash; template <> struct hash; template <> struct hash; template <> struct hash; template <> struct hash; template <> struct hash; template <> struct hash; template <> struct hash; template <> struct hash; template <> struct hash; template <> struct hash; template <> struct hash; template struct hash; template <> struct hash; // C++17 namespace ranges { // [range.cmp], concept-constrained comparisons struct equal_to; struct not_equal_to; struct greater; struct less; struct greater_equal; struct less_equal; } } // std POLICY: For non-variadic implementations, the number of arguments is limited to 3. It is hoped that the need for non-variadic implementations will be minimal. */ #include <__algorithm/search.h> #include <__assert> // all public C++ headers provide the assertion handler #include <__compare/compare_three_way.h> #include <__config> #include <__functional/binary_function.h> #include <__functional/binary_negate.h> #include <__functional/bind.h> #include <__functional/bind_back.h> #include <__functional/bind_front.h> #include <__functional/binder1st.h> #include <__functional/binder2nd.h> #include <__functional/boyer_moore_searcher.h> #include <__functional/compose.h> #include <__functional/default_searcher.h> #include <__functional/function.h> #include <__functional/hash.h> #include <__functional/identity.h> #include <__functional/invoke.h> #include <__functional/mem_fn.h> // TODO: deprecate #include <__functional/mem_fun_ref.h> #include <__functional/not_fn.h> #include <__functional/operations.h> #include <__functional/pointer_to_binary_function.h> #include <__functional/pointer_to_unary_function.h> #include <__functional/ranges_operations.h> #include <__functional/reference_wrapper.h> #include <__functional/unary_function.h> #include <__functional/unary_negate.h> #include <__type_traits/unwrap_ref.h> #include <__utility/forward.h> #include // TODO: find out why removing this breaks the modules build #include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header #endif #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 # include # include # include # include # include # include # include #endif #endif // _LIBCPP_FUNCTIONAL