I have an overload function, with the following signatures:
void Foo(const std::function<void(int )> &func); void Foo(const std::function<void(int, int)> &func); And when I want to use Foo() with lambdas, I'll have to do something like this:
Foo((std::function<void(int )>) [] (int i ) { /* do something */ }); Foo((std::function<void(int, int)>) [] (int i, int j) { /* do something */ }); Both of which are not so user-friendly. It'd be a lot easier to use the function without having to add the casting "(std::function<...>)" before the lambdas - like this:
Foo([] (int i ) { /* do something */ }); // executes the 1st Foo() Foo([] (int i, int j) { /* do something */ }); // executes the 2nd Foo() So, I need another overload, that accept lambda as its argument, and which automatically casts the lambda to one of the above signatures. How can this be done? Or, is it possible in the first place?
template <typename Function> void Foo(Function function) { // insert code here: should be something like // - check the signature of the 'function'; and // - call 'Foo()' corresponding to the signature } Please help.
PS. I'm using VS2010.