I’m now using this code:
size_t argc(std::function<Foo()>)
{ return 0; }
size_t argc(std::function<Foo(Bar)>)
{ return 1; }
size_t argc(std::function<Foo(Bar, Bar)>)
{ return 2; }
size_t argc(std::function<Foo(Bar, Bar, Bar)>)
{ return 3; }
// ...
But it is kinda ugly and limited (the user can’t call argc with a function with any number of arguments.) Is there a better way to do it?
Note: the return type and the argument type are always the same. I know I can use templates to accept any type, but I don’t need it.
Cleaner version of @Paolo’s answer, usable with actual objects: