[functional.syn] # 22 General utilities library [[utilities]](./#utilities) ## 22.10 Function objects [[function.objects]](function.objects#functional.syn) ### 22.10.2 Header synopsis [functional.syn] [🔗](#header:%3cfunctional%3e) namespace std {// [[func.invoke]](func.invoke "22.10.5 invoke functions"), invoketemplateconstexpr invoke_result_t invoke(F&& f, Args&&... args) // freestandingnoexcept(is_nothrow_invocable_v); templateconstexpr R invoke_r(F&& f, Args&&... args) // freestandingnoexcept(is_nothrow_invocable_r_v); // [[refwrap]](refwrap "22.10.6 Class template reference_­wrapper"), reference_wrappertemplate class reference_wrapper; // freestandingtemplate constexpr reference_wrapper ref(T&) noexcept; // freestandingtemplate constexpr reference_wrapper cref(const T&) noexcept; // freestandingtemplate void ref(const T&&) = delete; // freestandingtemplate void cref(const T&&) = delete; // freestandingtemplateconstexpr reference_wrapper ref(reference_wrapper) noexcept; // freestandingtemplateconstexpr reference_wrapper cref(reference_wrapper) noexcept; // freestanding// [[refwrap.common.ref]](refwrap.common.ref "22.10.6.8 common_­reference related specializations"), common_reference related specializationstemplate class RQual, template class TQual>requires *see below*struct basic_common_reference; template class TQual, template class RQual>requires *see below*struct basic_common_reference; // [[arithmetic.operations]](arithmetic.operations "22.10.7 Arithmetic operations"), arithmetic operationstemplate struct plus; // freestandingtemplate struct minus; // freestandingtemplate struct multiplies; // freestandingtemplate struct divides; // freestandingtemplate struct modulus; // freestandingtemplate struct negate; // freestandingtemplate<> struct plus; // freestandingtemplate<> struct minus; // freestandingtemplate<> struct multiplies; // freestandingtemplate<> struct divides; // freestandingtemplate<> struct modulus; // freestandingtemplate<> struct negate; // freestanding// [[comparisons]](comparisons "22.10.8 Comparisons"), comparisonstemplate struct equal_to; // freestandingtemplate struct not_equal_to; // freestandingtemplate struct greater; // freestandingtemplate struct less; // freestandingtemplate struct greater_equal; // freestandingtemplate struct less_equal; // freestandingtemplate<> struct equal_to; // freestandingtemplate<> struct not_equal_to; // freestandingtemplate<> struct greater; // freestandingtemplate<> struct less; // freestandingtemplate<> struct greater_equal; // freestandingtemplate<> struct less_equal; // 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 struct logical_and; // freestandingtemplate struct logical_or; // freestandingtemplate struct logical_not; // freestandingtemplate<> struct logical_and; // freestandingtemplate<> struct logical_or; // freestandingtemplate<> struct logical_not; // freestanding// [[bitwise.operations]](bitwise.operations "22.10.11 Bitwise operations"), bitwise operationstemplate struct bit_and; // freestandingtemplate struct bit_or; // freestandingtemplate struct bit_xor; // freestandingtemplate struct bit_not; // freestandingtemplate<> struct bit_and; // freestandingtemplate<> struct bit_or; // freestandingtemplate<> struct bit_xor; // freestandingtemplate<> struct bit_not; // 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 constexpr *unspecified* not_fn(F&& f); // freestandingtemplate 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_backtemplateconstexpr *unspecified* bind_front(F&&, Args&&...); // freestandingtemplateconstexpr *unspecified* bind_front(Args&&...); // freestandingtemplateconstexpr *unspecified* bind_back(F&&, Args&&...); // freestandingtemplateconstexpr *unspecified* bind_back(Args&&...); // freestanding// [[func.bind]](func.bind "22.10.15 Function object binders"), bindtemplate struct is_bind_expression; // freestandingtemplateconstexpr bool [is_bind_expression_v](#lib:is_bind_expression_v "22.10.2 Header synopsis [functional.syn]") = // freestanding is_bind_expression::value; template struct is_placeholder; // freestandingtemplateconstexpr int [is_placeholder_v](#lib:is_placeholder_v "22.10.2 Header synopsis [functional.syn]") = // freestanding is_placeholder::value; templateconstexpr *unspecified* bind(F&&, BoundArgs&&...); // freestandingtemplateconstexpr *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 adaptorstemplateconstexpr *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 function; // *not defined*template class function; // [[func.wrap.func.alg]](func.wrap.func.alg "22.10.17.3.8 Specialized algorithms"), function specialized algorithmstemplatevoid swap(function&, function&) noexcept; // [[func.wrap.func.nullptr]](func.wrap.func.nullptr "22.10.17.3.7 Null pointer comparison operator functions"), function null pointer comparison operator functionstemplatebool operator==(const function&, nullptr_t) noexcept; // [[func.wrap.move]](func.wrap.move "22.10.17.4 Move-only wrapper"), move-only wrappertemplate class move_only_function; // *not defined*templateclass move_only_function; // *see below*// [[func.wrap.copy]](func.wrap.copy "22.10.17.5 Copyable wrapper"), copyable wrappertemplate class copyable_function; // *not defined*templateclass copyable_function; // *see below*// [[func.wrap.ref]](func.wrap.ref "22.10.17.6 Non-owning wrapper"), non-owning wrappertemplate class function_ref; // freestanding, *not defined*templateclass function_ref; // freestanding, *see below*// [[func.search]](func.search "22.10.18 Searchers"), searcherstemplate>class default_searcher; // freestandingtemplate::value_type>, class BinaryPredicate = equal_to<>>class boyer_moore_searcher; template::value_type>, class BinaryPredicate = equal_to<>>class boyer_moore_horspool_searcher; // [[unord.hash]](unord.hash "22.10.19 Class template hash"), class template hashtemplatestruct 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}templateconcept [*callable*](#concept:callable "22.10.2 Header synopsis [functional.syn]") = // *exposition only*requires (Fn&& fn, Args&&... args) { std::forward(fn)(std::forward(args)...); }; templateconcept [*nothrow-callable*](#concept:nothrow-callable "22.10.2 Header synopsis [functional.syn]") = // *exposition only*[*callable*](#concept:callable "22.10.2 Header synopsis [functional.syn]") &&requires (Fn&& fn, Args&&... args) {{ std::forward(fn)(std::forward(args)...) } noexcept; }; templateusing *call-result-t* = decltype(declval()(declval()...)); // *exposition only*templateusing *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()); — *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()); — *end example*]