Boost logo

Boost :

Subject: Re: [boost] interest in a flag library
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2018-11-01 07:24:05

Le 26/10/2018 à 10:08, Hans Dembinski via Boost a écrit :
>> On 26. Oct 2018, at 09:35, Andrzej Krzemienski via Boost <boost_at_[hidden]> wrote:
>> Hi. I would use a type-safe library for flags. I am missing one today.
> […]
>> I would rather expect an interface using named functions or indexing
>> operator:
>> ```
>> if (!flags[Flag::READ])
>> flags.reset(Flag::EXEC);
>> ```
> There are std::bitset (fixed size, allocates on the stack) and boost::dynamic_bitset (dynamic size, allocates from stack and heap)
> The latter also has more sensible implementations of operator& and operator|. Before you invent a new thing, what is wrong with these classes?
Their size. The size of std::bitset<8> is not 8 bits but very often 64
bits. :(

We need something like std::bitset<N>, where we can define the size of
the block xxx::bitset<20, unsigned char>.

The size of xxx::bitset<20, unsigned char> should be 3 bytes.

Aside this point relative to the size, there is also the fact that
std::bitset<N> uses only index between 0 and N-1.

I've defined a ordinal library where the index is not a number between 0
and N-1, but any type that is isomorphic to O..N-1.

This library defines several container and in particular an ordinal_set

but also an ordinal array

and an ordinal range

You can find a draft proposal here

In particular enums with power of 2 constants are isomorphic to 0..N-1.

Unfortunately ordinal_set<O> when the cardinality of O is 24 is not 3
bytes as I use std::bitset as underlying implementation.

I started an implementation of a bitmask that has a builtin unsigned int
underlying representation in

but I have not put both together.

Please, be free to take whatever could be useful to you.

Hopping this helps,

Boost list run by bdawes at, gregod at, cpdaniel at, john at