0

Given an arbitrary template class/struct, just like:

template <typename T>
struct A {};

I would like to perform a <type_traits> fashion check (let's name it is_A) to determine whether an arbitrary type is a specialization of A or not, just like:

#include <type_traits>

template <typename T>
struct is_A: std::integral_constant<bool, /* perform the check here */ > {};

constexpr bool test0 = is_A< A<int> >::value // true
constexpr bool test1 = is_A< A<float> >::value // true
constexpr bool test2 = is_A< int >::value // false
constexpr bool test2 = is_A< float >::value // false

How is that possible?

Thanks in advance

plasmacel
  • 8,183
  • 7
  • 53
  • 101

1 Answers1

3

You need to specialize for A<T>:

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

template <typename T>
struct is_A<A<T>> : std::true_type { };
David G
  • 94,763
  • 41
  • 167
  • 253