Boost logo

Boost :

From: Daryle Walker (darylew_at_[hidden])
Date: 2004-04-25 13:14:20


On 4/13/04 5:17 AM, "Gennaro Prota" <gennaro_prota_at_[hidden]> wrote:

[SNIP]
> - Imitating std::bitset, the function to_ulong checks whether
> there's any 1 bit beyond the positions representable in an
> unsigned long, eventually throwing an overflow_error. That
> goes against the "don't pay for what you don't use" principle
> (think for instance if your bitset has 20 000 elements and you
> are sure that only the first 8 can be set). It's also the only
> place where we still check "preconditions" with exceptions and
> the only reason why dynamic_bitset.hpp still needs to include
> <stdexcept>.

I always thought that the exception-throwing behavior of
std::bitset::to_ulong was a misfeature. You could just have it truncate off
the top bits, just like in converting from one unsigned built-in to a
shorter type. If you don't have it, you could add a "highest bit" const
member function for those that have to know if truncation occurred.

Maybe you can change/add "to_ulong" to return boost::uintmax_t. The
function would have to be (re)named "to_uintmax".

-- 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT hotmail DOT com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk