1

I found this type trait in the Alexandrescu book and I have no idea how to understand this specification

template <typename T>
class TypeTraits
{
private:
template <class U> struct PToMTraits
{
enum { result = false };
};
template <class U, class V>
struct PToMTraits<U V::*>
{
enum { result = true };
};
public:
enum { isMemberPointer = PToMTraits<T>::result };
...
};
Scipio
  • 171
  • 1
  • 9
  • [this_link](http://stackoverflow.com/questions/580922/identifying-primitive-types-in-templates) might help you to understand. – Sigcont Nov 10 '15 at 18:28

1 Answers1

3

It's a Pointer to Member checker, hence PtoM.

It checks to see if the type passed in is a pointer-to-data-member type (or not). It does this by providing a primary template whose result is false and a partial specialization on any type that matches U V::* (that is a pointer to a data member of any class U of any type V), whose result is true.

Barry
  • 286,269
  • 29
  • 621
  • 977
  • Thank you for answer! Could you explain why this "U V::*" stands for pointer to a data member of type V which belongs to U? This syntax doesn't look like C++ for me:) – Scipio Nov 10 '15 at 18:39
  • @Scipio That's just what the syntax is. – Barry Nov 10 '15 at 18:44
  • Ok, I found a clarifying example here: http://en.cppreference.com/w/cpp/language/template_parameters (At the bottom of page) and finally understood it. – Scipio Nov 10 '15 at 19:03