As one of the class template parameters I need to use a pointer to member:
template <class Base, typename Member, Member Base::*m>
class MemPtrTestUgly
{
...
};
This needs to be used as
struct S
{
int t;
}
MembPtrTestUgly <S, int, &S::t> m;
But I want to use it as this:
MemPtrTestNice<S, &S::t> m;
The member type is deduced from the member pointer. I cannot use function template, as the MemPtrTest class is not supposed to be instantiated (there are just some static functions that will be used). Is there a way how to do it in pure C++03 (no Boost or TR1)?
You can use partial specialization and get a pretty nice-looking implementation:
This would be used as:
Of course, this requires
decltypeor an equivalent, if you don’t want to implicitly specify the member type.