|
|
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Old binders and adaptors | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
Afunction object is any object for which the function call operator is defined. C++ provides many built-in function objects as well as support for creation and manipulation of new function objects.
Contents |
The exposition-only operation Let type
| (since C++11) |
std::invoke
andstd::invoke_r
(since C++23) can invoke anyCallable object with given arguments according to the rules ofINVOKE
andINVOKE<R>
(since C++23).
(C++17)(C++23) | invokes anyCallable object with given argumentsand possibility to specify return type(since C++23) (function template)[edit] |
These polymorphic wrapper classes provide support for storing arbitrary function objects.
(C++11) | copyable wrapper of any copy constructible callable object (class template)[edit] |
(C++23) | move-only wrapper of any callable object that supports qualifiers in a given call signature (class template)[edit] |
(C++26) | copyable wrapper of any copy constructible callable object that supports qualifiers in a given call signature (class template)[edit] |
(C++26) | non-owning wrapper of any callable object (class template)[edit] |
(C++11) | the exception thrown when invoking an emptystd::function (class)[edit] |
(C++11) | creates a function object out of a pointer to a member (function template)[edit] |
std::identity is the identity function object: it returns its argument unchanged.
(C++20) | function object that returns its argument unchanged (class)[edit] |
std::bind_front andstd::bind provide support forpartial function application, i.e. binding arguments to functions to produce new functions.
(C++20)(C++23) | bind a variable number of arguments, in order, to a function object (function template)[edit] |
(C++11) | binds one or more arguments to a function object (function template)[edit] |
(C++11) | indicates that an object isstd::bind expression or can be used as one(class template)[edit] |
(C++11) | indicates that an object is a standard placeholder or can be used as one (class template)[edit] |
Defined in namespace std::placeholders | |
(C++11) | placeholders for the unbound arguments in astd::bind expression(constant)[edit] |
std::not_fn creates a function object that negates the result of the callable object passed to it.
(C++17) | creates a function object that returns the complement of the result of the function object it holds (function template)[edit] |
Searchers implementing several string searching algorithms are provided and can be used either directly or withstd::search.
(C++17) | standard C++ library search algorithm implementation (class template)[edit] |
(C++17) | Boyer-Moore search algorithm implementation (class template)[edit] |
Boyer-Moore-Horspool search algorithm implementation (class template)[edit] |
Reference wrappers allow reference arguments to be stored in copyable function objects:
(C++11) | CopyConstructible andCopyAssignable reference wrapper (class template)[edit] |
(C++11)(C++11) | creates astd::reference_wrapper with a type deduced from its argument (function template)[edit] |
(C++20)(C++20) | get the reference type wrapped instd::reference_wrapper (class template)[edit] |
Transparent function objectsAssociative containers andunordered associative containers(since C++20) provide heterogeneous lookup and erasure(since C++23) operations, but they are only enabled if the supplied function object type All transparent function object types in the standard library define a nested type | (since C++14) |
C++ defines the following function objects that represent common arithmetic and logical operations.
Thevoid specializations deduce their parameter types and return types from their arguments, they are alltransparent. | (since C++14) |
Arithmetic operations | |
function object implementingx+ y (class template)[edit] | |
(C++14) | function object implementingx+ y deducing parameter and return types (class template specialization)[edit] |
function object implementingx- y (class template)[edit] | |
(C++14) | function object implementingx- y deducing parameter and return types (class template specialization)[edit] |
function object implementingx* y (class template)[edit] | |
(C++14) | function object implementingx* y deducing parameter and return types (class template specialization)[edit] |
function object implementingx/ y (class template)[edit] | |
(C++14) | function object implementingx/ y deducing parameter and return types (class template specialization)[edit] |
function object implementingx% y (class template)[edit] | |
(C++14) | function object implementingx% y deducing parameter and return types (class template specialization)[edit] |
function object implementing-x (class template)[edit] | |
(C++14) | function object implementing-x deducing parameter and return types (class template specialization)[edit] |
Comparisons | |
function object implementingx== y (class template)[edit] | |
(C++14) | function object implementingx== y deducing parameter and return types (class template specialization)[edit] |
function object implementingx!= y (class template)[edit] | |
(C++14) | function object implementingx!= y deducing parameter and return types (class template specialization)[edit] |
function object implementingx> y (class template)[edit] | |
(C++14) | function object implementingx> y deducing parameter and return types (class template specialization)[edit] |
function object implementingx< y (class template)[edit] | |
(C++14) | function object implementingx< y deducing parameter and return types (class template specialization)[edit] |
function object implementingx>= y (class template)[edit] | |
(C++14) | function object implementingx>= y deducing parameter and return types (class template specialization)[edit] |
function object implementingx<= y (class template)[edit] | |
(C++14) | function object implementingx<= y deducing parameter and return types (class template specialization)[edit] |
Logical operations | |
function object implementingx&& y (class template)[edit] | |
(C++14) | function object implementingx&& y deducing parameter and return types (class template specialization)[edit] |
function object implementingx|| y (class template)[edit] | |
(C++14) | function object implementingx|| y deducing parameter and return types (class template specialization)[edit] |
function object implementing!x (class template)[edit] | |
(C++14) | function object implementing!x deducing parameter and return types (class template specialization)[edit] |
Bitwise operations | |
function object implementingx& y (class template)[edit] | |
(C++14) | function object implementingx& y deducing parameter and return types (class template specialization)[edit] |
function object implementingx| y (class template)[edit] | |
(C++14) | function object implementingx| y deducing parameter and return types (class template specialization)[edit] |
function object implementingx^ y (class template)[edit] | |
(C++14) | function object implementingx^ y deducing parameter and return types (class template specialization)[edit] |
(C++14) | function object implementing~x (class template)[edit] |
(C++14) | function object implementing~x deducing parameter and return types (class template specialization)[edit] |
Constrained comparison function objectsThe following comparison function objects areconstrained.
All these function objects aretransparent.
| (since C++20) |
Helper itemsFollowing exposition-only items are used for several components in the standard library but they are not part of the interface of the standard library.
| (since C++26) |
Old binders and adaptorsSeveral utilities that provided early functional support are deprecated and removed:
| (until C++20) |
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR | Applied to | Behavior as published | Correct behavior |
---|---|---|---|
LWG 185 | C++98 | using function objects improved the program efficiency | removed the claim |
LWG 660 | C++98 | function objects for bitwise operations are missing | added |
LWG 2149 | C++98 | function objects taking one or two arguments were required to provide nested types to denote the argument and result types | not required |
LWG 2219 | C++11 | INVOKE did not handlestd::reference_wrapper correctly | handles correctly |
LWG 2420 | C++11 | INVOKE<R> did not discard the return value ifR isvoid | discards the return value in this case |
LWG 2926 (P0604R0) | C++11 | the syntax of theINVOKE operation with a returntype R wasINVOKE (f, t1, t2, ..., tN, R) | changed toINVOKE<R> (f, t1, t2, ..., tN) |
LWG 3655 | C++11 | INVOKE did not handle unions correctlydue to the resolution ofLWG issue 2219 | handles correctly |