boost::dynamic_bitset::dynamic_bitset

Constructs a bitset from a string of the characters zero and one.

Synopsis

Declared in <boost/dynamic_bitset/dynamic_bitset.hpp>

template<
    typename CharT,
    typename Traits,
    typename Alloc,
    typename ZeroOne>
requires detail::dynamic_bitset_impl::is_character_type< CharT >::value && std::is_same< ZeroOne, CharT >::value
explicit
dynamic_bitset(
    std::basic_string<CharT, Traits, Alloc> const& s,
    std::basic_string<CharT, Traits, Alloc>::size_type pos,
    std::basic_string<CharT, Traits, Alloc>::size_type n,
    ZeroOne zero,
    ZeroOne one = ZeroOne( '1' ),
    size_type num_bits = npos,
    allocator_type const& alloc = allocator_type());

Description

The same as the constructor from a basic_string which doesn't take zero and one, except that the characters which stand for a zero bit and a one bit are zero and one, as with std::bitset. E.g., dynamic_bitset<>( std::string( ".**." ), 0, 4, '.', '*' ) is the same as dynamic_bitset<>( 4, 6ul ).

This constructor participates in overload resolution only if CharT is char, wchar_t, char8_t, char16_t or char32_t, and ZeroOne is CharT. So, e.g., dynamic_bitset<>( s, 0, 4, 8 ) still constructs a bitset of 8 bits with the constructor which doesn't take zero and one. Note, though, that an argument of type CharT after n (e.g., a char variable with a std::string) is taken as zero, not as num_bits, and that a zero of another type (e.g., '.' with a std::wstring) is taken as num_bits.

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.

zero

The character which stands for a zero bit.

one

The character which stands for a one bit.

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 zero or one.

Created with MrDocs