A Callable type is a type, for which the INVOKE operation, as defined by std::function, std::bind, or std::thread::thread is applicable. This operation may be performed explicitly using the library function std::invoke. (since C++17).
Requirements
The type T satisfies Callable if.
Given.
-
f, an object of typeTorconst T -
ArgTypes, suitable list of argument types -
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 static_cast<void>(INVOKE(f, t1, t2, ..., tN)) if R is possibly cv-qualified void, otherwise (since C++17) 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 classT:- If
std::is_base_of<T, std::decay_t<decltype(t1)>>::valueistrue, thenINVOKE(f, t1, t2, ..., tN)is equivalent to(t1.*f)(t2, ..., tN) - otherwise, if
std::decay_t<decltype(t1)>is a specialization ofstd::reference_wrapper, thenINVOKE(f, t1, t2, ..., tN)is equivalent to(t1.get().*f)(t2, ..., tN)(since C++17) - otherwise, if
t1does not satisfy the previous items, thenINVOKE(f, t1, t2, ..., tN)is equivalent to((*t1).*f)(t2, ..., tN).
- If
- otherwise, if N == 1 and
fis a pointer to data member of classT:- If
std::is_base_of<T, std::decay_t<decltype(t1)>>::valueistrue, thenINVOKE(f, t1)is equivalent tot1.*f - otherwise, if
std::decay_t<decltype(t1)>is a specialization ofstd::reference_wrapper, thenINVOKE(f, t1)is equivalent tot1.get().*f(since C++17) - otherwise, if
t1does not satisfy the previous items, thenINVOKE(f, t1)is equivalent to(*t1).*f
- If
- otherwise,
INVOKE(f, t1, t2, ..., tN)is equivalent tof(t1, t2, ..., tN)(that is,fis aFunctionObject)
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.
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 |
Please login to continue.