I have a code where I can have the type of the lambda, but not its instance, and I want to call it
I tried the following, and obviously, it does not work because operator() is not a static member function...
#include <utility>
template<typename F, typename ...Args>
void call(F, Args&&... args) {
&F::operator()(std::forward<Args>(args)...);
}
int main() {
auto is_odd = [](auto x) {return x % 2 == 1;};
call(is_odd, 5);
}
I tried also to convert it to a function pointer using :
template<typename F, typename ...Args>
void call(F, Args&&... args) {
using return_type = decltype(std::declval<F>()(std::declval<Args&&>()...));
using ptr = return_type(*)(Args...);
ptr f = static_cast<ptr>(&F::operator());
f(std::forward<Args>()...);
}
But it does not work either. Is it possible to do something like that?