I am referring to a possible implementation of std::is_member_function_pointer here.
template< class T >
struct is_member_function_pointer_helper : std::false_type {};
template< class T, class U>
struct is_member_function_pointer_helper<T U::*> : std::is_function<T> {};
template< class T >
struct is_member_function_pointer : is_member_function_pointer_helper< std::remove_cv_t<T> >
#include <type_traits>
class A {
public:
void member() { }
};
int main()
{
// fails at compile time if A::member is a data member and not a function
static_assert(std::is_member_function_pointer<decltype(&A::member)>::value,
"A::member is not a member function.");
}
I know that
"dectype(&A::member)"
will be
"void (A::*)()"
But I dont understand what type T and type U map to in "void (A::*)()"?
The pattern void (A::*)() decomposes into T U::* where U is A and T is void ().
You can see the construction in inverse, like this:
struct A {};
using T = void ();
using U = A;
template <typename> struct print;
int main() {
print<T U::*>{};
// error: implicit instantiation of undefined template 'print<void (A::*)()>'
}
So the T as void () is passed to std::is_function which determines whether the given type is a function type.
In the case of pointer to data members, this fails because the deduced T is going to be a non-function type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With