The question is inspired by a note in the standard [class.mem]
The type of a non-static member function is an ordinary function type, and the type of a non-static data member is an ordinary object type. There are no special member function types or data member types.
So, I decided to test it
struct S
{
using Fn = void();
Fn foo;
static_assert(std::is_same_v<decltype(foo), Fn>);
};
But its an error at decltype(foo)
: invalid use of non-static member fucntion.
How do you get the type of a member function? Or is the note just bogus?
Note: It is valid to do this to data members
struct U
{
int i;
static_assert(std::is_same_v<decltype(i), int>);
};
Note2: I'm not looking for how to grab the type through a pointer-to-member
template<typename>
struct NotLikeThis;
template<typename C, typename R, typename... Args>
struct NotLikeThis<R (C::*)(Args...)>
{
using type = R(Args...);
};
The note from the standard is irrelevant to this.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…