Is it possible to determine the cardinality of a c++ enum class
:
enum class Example { A, B, C, D, E };
I tried to use sizeof
, however, it returns the size of an enum element.
sizeof(Example); // Returns 4 (on my architecture)
Is there a standard way to get the cardinality (5 in my example) ?
You can also consider
static_cast<int>(Example::E) + 1
which eliminates the extra element.