[template.bitset.general] (original) (raw)
22 General utilities library [utilities]
22.9 Bitsets [bitset]
22.9.2 Class template bitset [template.bitset]
22.9.2.1 General [template.bitset.general]
namespace std { template<size_t N> class bitset { public: class reference { public: constexpr reference(const reference& x) noexcept;constexpr ~reference();constexpr reference& operator=(bool x) noexcept; constexpr reference& operator=(const reference& x) noexcept; constexpr const reference& operator=(bool x) const noexcept;constexpr operator bool() const noexcept; constexpr bool operator~() const noexcept; constexpr reference& flip() noexcept; friend constexpr void swap(reference x, reference y) noexcept;friend constexpr void swap(reference x, bool& y) noexcept;friend constexpr void swap(bool& x, reference y) noexcept;};constexpr bitset() noexcept;constexpr bitset(unsigned long long val) noexcept;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'));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'));constexpr bitset& operator&=(const bitset& rhs) noexcept;constexpr bitset& operator|=(const bitset& rhs) noexcept;constexpr bitset& operator^=(const bitset& rhs) noexcept;constexpr bitset& operator<<=(size_t pos) noexcept;constexpr bitset& operator>>=(size_t pos) noexcept;constexpr bitset operator<<(size_t pos) const noexcept;constexpr bitset operator>>(size_t pos) const noexcept;constexpr bitset& set() noexcept;constexpr bitset& set(size_t pos, bool val = true);constexpr bitset& reset() noexcept;constexpr bitset& reset(size_t pos);constexpr bitset operator~() const noexcept;constexpr bitset& flip() noexcept;constexpr bitset& flip(size_t pos);constexpr bool operator[](size_t pos) const;constexpr reference operator[](size_t pos);constexpr unsigned long to_ulong() const;constexpr unsigned long long to_ullong() const;template<class charT = char,class traits = char_traits<charT>,class Allocator = allocator<charT>> constexpr basic_string<charT, traits, Allocator> to_string(charT zero = charT('0'), charT one = charT('1')) const;constexpr size_t count() const noexcept;constexpr size_t size() const noexcept;constexpr bool operator==(const bitset& rhs) const noexcept;constexpr bool test(size_t pos) const;constexpr bool all() const noexcept;constexpr bool any() const noexcept;constexpr bool none() const noexcept;};template<class T> struct hash;template<size_t N> struct hash<bitset<N>>;}
The class templatebitset<N>describes an object that can store a sequence consisting of a fixed number of bits, N.
Each bit represents either the value zero (reset) or one (set).
Totogglea bit is to change the value zero to one, or the value one to zero.
Each bit has a non-negative position pos.
When converting between an object of typebitset<N>and a value of some integral type, bit position pos corresponds to thebit value 1 << pos.
The integral value corresponding to two or more bits is the sum of their bit values.
referenceis a class that simulates a reference to a single bit in the sequence.
constexpr reference::reference(const reference& x) noexcept;
Effects: Initializes *this to refer to the same bit as x.
constexpr reference::~reference();
constexpr reference& reference::operator=(bool x) noexcept;constexpr reference& reference::operator=(const reference& x) noexcept;constexpr const reference& reference::operator=(bool x) const noexcept;
Effects: Sets the bit referred to by *this if bool(x) is true, and clears it otherwise.
constexpr void swap(reference x, reference y) noexcept;constexpr void swap(reference x, bool& y) noexcept;constexpr void swap(bool& x, reference y) noexcept;
Effects: Exchanges the values denoted by x and y as if by:
bool b = x; x = y; y = b;
constexpr reference& reference::flip() noexcept;
Effects: Equivalent to *this = !*this.
The functions described in [template.bitset] can report three kinds of errors, each associated with a distinct exception:
- aninvalid-argumenterror is associated with exceptions of typeinvalid_argument ([invalid.argument]);
- anout-of-rangeerror is associated with exceptions of typeout_of_range ([out.of.range]);
- anoverflowerror is associated with exceptions of typeoverflow_error ([overflow.error]).