Nick Sabalausky:
enum Options
{
FeatureA = 0b0000_0001;
FeatureB = 0b0000_0010;
FeatureC = 0b0000_0100;
FeatureD = 0b0000_1000;
// etc...
}
// Use features A and C
auto myOptions = Options.FeatureA | Options.FeatureC;
That possibility means that D *can't* check for validity as you
suggest.
I'm convinced that scenario *should* be considered an entirely
separate
thing because cramming it together with regular enumerations
creates
conflicting goals with the two usages of "enum", and forces
unfortunate
design compromises with both.
This was discussed in past. A library code BitFlags similar to
struct bitfields is probably able to solve most of this problem
in a mostly type safe way. If you want a built-in solution, with
a @bitflags, you will have to wait longer.
Bye,
bearophile