Re: [Interest] Flags: Non-intrusive, type-safe bitwise operators for enums

Janko Dedic via Boost <[email protected]>
Newsgroups gmane.comp.lib.boost.devel
Message-ID <CANFwnCH8SwzK7RbMYwuRYtNdNofUMG1yLxXvyK8ngrpdDnG5CQ@mail.gmail.com>
On Tue, 17 Mar 2026 at 06:38, Julien Blanc via Boost <[email protected]>
wrote:

> I've come to the conclusion that any representation of enum flags with
> C++ enums is a design mistake by itself (a pretty widespread one, but
> still a mistake). Enums are individual values, enum flags are a set of
> values, they are different by nature. In C++, different things deserve
> a different type, call it an enum_bitset, an enum_set or whatever, but
> donc make it a plain enum / enum class.


I totally agree. We’ve had this same discussion in November and I’ve made
the same argument. Conceptually, enum values and sets of enum values should
be different things. C code has always made the distinction between enums
(`enum`) and enum sets (`unsigned int`).

The only hurdles here are practical in nature. C++ technically treats any
bit pattern of an enum type as a valid value, so you could argue there is
no need for a second type. Furthermore, there is no standard “enum set”
type, so you have to invent one yourself, which is kind of a big deal for
something so fundamental, especially in public interfaces.

-Janko

>
_______________________________________________
Boost mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://lists.boost.org/mailman3/lists/boost.lists.boost.org/
Archived at: https://lists.boost.org/archives/list/[email protected]/message/2X6O6W75EBSYFDGAZSEGJHGJEXWXVJ4S/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.