Files
2025-10-25 03:02:53 +03:00

33 lines
10 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[functional.syn]
# 22 General utilities library [[utilities]](./#utilities)
## 22.10 Function objects [[function.objects]](function.objects#functional.syn)
### 22.10.2 Header <functional> synopsis [functional.syn]
[🔗](#header:%3cfunctional%3e)
namespace std {// [[func.invoke]](func.invoke "22.10.5invoke functions"), invoketemplate<class F, class... Args>constexpr invoke_result_t<F, Args...> invoke(F&& f, Args&&... args) // freestandingnoexcept(is_nothrow_invocable_v<F, Args...>); template<class R, class F, class... Args>constexpr R invoke_r(F&& f, Args&&... args) // freestandingnoexcept(is_nothrow_invocable_r_v<R, F, Args...>); // [[refwrap]](refwrap "22.10.6Class template reference_­wrapper"), reference_wrappertemplate<class T> class reference_wrapper; // freestandingtemplate<class T> constexpr reference_wrapper<T> ref(T&) noexcept; // freestandingtemplate<class T> constexpr reference_wrapper<const T> cref(const T&) noexcept; // freestandingtemplate<class T> void ref(const T&&) = delete; // freestandingtemplate<class T> void cref(const T&&) = delete; // freestandingtemplate<class T>constexpr reference_wrapper<T> ref(reference_wrapper<T>) noexcept; // freestandingtemplate<class T>constexpr reference_wrapper<const T> cref(reference_wrapper<T>) noexcept; // freestanding// [[refwrap.common.ref]](refwrap.common.ref "22.10.6.8common_­reference related specializations"), common_reference related specializationstemplate<class R, class T, template<class> class RQual, template<class> class TQual>requires *see below*struct basic_common_reference<R, T, RQual, TQual>; template<class T, class R, template<class> class TQual, template<class> class RQual>requires *see below*struct basic_common_reference<T, R, TQual, RQual>; // [[arithmetic.operations]](arithmetic.operations "22.10.7Arithmetic operations"), arithmetic operationstemplate<class T = void> struct plus; // freestandingtemplate<class T = void> struct minus; // freestandingtemplate<class T = void> struct multiplies; // freestandingtemplate<class T = void> struct divides; // freestandingtemplate<class T = void> struct modulus; // freestandingtemplate<class T = void> struct negate; // freestandingtemplate<> struct plus<void>; // freestandingtemplate<> struct minus<void>; // freestandingtemplate<> struct multiplies<void>; // freestandingtemplate<> struct divides<void>; // freestandingtemplate<> struct modulus<void>; // freestandingtemplate<> struct negate<void>; // freestanding// [[comparisons]](comparisons "22.10.8Comparisons"), comparisonstemplate<class T = void> struct equal_to; // freestandingtemplate<class T = void> struct not_equal_to; // freestandingtemplate<class T = void> struct greater; // freestandingtemplate<class T = void> struct less; // freestandingtemplate<class T = void> struct greater_equal; // freestandingtemplate<class T = void> struct less_equal; // freestandingtemplate<> struct equal_to<void>; // freestandingtemplate<> struct not_equal_to<void>; // freestandingtemplate<> struct greater<void>; // freestandingtemplate<> struct less<void>; // freestandingtemplate<> struct greater_equal<void>; // freestandingtemplate<> struct less_equal<void>; // freestanding// [[comparisons.three.way]](comparisons.three.way "22.10.8.8Class compare_­three_­way"), class compare_three_waystruct compare_three_way; // freestanding// [[logical.operations]](logical.operations "22.10.10Logical operations"), logical operationstemplate<class T = void> struct logical_and; // freestandingtemplate<class T = void> struct logical_or; // freestandingtemplate<class T = void> struct logical_not; // freestandingtemplate<> struct logical_and<void>; // freestandingtemplate<> struct logical_or<void>; // freestandingtemplate<> struct logical_not<void>; // freestanding// [[bitwise.operations]](bitwise.operations "22.10.11Bitwise operations"), bitwise operationstemplate<class T = void> struct bit_and; // freestandingtemplate<class T = void> struct bit_or; // freestandingtemplate<class T = void> struct bit_xor; // freestandingtemplate<class T = void> struct bit_not; // freestandingtemplate<> struct bit_and<void>; // freestandingtemplate<> struct bit_or<void>; // freestandingtemplate<> struct bit_xor<void>; // freestandingtemplate<> struct bit_not<void>; // freestanding// [[func.identity]](func.identity "22.10.12Class identity"), identitystruct identity; // freestanding// [[func.not.fn]](func.not.fn "22.10.13Function template not_­fn"), function template not_fntemplate<class F> constexpr *unspecified* not_fn(F&& f); // freestandingtemplate<auto f> constexpr *unspecified* not_fn() noexcept; // freestanding// [[func.bind.partial]](func.bind.partial "22.10.14Function templates bind_­front and bind_­back"), function templates bind_front and bind_backtemplate<class F, class... Args>constexpr *unspecified* bind_front(F&&, Args&&...); // freestandingtemplate<auto f, class... Args>constexpr *unspecified* bind_front(Args&&...); // freestandingtemplate<class F, class... Args>constexpr *unspecified* bind_back(F&&, Args&&...); // freestandingtemplate<auto f, class... Args>constexpr *unspecified* bind_back(Args&&...); // freestanding// [[func.bind]](func.bind "22.10.15Function object binders"), bindtemplate<class T> struct is_bind_expression; // freestandingtemplate<class T>constexpr bool [is_bind_expression_v](#lib:is_bind_expression_v "22.10.2Header <functional> synopsis[functional.syn]") = // freestanding is_bind_expression<T>::value; template<class T> struct is_placeholder; // freestandingtemplate<class T>constexpr int [is_placeholder_v](#lib:is_placeholder_v "22.10.2Header <functional> synopsis[functional.syn]") = // freestanding is_placeholder<T>::value; template<class F, class... BoundArgs>constexpr *unspecified* bind(F&&, BoundArgs&&...); // freestandingtemplate<class R, class F, class... BoundArgs>constexpr *unspecified* bind(F&&, BoundArgs&&...); // freestandingnamespace placeholders {// *M* is the implementation-defined number of placeholders*see below* _1; // freestanding*see below* _2; // freestanding ⋮ *see below* _*M*; // freestanding}// [[func.memfn]](func.memfn "22.10.16Function template mem_­fn"), member function adaptorstemplate<class R, class T>constexpr *unspecified* mem_fn(R T::*) noexcept; // freestanding// [[func.wrap]](func.wrap "22.10.17Polymorphic function wrappers"), polymorphic function wrappers// [[func.wrap.badcall]](func.wrap.badcall "22.10.17.2Class bad_­function_­call"), class bad_function_callclass bad_function_call; // [[func.wrap.func]](func.wrap.func "22.10.17.3Class template function"), class template functiontemplate<class> class function; // *not defined*template<class R, class... ArgTypes> class function<R(ArgTypes...)>; // [[func.wrap.func.alg]](func.wrap.func.alg "22.10.17.3.8Specialized algorithms"), function specialized algorithmstemplate<class R, class... ArgTypes>void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept; // [[func.wrap.func.nullptr]](func.wrap.func.nullptr "22.10.17.3.7Null pointer comparison operator functions"), function null pointer comparison operator functionstemplate<class R, class... ArgTypes>bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept; // [[func.wrap.move]](func.wrap.move "22.10.17.4Move-only wrapper"), move-only wrappertemplate<class... S> class move_only_function; // *not defined*template<class R, class... ArgTypes>class move_only_function<R(ArgTypes...) cv *ref* noexcept(*noex*)>; // *see below*// [[func.wrap.copy]](func.wrap.copy "22.10.17.5Copyable wrapper"), copyable wrappertemplate<class... S> class copyable_function; // *not defined*template<class R, class... ArgTypes>class copyable_function<R(ArgTypes...) cv *ref* noexcept(*noex*)>; // *see below*// [[func.wrap.ref]](func.wrap.ref "22.10.17.6Non-owning wrapper"), non-owning wrappertemplate<class... S> class function_ref; // freestanding, *not defined*template<class R, class... ArgTypes>class function_ref<R(ArgTypes...) cv noexcept(*noex*)>; // freestanding, *see below*// [[func.search]](func.search "22.10.18Searchers"), searcherstemplate<class ForwardIterator1, class BinaryPredicate = equal_to<>>class default_searcher; // freestandingtemplate<class RandomAccessIterator, class Hash = hash<typename iterator_traits<RandomAccessIterator>::value_type>, class BinaryPredicate = equal_to<>>class boyer_moore_searcher; template<class RandomAccessIterator, class Hash = hash<typename iterator_traits<RandomAccessIterator>::value_type>, class BinaryPredicate = equal_to<>>class boyer_moore_horspool_searcher; // [[unord.hash]](unord.hash "22.10.19Class template hash"), class template hashtemplate<class T>struct hash; // freestandingnamespace ranges {// [[range.cmp]](range.cmp "22.10.9Concept-constrained comparisons"), concept-constrained comparisonsstruct equal_to; // freestandingstruct not_equal_to; // freestandingstruct greater; // freestandingstruct less; // freestandingstruct greater_equal; // freestandingstruct less_equal; // freestanding}template<class Fn, class... Args>concept [*callable*](#concept:callable "22.10.2Header <functional> synopsis[functional.syn]") = // *exposition only*requires (Fn&& fn, Args&&... args) { std::forward<Fn>(fn)(std::forward<Args>(args)...); }; template<class Fn, class... Args>concept [*nothrow-callable*](#concept:nothrow-callable "22.10.2Header <functional> synopsis[functional.syn]") = // *exposition only*[*callable*](#concept:callable "22.10.2Header <functional> synopsis[functional.syn]")<Fn, Args...> &&requires (Fn&& fn, Args&&... args) {{ std::forward<Fn>(fn)(std::forward<Args>(args)...) } noexcept; }; template<class Fn, class... Args>using *call-result-t* = decltype(declval<Fn>()(declval<Args>()...)); // *exposition only*template<const auto& T>using *decayed-typeof* = decltype(auto(T)); // *exposition only*}
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L11443)
[*Example [1](#example-1)*:
If a C++ program wants to have a by-element addition of two vectors a and b containing double and put the result into a,
it can do:transform(a.begin(), a.end(), b.begin(), a.begin(), plus<double>());
— *end example*]
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L11453)
[*Example [2](#example-2)*:
To negate every element of a:
transform(a.begin(), a.end(), a.begin(), negate<double>()); — *end example*]