samedi 29 août 2015

Check whether a type is a template specialization or not

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

Aucun commentaire:

Enregistrer un commentaire