Max and min values in a C++ enum

后端 未结 6 983
广开言路
广开言路 2020-12-09 00:34

Is there a way to find the maximum and minimum defined values of an enum in c++?

6条回答
  •  北海茫月
    2020-12-09 00:56

    Not automatically, but you can add artificial enum values to signify min and max values, e.g.

    typedef enum {start_of_colors=-1, eRed, eWhite, eBlue, eGray,
    end_of_colors} eListOfTags;
    
    for (eListOfTags i = start_of_colors+1; i < end_of_colors; i++) {
    .... 
    }
    

提交回复
热议问题