I have written a metafunction to retrieve the type of the first parameter of a member function, which of course receives one or more parameters. The code I have written is as follow:
template <typename...> struct parameter;
template < typename O, typename A, typename R, typename... Args>
struct parameter <R (O::*)(A, Args...) > {
using first_param = A;
};
I use this meta function as follow:
using mem_fn = void(mem_type::*)(std::vector<int>);
using f_pm = parameter<mem_fn>::first_param;
and it compiles and works. But when I have a class:
struct mem_type{
void update(std::vector<int>) {
}
};
and use my metafunction as follow:
using mem_fn = decltype(mem_type::update);
using f_pm = parameter<mem_fn>::first_param;
the code does not compiles and visual studio 2013 gives: error C2027: use of undefined type parameter<mem_fn>
.
Does anyone knows the reason for this error?
using mem_fn = decltype(&mem_type::update);
work? I've seen similar issues in the past and being more explicit on the address has helped. Here to match your member function pointer specialisation. – Didiusing
support is flaky. Trytypedef
? Oh, and&mem_type::update
might also help. Bah, @Didi beat me to the 2nd one.mem_type::update
isn't a valid way to get a pointer to it: unlike functions, member functions to not auto-decay the same way. – Bushdecltype(&mem_type::update)
. – Marelya