I need to pass a pointer to data member, its type and the class it's a member of, to a template struct. The following works:
template<typename T, typename Cls, T Cls::*member> struct Member {};
struct Struct { int x; };
Member<int, Struct, &Struct::x>
But it requires to explicitly mention the type (T: int) and the class (Cls: Struct). That should be unnecessary. The compiler should be able to figure those two types out on its own.
In fact it can inferm them if I pass the pointer to data member to a function:
template<typename T, typename Cls> void member( T Cls::*member ) {}
struct Struct { int x; };
member( &Struct::x );
Is it possible to pass a pointer to data member as a non-type template argument, while letting the compiler figure out the type and class?
template <auto member> struct Member{};
and then extract class and type fromdecltype(member)
– Igor Tandetnik