I want to build a functon template that takes any function pointer & its arguments list - and returns a (stateful) lambda that binds those arguments values inside (think std::bind but lambda-based)
#include <iostream>
#include <vector>
template <class ...D>
class DEB;
template <class Ret, class ... Args>
auto getLambdaFromFunction(Ret(*func)(Args...)) {
return [func](Args ... ar){ // auto could work here but lambda is anyway templated by external template's Args
func(ar...);
};
}
template <class Ret, class ... Args>
auto wrapFunction(Ret(*func)(Args...),Args... args) {
return [=](){
func(args...);
};
}
int doone(int a, float b) {
std::cout << "do one";
return a;
}
int main() {
auto lw = getLambdaFromFunction(doone); // compiles
lw(1,2.); // invokation works
auto lambda_parameters_binded = wrapFunction(doone, 1,2.); // **ERROR**: no matching function for call
lambda_parameters_binded(); // see mom, no hands ie no arguments!
}
I believe I need to make somehow the variadic arguments to be captured inside the lambda in wrapFunction the default [=] capture seems not to understand variadic argument list