I understand how to declare a function type:
typedef void (typedef_void_f)();
using alias_void_f = void();
And it can be used to declare function pointers:
void function() { std::cout << __PRETTY_FUNCTION__ << '\n'; }
typedef_void_f *a = function;
alias_void_f *b = function;
For member function pointers, the syntax is slightly more complex:
struct S { void function() { std::cout << __PRETTY_FUNCTION__ << '\n'; } };
typedef void (S::*typedef_void_m_f)();
using alias_void_m_f = void (S::*)();
typedef_void_m_f c = &S::function;
alias_void_m_f d = &S::function;
This is my understanding of function pointers in C ++, and I thought that was enough.
But in technical document p0172r0, I found a syntax that I don't know:
struct host {
int function() const;
};
template <typename TYPE>
constexpr bool test(TYPE host::*) {
return is_same_v<TYPE, int() const>;
}
constexpr auto member = &host::function;
test(member);
As I understand the code, the function testbreaks the type of the function into the type of the object to which the function belongs, so there will be a template testparameter in the template, but if I try the following:TYPEvoid()
void my_test(void() S::*) {}
my_test(&S::function);
I get a bunch of syntax errors:
error: variable or field 'my_test' declared void
void my_test(void() S::*) {}
^
error: expected ')' before 'S'
void my_test(void() S::*) {}
^
error: 'my_test' was not declared in this scope
my_test(&S::function);
So, it is obvious that I do not understand the syntax of the function p0172r0 test.
Can someone explain the details of the syntax template <typename TYPE> constexpr bool test(TYPE host::*)?