std::bitset<N>::bitset (3) - Linux Manuals
std::bitset<N>::bitset: std::bitset<N>::bitset
NAME
std::bitset<N>::bitset - std::bitset<N>::bitset
Synopsis
bitset(); (until C++11)
constexpr bitset() noexcept; (since C++11)
bitset( unsigned long val ); (until C++11)
constexpr bitset( unsigned long long val ) noexcept; (since C++11)
template< class CharT, class Traits, class Alloc >
explicit bitset( const std::basic_string<CharT,Traits,Alloc>& str,
typename std::basic_string<CharT,Traits,Alloc>::size_type (until C++11)
pos = 0,
typename std::basic_string<CharT,Traits,Alloc>::size_type
n = std::basic_string<CharT,Traits,Alloc>::npos);
template< class CharT, class Traits, class Alloc >
explicit bitset( const std::basic_string<CharT,Traits,Alloc>& str, (1)
typename std::basic_string<CharT,Traits,Alloc>::size_type (2)
pos = 0, (3) (since C++11)
typename std::basic_string<CharT,Traits,Alloc>::size_type
n = std::basic_string<CharT,Traits,Alloc>::npos,
CharT zero = CharT('0'),
CharT one = CharT('1'));
template< class CharT >
explicit bitset( const CharT* str,
typename std::basic_string<CharT>::size_type (4) (since C++11)
n = std::basic_string<CharT>::npos,
CharT zero = CharT('0'),
CharT one = CharT('1'));
Constructs a new bitset from one of several optional data sources:
1) Default constructor. Constructs a bitset with all bits set to zero.
2) Constructs a bitset, initializing the first (rightmost, least significant) M bit positions to the corresponding bit values of val, where M is the smaller of the number of bits in an unsigned long long and the number of bits N in the bitset being constructed. If M is less than N (the bitset is longer than
32
(until C++11)
64
(since C++11) bits, for typical implementations of unsigned
long
(since C++11)long), the remaining bit positions are initialized to zeroes.
3) Constructs a bitset using the characters in the std::basic_string str. An optional starting position pos and length n can be provided, as well as characters denoting alternate values for set (one) and unset (zero) bits. Traits::eq() is used to compare the character values.
The effective length of the initializing string is min(n, str.size() - pos).
If pos > str.size(), this constructor throws std::out_of_range. If any characters examined in str are not zero or one, it throws std::invalid_argument.
4) Similar to (3), but uses a CharT* instead of a std::basic_string. Equivalent to bitset(n == basic_string<CharT>::npos ? basic_string<CharT>(str) : basic_string<CharT>(str, n), 0, n, zero, one)
Parameters
val - number used to initialize the bitset
str - string used to initialize the bitset
pos - a starting offset into str
n - number of characters to use from str
one - alternate character for set bits in str
zero - alternate character for unset bits in str
Exceptions
3) std::out_of_range if pos > str.size(), std::invalid_argument if any character is not one or zero
4) std::invalid_argument if any character is not one or zero
Example
// Run this code
Possible output:
See also
set (public member function)
reset (public member function)