Files
cppdraft_translate/cppdraft/bitset/cons.md
2025-10-25 03:02:53 +03:00

3.9 KiB
Raw Blame History

[bitset.cons]

22 General utilities library [utilities]

22.9 Bitsets [bitset]

22.9.2 Class template bitset [template.bitset]

22.9.2.2 Constructors [bitset.cons]

🔗

constexpr bitset() noexcept;

1

#

Effects: Initializes all bits in *this to zero.

🔗

constexpr bitset(unsigned long long val) noexcept;

2

#

Effects: Initializes the first M bit positions to the corresponding bit values in val.

M is the smaller of N and the number of bits in the value representation ([basic.types.general]) of unsigned long long.

If M < N, the remaining bit positions are initialized to zero.

🔗

template<class charT, class traits, class Allocator> constexpr explicit bitset( const basic_string<charT, traits, Allocator>& str, typename basic_string<charT, traits, Allocator>::size_type pos = 0, typename basic_string<charT, traits, Allocator>::size_type n = basic_string<charT, traits, Allocator>::npos, charT zero = charT('0'), charT one = charT('1')); template<class charT, class traits> constexpr explicit bitset( basic_string_view<charT, traits> str, typename basic_string_view<charT, traits>::size_type pos = 0, typename basic_string_view<charT, traits>::size_type n = basic_string_view<charT, traits>::npos, charT zero = charT('0'), charT one = charT('1'));

3

#

Effects: Determines the effective lengthrlen of the initializing string as the smaller ofn andstr.size() - pos.

Initializes the first M bit positions to values determined from the corresponding characters in the stringstr.

M is the smaller of N and rlen.

4

#

An element of the constructed object has value zero if the corresponding character in str, beginning at positionpos, iszero.

Otherwise, the element has the value one.

Character position pos + M - 1 corresponds to bit position zero.

Subsequent decreasing character positions correspond to increasing bit positions.

5

#

If M < N, remaining bit positions are initialized to zero.

6

#

The function uses traits::eq to compare the character values.

7

#

Throws: out_of_range if pos > str.size() orinvalid_argument if any of the rlen characters in str beginning at position pos is other than zero or one.

🔗

template<class charT> constexpr explicit bitset( const charT* str, typename basic_string_view<charT>::size_type n = basic_string_view<charT>::npos, charT zero = charT('0'), charT one = charT('1'));

8

#

Effects: As if by:bitset(n == basic_string_view::npos ? basic_string_view(str): basic_string_view(str, n), 0, n, zero, one)