Is there a way to ensure a template parameter is an enum-class type?
I know type_traits
has std::is_enum
, but I don't want it to match regular enums, just enum_classes.
Example of the wanted effect:
enum class EnumClass {};
enum Enum {};
class Class {};
template <typename T>
void Example()
{
static_assert(/* T is EnumClass */, "`T` must be an enum class");
}
Example<EnumClass>(); // Ok
Example<Enum>(); // Error
Example<Class>(); // Error
I am using C++11, and unfortunately cannot go any higher (though I'd be curious to know the solution anyway, even if it involves newer standards).
Is it possible?
Aucun commentaire:
Enregistrer un commentaire