The question is based on a note in the standard [class.mem]
The type of a non-static member function is a regular type of function, and the type of a non-static data element is a regular type of object. There are no special types of member functions or types of data items.
So, I decided to check it out
struct S { using Fn = void(); Fn foo; static_assert(std::is_same_v<decltype(foo), Fn>); };
But its error in decltype(foo) : invalid use of a non-static member.
How do you get the type of a member function? Or is the note simply fictitious?
Note. This must be done for data members.
struct U { int i; static_assert(std::is_same_v<decltype(i), int>); };
Note2: I am not looking for how to capture a type using an element pointer
template<typename> struct NotLikeThis; template<typename C, typename R, typename... Args> struct NotLikeThis<R (C::*)(Args...)> { using type = R(Args...); };
A note of the standard does not apply to this.
c ++ language-lawyer
Passer by
source share