Le 06/02/13 00:59, Christian Henning a écrit :
low_bits_mask_t<Bits>::sig_bits is defined as
 (~( ~(unsigned_int(0u )) << Bits )) )

which is equivalent to 2^Bits-1 without risk of overflow.

Vicente, what's unsigned_int?

It is an unsigned type with at least Bits bits. It depends on what do you want, speed or size. 

low_bits_mask_t<Bits>::sig_bits uses the smallest unsigned int and  low_bits_mask_t<Bits>::sig_bits_fast uses the fastest one.


"
template <std::size_t Bits>
struct low_bits_mask_t
{
    typedef implementation-defined-type  least;
    typedef implementation-defined-type  fast;

    static const least       sig_bits       = implementation-defined;
    static const fast        sig_bits_fast  = implementation-defined;

    static const std::size_t bit_count      = Bits;
};

Group Bit-Mask Class Template

The boost::low_bits_mask_t class template provides constants for bit masks equivalent to the value (2Bits - 1), where Bits is the template parameter. The parameter Bits must be a non-negative integer from zero to Max, where Max is the number of bits supported by the largest, unsigned, built-in integral type. The following table describes the members of low_bits_mask_t.


Table 3. Members of the [^boost::low_bits_mask_t] Class Template

Member

Meaning

least

The smallest, unsigned built-in type that supports the given bit count.

fast

The easiest-to-manipulate analog of least.

sig_bits

A least constant of the desired bit-masking value.

sig_bits_fast

A fast analog of sig_bits.

bit_count

The value of the template parameter, in case its needed from a renamed instantiation of the class template.


"

Vicente