boost::dynamic_bitset::dynamic_bitset

Similar to the constructor from a basic_string, but takes a pointer to a C‐style string, or to an array of characters which need not be null‐terminated (and doesn't take a pos).

Synopsis

Declared in <boost/dynamic_bitset/dynamic_bitset.hpp>

template<typename CharT>
requires detail::dynamic_bitset_impl::is_character_type< CharT >::value
explicit
dynamic_bitset(
    CharT const* s,
    std::size_t n = std::size_t( ‐1 ),
    size_type num_bits = npos,
    allocator_type const& alloc = allocator_type());

Description

This constructor participates in overload resolution only if CharT is char, wchar_t, char8_t, char16_t or char32_t. So, e.g., a pointer to a std::pmr::memory_resource selects the constructor from an allocator when allocator_type is a std::pmr::polymorphic_allocator.

Let rlen be the number of characters that precede the first null character in s, if that number is less than n, or n otherwise. (So, if s is null‐terminated, rlen == min( n, std::char_traits< CharT >::length( s ) ).) The constructor reads only the first rlen characters of s and, if rlen < n, the null character that follows them. The size of the bitset is num_bits if num_bits != npos, otherwise rlen. The first M = min( num_bits, rlen ) bits are initialized to the corresponding characters in s. Note that, unlike with std::bitset, a null character among the first n characters ends the input, rather than being an invalid digit.

Throws

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

Parameters

Name

Description

s

The string or array to construct from.

n

The maximum number of characters to read from s.

num_bits

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

alloc

The allocator to use.

Preconditions

  • ‐ s points to the first character of either a null‐terminated string or an array of at least n characters. E.g.: const char a[]= { '1', '0' }; dynamic_bitset<> b( a, 2 ); // OK. ‐ Each character of s used to initialize a bit compares equal, according to std::char_traits< CharT >::eq, to either CharT( '0' ) or CharT( '1' ). E.g.: dynamic_bitset<> b( "10xyz", 2 ); // OK.

Created with MrDocs