Is it possible to determine the number of elements of a c++ enum class?
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) ? Not directly, but you could use the following trick: enum class Example { A, B, C, D, E, Count }; Then the cardinality is available as (int)Example::Count . Of course, this only works nicely if you let values of the enum be automatically assigned, starting from 0. If that's not the case, you can manually