2

I have a templated struct:

template <typename T, typename T2>
struct MyStruct {};

and I want to determine if some type is a "MyStruct" (I don't care what the template parameters are).

template <typename OtherType, typename TestingType, typename = std::enable_if< IsMyStruct<TestingType>::value, TestingType>::type >
struct OtherStruct {};

How do I write IsMyStruct

R. Martinho Fernandes
  • 228,013
  • 71
  • 433
  • 510
Andrew Spott
  • 3,457
  • 8
  • 33
  • 59

1 Answers1

4

You can do it like this:

#include <type_traits>

template <typename T>
struct IsMyStruct : std::false_type { };

template <typename T1,typename T2>
struct IsMyStruct<MyStruct<T1,T2> > : std::true_type { };
Vaughn Cato
  • 63,448
  • 5
  • 82
  • 132
  • 1
    The normal idiom is to inherit from `std::false_type` and `std::true_type` respectively, just as a side-note. – Xeo Mar 11 '13 at 08:25