33 lines
10 KiB
Markdown
33 lines
10 KiB
Markdown
[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.5 invoke 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.6 Class 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.8 common_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.7 Arithmetic 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.8 Comparisons"), 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.8 Class compare_three_way"), class compare_three_waystruct compare_three_way; // freestanding// [[logical.operations]](logical.operations "22.10.10 Logical 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.11 Bitwise 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.12 Class identity"), identitystruct identity; // freestanding// [[func.not.fn]](func.not.fn "22.10.13 Function 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.14 Function 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.15 Function 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.2 Header <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.2 Header <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.16 Function template mem_fn"), member function adaptorstemplate<class R, class T>constexpr *unspecified* mem_fn(R T::*) noexcept; // freestanding// [[func.wrap]](func.wrap "22.10.17 Polymorphic function wrappers"), polymorphic function wrappers// [[func.wrap.badcall]](func.wrap.badcall "22.10.17.2 Class bad_function_call"), class bad_function_callclass bad_function_call; // [[func.wrap.func]](func.wrap.func "22.10.17.3 Class 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.8 Specialized 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.7 Null 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.4 Move-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.5 Copyable 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.6 Non-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.18 Searchers"), 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.19 Class template hash"), class template hashtemplate<class T>struct hash; // freestandingnamespace ranges {// [[range.cmp]](range.cmp "22.10.9 Concept-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.2 Header <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.2 Header <functional> synopsis [functional.syn]") = // *exposition only*[*callable*](#concept:callable "22.10.2 Header <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*]
|