[bitset] # 22 General utilities library [[utilities]](./#utilities) ## 22.9 Bitsets [bitset] ### [22.9.1](#syn) Header synopsis [[bitset.syn]](bitset.syn) [1](#syn-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10360) The header defines a class template and several related functions for representing and manipulating fixed-size sequences of bits[.](#syn-1.sentence-1) #include // see [[string.syn]](string.syn "27.4.2 Header synopsis")#include // for istream ([[istream.syn]](istream.syn "31.7.1 Header synopsis")), ostream ([[ostream.syn]](ostream.syn "31.7.2 Header synopsis")), see [[iosfwd.syn]](iosfwd.syn "31.3.1 Header synopsis")namespace std {template class bitset; // [[bitset.operators]](#operators "22.9.4 bitset operators"), bitset operatorstemplateconstexpr bitset operator&(const bitset&, const bitset&) noexcept; templateconstexpr bitset operator|(const bitset&, const bitset&) noexcept; templateconstexpr bitset operator^(const bitset&, const bitset&) noexcept; template basic_istream&operator>>(basic_istream& is, bitset& x); template basic_ostream&operator<<(basic_ostream& os, const bitset& x);} ### [22.9.2](#template.bitset) Class template bitset [[template.bitset]](template.bitset) #### [22.9.2.1](#template.bitset.general) General [[template.bitset.general]](template.bitset.general) [🔗](#lib:bitset_) namespace std {template class bitset {public:// bit referenceclass reference {public:constexpr reference(const reference&) = default; constexpr ~reference(); constexpr reference& operator=(bool x) noexcept; // for b[i] = x;constexpr reference& operator=(const reference&) noexcept; // for b[i] = b[j];constexpr bool operator~() const noexcept; // flips the bitconstexpr operator bool() const noexcept; // for x = b[i];constexpr reference& flip() noexcept; // for b[i].flip();}; // [[bitset.cons]](#cons "22.9.2.2 Constructors"), constructorsconstexpr bitset() noexcept; constexpr bitset(unsigned long long val) noexcept; templateconstexpr explicit bitset(const basic_string& str, typename basic_string::size_type pos = 0, typename basic_string::size_type n = basic_string::npos, charT zero = charT('0'), charT one = charT('1')); templateconstexpr explicit bitset( basic_string_view str, typename basic_string_view::size_type pos = 0, typename basic_string_view::size_type n = basic_string_view::npos, charT zero = charT('0'), charT one = charT('1')); templateconstexpr explicit bitset(const charT* str, typename basic_string_view::size_type n = basic_string_view::npos, charT zero = charT('0'), charT one = charT('1')); // [[bitset.members]](#members "22.9.2.3 Members"), bitset operationsconstexpr 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); // element accessconstexpr 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 Allocator = allocator>constexpr basic_string to_string(charT zero = charT('0'), charT one = charT('1')) const; // observersconstexpr 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; }; // [[bitset.hash]](#hash "22.9.3 bitset hash support"), hash supporttemplate struct hash; template struct hash>;} [1](#template.bitset.general-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10478) The class templatebitset describes an object that can store a sequence consisting of a fixed number of bits, N[.](#template.bitset.general-1.sentence-1) [2](#template.bitset.general-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10484) Each bit represents either the value zero (reset) or one (set)[.](#template.bitset.general-2.sentence-1) To[*toggle*](#def:toggle) a bit is to change the value zero to one, or the value one to zero[.](#template.bitset.general-2.sentence-2) Each bit has a non-negative position pos[.](#template.bitset.general-2.sentence-3) When converting between an object of classbitset and a value of some integral type, bit position pos corresponds to the[*bit value*](#def:bit_value)1 << pos[.](#template.bitset.general-2.sentence-4) The integral value corresponding to two or more bits is the sum of their bit values[.](#template.bitset.general-2.sentence-5) [3](#template.bitset.general-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10501) The functions described in [[template.bitset]](#template.bitset "22.9.2 Class template bitset") can report three kinds of errors, each associated with a distinct exception: - [(3.1)](#template.bitset.general-3.1) an[*invalid-argument*](#def:invalid-argument) error is associated with exceptions of typeinvalid_argument ([[invalid.argument]](invalid.argument "19.2.5 Class invalid_­argument")); - [(3.2)](#template.bitset.general-3.2) an[*out-of-range*](#def:out-of-range) error is associated with exceptions of typeout_of_range ([[out.of.range]](out.of.range "19.2.7 Class out_­of_­range")); - [(3.3)](#template.bitset.general-3.3) an[*overflow*](#def:overflow) error is associated with exceptions of typeoverflow_error ([[overflow.error]](overflow.error "19.2.10 Class overflow_­error"))[.](#template.bitset.general-3.sentence-1) #### [22.9.2.2](#cons) Constructors [[bitset.cons]](bitset.cons) [🔗](#lib:bitset,constructor) `constexpr bitset() noexcept; ` [1](#cons-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10533) *Effects*: Initializes all bits in *this to zero[.](#cons-1.sentence-1) [🔗](#lib:bitset,constructor_) `constexpr bitset(unsigned long long val) noexcept; ` [2](#cons-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10544) *Effects*: Initializes the first M bit positions to the corresponding bit values in val[.](#cons-2.sentence-1) M is the smaller of N and the number of bits in the value representation ([[basic.types.general]](basic.types.general#term.object.representation "6.9.1 General")) of unsigned long long[.](#cons-2.sentence-2) If M < N, the remaining bit positions are initialized to zero[.](#cons-2.sentence-3) [🔗](#lib:bitset,constructor__) `template constexpr explicit bitset( const basic_string& str, typename basic_string::size_type pos = 0, typename basic_string::size_type n = basic_string::npos, charT zero = charT('0'), charT one = charT('1')); template constexpr explicit bitset( basic_string_view str, typename basic_string_view::size_type pos = 0, typename basic_string_view::size_type n = basic_string_view::npos, charT zero = charT('0'), charT one = charT('1')); ` [3](#cons-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10574) *Effects*: Determines the effective lengthrlen of the initializing string as the smaller ofn andstr.size() - pos[.](#cons-3.sentence-1) Initializes the first M bit positions to values determined from the corresponding characters in the stringstr[.](#cons-3.sentence-2) M is the smaller of N and rlen[.](#cons-3.sentence-3) [4](#cons-4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10585) An element of the constructed object has value zero if the corresponding character in str, beginning at positionpos, iszero[.](#cons-4.sentence-1) Otherwise, the element has the value one[.](#cons-4.sentence-2) Character position pos + M - 1 corresponds to bit position zero[.](#cons-4.sentence-3) Subsequent decreasing character positions correspond to increasing bit positions[.](#cons-4.sentence-4) [5](#cons-5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10594) If M < N, remaining bit positions are initialized to zero[.](#cons-5.sentence-1) [6](#cons-6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10597) The function uses traits​::​eq to compare the character values[.](#cons-6.sentence-1) [7](#cons-7) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10601) *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[.](#cons-7.sentence-1) [🔗](#lib:bitset,constructor___) `template constexpr explicit bitset( const charT* str, typename basic_string_view::size_type n = basic_string_view::npos, charT zero = charT('0'), charT one = charT('1')); ` [8](#cons-8) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10623) *Effects*: As if by:bitset(n == basic_string_view::npos ? basic_string_view(str): basic_string_view(str, n), 0, n, zero, one) #### [22.9.2.3](#members) Members [[bitset.members]](bitset.members) [🔗](#lib:operator&=,bitset) `constexpr bitset& operator&=(const bitset& rhs) noexcept; ` [1](#members-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10643) *Effects*: Clears each bit in*this for which the corresponding bit in rhs is clear, and leaves all other bits unchanged[.](#members-1.sentence-1) [2](#members-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10649) *Returns*: *this[.](#members-2.sentence-1) [🔗](#lib:operator%7c=,bitset) `constexpr bitset& operator|=(const bitset& rhs) noexcept; ` [3](#members-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10660) *Effects*: Sets each bit in*this for which the corresponding bit in rhs is set, and leaves all other bits unchanged[.](#members-3.sentence-1) [4](#members-4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10666) *Returns*: *this[.](#members-4.sentence-1) [🔗](#lib:operator%5e=,bitset) `constexpr bitset& operator^=(const bitset& rhs) noexcept; ` [5](#members-5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10677) *Effects*: Toggles each bit in*this for which the corresponding bit in rhs is set, and leaves all other bits unchanged[.](#members-5.sentence-1) [6](#members-6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10683) *Returns*: *this[.](#members-6.sentence-1) [🔗](#lib:operator%3c%3c=,bitset) `constexpr bitset& operator<<=(size_t pos) noexcept; ` [7](#members-7) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10694) *Effects*: Replaces each bit at position I in*this with a value determined as follows: - [(7.1)](#members-7.1) If I < pos, the new value is zero; - [(7.2)](#members-7.2) If I >= pos, the new value is the previous value of the bit at position I - pos[.](#members-7.sentence-1) [8](#members-8) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10707) *Returns*: *this[.](#members-8.sentence-1) [🔗](#lib:operator%3e%3e=,bitset) `constexpr bitset& operator>>=(size_t pos) noexcept; ` [9](#members-9) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10718) *Effects*: Replaces each bit at position I in*this with a value determined as follows: - [(9.1)](#members-9.1) If pos >= N - I, the new value is zero; - [(9.2)](#members-9.2) If pos < N - I, the new value is the previous value of the bit at position I + pos[.](#members-9.sentence-1) [10](#members-10) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10730) *Returns*: *this[.](#members-10.sentence-1) [🔗](#lib:operator%3c%3c,bitset) `constexpr bitset operator<<(size_t pos) const noexcept; ` [11](#members-11) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10741) *Returns*: bitset(*this) <<= pos[.](#members-11.sentence-1) [🔗](#lib:operator%3e%3e,bitset) `constexpr bitset operator>>(size_t pos) const noexcept; ` [12](#members-12) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10752) *Returns*: bitset(*this) >>= pos[.](#members-12.sentence-1) [🔗](#lib:set_(member),bitset) `constexpr bitset& set() noexcept; ` [13](#members-13) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10765) *Effects*: Sets all bits in*this[.](#members-13.sentence-1) [14](#members-14) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10770) *Returns*: *this[.](#members-14.sentence-1) [🔗](#lib:set_(member),bitset_) `constexpr bitset& set(size_t pos, bool val = true); ` [15](#members-15) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10783) *Effects*: Stores a new value in the bit at position pos in*this[.](#members-15.sentence-1) If val is true, the stored value is one, otherwise it is zero[.](#members-15.sentence-2) [16](#members-16) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10789) *Returns*: *this[.](#members-16.sentence-1) [17](#members-17) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10793) *Throws*: out_of_range if pos does not correspond to a valid bit position[.](#members-17.sentence-1) [🔗](#lib:reset,bitset) `constexpr bitset& reset() noexcept; ` [18](#members-18) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10805) *Effects*: Resets all bits in*this[.](#members-18.sentence-1) [19](#members-19) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10810) *Returns*: *this[.](#members-19.sentence-1) [🔗](#lib:reset,bitset_) `constexpr bitset& reset(size_t pos); ` [20](#members-20) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10821) *Effects*: Resets the bit at position pos in*this[.](#members-20.sentence-1) [21](#members-21) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10826) *Returns*: *this[.](#members-21.sentence-1) [22](#members-22) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10830) *Throws*: out_of_range if pos does not correspond to a valid bit position[.](#members-22.sentence-1) [🔗](#lib:operator~,bitset) `constexpr bitset operator~() const noexcept; ` [23](#members-23) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10842) *Effects*: Constructs an object x of classbitset and initializes it with*this[.](#members-23.sentence-1) [24](#members-24) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10849) *Returns*: x.flip()[.](#members-24.sentence-1) [🔗](#lib:flip,bitset) `constexpr bitset& flip() noexcept; ` [25](#members-25) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10860) *Effects*: Toggles all bits in*this[.](#members-25.sentence-1) [26](#members-26) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10865) *Returns*: *this[.](#members-26.sentence-1) [🔗](#lib:flip,bitset_) `constexpr bitset& flip(size_t pos); ` [27](#members-27) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10876) *Effects*: Toggles the bit at position pos in*this[.](#members-27.sentence-1) [28](#members-28) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10881) *Returns*: *this[.](#members-28.sentence-1) [29](#members-29) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10885) *Throws*: out_of_range if pos does not correspond to a valid bit position[.](#members-29.sentence-1) [🔗](#lib:operator%5b%5d,bitset) `constexpr bool operator[](size_t pos) const; ` [30](#members-30) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10897) *Hardened preconditions*: pos < size() is true[.](#members-30.sentence-1) [31](#members-31) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10901) *Returns*: true if the bit at position pos in *this has the value one, otherwise false[.](#members-31.sentence-1) [32](#members-32) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10906) *Throws*: Nothing[.](#members-32.sentence-1) [🔗](#lib:operator%5b%5d,bitset_) `constexpr bitset::reference operator[](size_t pos); ` [33](#members-33) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10917) *Hardened preconditions*: pos < size() is true[.](#members-33.sentence-1) [34](#members-34) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10921) *Returns*: An object of typebitset​::​reference such that(*this)[pos] == this->test(pos), and such that(*this)[pos] = val is equivalent tothis->set(pos, val)[.](#members-34.sentence-1) [35](#members-35) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10932) *Throws*: Nothing[.](#members-35.sentence-1) [36](#members-36) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10936) *Remarks*: For the purpose of determining the presence of a data race ([[intro.multithread]](intro.multithread "6.10.2 Multi-threaded executions and data races")), any access or update through the resulting reference potentially accesses or modifies, respectively, the entire underlying bitset[.](#members-36.sentence-1) [🔗](#lib:to_ulong,bitset) `constexpr unsigned long to_ulong() const; ` [37](#members-37) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10950) *Returns*: x[.](#members-37.sentence-1) [38](#members-38) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10954) *Throws*: overflow_error if the integral value x corresponding to the bits in *this cannot be represented as type unsigned long[.](#members-38.sentence-1) [🔗](#lib:to_ullong,bitset) `constexpr unsigned long long to_ullong() const; ` [39](#members-39) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10968) *Returns*: x[.](#members-39.sentence-1) [40](#members-40) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10972) *Throws*: overflow_error if the integral value x corresponding to the bits in *this cannot be represented as type unsigned long long[.](#members-40.sentence-1) [🔗](#lib:to_string,bitset) `template, class Allocator = allocator> constexpr basic_string to_string(charT zero = charT('0'), charT one = charT('1')) const; ` [41](#members-41) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L10990) *Effects*: Constructs a string object of the appropriate type and initializes it to a string of length N characters[.](#members-41.sentence-1) Each character is determined by the value of its corresponding bit position in*this[.](#members-41.sentence-2) Character position N - 1 corresponds to bit position zero[.](#members-41.sentence-3) Subsequent decreasing character positions correspond to increasing bit positions[.](#members-41.sentence-4) Bit value zero becomes the character zero, bit value one becomes the characterone[.](#members-41.sentence-5) [42](#members-42) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L11003) *Returns*: The created object[.](#members-42.sentence-1) [🔗](#lib:count,bitset) `constexpr size_t count() const noexcept; ` [43](#members-43) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L11014) *Returns*: A count of the number of bits set in*this[.](#members-43.sentence-1) [🔗](#lib:size,bitset) `constexpr size_t size() const noexcept; ` [44](#members-44) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L11026) *Returns*: N[.](#members-44.sentence-1) [🔗](#lib:operator==,bitset) `constexpr bool operator==(const bitset& rhs) const noexcept; ` [45](#members-45) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L11037) *Returns*: true if the value of each bit in*this equals the value of the corresponding bit in rhs[.](#members-45.sentence-1) [🔗](#lib:test,bitset) `constexpr bool test(size_t pos) const; ` [46](#members-46) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L11050) *Returns*: true if the bit at position pos in*this has the value one[.](#members-46.sentence-1) [47](#members-47) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L11058) *Throws*: out_of_range if pos does not correspond to a valid bit position[.](#members-47.sentence-1) [🔗](#lib:all,bitset) `constexpr bool all() const noexcept; ` [48](#members-48) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L11070) *Returns*: count() == size()[.](#members-48.sentence-1) [🔗](#lib:any_(member),bitset) `constexpr bool any() const noexcept; ` [49](#members-49) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L11083) *Returns*: count() != 0[.](#members-49.sentence-1) [🔗](#lib:none,bitset) `constexpr bool none() const noexcept; ` [50](#members-50) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L11094) *Returns*: count() == 0[.](#members-50.sentence-1) ### [22.9.3](#hash) bitset hash support [[bitset.hash]](bitset.hash) [🔗](#lib:hash_code) `template struct hash>; ` [1](#hash-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L11107) The specialization is enabled ([[unord.hash]](unord.hash "22.10.19 Class template hash"))[.](#hash-1.sentence-1) ### [22.9.4](#operators) bitset operators [[bitset.operators]](bitset.operators) [🔗](#lib:operator&,bitset) `template constexpr bitset operator&(const bitset& lhs, const bitset& rhs) noexcept; ` [1](#operators-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L11121) *Returns*: bitset(lhs) &= rhs[.](#operators-1.sentence-1) [🔗](#lib:operator%7c,bitset) `template constexpr bitset operator|(const bitset& lhs, const bitset& rhs) noexcept; ` [2](#operators-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L11133) *Returns*: bitset(lhs) |= rhs[.](#operators-2.sentence-1) [🔗](#lib:operator%5e,bitset) `template constexpr bitset operator^(const bitset& lhs, const bitset& rhs) noexcept; ` [3](#operators-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L11145) *Returns*: bitset(lhs) ^= rhs[.](#operators-3.sentence-1) [🔗](#lib:operator%3e%3e,bitset_) `template basic_istream& operator>>(basic_istream& is, bitset& x); ` [4](#operators-4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L11158) A formatted input function ([[istream.formatted]](istream.formatted "31.7.5.3 Formatted input functions"))[.](#operators-4.sentence-1) [5](#operators-5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L11161) *Effects*: Extracts up to N characters from is[.](#operators-5.sentence-1) Stores these characters in a temporary object str of typebasic_string, then evaluates the expressionx = bitset(str)[.](#operators-5.sentence-2) Characters are extracted and stored until any of the following occurs: - [(5.1)](#operators-5.1) N characters have been extracted and stored; - [(5.2)](#operators-5.2) end-of-file occurs on the input sequence; - [(5.3)](#operators-5.3) the next input character is neitheris.widen('0') noris.widen('1') (in which case the input character is not extracted)[.](#operators-5.sentence-3) [6](#operators-6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L11183) If N > 0 and no characters are stored in str,ios_base​::​failbit is set in the input function's local error state before setstate is called[.](#operators-6.sentence-1) [7](#operators-7) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L11188) *Returns*: is[.](#operators-7.sentence-1) [🔗](#lib:operator%3c%3c,bitset_) `template basic_ostream& operator<<(basic_ostream& os, const bitset& x); ` [8](#operators-8) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L11201) *Returns*: os << x.template to_string>( use_facet>(os.getloc()).widen('0'), use_facet>(os.getloc()).widen('1')) (see [[ostream.formatted]](ostream.formatted "31.7.6.3 Formatted output functions"))[.](#operators-8.sentence-1)