Max and min values in a C++ enum

后端 未结 6 992
广开言路
广开言路 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 01:10

    No, not in standard C++. You could do it manually:

    enum Name
    {
       val0,
       val1,
       val2,
       num_values
    };
    

    num_values will contain the number of values in the enum.

提交回复
热议问题