Subject: [boost] interest in a flag library
From: Masse Nicolas (masse.nicolas_at_[hidden])
Date: 2018-10-25 20:41:18
This is the first time I post on this mailing list :).
I'm posting because i'd like to know if people would be interested in a
library to treat enum types as flags. I find that's something which is
lacking in the language since the introduction of strongly typed enums, and
I've since written some code in order to do this.
So far I've seen some discussion on this mailing list about that, but it
doesn't seems that any library have been written yet.
So do you think it is worth the effort of porting and documenting my code
so that it can integrated into boost, or not?
For those interested, the code consists of a flag class, and overloads
operators like '|' or &.
It can be used like this:
enum struct option : uint
none = 0,
first = 1,
second = 2,
third = 4,
forth = 8
static constexpr flags<option> var1 = option::first;
static constexpr flags<option> var2 = option::second | option::third;
static constexpr auto var3 = var1 | var2; /* type will be resolved into
static constexpr auto var4 = option::first | option::second |
option::third; /* works too */
std::cout << var1 << std::endl;
std::cout << static_cast<uint>(var2) << std::endl; /* note that
static_cast<int> won't compile since the underlying type is uint */
std::cout << (var3 & option::forth) << std::endl;
std::cout << (var3 == var4) << std::endl;
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk