template<class... FreeArgs>
class Cgu::Callback::FunctorArg< FreeArgs >
Functor class holding a Callback::CallbackArg object.
- See also
- SafeFunctorArg
-
Callback namespace
This class wraps a CallbackArg object. The callback object is kept by SharedPtr so the functor can be copied and offers automatic lifetime management of the wrapped callback object, as well as providing an operator()() function. Ownership is taken of the CallbackArg object passed to the constructor taking a CallbackArg pointer, so that constructor should be treated like a shared pointer constructor - only pass a newly allocated object to it (or copy construct it or assign to it from another existing FunctorArg object). The template types are the types of the unbound arguments, if any. Callback::FunctorArg<> is typedef'ed to Callback::Functor.
The constructor taking a Callback::CallbackArg pointer is not marked explicit, so the results of Callback::lambda(), Callback::make() or Callback::make_ref() can be passed directly to a function taking a Callback::FunctorArg argument, and implicit conversion will take place.
Functor/FunctorArg classes do not provide for a return value. If a result is wanted, users should pass an unbound argument by reference or pointer (or pointer to pointer).
Usage
These are examples:
f1();
f2();
int res;
f3(2, res);
std::cout << "10 times 2 is " << res << '\n';
For further background, including about the Callback::make(), Callback::make_ref() and Callback::to_functor() functions, read this: Callback
template<class... FreeArgs>
This will execute the function, callable object or class method represented by the callback encapsulated by this object, or do nothing if this object has not been initialized with a callback. It will only throw if the executed function, callable object or class method throws, or if the copy constructor of a free or bound argument throws and it is not a reference argument. It is thread safe if the referenced function or class method is thread safe.
- Parameters
-
args | The unbound arguments to be passed to the referenced function, callable object or class method, if any. |