M
Mark P
I'm working on a project where I have something like
enum Modes {mode_a, mode_b, ...};
Due to project spec changes, the number of Modes has increased several
times. There are a few places where it's useful to know the number of
image modes (to set the size of bitsets, etc.) Currently I just use a
const int to hold this size:
enum Modes {mode_a, mode_b, mode_c};
const int number_of_modes = 3;
I'm wondering what the style gurus think about this alternative:
enum Modes {mode_a, mode_b, mode_c, mode_sentinel};
const int number_of_modes = mode_sentinel;
The second version requires just a bit less work to maintain, but is it
trying to be too clever? FWIW, the numerical values of the enum
elements are otherwise not used anywhere.
enum Modes {mode_a, mode_b, ...};
Due to project spec changes, the number of Modes has increased several
times. There are a few places where it's useful to know the number of
image modes (to set the size of bitsets, etc.) Currently I just use a
const int to hold this size:
enum Modes {mode_a, mode_b, mode_c};
const int number_of_modes = 3;
I'm wondering what the style gurus think about this alternative:
enum Modes {mode_a, mode_b, mode_c, mode_sentinel};
const int number_of_modes = mode_sentinel;
The second version requires just a bit less work to maintain, but is it
trying to be too clever? FWIW, the numerical values of the enum
elements are otherwise not used anywhere.