Boost logo

Boost Users :

Subject: Re: [Boost-users] Needs advices on design ( mpl or processor )
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2012-01-07 03:53:24

Le 06/01/12 17:19, Allan Nielsen a écrit :
> Hi
> This is not a specific questions directly related to Boost::mpl, but a request
> for help if somebody has the time...
> For the last couple of month I have been trying to learn to use the boost::mpl
> library.
> To learn to use the library I decided to use it for creating a
> "compressed-enum" library. The library should make it possible to store several
> enums in a single variable (for instance an unsigned int)

I have no see yet your implementation and how I can help you in, but I
guess that you can find your own responses in the implementation of this

In addition to what you want to do, I think that all this stuff can be
generalized to a compressed_tuple.

About compressed_tuple.

Tuples of types can be compressed depending on the bits needed to store
the underlying type of each one of the tuple elements. For example a
compressed_tuple<month,day,weekday> would take 3 bytes, but month needs
only 5 bits, day 3 bits and weekday 3 bits, that is 11 bits which can be
represented using just 2 bytes.

This is quite close to the bitfield library. The main difference is that
bitfield worked only with built-in types and required to state
explicitly the number of bits for each field while compressed_tuple can
work with UDT for which the user has stated once for all the number of
bits needed to store the UDT.

In addition, the UDT need to DefaultConstructible be
ExplicitlyConstructible from its underlying type and be
ExplicitlyConvertible to it's underlying type.

There is yet another difference. The motivation of the bitfield library
was to make possible to work with bitfields in a portable way (endianness).
The motivation of the compressed_tuple, is to compress UDT which cannot
be used with C-bitfields.

The compressed_tuple_traits template needs to be specialized for each
UDT and define the width_in_bits, underlying_type ...

As the bitfield library, the total number of needed bits cannot exceed
64 bits.

This should work also for ordinal types. An ordinal type is a type that
allows to get the value from an index (0..n) and retrieve the associated
position of a value (See
for more details - section Tutorial/Ordinal Enums).

Let me know if you are interested.


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at