C++ concepts: Callable
A Callable type is a type, for which the INVOKE operation, as defined by std::function, std::bind, or std::thread::thread is applicable.
[edit] Requirements
The type T satisfies Callable if
Given
-
f, an object of typeTorconst T -
ArgTypes, suitable argument list -
R, suitable return type
The following expressions must be valid:
| Expression | Requirements |
|---|---|
| INVOKE(f, std::declval<ArgTypes>..., R) | the expression is well-formed in unevaluated context |
where INVOKE(f, t1, t2, ..., tn, R) is defined as INVOKE(f, t1, t2, ..., tn), implicitly converted to R
where INVOKE(f, t1, t2, ..., tn) is defined as follows:
- if
fis a pointer to member function of classTandt1is an object of classTor reference to an object of classTor derived fromT, then INVOKE(f, t1, t2, ..., tn) is equivalent to (t1.*f)(t2, ..., tn) - otherwise, if
fis a pointer to member function andt1is not one of the types described above, then INVOKE(f, t1, t2, ..., tn) is equivalent to ((*t1).*f)(t2, ..., tn) - otherwise, if N == 1 and
fis a pointer to data member of classTandt1is an object of classTor reference to an object of classTor derived fromT, then INVOKE(f, t1) is equivalent to t1.*f - otherwise, if N == 1 and
fis a pointer to data member of classTandt1is not one of the types described above, then INVOKE(f, t1) is equivalent to (*t1).*f - otherwise, INVOKE(f, t1, t2, ..., tn) is equivalent to f(t1, t2, ..., tn) (that is,
fis aFunctionObject)
[edit] Notes
For pointers to member functions and pointers to data members, t1 may be a regular pointer or an object of class type that overloads operator*, such as std::unique_ptr or std::shared_ptr.
Pointers to data members are Callable, even though no function calls take place.
[edit] Standard library
In addition, the following standard library facilities accept any Callable type (not just FunctionObject)
| std::function | |
| std::bind | |
| std::result_of | |
| std::thread::thread | |
| std::call_once | |
| std::async | |
| std::packaged_task | |
| std::reference_wrapper |