Is there a way, possibly requiring C ++ 11/14, to infer the number of elements in an enumeration, regardless of the values ββof the enumeration elements themselves?
Consider an enumeration of type
enum { Val1 = 1, Val2 = 2, Val3 = 4 }
for which the answer will be 3. I know that this is a wrinkle where I could, for example Val3 = Val1, but it can be ignored for my use.
I have seen quite a few similar questions, both here and elsewhere, but I still have to find the right answer. If not at all.
Usually the suggested solution is to introduce a LAST element, but that will only give me the next higher enum value (using the example above, it will be 5), which would be useless to me.
source
share