Strange pointer to member function syntax

I understand how to declare a function type:

typedef void (typedef_void_f)(); // typedef_void_f is void()
using alias_void_f     = void(); // alias_void_f is void()

And it can be used to declare function pointers:

void function() { std::cout << __PRETTY_FUNCTION__ << '\n'; }

typedef_void_f *a = function; // pointer to void()
alias_void_f   *b = function; // pointer to void()

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; // pointer to S void() member function
alias_void_m_f   d = &S::function; // pointer to S void() member 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::*) { // <---- What is this??
    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::*)?

+4
2

TYPE host::* - . TYPE - , host::* host. , TYPE host::* host

+3

:

constexpr void my_test(void (S::*)()) {}

, - S, void .

http://ideone.com/EqfYmb

+1

Source: https://habr.com/ru/post/1626228/


All Articles