Warning, /include/c++/v1/bitset is written in an unsupported language. File is not indexed.
0001 // -*- C++ -*-
0002 //===----------------------------------------------------------------------===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009
0010 #ifndef _LIBCPP_BITSET
0011 #define _LIBCPP_BITSET
0012
0013 // clang-format off
0014
0015 /*
0016 bitset synopsis
0017
0018 namespace std
0019 {
0020
0021 namespace std {
0022
0023 template <size_t N>
0024 class bitset
0025 {
0026 public:
0027 // bit reference:
0028 class reference
0029 {
0030 friend class bitset;
0031 reference() noexcept;
0032 public:
0033 ~reference() noexcept;
0034 reference& operator=(bool x) noexcept; // for b[i] = x;
0035 reference& operator=(const reference&) noexcept; // for b[i] = b[j];
0036 bool operator~() const noexcept; // flips the bit
0037 operator bool() const noexcept; // for x = b[i];
0038 reference& flip() noexcept; // for b[i].flip();
0039 };
0040
0041 // 23.3.5.1 constructors:
0042 constexpr bitset() noexcept;
0043 constexpr bitset(unsigned long long val) noexcept;
0044 template <class charT>
0045 constexpr explicit bitset(const charT* str,
0046 typename basic_string<charT>::size_type n = basic_string<charT>::npos,
0047 charT zero = charT('0'), charT one = charT('1')); // until C++26, constexpr since C++23
0048 template <class charT>
0049 constexpr explicit bitset(const charT* str,
0050 typename basic_string_view<charT>::size_type n = basic_string_view<charT>::npos,
0051 charT zero = charT('0'), charT one = charT('1')); // since C++26
0052 template<class charT, class traits>
0053 explicit bitset(
0054 const basic_string_view<charT,traits>& str,
0055 typename basic_string_view<charT,traits>::size_type pos = 0,
0056 typename basic_string_view<charT,traits>::size_type n = basic_string_view<charT,traits>::npos,
0057 charT zero = charT('0'), charT one = charT('1')); // since C++26
0058 template<class charT, class traits, class Allocator>
0059 constexpr explicit bitset(
0060 const basic_string<charT,traits,Allocator>& str,
0061 typename basic_string<charT,traits,Allocator>::size_type pos = 0,
0062 typename basic_string<charT,traits,Allocator>::size_type n = basic_string<charT,traits,Allocator>::npos,
0063 charT zero = charT('0'), charT one = charT('1')); // constexpr since C++23
0064
0065 // 23.3.5.2 bitset operations:
0066 bitset& operator&=(const bitset& rhs) noexcept; // constexpr since C++23
0067 bitset& operator|=(const bitset& rhs) noexcept; // constexpr since C++23
0068 bitset& operator^=(const bitset& rhs) noexcept; // constexpr since C++23
0069 bitset& operator<<=(size_t pos) noexcept; // constexpr since C++23
0070 bitset& operator>>=(size_t pos) noexcept; // constexpr since C++23
0071 bitset& set() noexcept; // constexpr since C++23
0072 bitset& set(size_t pos, bool val = true); // constexpr since C++23
0073 bitset& reset() noexcept; // constexpr since C++23
0074 bitset& reset(size_t pos); // constexpr since C++23
0075 bitset operator~() const noexcept; // constexpr since C++23
0076 bitset& flip() noexcept; // constexpr since C++23
0077 bitset& flip(size_t pos); // constexpr since C++23
0078
0079 // element access:
0080 constexpr bool operator[](size_t pos) const;
0081 reference operator[](size_t pos); // constexpr since C++23
0082 unsigned long to_ulong() const; // constexpr since C++23
0083 unsigned long long to_ullong() const; // constexpr since C++23
0084 template <class charT, class traits, class Allocator> // constexpr since C++23
0085 basic_string<charT, traits, Allocator> to_string(charT zero = charT('0'), charT one = charT('1')) const;
0086 template <class charT, class traits> // constexpr since C++23
0087 basic_string<charT, traits, allocator<charT> > to_string(charT zero = charT('0'), charT one = charT('1')) const;
0088 template <class charT> // constexpr since C++23
0089 basic_string<charT, char_traits<charT>, allocator<charT> > to_string(charT zero = charT('0'), charT one = charT('1')) const;
0090 basic_string<char, char_traits<char>, allocator<char> > to_string(char zero = '0', char one = '1') const; // constexpr since C++23
0091 size_t count() const noexcept; // constexpr since C++23
0092 constexpr size_t size() const noexcept; // constexpr since C++23
0093 bool operator==(const bitset& rhs) const noexcept; // constexpr since C++23
0094 bool operator!=(const bitset& rhs) const noexcept; // removed in C++20
0095 bool test(size_t pos) const; // constexpr since C++23
0096 bool all() const noexcept; // constexpr since C++23
0097 bool any() const noexcept; // constexpr since C++23
0098 bool none() const noexcept; // constexpr since C++23
0099 bitset<N> operator<<(size_t pos) const noexcept; // constexpr since C++23
0100 bitset<N> operator>>(size_t pos) const noexcept; // constexpr since C++23
0101 };
0102
0103 // 23.3.5.3 bitset operators:
0104 template <size_t N>
0105 bitset<N> operator&(const bitset<N>&, const bitset<N>&) noexcept; // constexpr since C++23
0106
0107 template <size_t N>
0108 bitset<N> operator|(const bitset<N>&, const bitset<N>&) noexcept; // constexpr since C++23
0109
0110 template <size_t N>
0111 bitset<N> operator^(const bitset<N>&, const bitset<N>&) noexcept; // constexpr since C++23
0112
0113 template <class charT, class traits, size_t N>
0114 basic_istream<charT, traits>&
0115 operator>>(basic_istream<charT, traits>& is, bitset<N>& x);
0116
0117 template <class charT, class traits, size_t N>
0118 basic_ostream<charT, traits>&
0119 operator<<(basic_ostream<charT, traits>& os, const bitset<N>& x);
0120
0121 template <size_t N> struct hash<std::bitset<N>>;
0122
0123 } // std
0124
0125 */
0126
0127 // clang-format on
0128
0129 #if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
0130 # include <__cxx03/bitset>
0131 #else
0132 # include <__algorithm/count.h>
0133 # include <__algorithm/fill.h>
0134 # include <__algorithm/fill_n.h>
0135 # include <__algorithm/find.h>
0136 # include <__assert>
0137 # include <__bit_reference>
0138 # include <__config>
0139 # include <__cstddef/ptrdiff_t.h>
0140 # include <__cstddef/size_t.h>
0141 # include <__functional/hash.h>
0142 # include <__functional/unary_function.h>
0143 # include <__type_traits/is_char_like_type.h>
0144 # include <climits>
0145 # include <stdexcept>
0146 # include <string_view>
0147 # include <version>
0148
0149 // standard-mandated includes
0150
0151 // [bitset.syn]
0152 # include <iosfwd>
0153 # include <string>
0154
0155 # if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0156 # pragma GCC system_header
0157 # endif
0158
0159 _LIBCPP_PUSH_MACROS
0160 # include <__undef_macros>
0161
0162 _LIBCPP_BEGIN_NAMESPACE_STD
0163
0164 template <size_t _N_words, size_t _Size>
0165 class __bitset;
0166
0167 template <size_t _N_words, size_t _Size>
0168 struct __has_storage_type<__bitset<_N_words, _Size> > {
0169 static const bool value = true;
0170 };
0171
0172 template <size_t _N_words, size_t _Size>
0173 class __bitset {
0174 public:
0175 typedef size_t __storage_type;
0176
0177 protected:
0178 typedef __bitset __self;
0179 typedef __storage_type* __storage_pointer;
0180 typedef const __storage_type* __const_storage_pointer;
0181 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
0182
0183 friend class __bit_reference<__bitset>;
0184 friend class __bit_const_reference<__bitset>;
0185 friend class __bit_iterator<__bitset, false>;
0186 friend class __bit_iterator<__bitset, true>;
0187 friend struct __bit_array<__bitset>;
0188
0189 __storage_type __first_[_N_words];
0190
0191 typedef __bit_reference<__bitset> reference;
0192 typedef __bit_const_reference<__bitset> __const_reference;
0193 typedef __bit_iterator<__bitset, false> __iterator;
0194 typedef __bit_iterator<__bitset, true> __const_iterator;
0195
0196 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
0197 _LIBCPP_HIDE_FROM_ABI explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT;
0198
0199 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 reference __make_ref(size_t __pos) _NOEXCEPT {
0200 return reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);
0201 }
0202 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __const_reference __make_ref(size_t __pos) const _NOEXCEPT {
0203 return __const_reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);
0204 }
0205 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 __iterator __make_iter(size_t __pos) _NOEXCEPT {
0206 return __iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);
0207 }
0208 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 __const_iterator __make_iter(size_t __pos) const _NOEXCEPT {
0209 return __const_iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);
0210 }
0211
0212 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator&=(const __bitset& __v) _NOEXCEPT;
0213 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator|=(const __bitset& __v) _NOEXCEPT;
0214 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator^=(const __bitset& __v) _NOEXCEPT;
0215
0216 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void flip() _NOEXCEPT;
0217 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong() const {
0218 return to_ulong(integral_constant < bool, _Size< sizeof(unsigned long) * CHAR_BIT>());
0219 }
0220 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong() const {
0221 return to_ullong(integral_constant < bool, _Size< sizeof(unsigned long long) * CHAR_BIT>());
0222 }
0223
0224 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT;
0225 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT;
0226 _LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT;
0227
0228 private:
0229 # ifdef _LIBCPP_CXX03_LANG
0230 void __init(unsigned long long __v, false_type) _NOEXCEPT;
0231 _LIBCPP_HIDE_FROM_ABI void __init(unsigned long long __v, true_type) _NOEXCEPT;
0232 # endif // _LIBCPP_CXX03_LANG
0233 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong(false_type) const;
0234 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong(true_type) const;
0235 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong(false_type) const;
0236 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong(true_type) const;
0237 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong(true_type, false_type) const;
0238 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong(true_type, true_type) const;
0239 };
0240
0241 template <size_t _N_words, size_t _Size>
0242 inline _LIBCPP_CONSTEXPR __bitset<_N_words, _Size>::__bitset() _NOEXCEPT
0243 # ifndef _LIBCPP_CXX03_LANG
0244 : __first_{0}
0245 # endif
0246 {
0247 # ifdef _LIBCPP_CXX03_LANG
0248 std::fill_n(__first_, _N_words, __storage_type(0));
0249 # endif
0250 }
0251
0252 # ifdef _LIBCPP_CXX03_LANG
0253
0254 template <size_t _N_words, size_t _Size>
0255 void __bitset<_N_words, _Size>::__init(unsigned long long __v, false_type) _NOEXCEPT {
0256 __storage_type __t[sizeof(unsigned long long) / sizeof(__storage_type)];
0257 size_t __sz = _Size;
0258 for (size_t __i = 0; __i < sizeof(__t) / sizeof(__t[0]); ++__i, __v >>= __bits_per_word, __sz -= __bits_per_word)
0259 if (__sz < __bits_per_word)
0260 __t[__i] = static_cast<__storage_type>(__v) & (1ULL << __sz) - 1;
0261 else
0262 __t[__i] = static_cast<__storage_type>(__v);
0263
0264 std::copy(__t, __t + sizeof(__t) / sizeof(__t[0]), __first_);
0265 std::fill(
0266 __first_ + sizeof(__t) / sizeof(__t[0]), __first_ + sizeof(__first_) / sizeof(__first_[0]), __storage_type(0));
0267 }
0268
0269 template <size_t _N_words, size_t _Size>
0270 inline _LIBCPP_HIDE_FROM_ABI void __bitset<_N_words, _Size>::__init(unsigned long long __v, true_type) _NOEXCEPT {
0271 __first_[0] = __v;
0272 if (_Size < __bits_per_word)
0273 __first_[0] &= (1ULL << _Size) - 1;
0274
0275 std::fill(__first_ + 1, __first_ + sizeof(__first_) / sizeof(__first_[0]), __storage_type(0));
0276 }
0277
0278 # endif // _LIBCPP_CXX03_LANG
0279
0280 template <size_t _N_words, size_t _Size>
0281 inline _LIBCPP_CONSTEXPR __bitset<_N_words, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
0282 # ifndef _LIBCPP_CXX03_LANG
0283 # if __SIZEOF_SIZE_T__ == 8
0284 : __first_{__v}
0285 # elif __SIZEOF_SIZE_T__ == 4
0286 : __first_{static_cast<__storage_type>(__v),
0287 _Size >= 2 * __bits_per_word
0288 ? static_cast<__storage_type>(__v >> __bits_per_word)
0289 : static_cast<__storage_type>((__v >> __bits_per_word) &
0290 (__storage_type(1) << (_Size - __bits_per_word)) - 1)}
0291 # else
0292 # error This constructor has not been ported to this platform
0293 # endif
0294 # endif
0295 {
0296 # ifdef _LIBCPP_CXX03_LANG
0297 __init(__v, integral_constant<bool, sizeof(unsigned long long) == sizeof(__storage_type)>());
0298 # endif
0299 }
0300
0301 template <size_t _N_words, size_t _Size>
0302 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void
0303 __bitset<_N_words, _Size>::operator&=(const __bitset& __v) _NOEXCEPT {
0304 for (size_t __i = 0; __i < _N_words; ++__i)
0305 __first_[__i] &= __v.__first_[__i];
0306 }
0307
0308 template <size_t _N_words, size_t _Size>
0309 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void
0310 __bitset<_N_words, _Size>::operator|=(const __bitset& __v) _NOEXCEPT {
0311 for (size_t __i = 0; __i < _N_words; ++__i)
0312 __first_[__i] |= __v.__first_[__i];
0313 }
0314
0315 template <size_t _N_words, size_t _Size>
0316 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void
0317 __bitset<_N_words, _Size>::operator^=(const __bitset& __v) _NOEXCEPT {
0318 for (size_t __i = 0; __i < _N_words; ++__i)
0319 __first_[__i] ^= __v.__first_[__i];
0320 }
0321
0322 template <size_t _N_words, size_t _Size>
0323 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void __bitset<_N_words, _Size>::flip() _NOEXCEPT {
0324 // do middle whole words
0325 size_t __n = _Size;
0326 __storage_pointer __p = __first_;
0327 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
0328 *__p = ~*__p;
0329 // do last partial word
0330 if (__n > 0) {
0331 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
0332 __storage_type __b = *__p & __m;
0333 *__p &= ~__m;
0334 *__p |= ~__b & __m;
0335 }
0336 }
0337
0338 template <size_t _N_words, size_t _Size>
0339 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long
0340 __bitset<_N_words, _Size>::to_ulong(false_type) const {
0341 __const_iterator __e = __make_iter(_Size);
0342 __const_iterator __i = std::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true);
0343 if (__i != __e)
0344 __throw_overflow_error("bitset to_ulong overflow error");
0345
0346 return __first_[0];
0347 }
0348
0349 template <size_t _N_words, size_t _Size>
0350 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long
0351 __bitset<_N_words, _Size>::to_ulong(true_type) const {
0352 return __first_[0];
0353 }
0354
0355 template <size_t _N_words, size_t _Size>
0356 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long
0357 __bitset<_N_words, _Size>::to_ullong(false_type) const {
0358 __const_iterator __e = __make_iter(_Size);
0359 __const_iterator __i = std::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true);
0360 if (__i != __e)
0361 __throw_overflow_error("bitset to_ullong overflow error");
0362
0363 return to_ullong(true_type());
0364 }
0365
0366 template <size_t _N_words, size_t _Size>
0367 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long
0368 __bitset<_N_words, _Size>::to_ullong(true_type) const {
0369 return to_ullong(true_type(), integral_constant<bool, sizeof(__storage_type) < sizeof(unsigned long long)>());
0370 }
0371
0372 template <size_t _N_words, size_t _Size>
0373 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long
0374 __bitset<_N_words, _Size>::to_ullong(true_type, false_type) const {
0375 return __first_[0];
0376 }
0377
0378 template <size_t _N_words, size_t _Size>
0379 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long
0380 __bitset<_N_words, _Size>::to_ullong(true_type, true_type) const {
0381 unsigned long long __r = __first_[0];
0382 _LIBCPP_DIAGNOSTIC_PUSH
0383 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wshift-count-overflow")
0384 for (size_t __i = 1; __i < sizeof(unsigned long long) / sizeof(__storage_type); ++__i)
0385 __r |= static_cast<unsigned long long>(__first_[__i]) << (sizeof(__storage_type) * CHAR_BIT);
0386 _LIBCPP_DIAGNOSTIC_POP
0387 return __r;
0388 }
0389
0390 template <size_t _N_words, size_t _Size>
0391 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool __bitset<_N_words, _Size>::all() const _NOEXCEPT {
0392 // do middle whole words
0393 size_t __n = _Size;
0394 __const_storage_pointer __p = __first_;
0395 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
0396 if (~*__p)
0397 return false;
0398 // do last partial word
0399 if (__n > 0) {
0400 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
0401 if (~*__p & __m)
0402 return false;
0403 }
0404 return true;
0405 }
0406
0407 template <size_t _N_words, size_t _Size>
0408 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool __bitset<_N_words, _Size>::any() const _NOEXCEPT {
0409 // do middle whole words
0410 size_t __n = _Size;
0411 __const_storage_pointer __p = __first_;
0412 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
0413 if (*__p)
0414 return true;
0415 // do last partial word
0416 if (__n > 0) {
0417 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
0418 if (*__p & __m)
0419 return true;
0420 }
0421 return false;
0422 }
0423
0424 template <size_t _N_words, size_t _Size>
0425 inline size_t __bitset<_N_words, _Size>::__hash_code() const _NOEXCEPT {
0426 size_t __h = 0;
0427 for (size_t __i = 0; __i < _N_words; ++__i)
0428 __h ^= __first_[__i];
0429 return __h;
0430 }
0431
0432 template <size_t _Size>
0433 class __bitset<1, _Size> {
0434 public:
0435 typedef size_t __storage_type;
0436
0437 protected:
0438 typedef __bitset __self;
0439 typedef __storage_type* __storage_pointer;
0440 typedef const __storage_type* __const_storage_pointer;
0441 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
0442
0443 friend class __bit_reference<__bitset>;
0444 friend class __bit_const_reference<__bitset>;
0445 friend class __bit_iterator<__bitset, false>;
0446 friend class __bit_iterator<__bitset, true>;
0447 friend struct __bit_array<__bitset>;
0448
0449 __storage_type __first_;
0450
0451 typedef __bit_reference<__bitset> reference;
0452 typedef __bit_const_reference<__bitset> __const_reference;
0453 typedef __bit_iterator<__bitset, false> __iterator;
0454 typedef __bit_iterator<__bitset, true> __const_iterator;
0455
0456 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
0457 _LIBCPP_HIDE_FROM_ABI explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT;
0458
0459 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 reference __make_ref(size_t __pos) _NOEXCEPT {
0460 return reference(&__first_, __storage_type(1) << __pos);
0461 }
0462 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __const_reference __make_ref(size_t __pos) const _NOEXCEPT {
0463 return __const_reference(&__first_, __storage_type(1) << __pos);
0464 }
0465 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 __iterator __make_iter(size_t __pos) _NOEXCEPT {
0466 return __iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);
0467 }
0468 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 __const_iterator __make_iter(size_t __pos) const _NOEXCEPT {
0469 return __const_iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);
0470 }
0471
0472 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator&=(const __bitset& __v) _NOEXCEPT;
0473 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator|=(const __bitset& __v) _NOEXCEPT;
0474 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator^=(const __bitset& __v) _NOEXCEPT;
0475
0476 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void flip() _NOEXCEPT;
0477
0478 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong() const;
0479 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong() const;
0480
0481 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT;
0482 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT;
0483
0484 _LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT;
0485 };
0486
0487 template <size_t _Size>
0488 inline _LIBCPP_CONSTEXPR __bitset<1, _Size>::__bitset() _NOEXCEPT : __first_(0) {}
0489
0490 template <size_t _Size>
0491 inline _LIBCPP_CONSTEXPR __bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
0492 : __first_(_Size == __bits_per_word ? static_cast<__storage_type>(__v)
0493 : static_cast<__storage_type>(__v) & ((__storage_type(1) << _Size) - 1)) {}
0494
0495 template <size_t _Size>
0496 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void
0497 __bitset<1, _Size>::operator&=(const __bitset& __v) _NOEXCEPT {
0498 __first_ &= __v.__first_;
0499 }
0500
0501 template <size_t _Size>
0502 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void
0503 __bitset<1, _Size>::operator|=(const __bitset& __v) _NOEXCEPT {
0504 __first_ |= __v.__first_;
0505 }
0506
0507 template <size_t _Size>
0508 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void
0509 __bitset<1, _Size>::operator^=(const __bitset& __v) _NOEXCEPT {
0510 __first_ ^= __v.__first_;
0511 }
0512
0513 template <size_t _Size>
0514 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void __bitset<1, _Size>::flip() _NOEXCEPT {
0515 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
0516 __first_ = ~__first_;
0517 __first_ &= __m;
0518 }
0519
0520 template <size_t _Size>
0521 inline _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long __bitset<1, _Size>::to_ulong() const {
0522 return __first_;
0523 }
0524
0525 template <size_t _Size>
0526 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long __bitset<1, _Size>::to_ullong() const {
0527 return __first_;
0528 }
0529
0530 template <size_t _Size>
0531 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool __bitset<1, _Size>::all() const _NOEXCEPT {
0532 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
0533 return !(~__first_ & __m);
0534 }
0535
0536 template <size_t _Size>
0537 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool __bitset<1, _Size>::any() const _NOEXCEPT {
0538 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
0539 return __first_ & __m;
0540 }
0541
0542 template <size_t _Size>
0543 inline size_t __bitset<1, _Size>::__hash_code() const _NOEXCEPT {
0544 return __first_;
0545 }
0546
0547 template <>
0548 class __bitset<0, 0> {
0549 public:
0550 typedef size_t __storage_type;
0551
0552 protected:
0553 typedef __bitset __self;
0554 typedef __storage_type* __storage_pointer;
0555 typedef const __storage_type* __const_storage_pointer;
0556 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
0557
0558 friend class __bit_reference<__bitset>;
0559 friend class __bit_const_reference<__bitset>;
0560 friend class __bit_iterator<__bitset, false>;
0561 friend class __bit_iterator<__bitset, true>;
0562 friend struct __bit_array<__bitset>;
0563
0564 typedef __bit_reference<__bitset> reference;
0565 typedef __bit_const_reference<__bitset> __const_reference;
0566 typedef __bit_iterator<__bitset, false> __iterator;
0567 typedef __bit_iterator<__bitset, true> __const_iterator;
0568
0569 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
0570 _LIBCPP_HIDE_FROM_ABI explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long) _NOEXCEPT;
0571
0572 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 reference __make_ref(size_t) _NOEXCEPT {
0573 return reference(nullptr, 1);
0574 }
0575 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __const_reference __make_ref(size_t) const _NOEXCEPT {
0576 return __const_reference(nullptr, 1);
0577 }
0578 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 __iterator __make_iter(size_t) _NOEXCEPT {
0579 return __iterator(nullptr, 0);
0580 }
0581 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 __const_iterator __make_iter(size_t) const _NOEXCEPT {
0582 return __const_iterator(nullptr, 0);
0583 }
0584
0585 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator&=(const __bitset&) _NOEXCEPT {}
0586 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator|=(const __bitset&) _NOEXCEPT {}
0587 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator^=(const __bitset&) _NOEXCEPT {}
0588
0589 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void flip() _NOEXCEPT {}
0590
0591 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong() const { return 0; }
0592 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong() const { return 0; }
0593
0594 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT { return true; }
0595 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT { return false; }
0596
0597 _LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT { return 0; }
0598 };
0599
0600 inline _LIBCPP_CONSTEXPR __bitset<0, 0>::__bitset() _NOEXCEPT {}
0601
0602 inline _LIBCPP_CONSTEXPR __bitset<0, 0>::__bitset(unsigned long long) _NOEXCEPT {}
0603
0604 template <size_t _Size>
0605 class _LIBCPP_TEMPLATE_VIS bitset;
0606 template <size_t _Size>
0607 struct hash<bitset<_Size> >;
0608
0609 template <size_t _Size>
0610 class _LIBCPP_TEMPLATE_VIS bitset
0611 : private __bitset<_Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1, _Size> {
0612 public:
0613 static const unsigned __n_words = _Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1;
0614 typedef __bitset<__n_words, _Size> __base;
0615
0616 public:
0617 typedef typename __base::reference reference;
0618 typedef typename __base::__const_reference __const_reference;
0619
0620 // 23.3.5.1 constructors:
0621 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bitset() _NOEXCEPT {}
0622 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bitset(unsigned long long __v) _NOEXCEPT : __base(__v) {}
0623 template <class _CharT, __enable_if_t<_IsCharLikeType<_CharT>::value, int> = 0>
0624 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit bitset(
0625 const _CharT* __str,
0626 # if _LIBCPP_STD_VER >= 26
0627 typename basic_string_view<_CharT>::size_type __n = basic_string_view<_CharT>::npos,
0628 # else
0629 typename basic_string<_CharT>::size_type __n = basic_string<_CharT>::npos,
0630 # endif
0631 _CharT __zero = _CharT('0'),
0632 _CharT __one = _CharT('1')) {
0633
0634 size_t __rlen = std::min(__n, char_traits<_CharT>::length(__str));
0635 __init_from_string_view(basic_string_view<_CharT>(__str, __rlen), __zero, __one);
0636 }
0637 # if _LIBCPP_STD_VER >= 26
0638 template <class _CharT, class _Traits>
0639 _LIBCPP_HIDE_FROM_ABI constexpr explicit bitset(
0640 basic_string_view<_CharT, _Traits> __str,
0641 typename basic_string_view<_CharT, _Traits>::size_type __pos = 0,
0642 typename basic_string_view<_CharT, _Traits>::size_type __n = basic_string_view<_CharT, _Traits>::npos,
0643 _CharT __zero = _CharT('0'),
0644 _CharT __one = _CharT('1')) {
0645 if (__pos > __str.size())
0646 __throw_out_of_range("bitset string pos out of range");
0647
0648 size_t __rlen = std::min(__n, __str.size() - __pos);
0649 __init_from_string_view(basic_string_view<_CharT, _Traits>(__str.data() + __pos, __rlen), __zero, __one);
0650 }
0651 # endif
0652 template <class _CharT, class _Traits, class _Allocator>
0653 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit bitset(
0654 const basic_string<_CharT, _Traits, _Allocator>& __str,
0655 typename basic_string<_CharT, _Traits, _Allocator>::size_type __pos = 0,
0656 typename basic_string<_CharT, _Traits, _Allocator>::size_type __n =
0657 basic_string<_CharT, _Traits, _Allocator>::npos,
0658 _CharT __zero = _CharT('0'),
0659 _CharT __one = _CharT('1')) {
0660 if (__pos > __str.size())
0661 std::__throw_out_of_range("bitset string pos out of range");
0662
0663 size_t __rlen = std::min(__n, __str.size() - __pos);
0664 __init_from_string_view(basic_string_view<_CharT, _Traits>(__str.data() + __pos, __rlen), __zero, __one);
0665 }
0666
0667 // 23.3.5.2 bitset operations:
0668 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& operator&=(const bitset& __rhs) _NOEXCEPT;
0669 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& operator|=(const bitset& __rhs) _NOEXCEPT;
0670 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& operator^=(const bitset& __rhs) _NOEXCEPT;
0671 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& operator<<=(size_t __pos) _NOEXCEPT;
0672 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& operator>>=(size_t __pos) _NOEXCEPT;
0673 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& set() _NOEXCEPT;
0674 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& set(size_t __pos, bool __val = true);
0675 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& reset() _NOEXCEPT;
0676 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& reset(size_t __pos);
0677 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset operator~() const _NOEXCEPT;
0678 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& flip() _NOEXCEPT;
0679 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& flip(size_t __pos);
0680
0681 // element access:
0682 # ifdef _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL
0683 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool operator[](size_t __p) const {
0684 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__p < _Size, "bitset::operator[] index out of bounds");
0685 return __base::__make_ref(__p);
0686 }
0687 # else
0688 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __const_reference operator[](size_t __p) const {
0689 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__p < _Size, "bitset::operator[] index out of bounds");
0690 return __base::__make_ref(__p);
0691 }
0692 # endif
0693 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 reference operator[](size_t __p) {
0694 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__p < _Size, "bitset::operator[] index out of bounds");
0695 return __base::__make_ref(__p);
0696 }
0697 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong() const;
0698 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong() const;
0699 template <class _CharT, class _Traits, class _Allocator>
0700 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, _Traits, _Allocator>
0701 to_string(_CharT __zero = _CharT('0'), _CharT __one = _CharT('1')) const;
0702 template <class _CharT, class _Traits>
0703 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, _Traits, allocator<_CharT> >
0704 to_string(_CharT __zero = _CharT('0'), _CharT __one = _CharT('1')) const;
0705 template <class _CharT>
0706 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> >
0707 to_string(_CharT __zero = _CharT('0'), _CharT __one = _CharT('1')) const;
0708 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<char, char_traits<char>, allocator<char> >
0709 to_string(char __zero = '0', char __one = '1') const;
0710 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 size_t count() const _NOEXCEPT;
0711 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR size_t size() const _NOEXCEPT { return _Size; }
0712 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool operator==(const bitset& __rhs) const _NOEXCEPT;
0713 # if _LIBCPP_STD_VER <= 17
0714 _LIBCPP_HIDE_FROM_ABI bool operator!=(const bitset& __rhs) const _NOEXCEPT;
0715 # endif
0716 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool test(size_t __pos) const;
0717 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT;
0718 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT;
0719 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool none() const _NOEXCEPT { return !any(); }
0720 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset operator<<(size_t __pos) const _NOEXCEPT;
0721 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset operator>>(size_t __pos) const _NOEXCEPT;
0722
0723 private:
0724 template <class _CharT, class _Traits>
0725 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void
0726 __init_from_string_view(basic_string_view<_CharT, _Traits> __str, _CharT __zero, _CharT __one) {
0727 for (size_t __i = 0; __i < __str.size(); ++__i)
0728 if (!_Traits::eq(__str[__i], __zero) && !_Traits::eq(__str[__i], __one))
0729 std::__throw_invalid_argument("bitset string ctor has invalid argument");
0730
0731 size_t __mp = std::min(__str.size(), _Size);
0732 size_t __i = 0;
0733 for (; __i < __mp; ++__i) {
0734 _CharT __c = __str[__mp - 1 - __i];
0735 (*this)[__i] = _Traits::eq(__c, __one);
0736 }
0737 std::fill(__base::__make_iter(__i), __base::__make_iter(_Size), false);
0738 }
0739
0740 _LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT { return __base::__hash_code(); }
0741
0742 friend struct hash<bitset>;
0743 };
0744
0745 template <size_t _Size>
0746 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>&
0747 bitset<_Size>::operator&=(const bitset& __rhs) _NOEXCEPT {
0748 __base::operator&=(__rhs);
0749 return *this;
0750 }
0751
0752 template <size_t _Size>
0753 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>&
0754 bitset<_Size>::operator|=(const bitset& __rhs) _NOEXCEPT {
0755 __base::operator|=(__rhs);
0756 return *this;
0757 }
0758
0759 template <size_t _Size>
0760 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>&
0761 bitset<_Size>::operator^=(const bitset& __rhs) _NOEXCEPT {
0762 __base::operator^=(__rhs);
0763 return *this;
0764 }
0765
0766 template <size_t _Size>
0767 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::operator<<=(size_t __pos) _NOEXCEPT {
0768 __pos = std::min(__pos, _Size);
0769 std::copy_backward(__base::__make_iter(0), __base::__make_iter(_Size - __pos), __base::__make_iter(_Size));
0770 std::fill_n(__base::__make_iter(0), __pos, false);
0771 return *this;
0772 }
0773
0774 template <size_t _Size>
0775 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::operator>>=(size_t __pos) _NOEXCEPT {
0776 __pos = std::min(__pos, _Size);
0777 std::copy(__base::__make_iter(__pos), __base::__make_iter(_Size), __base::__make_iter(0));
0778 std::fill_n(__base::__make_iter(_Size - __pos), __pos, false);
0779 return *this;
0780 }
0781
0782 template <size_t _Size>
0783 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::set() _NOEXCEPT {
0784 std::fill_n(__base::__make_iter(0), _Size, true);
0785 return *this;
0786 }
0787
0788 template <size_t _Size>
0789 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::set(size_t __pos, bool __val) {
0790 if (__pos >= _Size)
0791 __throw_out_of_range("bitset set argument out of range");
0792
0793 (*this)[__pos] = __val;
0794 return *this;
0795 }
0796
0797 template <size_t _Size>
0798 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::reset() _NOEXCEPT {
0799 std::fill_n(__base::__make_iter(0), _Size, false);
0800 return *this;
0801 }
0802
0803 template <size_t _Size>
0804 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::reset(size_t __pos) {
0805 if (__pos >= _Size)
0806 __throw_out_of_range("bitset reset argument out of range");
0807
0808 (*this)[__pos] = false;
0809 return *this;
0810 }
0811
0812 template <size_t _Size>
0813 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size> bitset<_Size>::operator~() const _NOEXCEPT {
0814 bitset __x(*this);
0815 __x.flip();
0816 return __x;
0817 }
0818
0819 template <size_t _Size>
0820 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::flip() _NOEXCEPT {
0821 __base::flip();
0822 return *this;
0823 }
0824
0825 template <size_t _Size>
0826 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::flip(size_t __pos) {
0827 if (__pos >= _Size)
0828 __throw_out_of_range("bitset flip argument out of range");
0829
0830 reference __r = __base::__make_ref(__pos);
0831 __r = ~__r;
0832 return *this;
0833 }
0834
0835 template <size_t _Size>
0836 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long bitset<_Size>::to_ulong() const {
0837 return __base::to_ulong();
0838 }
0839
0840 template <size_t _Size>
0841 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long bitset<_Size>::to_ullong() const {
0842 return __base::to_ullong();
0843 }
0844
0845 template <size_t _Size>
0846 template <class _CharT, class _Traits, class _Allocator>
0847 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, _Traits, _Allocator>
0848 bitset<_Size>::to_string(_CharT __zero, _CharT __one) const {
0849 basic_string<_CharT, _Traits, _Allocator> __r(_Size, __zero);
0850 for (size_t __i = 0; __i != _Size; ++__i) {
0851 if ((*this)[__i])
0852 __r[_Size - 1 - __i] = __one;
0853 }
0854 return __r;
0855 }
0856
0857 template <size_t _Size>
0858 template <class _CharT, class _Traits>
0859 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, _Traits, allocator<_CharT> >
0860 bitset<_Size>::to_string(_CharT __zero, _CharT __one) const {
0861 return to_string<_CharT, _Traits, allocator<_CharT> >(__zero, __one);
0862 }
0863
0864 template <size_t _Size>
0865 template <class _CharT>
0866 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> >
0867 bitset<_Size>::to_string(_CharT __zero, _CharT __one) const {
0868 return to_string<_CharT, char_traits<_CharT>, allocator<_CharT> >(__zero, __one);
0869 }
0870
0871 template <size_t _Size>
0872 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<char, char_traits<char>, allocator<char> >
0873 bitset<_Size>::to_string(char __zero, char __one) const {
0874 return to_string<char, char_traits<char>, allocator<char> >(__zero, __one);
0875 }
0876
0877 template <size_t _Size>
0878 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 size_t bitset<_Size>::count() const _NOEXCEPT {
0879 return static_cast<size_t>(std::count(__base::__make_iter(0), __base::__make_iter(_Size), true));
0880 }
0881
0882 template <size_t _Size>
0883 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool
0884 bitset<_Size>::operator==(const bitset& __rhs) const _NOEXCEPT {
0885 return std::equal(__base::__make_iter(0), __base::__make_iter(_Size), __rhs.__make_iter(0));
0886 }
0887
0888 # if _LIBCPP_STD_VER <= 17
0889
0890 template <size_t _Size>
0891 inline _LIBCPP_HIDE_FROM_ABI bool bitset<_Size>::operator!=(const bitset& __rhs) const _NOEXCEPT {
0892 return !(*this == __rhs);
0893 }
0894
0895 # endif
0896
0897 template <size_t _Size>
0898 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool bitset<_Size>::test(size_t __pos) const {
0899 if (__pos >= _Size)
0900 __throw_out_of_range("bitset test argument out of range");
0901
0902 return (*this)[__pos];
0903 }
0904
0905 template <size_t _Size>
0906 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool bitset<_Size>::all() const _NOEXCEPT {
0907 return __base::all();
0908 }
0909
0910 template <size_t _Size>
0911 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool bitset<_Size>::any() const _NOEXCEPT {
0912 return __base::any();
0913 }
0914
0915 template <size_t _Size>
0916 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>
0917 bitset<_Size>::operator<<(size_t __pos) const _NOEXCEPT {
0918 bitset __r = *this;
0919 __r <<= __pos;
0920 return __r;
0921 }
0922
0923 template <size_t _Size>
0924 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>
0925 bitset<_Size>::operator>>(size_t __pos) const _NOEXCEPT {
0926 bitset __r = *this;
0927 __r >>= __pos;
0928 return __r;
0929 }
0930
0931 template <size_t _Size>
0932 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>
0933 operator&(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT {
0934 bitset<_Size> __r = __x;
0935 __r &= __y;
0936 return __r;
0937 }
0938
0939 template <size_t _Size>
0940 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>
0941 operator|(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT {
0942 bitset<_Size> __r = __x;
0943 __r |= __y;
0944 return __r;
0945 }
0946
0947 template <size_t _Size>
0948 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>
0949 operator^(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT {
0950 bitset<_Size> __r = __x;
0951 __r ^= __y;
0952 return __r;
0953 }
0954
0955 template <size_t _Size>
0956 struct _LIBCPP_TEMPLATE_VIS hash<bitset<_Size> > : public __unary_function<bitset<_Size>, size_t> {
0957 _LIBCPP_HIDE_FROM_ABI size_t operator()(const bitset<_Size>& __bs) const _NOEXCEPT { return __bs.__hash_code(); }
0958 };
0959
0960 template <class _CharT, class _Traits, size_t _Size>
0961 _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
0962 operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x);
0963
0964 template <class _CharT, class _Traits, size_t _Size>
0965 _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
0966 operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x);
0967
0968 _LIBCPP_END_NAMESPACE_STD
0969
0970 _LIBCPP_POP_MACROS
0971
0972 # if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
0973 # include <concepts>
0974 # include <cstdlib>
0975 # include <type_traits>
0976 # endif
0977 #endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
0978
0979 #endif // _LIBCPP_BITSET