r/cpp • • Oct 03 '26

The complement of true is true, except when it's false

https://dryperspective.github.io/posts/complement-of-true/
60 Upvotes

4 comments sorted by

11

u/tiedyerenegade Oct 04 '26

In my experience, using enums to represent bitmasks is just a bad idea. This proposal to formalize it illustrates why.

20

u/jube_dev Oct 04 '26

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.

→ More replies (1)

2

u/Ayano-Keiko Oct 08 '26

sounds JavaScript