In C++17, void_t allow to easily do SFINAE with class/struct templates:
template <class T, class = void>
struct test {
static constexpr auto text = "general case";
};
template <class T>
struct test<T, std::void_t<decltype(std::begin(std::declval<T>())>> {
static constexpr auto text = "has begin iterator";
};
What's inside void_t is a type. My question is: how to do the same, when what's inside void_t is a type trait. Using enable_if works well:
template <class T>
struct test<T, std::void_t<std::enable_if_t<std::is_class_v<T>>> {
static constexpr auto text = "is a class";
};
Is there a shorter/more elegant way to write this, or "the right way" to do it, is really to combine void_t and enable_if?