|
Boost : |
Subject: Re: [boost] [Library idea] Type-safe Flagsets
From: Gavin Lambert (gavinl_at_[hidden])
Date: 2018-06-26 00:30:32
On 25/06/2018 18:09, Julien Vernay wrote:
> The aim is that each flag is independent, so you can have two flags active
> at a same time, while an enum should have only one value at a time.
> Scoped enums do not solve those issues because they can not be combined, if
> you want to combine them you first need to used "static_cast" for
> converting it to an int, then using & | ^ to combine them.
For that, I like the approach in this answer:
https://softwareengineering.stackexchange.com/a/338472/303655
Where you use a standard (non-power-of-two) enum to define the bit
positions, and a separate class that turns it into a bitset.
If you do want to explicitly define the power-of-two values, then you
can use something like this instead:
https://github.com/grisumbras/enum-flags
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk