Boost logo

Boost Users :

From: Daniel Krügler (dsp_at_[hidden])
Date: 2005-12-15 03:26:11


Dave Steffen wrote:
> Folks,
>
> I used dynamic_bitset for the first time last night - nifty! I am
> curious, though, about how to construct a bitset of all 1's. Right
> now I'm doing this:
>
> dynamic_bitset foo(n);
> foo.set();
>
> Is there a more efficient way to generate a bitset will all bits set?
>
> Thanks very much!

boost::dynamic_bitset strongly matches the interface of std::bitset,
this is probably the reason for the non-existence of a constructor
allowing to set an initial value for each element. Since dynamic_bitset
behaves more like std::vector<bool>, I would recommend a constructor:

explicit dynamic_bitset(size_type num_bits, bool value,
const Allocator& = Allocator());

Note that I removed the default value of the second parameter in
contrast to std::vector<bool> to prevent a clash with the already
existing c'tor

explicit
     dynamic_bitset(size_type num_bits, unsigned long value = 0,
                const Allocator& alloc = Allocator());

This proposal would also make sense for std::bitset, I assume.

Greetings from Bremen,

Daniel Krügler


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