llvm-project
969 строк · 38.7 Кб
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_BITSET11#define _LIBCPP_BITSET12
13// clang-format off
14
15/*
16bitset synopsis
17
18namespace std
19{
20
21namespace std {
22
23template <size_t N>
24class bitset
25{
26public:
27// bit reference:
28class reference
29{
30friend class bitset;
31reference() noexcept;
32public:
33~reference() noexcept;
34reference& operator=(bool x) noexcept; // for b[i] = x;
35reference& operator=(const reference&) noexcept; // for b[i] = b[j];
36bool operator~() const noexcept; // flips the bit
37operator bool() const noexcept; // for x = b[i];
38reference& flip() noexcept; // for b[i].flip();
39};
40
41// 23.3.5.1 constructors:
42constexpr bitset() noexcept;
43constexpr bitset(unsigned long long val) noexcept;
44template <class charT>
45constexpr explicit bitset(const charT* str,
46typename basic_string<charT>::size_type n = basic_string<charT>::npos,
47charT zero = charT('0'), charT one = charT('1')); // until C++26, constexpr since C++23
48template <class charT>
49constexpr explicit bitset(const charT* str,
50typename basic_string_view<charT>::size_type n = basic_string_view<charT>::npos,
51charT zero = charT('0'), charT one = charT('1')); // since C++26
52template<class charT, class traits>
53explicit bitset(
54const basic_string_view<charT,traits>& str,
55typename basic_string_view<charT,traits>::size_type pos = 0,
56typename basic_string_view<charT,traits>::size_type n = basic_string_view<charT,traits>::npos,
57charT zero = charT('0'), charT one = charT('1')); // since C++26
58template<class charT, class traits, class Allocator>
59constexpr explicit bitset(
60const basic_string<charT,traits,Allocator>& str,
61typename basic_string<charT,traits,Allocator>::size_type pos = 0,
62typename basic_string<charT,traits,Allocator>::size_type n = basic_string<charT,traits,Allocator>::npos,
63charT zero = charT('0'), charT one = charT('1')); // constexpr since C++23
64
65// 23.3.5.2 bitset operations:
66bitset& operator&=(const bitset& rhs) noexcept; // constexpr since C++23
67bitset& operator|=(const bitset& rhs) noexcept; // constexpr since C++23
68bitset& operator^=(const bitset& rhs) noexcept; // constexpr since C++23
69bitset& operator<<=(size_t pos) noexcept; // constexpr since C++23
70bitset& operator>>=(size_t pos) noexcept; // constexpr since C++23
71bitset& set() noexcept; // constexpr since C++23
72bitset& set(size_t pos, bool val = true); // constexpr since C++23
73bitset& reset() noexcept; // constexpr since C++23
74bitset& reset(size_t pos); // constexpr since C++23
75bitset operator~() const noexcept; // constexpr since C++23
76bitset& flip() noexcept; // constexpr since C++23
77bitset& flip(size_t pos); // constexpr since C++23
78
79// element access:
80constexpr bool operator[](size_t pos) const;
81reference operator[](size_t pos); // constexpr since C++23
82unsigned long to_ulong() const; // constexpr since C++23
83unsigned long long to_ullong() const; // constexpr since C++23
84template <class charT, class traits, class Allocator> // constexpr since C++23
85basic_string<charT, traits, Allocator> to_string(charT zero = charT('0'), charT one = charT('1')) const;
86template <class charT, class traits> // constexpr since C++23
87basic_string<charT, traits, allocator<charT> > to_string(charT zero = charT('0'), charT one = charT('1')) const;
88template <class charT> // constexpr since C++23
89basic_string<charT, char_traits<charT>, allocator<charT> > to_string(charT zero = charT('0'), charT one = charT('1')) const;
90basic_string<char, char_traits<char>, allocator<char> > to_string(char zero = '0', char one = '1') const; // constexpr since C++23
91size_t count() const noexcept; // constexpr since C++23
92constexpr size_t size() const noexcept; // constexpr since C++23
93bool operator==(const bitset& rhs) const noexcept; // constexpr since C++23
94bool operator!=(const bitset& rhs) const noexcept; // removed in C++20
95bool test(size_t pos) const; // constexpr since C++23
96bool all() const noexcept; // constexpr since C++23
97bool any() const noexcept; // constexpr since C++23
98bool none() const noexcept; // constexpr since C++23
99bitset<N> operator<<(size_t pos) const noexcept; // constexpr since C++23
100bitset<N> operator>>(size_t pos) const noexcept; // constexpr since C++23
101};
102
103// 23.3.5.3 bitset operators:
104template <size_t N>
105bitset<N> operator&(const bitset<N>&, const bitset<N>&) noexcept; // constexpr since C++23
106
107template <size_t N>
108bitset<N> operator|(const bitset<N>&, const bitset<N>&) noexcept; // constexpr since C++23
109
110template <size_t N>
111bitset<N> operator^(const bitset<N>&, const bitset<N>&) noexcept; // constexpr since C++23
112
113template <class charT, class traits, size_t N>
114basic_istream<charT, traits>&
115operator>>(basic_istream<charT, traits>& is, bitset<N>& x);
116
117template <class charT, class traits, size_t N>
118basic_ostream<charT, traits>&
119operator<<(basic_ostream<charT, traits>& os, const bitset<N>& x);
120
121template <size_t N> struct hash<std::bitset<N>>;
122
123} // std
124
125*/
126
127// clang-format on
128
129#include <__algorithm/count.h>130#include <__algorithm/fill.h>131#include <__algorithm/find.h>132#include <__bit_reference>133#include <__config>134#include <__functional/hash.h>135#include <__functional/unary_function.h>136#include <__type_traits/is_char_like_type.h>137#include <climits>138#include <cstddef>139#include <stdexcept>140#include <string_view>141#include <version>142
143// standard-mandated includes
144
145// [bitset.syn]
146#include <iosfwd>147#include <string>148
149#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)150# pragma GCC system_header151#endif152
153_LIBCPP_PUSH_MACROS
154#include <__undef_macros>155
156_LIBCPP_BEGIN_NAMESPACE_STD
157
158template <size_t _N_words, size_t _Size>159class __bitset;160
161template <size_t _N_words, size_t _Size>162struct __has_storage_type<__bitset<_N_words, _Size> > {163static const bool value = true;164};165
166template <size_t _N_words, size_t _Size>167class __bitset {168public:169typedef ptrdiff_t difference_type;170typedef size_t size_type;171typedef size_type __storage_type;172
173protected:174typedef __bitset __self;175typedef __storage_type* __storage_pointer;176typedef const __storage_type* __const_storage_pointer;177static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);178
179friend class __bit_reference<__bitset>;180friend class __bit_const_reference<__bitset>;181friend class __bit_iterator<__bitset, false>;182friend class __bit_iterator<__bitset, true>;183friend struct __bit_array<__bitset>;184
185__storage_type __first_[_N_words];186
187typedef __bit_reference<__bitset> reference;188typedef __bit_const_reference<__bitset> const_reference;189typedef __bit_iterator<__bitset, false> iterator;190typedef __bit_iterator<__bitset, true> const_iterator;191
192_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;193_LIBCPP_HIDE_FROM_ABI explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT;194
195_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 reference __make_ref(size_t __pos) _NOEXCEPT {196return reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);197}198_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT {199return const_reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);200}201_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 iterator __make_iter(size_t __pos) _NOEXCEPT {202return iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);203}204_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 const_iterator __make_iter(size_t __pos) const _NOEXCEPT {205return const_iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);206}207
208_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator&=(const __bitset& __v) _NOEXCEPT;209_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator|=(const __bitset& __v) _NOEXCEPT;210_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator^=(const __bitset& __v) _NOEXCEPT;211
212_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void flip() _NOEXCEPT;213_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong() const {214return to_ulong(integral_constant < bool, _Size< sizeof(unsigned long) * CHAR_BIT>());215}216_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong() const {217return to_ullong(integral_constant < bool, _Size< sizeof(unsigned long long) * CHAR_BIT>());218}219
220_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT;221_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT;222_LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT;223
224private:225#ifdef _LIBCPP_CXX03_LANG226void __init(unsigned long long __v, false_type) _NOEXCEPT;227_LIBCPP_HIDE_FROM_ABI void __init(unsigned long long __v, true_type) _NOEXCEPT;228#endif // _LIBCPP_CXX03_LANG229_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong(false_type) const;230_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong(true_type) const;231_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong(false_type) const;232_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong(true_type) const;233_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong(true_type, false_type) const;234_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong(true_type, true_type) const;235};236
237template <size_t _N_words, size_t _Size>238inline _LIBCPP_CONSTEXPR __bitset<_N_words, _Size>::__bitset() _NOEXCEPT239#ifndef _LIBCPP_CXX03_LANG240: __first_{0}241#endif242{
243#ifdef _LIBCPP_CXX03_LANG244std::fill_n(__first_, _N_words, __storage_type(0));245#endif246}
247
248#ifdef _LIBCPP_CXX03_LANG249
250template <size_t _N_words, size_t _Size>251void __bitset<_N_words, _Size>::__init(unsigned long long __v, false_type) _NOEXCEPT {252__storage_type __t[sizeof(unsigned long long) / sizeof(__storage_type)];253size_t __sz = _Size;254for (size_t __i = 0; __i < sizeof(__t) / sizeof(__t[0]); ++__i, __v >>= __bits_per_word, __sz -= __bits_per_word)255if (__sz < __bits_per_word)256__t[__i] = static_cast<__storage_type>(__v) & (1ULL << __sz) - 1;257else258__t[__i] = static_cast<__storage_type>(__v);259
260std::copy(__t, __t + sizeof(__t) / sizeof(__t[0]), __first_);261std::fill(262__first_ + sizeof(__t) / sizeof(__t[0]), __first_ + sizeof(__first_) / sizeof(__first_[0]), __storage_type(0));263}
264
265template <size_t _N_words, size_t _Size>266inline _LIBCPP_HIDE_FROM_ABI void __bitset<_N_words, _Size>::__init(unsigned long long __v, true_type) _NOEXCEPT {267__first_[0] = __v;268if (_Size < __bits_per_word)269__first_[0] &= (1ULL << _Size) - 1;270
271std::fill(__first_ + 1, __first_ + sizeof(__first_) / sizeof(__first_[0]), __storage_type(0));272}
273
274#endif // _LIBCPP_CXX03_LANG275
276template <size_t _N_words, size_t _Size>277inline _LIBCPP_CONSTEXPR __bitset<_N_words, _Size>::__bitset(unsigned long long __v) _NOEXCEPT278#ifndef _LIBCPP_CXX03_LANG279# if __SIZEOF_SIZE_T__ == 8280: __first_{__v}281# elif __SIZEOF_SIZE_T__ == 4282: __first_{static_cast<__storage_type>(__v),283_Size >= 2 * __bits_per_word284? static_cast<__storage_type>(__v >> __bits_per_word)285: static_cast<__storage_type>((__v >> __bits_per_word) &286(__storage_type(1) << (_Size - __bits_per_word)) - 1)}287# else288# error This constructor has not been ported to this platform289# endif290#endif291{
292#ifdef _LIBCPP_CXX03_LANG293__init(__v, integral_constant<bool, sizeof(unsigned long long) == sizeof(__storage_type)>());294#endif295}
296
297template <size_t _N_words, size_t _Size>298inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void299__bitset<_N_words, _Size>::operator&=(const __bitset& __v) _NOEXCEPT {300for (size_type __i = 0; __i < _N_words; ++__i)301__first_[__i] &= __v.__first_[__i];302}
303
304template <size_t _N_words, size_t _Size>305inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void306__bitset<_N_words, _Size>::operator|=(const __bitset& __v) _NOEXCEPT {307for (size_type __i = 0; __i < _N_words; ++__i)308__first_[__i] |= __v.__first_[__i];309}
310
311template <size_t _N_words, size_t _Size>312inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void313__bitset<_N_words, _Size>::operator^=(const __bitset& __v) _NOEXCEPT {314for (size_type __i = 0; __i < _N_words; ++__i)315__first_[__i] ^= __v.__first_[__i];316}
317
318template <size_t _N_words, size_t _Size>319_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void __bitset<_N_words, _Size>::flip() _NOEXCEPT {320// do middle whole words321size_type __n = _Size;322__storage_pointer __p = __first_;323for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)324*__p = ~*__p;325// do last partial word326if (__n > 0) {327__storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);328__storage_type __b = *__p & __m;329*__p &= ~__m;330*__p |= ~__b & __m;331}332}
333
334template <size_t _N_words, size_t _Size>335_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long336__bitset<_N_words, _Size>::to_ulong(false_type) const {337const_iterator __e = __make_iter(_Size);338const_iterator __i = std::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true);339if (__i != __e)340__throw_overflow_error("bitset to_ulong overflow error");341
342return __first_[0];343}
344
345template <size_t _N_words, size_t _Size>346inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long347__bitset<_N_words, _Size>::to_ulong(true_type) const {348return __first_[0];349}
350
351template <size_t _N_words, size_t _Size>352_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long353__bitset<_N_words, _Size>::to_ullong(false_type) const {354const_iterator __e = __make_iter(_Size);355const_iterator __i = std::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true);356if (__i != __e)357__throw_overflow_error("bitset to_ullong overflow error");358
359return to_ullong(true_type());360}
361
362template <size_t _N_words, size_t _Size>363inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long364__bitset<_N_words, _Size>::to_ullong(true_type) const {365return to_ullong(true_type(), integral_constant<bool, sizeof(__storage_type) < sizeof(unsigned long long)>());366}
367
368template <size_t _N_words, size_t _Size>369inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long370__bitset<_N_words, _Size>::to_ullong(true_type, false_type) const {371return __first_[0];372}
373
374template <size_t _N_words, size_t _Size>375_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long376__bitset<_N_words, _Size>::to_ullong(true_type, true_type) const {377unsigned long long __r = __first_[0];378_LIBCPP_DIAGNOSTIC_PUSH
379_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wshift-count-overflow")380for (size_t __i = 1; __i < sizeof(unsigned long long) / sizeof(__storage_type); ++__i)381__r |= static_cast<unsigned long long>(__first_[__i]) << (sizeof(__storage_type) * CHAR_BIT);382_LIBCPP_DIAGNOSTIC_POP
383return __r;384}
385
386template <size_t _N_words, size_t _Size>387_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool __bitset<_N_words, _Size>::all() const _NOEXCEPT {388// do middle whole words389size_type __n = _Size;390__const_storage_pointer __p = __first_;391for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)392if (~*__p)393return false;394// do last partial word395if (__n > 0) {396__storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);397if (~*__p & __m)398return false;399}400return true;401}
402
403template <size_t _N_words, size_t _Size>404_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool __bitset<_N_words, _Size>::any() const _NOEXCEPT {405// do middle whole words406size_type __n = _Size;407__const_storage_pointer __p = __first_;408for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)409if (*__p)410return true;411// do last partial word412if (__n > 0) {413__storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);414if (*__p & __m)415return true;416}417return false;418}
419
420template <size_t _N_words, size_t _Size>421inline size_t __bitset<_N_words, _Size>::__hash_code() const _NOEXCEPT {422size_t __h = 0;423for (size_type __i = 0; __i < _N_words; ++__i)424__h ^= __first_[__i];425return __h;426}
427
428template <size_t _Size>429class __bitset<1, _Size> {430public:431typedef ptrdiff_t difference_type;432typedef size_t size_type;433typedef size_type __storage_type;434
435protected:436typedef __bitset __self;437typedef __storage_type* __storage_pointer;438typedef const __storage_type* __const_storage_pointer;439static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);440
441friend class __bit_reference<__bitset>;442friend class __bit_const_reference<__bitset>;443friend class __bit_iterator<__bitset, false>;444friend class __bit_iterator<__bitset, true>;445friend struct __bit_array<__bitset>;446
447__storage_type __first_;448
449typedef __bit_reference<__bitset> reference;450typedef __bit_const_reference<__bitset> const_reference;451typedef __bit_iterator<__bitset, false> iterator;452typedef __bit_iterator<__bitset, true> const_iterator;453
454_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;455_LIBCPP_HIDE_FROM_ABI explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT;456
457_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 reference __make_ref(size_t __pos) _NOEXCEPT {458return reference(&__first_, __storage_type(1) << __pos);459}460_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT {461return const_reference(&__first_, __storage_type(1) << __pos);462}463_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 iterator __make_iter(size_t __pos) _NOEXCEPT {464return iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);465}466_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 const_iterator __make_iter(size_t __pos) const _NOEXCEPT {467return const_iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);468}469
470_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator&=(const __bitset& __v) _NOEXCEPT;471_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator|=(const __bitset& __v) _NOEXCEPT;472_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator^=(const __bitset& __v) _NOEXCEPT;473
474_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void flip() _NOEXCEPT;475
476_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong() const;477_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong() const;478
479_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT;480_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT;481
482_LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT;483};484
485template <size_t _Size>486inline _LIBCPP_CONSTEXPR __bitset<1, _Size>::__bitset() _NOEXCEPT : __first_(0) {}487
488template <size_t _Size>489inline _LIBCPP_CONSTEXPR __bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT490: __first_(_Size == __bits_per_word ? static_cast<__storage_type>(__v)491: static_cast<__storage_type>(__v) & ((__storage_type(1) << _Size) - 1)) {}492
493template <size_t _Size>494inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void495__bitset<1, _Size>::operator&=(const __bitset& __v) _NOEXCEPT {496__first_ &= __v.__first_;497}
498
499template <size_t _Size>500inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void501__bitset<1, _Size>::operator|=(const __bitset& __v) _NOEXCEPT {502__first_ |= __v.__first_;503}
504
505template <size_t _Size>506inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void507__bitset<1, _Size>::operator^=(const __bitset& __v) _NOEXCEPT {508__first_ ^= __v.__first_;509}
510
511template <size_t _Size>512inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void __bitset<1, _Size>::flip() _NOEXCEPT {513__storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);514__first_ = ~__first_;515__first_ &= __m;516}
517
518template <size_t _Size>519inline _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long __bitset<1, _Size>::to_ulong() const {520return __first_;521}
522
523template <size_t _Size>524inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long __bitset<1, _Size>::to_ullong() const {525return __first_;526}
527
528template <size_t _Size>529inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool __bitset<1, _Size>::all() const _NOEXCEPT {530__storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);531return !(~__first_ & __m);532}
533
534template <size_t _Size>535inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool __bitset<1, _Size>::any() const _NOEXCEPT {536__storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);537return __first_ & __m;538}
539
540template <size_t _Size>541inline size_t __bitset<1, _Size>::__hash_code() const _NOEXCEPT {542return __first_;543}
544
545template <>546class __bitset<0, 0> {547public:548typedef ptrdiff_t difference_type;549typedef size_t size_type;550typedef size_type __storage_type;551
552protected:553typedef __bitset __self;554typedef __storage_type* __storage_pointer;555typedef const __storage_type* __const_storage_pointer;556static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);557
558friend class __bit_reference<__bitset>;559friend class __bit_const_reference<__bitset>;560friend class __bit_iterator<__bitset, false>;561friend class __bit_iterator<__bitset, true>;562friend struct __bit_array<__bitset>;563
564typedef __bit_reference<__bitset> reference;565typedef __bit_const_reference<__bitset> const_reference;566typedef __bit_iterator<__bitset, false> iterator;567typedef __bit_iterator<__bitset, true> const_iterator;568
569_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;570_LIBCPP_HIDE_FROM_ABI explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long) _NOEXCEPT;571
572_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 reference __make_ref(size_t) _NOEXCEPT {573return reference(nullptr, 1);574}575_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference __make_ref(size_t) const _NOEXCEPT {576return const_reference(nullptr, 1);577}578_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 iterator __make_iter(size_t) _NOEXCEPT {579return iterator(nullptr, 0);580}581_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 const_iterator __make_iter(size_t) const _NOEXCEPT {582return const_iterator(nullptr, 0);583}584
585_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator&=(const __bitset&) _NOEXCEPT {}586_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator|=(const __bitset&) _NOEXCEPT {}587_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator^=(const __bitset&) _NOEXCEPT {}588
589_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void flip() _NOEXCEPT {}590
591_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong() const { return 0; }592_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong() const { return 0; }593
594_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT { return true; }595_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT { return false; }596
597_LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT { return 0; }598};599
600inline _LIBCPP_CONSTEXPR __bitset<0, 0>::__bitset() _NOEXCEPT {}601
602inline _LIBCPP_CONSTEXPR __bitset<0, 0>::__bitset(unsigned long long) _NOEXCEPT {}603
604template <size_t _Size>605class _LIBCPP_TEMPLATE_VIS bitset;606template <size_t _Size>607struct hash<bitset<_Size> >;608
609template <size_t _Size>610class _LIBCPP_TEMPLATE_VIS bitset611: private __bitset<_Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1, _Size> {612public:613static const unsigned __n_words = _Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1;614typedef __bitset<__n_words, _Size> base;615
616public:617typedef typename base::reference reference;618typedef typename base::const_reference const_reference;619
620// 23.3.5.1 constructors:621_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bitset() _NOEXCEPT {}622_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bitset(unsigned long long __v) _NOEXCEPT : base(__v) {}623template <class _CharT, __enable_if_t<_IsCharLikeType<_CharT>::value, int> = 0>624_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit bitset(625const _CharT* __str,626#if _LIBCPP_STD_VER >= 26627typename basic_string_view<_CharT>::size_type __n = basic_string_view<_CharT>::npos,628#else629typename basic_string<_CharT>::size_type __n = basic_string<_CharT>::npos,630#endif631_CharT __zero = _CharT('0'),632_CharT __one = _CharT('1')) {633
634size_t __rlen = std::min(__n, char_traits<_CharT>::length(__str));635__init_from_string_view(basic_string_view<_CharT>(__str, __rlen), __zero, __one);636}637#if _LIBCPP_STD_VER >= 26638template <class _CharT, class _Traits>639_LIBCPP_HIDE_FROM_ABI constexpr explicit bitset(640basic_string_view<_CharT, _Traits> __str,641typename basic_string_view<_CharT, _Traits>::size_type __pos = 0,642typename basic_string_view<_CharT, _Traits>::size_type __n = basic_string_view<_CharT, _Traits>::npos,643_CharT __zero = _CharT('0'),644_CharT __one = _CharT('1')) {645if (__pos > __str.size())646__throw_out_of_range("bitset string pos out of range");647
648size_t __rlen = std::min(__n, __str.size() - __pos);649__init_from_string_view(basic_string_view<_CharT, _Traits>(__str.data() + __pos, __rlen), __zero, __one);650}651#endif652template <class _CharT, class _Traits, class _Allocator>653_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit bitset(654const basic_string<_CharT, _Traits, _Allocator>& __str,655typename basic_string<_CharT, _Traits, _Allocator>::size_type __pos = 0,656typename basic_string<_CharT, _Traits, _Allocator>::size_type __n =657basic_string<_CharT, _Traits, _Allocator>::npos,658_CharT __zero = _CharT('0'),659_CharT __one = _CharT('1')) {660if (__pos > __str.size())661std::__throw_out_of_range("bitset string pos out of range");662
663size_t __rlen = std::min(__n, __str.size() - __pos);664__init_from_string_view(basic_string_view<_CharT, _Traits>(__str.data() + __pos, __rlen), __zero, __one);665}666
667// 23.3.5.2 bitset operations:668_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& operator&=(const bitset& __rhs) _NOEXCEPT;669_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& operator|=(const bitset& __rhs) _NOEXCEPT;670_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& operator^=(const bitset& __rhs) _NOEXCEPT;671_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& operator<<=(size_t __pos) _NOEXCEPT;672_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& operator>>=(size_t __pos) _NOEXCEPT;673_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& set() _NOEXCEPT;674_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& set(size_t __pos, bool __val = true);675_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& reset() _NOEXCEPT;676_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& reset(size_t __pos);677_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset operator~() const _NOEXCEPT;678_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& flip() _NOEXCEPT;679_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& flip(size_t __pos);680
681// element access:682#ifdef _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL683_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool operator[](size_t __p) const { return base::__make_ref(__p); }684#else685_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference operator[](size_t __p) const { return base::__make_ref(__p); }686#endif687_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 reference operator[](size_t __p) { return base::__make_ref(__p); }688_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong() const;689_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong() const;690template <class _CharT, class _Traits, class _Allocator>691_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, _Traits, _Allocator>692to_string(_CharT __zero = _CharT('0'), _CharT __one = _CharT('1')) const;693template <class _CharT, class _Traits>694_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, _Traits, allocator<_CharT> >695to_string(_CharT __zero = _CharT('0'), _CharT __one = _CharT('1')) const;696template <class _CharT>697_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> >698to_string(_CharT __zero = _CharT('0'), _CharT __one = _CharT('1')) const;699_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<char, char_traits<char>, allocator<char> >700to_string(char __zero = '0', char __one = '1') const;701_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 size_t count() const _NOEXCEPT;702_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR size_t size() const _NOEXCEPT { return _Size; }703_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool operator==(const bitset& __rhs) const _NOEXCEPT;704#if _LIBCPP_STD_VER <= 17705_LIBCPP_HIDE_FROM_ABI bool operator!=(const bitset& __rhs) const _NOEXCEPT;706#endif707_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool test(size_t __pos) const;708_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT;709_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT;710_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool none() const _NOEXCEPT { return !any(); }711_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset operator<<(size_t __pos) const _NOEXCEPT;712_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset operator>>(size_t __pos) const _NOEXCEPT;713
714private:715template <class _CharT, class _Traits>716_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void717__init_from_string_view(basic_string_view<_CharT, _Traits> __str, _CharT __zero, _CharT __one) {718for (size_t __i = 0; __i < __str.size(); ++__i)719if (!_Traits::eq(__str[__i], __zero) && !_Traits::eq(__str[__i], __one))720std::__throw_invalid_argument("bitset string ctor has invalid argument");721
722size_t __mp = std::min(__str.size(), _Size);723size_t __i = 0;724for (; __i < __mp; ++__i) {725_CharT __c = __str[__mp - 1 - __i];726(*this)[__i] = _Traits::eq(__c, __one);727}728std::fill(base::__make_iter(__i), base::__make_iter(_Size), false);729}730
731_LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT { return base::__hash_code(); }732
733friend struct hash<bitset>;734};735
736template <size_t _Size>737inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>&738bitset<_Size>::operator&=(const bitset& __rhs) _NOEXCEPT {739base::operator&=(__rhs);740return *this;741}
742
743template <size_t _Size>744inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>&745bitset<_Size>::operator|=(const bitset& __rhs) _NOEXCEPT {746base::operator|=(__rhs);747return *this;748}
749
750template <size_t _Size>751inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>&752bitset<_Size>::operator^=(const bitset& __rhs) _NOEXCEPT {753base::operator^=(__rhs);754return *this;755}
756
757template <size_t _Size>758_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::operator<<=(size_t __pos) _NOEXCEPT {759__pos = std::min(__pos, _Size);760std::copy_backward(base::__make_iter(0), base::__make_iter(_Size - __pos), base::__make_iter(_Size));761std::fill_n(base::__make_iter(0), __pos, false);762return *this;763}
764
765template <size_t _Size>766_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::operator>>=(size_t __pos) _NOEXCEPT {767__pos = std::min(__pos, _Size);768std::copy(base::__make_iter(__pos), base::__make_iter(_Size), base::__make_iter(0));769std::fill_n(base::__make_iter(_Size - __pos), __pos, false);770return *this;771}
772
773template <size_t _Size>774inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::set() _NOEXCEPT {775std::fill_n(base::__make_iter(0), _Size, true);776return *this;777}
778
779template <size_t _Size>780_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::set(size_t __pos, bool __val) {781if (__pos >= _Size)782__throw_out_of_range("bitset set argument out of range");783
784(*this)[__pos] = __val;785return *this;786}
787
788template <size_t _Size>789inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::reset() _NOEXCEPT {790std::fill_n(base::__make_iter(0), _Size, false);791return *this;792}
793
794template <size_t _Size>795_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::reset(size_t __pos) {796if (__pos >= _Size)797__throw_out_of_range("bitset reset argument out of range");798
799(*this)[__pos] = false;800return *this;801}
802
803template <size_t _Size>804inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size> bitset<_Size>::operator~() const _NOEXCEPT {805bitset __x(*this);806__x.flip();807return __x;808}
809
810template <size_t _Size>811inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::flip() _NOEXCEPT {812base::flip();813return *this;814}
815
816template <size_t _Size>817_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::flip(size_t __pos) {818if (__pos >= _Size)819__throw_out_of_range("bitset flip argument out of range");820
821reference __r = base::__make_ref(__pos);822__r = ~__r;823return *this;824}
825
826template <size_t _Size>827inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long bitset<_Size>::to_ulong() const {828return base::to_ulong();829}
830
831template <size_t _Size>832inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long bitset<_Size>::to_ullong() const {833return base::to_ullong();834}
835
836template <size_t _Size>837template <class _CharT, class _Traits, class _Allocator>838_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, _Traits, _Allocator>839bitset<_Size>::to_string(_CharT __zero, _CharT __one) const {840basic_string<_CharT, _Traits, _Allocator> __r(_Size, __zero);841for (size_t __i = 0; __i != _Size; ++__i) {842if ((*this)[__i])843__r[_Size - 1 - __i] = __one;844}845return __r;846}
847
848template <size_t _Size>849template <class _CharT, class _Traits>850inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, _Traits, allocator<_CharT> >851bitset<_Size>::to_string(_CharT __zero, _CharT __one) const {852return to_string<_CharT, _Traits, allocator<_CharT> >(__zero, __one);853}
854
855template <size_t _Size>856template <class _CharT>857inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> >858bitset<_Size>::to_string(_CharT __zero, _CharT __one) const {859return to_string<_CharT, char_traits<_CharT>, allocator<_CharT> >(__zero, __one);860}
861
862template <size_t _Size>863inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<char, char_traits<char>, allocator<char> >864bitset<_Size>::to_string(char __zero, char __one) const {865return to_string<char, char_traits<char>, allocator<char> >(__zero, __one);866}
867
868template <size_t _Size>869inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 size_t bitset<_Size>::count() const _NOEXCEPT {870return static_cast<size_t>(std::count(base::__make_iter(0), base::__make_iter(_Size), true));871}
872
873template <size_t _Size>874inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool875bitset<_Size>::operator==(const bitset& __rhs) const _NOEXCEPT {876return std::equal(base::__make_iter(0), base::__make_iter(_Size), __rhs.__make_iter(0));877}
878
879#if _LIBCPP_STD_VER <= 17880
881template <size_t _Size>882inline _LIBCPP_HIDE_FROM_ABI bool bitset<_Size>::operator!=(const bitset& __rhs) const _NOEXCEPT {883return !(*this == __rhs);884}
885
886#endif887
888template <size_t _Size>889_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool bitset<_Size>::test(size_t __pos) const {890if (__pos >= _Size)891__throw_out_of_range("bitset test argument out of range");892
893return (*this)[__pos];894}
895
896template <size_t _Size>897inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool bitset<_Size>::all() const _NOEXCEPT {898return base::all();899}
900
901template <size_t _Size>902inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool bitset<_Size>::any() const _NOEXCEPT {903return base::any();904}
905
906template <size_t _Size>907inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>908bitset<_Size>::operator<<(size_t __pos) const _NOEXCEPT {909bitset __r = *this;910__r <<= __pos;911return __r;912}
913
914template <size_t _Size>915inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>916bitset<_Size>::operator>>(size_t __pos) const _NOEXCEPT {917bitset __r = *this;918__r >>= __pos;919return __r;920}
921
922template <size_t _Size>923inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>924operator&(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT {925bitset<_Size> __r = __x;926__r &= __y;927return __r;928}
929
930template <size_t _Size>931inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>932operator|(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT {933bitset<_Size> __r = __x;934__r |= __y;935return __r;936}
937
938template <size_t _Size>939inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>940operator^(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT {941bitset<_Size> __r = __x;942__r ^= __y;943return __r;944}
945
946template <size_t _Size>947struct _LIBCPP_TEMPLATE_VIS hash<bitset<_Size> > : public __unary_function<bitset<_Size>, size_t> {948_LIBCPP_HIDE_FROM_ABI size_t operator()(const bitset<_Size>& __bs) const _NOEXCEPT { return __bs.__hash_code(); }949};950
951template <class _CharT, class _Traits, size_t _Size>952_LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&953operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x);954
955template <class _CharT, class _Traits, size_t _Size>956_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&957operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x);958
959_LIBCPP_END_NAMESPACE_STD
960
961_LIBCPP_POP_MACROS
962
963#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20964# include <concepts>965# include <cstdlib>966# include <type_traits>967#endif968
969#endif // _LIBCPP_BITSET970