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