bearophile wrote:
Don:
OTOH if each member has an explicitly defined value, it's reasonable to
perform logical operations on it.
See my recent answer to Schveighoffer. I think that's not a fully good idea
because when you define an enum like that and you use its values as
powers-of-two flags, the type system doesn't help you enforce it is a true
combination of the flags instead of a generic number (and you may put bugs when
you define the values to assign to the flags), so I think something like a
std.bitmanip.flagset that produces a struct is better when you need to define a
flag set.
Bye,
bearophile
That's impossible. That would make interfacing to C a nightmare.
By the way, enums which consist of flags frequently have values which
have more than one bit set. The case { A=1, B=2, C=4, D=8 } is only a
special case.
In the general case, it's not realistic to hope that the compiler could
determine which values are valid, and which are not.
But, with my suggestion, simple enums (a list of mutually exclusive
values) would become strong enums.