c++ - Weird pointer to member function syntax -
i understand how declare type of function:
typedef void (typedef_void_f)(); // typedef_void_f void() using alias_void_f = void(); // alias_void_f void() and can used declare function pointers:
void function() { std::cout << __pretty_function__ << '\n'; } typedef_void_f *a = function; // pointer void() alias_void_f *b = function; // pointer void() for member function pointers syntax more complicated:
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 s void() member function alias_void_m_f d = &s::function; // pointer s void() member function this understanding of function pointers in c++ , thought enough.
but in p0172r0 technical paper i've found syntax i'm not familiar:
struct host { int function() const; }; template <typename type> constexpr bool test(type host::*) { // <---- this?? return is_same_v<type, int() const>; } constexpr auto member = &host::function; test(member); as understand code, test function splits type of function type of object function belongs, in template test function type template parameter void() if try following:
void my_test(void() s::*) {} my_test(&s::function); i 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' not declared in scope my_test(&s::function);
so obvious i'm not understanding p0172r0's test function syntax.
can explain details of template <typename type> constexpr bool test(type host::*) syntax?
type host::* pointer class data member. type type of class member , host::* means pointer member of host. type host::* accepts pointer of member of host
Comments
Post a Comment