|
template<typename Callable > |
| Function (Callable &&callable) |
| Constructs a Function from a Callable object. More...
|
|
bool | empty () const |
| Checks if the object is empty (No callable assigned)
|
|
template<typename... Args> |
SimpleAny< ReturnStorage > | operator() (Args &&...args) |
| Invokes the callable with the given arguments. More...
|
|
template<typename... Args> |
SimpleAny< ReturnStorage > | operator() (Args &&...args) const |
| Invokes the callable with the given arguments. More...
|
|
template<typename ArgsVector > |
SimpleAny< ReturnStorage > | invoke (ArgsVector &&args) |
| Invokes the callable with the given arguments The arguments are passed as a vector of SimpleAny. More...
|
|
template<typename ArgsVector > |
SimpleAny< ReturnStorage > | invoke (ArgsVector &&args) const |
| Invokes the callable with the given arguments The arguments are passed as a vector of SimpleAny. More...
|
|
SimpleAny< ReturnStorage > | invoke (AnyArg *args) |
| Invokes the callable with the given arguments The arguments are passed as a vector of SimpleAny. More...
|
|
SimpleAny< ReturnStorage > | invoke (AnyArg *args) const |
| Invokes the callable with the given arguments The arguments are passed as a vector of SimpleAny. More...
|
|
template<typename Callable > |
Function & | operator= (Callable &&callable) |
| Assigns a new callable to the function.
|
|
cpp::FunctionKind | kind () const |
| Returns the function kind (free function, pointer to member function, functor, etc) of the callable.
|
|
template<typename Storage, typename ArgsStorage = Storage, typename ReturnStorage = Storage>
class cpp::typeerasure::Function< Storage, ArgsStorage, ReturnStorage >
Stores a type-erased callable of any signature and kind.
The Function class goes one step beyond std::function
and provides a unique class to store any kind of C++ callable object
class MyClass
{
public:
int method(const std::vector<int>&);
};
void freeFunction(int i);
MyClass object;
std::vector<Function> functions = {
&MyClass::method,
[](int i, const std::string& str) {
return std::to_string(i) + str;
},
freeFunction
};
int i = functions[0](object, std::vector<int>{1, 2, 3, 4});
const std::string& str = functions[1](42, "hello");
functions[3](42);
Invoking a Function objects with the wrong arguments has undefined behavior
- Template Parameters
-
Storage | Storage for the hosted callable |
ArgsStorage | Storage for type-erased call arguments |
ReturnStorage | Storage for the return value |
template<typename Storage , typename ArgsStorage = Storage, typename ReturnStorage = Storage>
template<typename Callable >
Constructs a Function from a Callable object.
This constructor takes any kind of callable and stores it in a Function. The behavior is undefined if Function is initialized with a type that is not callable.
- Parameters
-
callable | Callable entity to store. Could be a function pointer, a member function pointer, a lambda expression, etc. |
template<typename Storage , typename ArgsStorage = Storage, typename ReturnStorage = Storage>
template<typename... Args>
Invokes the callable with the given arguments.
The behavior is undefined if the arguments don't match the underlying callable signature
- Parameters
-
args | function arguments. If the underlying callable is a pointer to to member function, the first argument is assumed to be the caller object |
- Returns
- the return value of the callable as in
cpp::invoke(<underlying callable>, std::forward(args)...)
template<typename Storage , typename ArgsStorage = Storage, typename ReturnStorage = Storage>
template<typename... Args>
Invokes the callable with the given arguments.
The behavior is undefined if the arguments don't match the underlying callable signature
- Parameters
-
args | function arguments. If the underlying callable is a pointer to to member function, the first argument is assumed to be the caller object |
- Returns
- the return value of the callable as in
cpp::invoke(<underlying callable>, std::forward(args)...)