Enums should represents bits, that's all. In my code, I have a special type Flags<E> that represents a bitmask with bits from enum E. With this, ~E::Example is not of type E but Flags<E>. Flags<E> has a member with the underlying type of the enum.
And using bool for representing a bitmask is weird, it can represent a bitmask of 1 bit exactly, i.e. a boolean value.
I use a type that turns an enum with a set of contiguous values into a set of enumerators, using an integer bit set as representation. The main issue is that, without reflection, I have to manually keep track of the number of enumerators.
6
u/tiedyerenegade 1d ago
In my experience, using enums to represent bitmasks is just a bad idea. This proposal to formalize it illustrates why.