Consider classes with member variables, for example:
struct A {
int a;
char b;
};
struct B {
double c;
bool d;
};
Is it possible to declare a template class that accepts a pointer-member-object argument as a template to any declared member in the above classes? A class that accepts a common member pointer object can be declared and used as follows:
template<typename Class, typename Type, Type (Class::*Member)>
struct Magic
{ };
typedef Magic<A, int, &A::a> MagicWithA_a;
Unfortunately, it is rather cumbersome to have to go into Class
and
Type
the template arguments each time to make the final pointer work.
Is there a way for these arguments to be deduced by partial specialization, for example? That is, how can you declare a class Magic
to make lower definitions work?
typedef Magic<&B::c> MagicWithB_c;
typedef Magic<&A::b> MagicWithA_b;
source
share