I've been thinking in this for a while as a possible replacement of bitfields, superior in terms of being more C++like (constructors, inheritance, iteration) and also the ability to specify bit order.
Wat I came out so far is a special compact tuple for containing elements of size in terms of bits.
Let's call it momentarily std::bit_tuple, and it can contain (for now) the following elements:
Std::bit, std::signed_integer<n>, std::unsigned_integer<n>, std::enumerator<E, n>.
This bit_tuple would have a similar interface to std::tuple(get, tie, initialization, etc), with the addition of a size() method that returns the number of bits (so sizeof(bit_tuple) >= bit_tuple.size()/8).
Example:
bit_tuple<bit, bit, unsigned_integer<3>> bt;
static_assert(bt.size() == 5);
I omitted the byte order specificatipn for now.
Ideas?
Daniel.
El 21/11/2015 14:56, "dgutson ." <daniel...@gmail.com> escribió:
>
> I've been thinking in this for a while as a possible replacement of bitfields, superior in terms of being more C++like (constructors, inheritance, iteration) and also the ability to specify bit order.
> Wat I came out so far is a special compact tuple for containing elements of size in terms of bits.
> Let's call it momentarily std::bit_tuple, and it can contain (for now) the following elements:
> Std::bit, std::signed_integer<n>, std::unsigned_integer<n>, std::enumerator<E, n>.
Just realized: another interesting type could be a bit_tuple too, allowing multidimensional bit elements.