Basically, what I want to do is take a lambda with any number of parameters of any type and convert it to std :: function. I tried the following and none of the methods work.
std::function([](){});//Complains that std::function is missing template parameters template <typename T> void foo(function<T> f){} foo([](){});//Complains that it cannot find a matching candidate
The following code really works, but this is not what I want, because it requires explicitly specifying template parameters that do not work for general code.
std::function<void()>([](){});
I've been hanging around with features and templates all day, and I just can't figure it out, so any help would be greatly appreciated.
As mentioned in the comment, the reason I am trying to do this is because I am trying to implement currying in C ++ using variable templates. Unfortunately this fails with lambda. For example, I can pass a standard function using a function pointer.
template <typename R, typename...A> void foo(R (*f)(A...)) {} void bar() {} int main() { foo(bar); }
However, I cannot figure out how to pass lambda to such a variational function. Why am I interested in converting a common lambda to a std :: function, because I can do the following, but ultimately it requires me to explicitly specify the template parameters in std :: function, which I am trying to avoid.
template <typename R, typename...A> void foo(std::function<R(A...)>) {} int main() { foo(std::function<void()>([](){})); }
c ++ function lambda c ++ 11 templates
retep998 Nov 13 '12 at 9:59 2012-11-13 09:59
source share