boost::dynamic_bitset::dynamic_bitset
Constructs a bitset from an integer.
Synopsis
Declared in <boost/dynamic_bitset/dynamic_bitset.hpp>
dynamic_bitset(
size_type num_bits,
unsigned long long value,
allocator_type const& alloc = allocator_type());
Description
The first M bits (where `M = min( num_bits, std::numeric_limits< unsigned long long >::digits )`) are initialized to the corresponding bits in value and all other bits, if any, to zero. A copy of the alloc object will be used in subsequent bitset operations such as resize() to allocate memory.
Like the corresponding constructor of std::bitset, this constructor takes the value as an unsigned long long, so the result doesn't depend on the width of unsigned long. E.g., dynamic_bitset<>( 64, ‐1 ) has all of its 64 bits set on all platforms.
Note that, e.g., the following
dynamic_bitset<> b( 16, 7 );
will match the constructor from an iterator range (not this one), but the underlying implementation will still "do the right thing" and construct a bitset of 16 bits, from the value 7.
Unlike the constructor from a size alone, and like the corresponding constructor of std::vector, this constructor isn't explicit. So, a bitset can be copy‐list‐initialized from a size and a value, as in
dynamic_bitset<> b = { 8, 7ul };
As with any list‐initialization, though, a narrowing conversion of an argument (e.g. from a non‐constant int to size_type) makes the program ill‐formed.
Throws
An allocation error if memory is exhausted (std::bad_alloc if allocator_type is a std::allocator).
Parameters
Name |
Description |
num_bits |
The size of the constructed bitset. |
value |
The value to initialize the bitset from. |
alloc |
The allocator to use. |
Postconditions
-
‐
this‐>size() == num_bits‐ For all i in the range[0, M)], `( *this )[ i ] == ( value >> i ) & 1`. ‐ For all i in the range[M, num_bits)], `( *this )[ i ] == false`.
Created with MrDocs