This is a follow up of this problem: Generic functor for functions with any argument list
I have this functor class (full code see link above):
template<typename... ARGS>
class Foo
{
std::function<void(ARGS...)> m_f;
public:
Foo( std::function<void(ARGS...)> f ) : m_f(f) {}
void operator()(ARGS... args) const { m_f(args...); }
};
In operator() I can access the args... easily with a recursive "peeling" function as described here http://www2.research.att.com/~bs/C++0xFAQ.html#variadic-templates
My problem is: I want to access the types of the arguments of f, i.e. ARGS..., in the constructor. Obviously I can't access values because there are none so far, but the argument type list is somehow burried in f, isn't it?
You can write
function_traits
class as shown below, to discover the argument types, return type, and number of arguments:Test code:
Demo : http://ideone.com/YeN29