Given a template function of the signature
template <typename F>
void fn(F f);
I would like to extract the parameter pack of the given function signature F
, if a callable function was given to fn()
.
Unlike in foo0()
I am not able to do this in foo1()
and foo2()
in the following example (simplified to a single parameter instead of a parameter pack):
#include <type_traits>
template <typename Sig> struct argument_of;
template <typename R, typename Arg> struct argument_of<R(Arg)> { typedef Arg type; };
void bar(int);
void foo0() {
static_assert(std::is_same<int, typename argument_of<decltype(bar)>::type>::value, "!");
}
template <typename F>
void foo1(F) {
static_assert(std::is_same<int, typename argument_of<F>::type>::value, "!");
}
template <typename F>
void foo2(F f) {
static_assert(std::is_same<int, typename argument_of<decltype(f)>::type>::value, "!");
}
int main() {
foo0();
foo1(bar);
foo2(bar);
}
See live example.
What would be the proper way if the calling style of fn()
remains as given for foo1()
and foo2()
in the example above?