I\'m trying to create a function which can be called with a lambda that takes either 0, 1 or 2 arguments. Since I need the code to work on both g++ 4.5 and vs2010(which doe
I thought the following would work but it doesn't, I'm posting it for two reasons.
Code follows:
#include
#include
template
unsigned arity(std::function) { return 0; }
template
unsigned arity(std::function) { return 1; }
template
unsigned arity(std::function) { return 2; }
// rinse and repeat
int main()
{
std::function f = [](int i) { }; // this binds fine
// Error: no matching function for call to 'arity(main()::)'
std::cout << arity([](int i) { });
}