Boost logo

Boost Users :

Subject: Re: [Boost-users] max value by the number of bits
From: Robert Ramey (ramey_at_[hidden])
Date: 2013-02-05 19:56:07


Christian Henning wrote:
>> boost::int_max_value_t<V>
>>
>> http://www.boost.org/doc/libs/1_53_0/libs/integer/doc/html/boost_integer/integer.html
>>
>
> Robert, are you sure I can get the max value of a 15bit value using
> int_max_value_t?

whoops - I totally misread your question, I was thinking you wanted the TYPE
which
would hold a max value corresponding to 15 bits.

It turns out that I've been working in this area recently. I would suggest
skipping
the mpl layer and using BOOST_STATIC_CONSTANT directly. The reason
is that mpl includes some operations like next which might not work for 2^64
etc.

template <int K>
struct unsigned_integral_max_value struct {
    BOOST_STATIC_CONSTANT( boost::uintmax_t, value = ((boost::uintmax_t)1 <<
K)-1);
};

Robert Ramey


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net