Single header container for lambdas with (or without) move-only encapsulation that can be invoked only once.
The topic of this repository is to address the need to store lambdas in containers (such as vectors). The generic way you are expected to do this is in std::function. However, std::function
requires the encapsulated contents to be copy constructable. This is easy to imagine from the above struct: encapsulations sometimes cause issue! If you have members that are not copiable, then you cannot use std::function
even though contents are movable. This is the need we are trying to address in flexInvokable
. You can store your lambdas in move-only containers.
Example is shown in test/src/example.cpp
.
Add flexInvokable/include/flexInvokable.hpp to your project.
Originally found as an answer to the request in stackoverflow.
I had to make slight changes from source demo
void(*invoke)(void*, Args...) = nullptr;
to
R(*invoke)(void*, Args...) = nullptr;
Moreover,
std::result_of_t<std::decay_t<F>&(Args...)>
is getting deprecated, and therefore replaced to
#if _HAS_CXX17
std::invoke_result_t<F, Args...>
#else
std::result_of_t<std::decay_t<F>&(Args...)>
#endif