boost::dynamic_bitset::dynamic_bitset
Constructs a bitset from a range of blocks or from an integer.
Synopsis
Declared in <boost/dynamic_bitset/dynamic_bitset.hpp>
template<typename BlockInputIterator>
dynamic_bitset(
BlockInputIterator first,
BlockInputIterator last,
allocator_type const& alloc = allocator_type());
Description
If this constructor is called with a type BlockInputIterator which is actually an integral type, the library behaves as if the constructor from unsigned long were called, with arguments static_cast< size_type >( first ), last and alloc, in that order.
Example
Given:
dynamic_bitset< unsigned short > b( 8, 7 );
b is constructed as if by calling the constructor:
dynamic_bitset(size_type num_bits,
unsigned long value = 0,
const allocator_type & alloc = allocator_type())
with arguments:
static_cast< dynamic_bitset< unsigned short >::size_type >( 8 ),
7,
allocator_type()
Note: At the time of writing (October 2008) this is aligned with the proposed resolution for library issue 438. That is a post C++03 change, and is currently in the working paper for C++0x. Informally speaking, the critical changes with respect to C++03 are the drop of a static_cast on the second argument, and more leeway as to when the templated constructor should have the same effect as the (size, value) one: Only when InputIterator is an integral type, in C++03; when it is either an integral type or any other type that the implementation might detect as impossible to be an input iterator, with the proposed resolution. For the purposes of dynamic_bitset we limit ourselves to the first of these two changes.
Otherwise (i.e. if the template argument is not an integral type), constructs a bitset based on a range of blocks. Let *first be block number 0, \*++first block number 1, etc. Block number b is used to initialize the bits of the dynamic_bitset in the position range [b * bits_per_block, ( b + 1 ) * bits_per_block). For each block number b with value bval, the bit ( bval >> i ) & 1 corresponds to the bit at position b * bits_per_block + i in the bitset (where i goes through the range [0, bits_per_block)).
Throws
An allocation error if memory is exhausted (std::bad_alloc if allocator_type is a std::allocator).
Parameters
| Name | Description |
|---|---|
first |
|
last |
|
alloc |
The allocator to use. |
Preconditions
-
BlockInputIteratormust be either an integral type or a model of LegacyInputIterator whosevalue_typeis the same type asBlock.
Created with MrDocs