Difference between revisions of "cpp/named req/Callable"
From cppreference.com
(Removed the definition of 'INVOKE', it is in cpp/utility/functional now, applied {{lti}} to create links to the definition.) |
Andreas Krug (Talk | contribs) m (fmt, .) |
||
Line 17: | Line 17: | ||
Given | Given | ||
− | * {{tt|f}}, an object of type {{tt|T}} | + | * {{tt|f}}, an object of type {{tt|T}}, |
− | * {{tt|ArgTypes}}, suitable list of argument types | + | * {{tt|ArgTypes}}, suitable list of argument types, |
− | * {{tt|R}}, suitable return type | + | * {{tt|R}}, suitable return type. |
The following expressions must be valid: | The following expressions must be valid: | ||
Line 27: | Line 27: | ||
!Expression||Requirements | !Expression||Requirements | ||
|- | |- | ||
− | | {{box|{{lti|cpp/utility/functional|INVOKE<R>}}{{c/core|(f, std::declval<ArgTypes>()...)}}}} | + | |{{box|{{lti|cpp/utility/functional|INVOKE<R>}}{{c/core|(f, std::declval<ArgTypes>()...)}}}} |
− | | | + | |The expression is well-formed in unevaluated context. |
|} | |} | ||
Revision as of 11:35, 9 August 2023
A Callable type is a type for which the INVOKE and INVOKE<R> operations (used by, e.g., std::function, std::bind, and std::thread::thread) are applicable.
|
(since C++17) |
|
(since C++23) |
Contents |
Requirements
The type T
satisfies Callable if
Given
-
f
, an object of typeT
, -
ArgTypes
, suitable list of argument types, -
R
, suitable return type.
The following expressions must be valid:
Expression | Requirements |
---|---|
INVOKE<R>(f, std::declval<ArgTypes>()...) | The expression is well-formed in unevaluated context. |
Notes
Pointers to data members are Callable, even though no function calls take place.
Standard library
In addition, the following standard library facilities accept any Callable type (not just FunctionObject):
(C++11) |
copyable wrapper of any copy constructible callable object (class template) |
(C++23) |
move-only wrapper of any callable object that supports qualifiers in a given call signature (class template) |
(C++11) |
binds one or more arguments to a function object (function template) |
(C++20)(C++23) |
bind a variable number of arguments, in order, to a function object (function template) |
(C++11) |
CopyConstructible and CopyAssignable reference wrapper (class template) |
(C++11)(removed in C++20)(C++17) |
deduces the result type of invoking a callable object with a set of arguments (class template) |
(C++11) |
manages a separate thread (class) |
(C++20) |
std::thread with support for auto-joining and cancellation (class) |
(C++11) |
invokes a function only once even if called from multiple threads (function template) |
(C++11) |
runs a function asynchronously (potentially in a new thread) and returns a std::future that will hold the result (function template) |
(C++11) |
packages a function to store its return value for asynchronous retrieval (class template) |
See also
checks if a type can be invoked (as if by std::invoke) with the given argument types (class template) | |
(C++20) |
specifies that a callable type can be invoked with a given set of argument types (concept) |
(C++17)(C++23) |
invokes any Callable object with given arguments and possibility to specify return type(since C++23) (function template) |