initializing dynamic_bitsets
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! ------------------------------------------------------------------------ Dave Steffen, Ph.D. "We warn the reader in advance that the proof Software Engineer IV presented here depends on a clever but highly Numerica Corporation unmotivated trick." ph (970) 419-8343 x27 fax (970) 223-6797 -- Howard Anton, "Elementary Linear Algebra" dgsteffen@numerica.us
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
Daniel Krügler writes:
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.
Never having used std::bitset, I sort of assumed that such a constructor would exist. :-) I like your proposal for an additional ctor for both sorts of bitset. ------------------------------------------------------------------------ Dave Steffen, Ph.D. "We warn the reader in advance that the proof Software Engineer IV presented here depends on a clever but highly Numerica Corporation unmotivated trick." ph (970) 419-8343 x27 fax (970) 223-6797 -- Howard Anton, "Elementary Linear Algebra" dgsteffen@numerica.us ______________________ Numerica Disclaimer: This message and any attachments are intended only for the individual or entity to which the message is addressed. It is proprietary and may contain privileged information. If you are neither the intended recipient nor the agent responsible for delivering the message to the intended recipient, you are hereby notified that any review, retransmission, dissemination, or taking of any action in reliance upon, the information in this communication is strictly prohibited, and may be unlawful. If you feel you have received this communication in error, please notify us immediately by returning this Email to the sender and deleting it from your computer.
participants (2)
-
Daniel Krügler
-
Dave Steffen