boost::dynamic_bitset::dynamic_bitset

Constructs a bitset from a string of 0's and 1's.

Synopsis

Declared in <boost/dynamic_bitset/dynamic_bitset.hpp>

template<
    typename CharT,
    typename Traits,
    typename Alloc>
explicit
dynamic_bitset(
    std::basic_string<CharT, Traits, Alloc> const& s,
    std::basic_string<CharT, Traits, Alloc>::size_type pos = 0,
    std::basic_string<CharT, Traits, Alloc>::size_type n = ( std::basic_string< CharT, Traits, Alloc >::npos ),
    size_type num_bits = npos,
    allocator_type const& alloc = allocator_type());

Description

The size of the bitset is num_bits if num_bits != npos, otherwise rlen = min( n, s.size() ‐ pos ). The first `M = min( num_bits, rlen )` bits are initialized to the corresponding characters in s. Note that the highest character position in s, not the lowest, corresponds to the least significant bit. So, for example, `dynamic_bitset( std::string( "1101" ))` is the same as `dynamic_bitset( 13ul)`.

Throws

An allocation error if memory is exhausted (std::bad_alloc if allocator_type is a std::allocator).

Parameters

Name

Description

s

The string to construct from.

pos

The start position in the string.

n

The maximum number of characters in the string to consider.

num_bits

The size of the bitset to construct, if different from npos.

alloc

The allocator to use.

Preconditions

  • pos <= s.size() and each character of s used to initialize a bit compares equal, according to Traits::eq, to either CharT( '0' ) or CharT( '1' ). Unlike the digits of the stream operators, these don't depend on any locale. E.g.: dynamic_bitset<> b( std::string( "10xyz" ), 0, 2 ); // OK.

Created with MrDocs