Использование ограничения шаблона SFINAE при полной специализации

Необходимо получать некий идентификатор для типа, сделано через полную специализацию шаблона.

template<typename T> struct ids;
template<> struct ids<int> { static const int id = 1; };
template<> struct ids<float> { static const int id = 2; };

Возможно ли аналогично специализировать шаблон для любого типа, проходящего ограничение std::is_class? Не совсем представляю, как это правильно сделать. Думал, что это должно выглядеть примерно так:

template<typename T, typename = typename std::enable_if<std::is_class<A>::value>>
struct ids { static const int id = 3 };

Ответы (1 шт):

Автор решения: user7860670
#include <type_traits>

template<typename x_Value, typename x_Enabled = void>
struct ids;

template<>
struct ids<int, void>
{ static inline constexpr int const id{1}; };

template<>
struct ids<float, void>
{ static inline constexpr int const id{2}; };

template<typename x_Value>
struct ids<x_Value, ::std::enable_if_t<::std::is_class_v<x_Value>>>
{ static inline constexpr int const id{3}; };

static_assert(1 == ids<int>::id);
static_assert(2 == ids<float>::id);

struct something{};

static_assert(3 == ids<something>::id);

https://godbolt.org/z/6ax86d

→ Ссылка