Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get the maximum value of enumeration constants at compile time

Tags:

c++

enums

is there any way to get the maximum value of enumeration constants?

since the enum constants may have explicitly assigned values its not necessarily the last element. Mostly there is a constant called like XXX_cnt but in my case its not. Also the enum may be changed without my notice so just using the last element is error prone.

So is there any way?

like image 823
vlad_tepesch Avatar asked Sep 13 '25 01:09

vlad_tepesch


1 Answers

No. This is why sometimes you can find explicit definition of max and min in enumeration type:

enum e { zero, one, two, min = zero, max = two};
like image 116
4pie0 Avatar answered Sep 14 '25 16:09

4pie0