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_BITSET 11#define _LIBCPP_BITSET 12 13/* 14 bitset synopsis 15 16namespace std 17{ 18 19namespace std { 20 21template <size_t N> 22class bitset 23{ 24public: 25 // bit reference: 26 class reference 27 { 28 friend class bitset; 29 reference() noexcept; 30 public: 31 ~reference() noexcept; 32 reference& operator=(bool x) noexcept; // for b[i] = x; 33 reference& operator=(const reference&) noexcept; // for b[i] = b[j]; 34 bool operator~() const noexcept; // flips the bit 35 operator bool() const noexcept; // for x = b[i]; 36 reference& flip() noexcept; // for b[i].flip(); 37 }; 38 39 // 23.3.5.1 constructors: 40 constexpr bitset() noexcept; 41 constexpr bitset(unsigned long long val) noexcept; 42 template <class charT> 43 explicit bitset(const charT* str, 44 typename basic_string<charT>::size_type n = basic_string<charT>::npos, 45 charT zero = charT('0'), charT one = charT('1')); // constexpr since C++23 46 template<class charT, class traits, class Allocator> 47 explicit bitset(const basic_string<charT,traits,Allocator>& str, 48 typename basic_string<charT,traits,Allocator>::size_type pos = 0, 49 typename basic_string<charT,traits,Allocator>::size_type n = 50 basic_string<charT,traits,Allocator>::npos, 51 charT zero = charT('0'), charT one = charT('1')); // constexpr since C++23 52 53 // 23.3.5.2 bitset operations: 54 bitset& operator&=(const bitset& rhs) noexcept; // constexpr since C++23 55 bitset& operator|=(const bitset& rhs) noexcept; // constexpr since C++23 56 bitset& operator^=(const bitset& rhs) noexcept; // constexpr since C++23 57 bitset& operator<<=(size_t pos) noexcept; // constexpr since C++23 58 bitset& operator>>=(size_t pos) noexcept; // constexpr since C++23 59 bitset& set() noexcept; // constexpr since C++23 60 bitset& set(size_t pos, bool val = true); // constexpr since C++23 61 bitset& reset() noexcept; // constexpr since C++23 62 bitset& reset(size_t pos); // constexpr since C++23 63 bitset operator~() const noexcept; // constexpr since C++23 64 bitset& flip() noexcept; // constexpr since C++23 65 bitset& flip(size_t pos); // constexpr since C++23 66 67 // element access: 68 constexpr bool operator[](size_t pos) const; 69 reference operator[](size_t pos); // constexpr since C++23 70 unsigned long to_ulong() const; // constexpr since C++23 71 unsigned long long to_ullong() const; // constexpr since C++23 72 template <class charT, class traits, class Allocator> // constexpr since C++23 73 basic_string<charT, traits, Allocator> to_string(charT zero = charT('0'), charT one = charT('1')) const; 74 template <class charT, class traits> // constexpr since C++23 75 basic_string<charT, traits, allocator<charT> > to_string(charT zero = charT('0'), charT one = charT('1')) const; 76 template <class charT> // constexpr since C++23 77 basic_string<charT, char_traits<charT>, allocator<charT> > to_string(charT zero = charT('0'), charT one = charT('1')) const; 78 basic_string<char, char_traits<char>, allocator<char> > to_string(char zero = '0', char one = '1') const; // constexpr since C++23 79 size_t count() const noexcept; // constexpr since C++23 80 constexpr size_t size() const noexcept; // constexpr since C++23 81 bool operator==(const bitset& rhs) const noexcept; // constexpr since C++23 82 bool operator!=(const bitset& rhs) const noexcept; // constexpr since C++23 83 bool test(size_t pos) const; // constexpr since C++23 84 bool all() const noexcept; // constexpr since C++23 85 bool any() const noexcept; // constexpr since C++23 86 bool none() const noexcept; // constexpr since C++23 87 bitset<N> operator<<(size_t pos) const noexcept; // constexpr since C++23 88 bitset<N> operator>>(size_t pos) const noexcept; // constexpr since C++23 89}; 90 91// 23.3.5.3 bitset operators: 92template <size_t N> 93bitset<N> operator&(const bitset<N>&, const bitset<N>&) noexcept; // constexpr since C++23 94 95template <size_t N> 96bitset<N> operator|(const bitset<N>&, const bitset<N>&) noexcept; // constexpr since C++23 97 98template <size_t N> 99bitset<N> operator^(const bitset<N>&, const bitset<N>&) noexcept; // constexpr since C++23 100 101template <class charT, class traits, size_t N> 102basic_istream<charT, traits>& 103operator>>(basic_istream<charT, traits>& is, bitset<N>& x); 104 105template <class charT, class traits, size_t N> 106basic_ostream<charT, traits>& 107operator<<(basic_ostream<charT, traits>& os, const bitset<N>& x); 108 109template <size_t N> struct hash<std::bitset<N>>; 110 111} // std 112 113*/ 114 115#include <__algorithm/fill.h> 116#include <__assert> // all public C++ headers provide the assertion handler 117#include <__bit_reference> 118#include <__config> 119#include <__functional/hash.h> 120#include <__functional/unary_function.h> 121#include <__type_traits/is_char_like_type.h> 122#include <climits> 123#include <cstddef> 124#include <stdexcept> 125#include <version> 126 127// standard-mandated includes 128 129// [bitset.syn] 130#include <iosfwd> 131#include <string> 132 133#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 134# pragma GCC system_header 135#endif 136 137_LIBCPP_PUSH_MACROS 138#include <__undef_macros> 139 140 141_LIBCPP_BEGIN_NAMESPACE_STD 142 143template <size_t _N_words, size_t _Size> 144class __bitset; 145 146template <size_t _N_words, size_t _Size> 147struct __has_storage_type<__bitset<_N_words, _Size> > 148{ 149 static const bool value = true; 150}; 151 152template <size_t _N_words, size_t _Size> 153class __bitset 154{ 155public: 156 typedef ptrdiff_t difference_type; 157 typedef size_t size_type; 158 typedef size_type __storage_type; 159protected: 160 typedef __bitset __self; 161 typedef __storage_type* __storage_pointer; 162 typedef const __storage_type* __const_storage_pointer; 163 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); 164 165 friend class __bit_reference<__bitset>; 166 friend class __bit_const_reference<__bitset>; 167 friend class __bit_iterator<__bitset, false>; 168 friend class __bit_iterator<__bitset, true>; 169 friend struct __bit_array<__bitset>; 170 171 __storage_type __first_[_N_words]; 172 173 typedef __bit_reference<__bitset> reference; 174 typedef __bit_const_reference<__bitset> const_reference; 175 typedef __bit_iterator<__bitset, false> iterator; 176 typedef __bit_iterator<__bitset, true> const_iterator; 177 178 _LIBCPP_INLINE_VISIBILITY 179 _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT; 180 _LIBCPP_INLINE_VISIBILITY 181 explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT; 182 183 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 reference __make_ref(size_t __pos) _NOEXCEPT 184 {return reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);} 185 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT 186 {return const_reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);} 187 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 iterator __make_iter(size_t __pos) _NOEXCEPT 188 {return iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);} 189 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 const_iterator __make_iter(size_t __pos) const _NOEXCEPT 190 {return const_iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);} 191 192 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 193 void operator&=(const __bitset& __v) _NOEXCEPT; 194 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 195 void operator|=(const __bitset& __v) _NOEXCEPT; 196 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 197 void operator^=(const __bitset& __v) _NOEXCEPT; 198 199 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void flip() _NOEXCEPT; 200 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong() const 201 {return to_ulong(integral_constant<bool, _Size < sizeof(unsigned long) * CHAR_BIT>());} 202 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong() const 203 {return to_ullong(integral_constant<bool, _Size < sizeof(unsigned long long) * CHAR_BIT>());} 204 205 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT; 206 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT; 207 _LIBCPP_INLINE_VISIBILITY 208 size_t __hash_code() const _NOEXCEPT; 209private: 210#ifdef _LIBCPP_CXX03_LANG 211 void __init(unsigned long long __v, false_type) _NOEXCEPT; 212 _LIBCPP_INLINE_VISIBILITY 213 void __init(unsigned long long __v, true_type) _NOEXCEPT; 214#endif // _LIBCPP_CXX03_LANG 215 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 216 unsigned long to_ulong(false_type) const; 217 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 218 unsigned long to_ulong(true_type) const; 219 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 220 unsigned long long to_ullong(false_type) const; 221 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 222 unsigned long long to_ullong(true_type) const; 223 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 224 unsigned long long to_ullong(true_type, false_type) const; 225 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 226 unsigned long long to_ullong(true_type, true_type) const; 227}; 228 229template <size_t _N_words, size_t _Size> 230inline 231_LIBCPP_CONSTEXPR 232__bitset<_N_words, _Size>::__bitset() _NOEXCEPT 233#ifndef _LIBCPP_CXX03_LANG 234 : __first_{0} 235#endif 236{ 237#ifdef _LIBCPP_CXX03_LANG 238 _VSTD::fill_n(__first_, _N_words, __storage_type(0)); 239#endif 240} 241 242#ifdef _LIBCPP_CXX03_LANG 243 244template <size_t _N_words, size_t _Size> 245void 246__bitset<_N_words, _Size>::__init(unsigned long long __v, false_type) _NOEXCEPT 247{ 248 __storage_type __t[sizeof(unsigned long long) / sizeof(__storage_type)]; 249 size_t __sz = _Size; 250 for (size_t __i = 0; __i < sizeof(__t)/sizeof(__t[0]); ++__i, __v >>= __bits_per_word, __sz -= __bits_per_word ) 251 if ( __sz < __bits_per_word) 252 __t[__i] = static_cast<__storage_type>(__v) & ( 1ULL << __sz ) - 1; 253 else 254 __t[__i] = static_cast<__storage_type>(__v); 255 256 _VSTD::copy(__t, __t + sizeof(__t)/sizeof(__t[0]), __first_); 257 _VSTD::fill(__first_ + sizeof(__t)/sizeof(__t[0]), __first_ + sizeof(__first_)/sizeof(__first_[0]), 258 __storage_type(0)); 259} 260 261template <size_t _N_words, size_t _Size> 262inline _LIBCPP_INLINE_VISIBILITY 263void 264__bitset<_N_words, _Size>::__init(unsigned long long __v, true_type) _NOEXCEPT 265{ 266 __first_[0] = __v; 267 if (_Size < __bits_per_word) 268 __first_[0] &= ( 1ULL << _Size ) - 1; 269 270 _VSTD::fill(__first_ + 1, __first_ + sizeof(__first_)/sizeof(__first_[0]), __storage_type(0)); 271} 272 273#endif // _LIBCPP_CXX03_LANG 274 275template <size_t _N_words, size_t _Size> 276inline 277_LIBCPP_CONSTEXPR 278__bitset<_N_words, _Size>::__bitset(unsigned long long __v) _NOEXCEPT 279#ifndef _LIBCPP_CXX03_LANG 280#if __SIZEOF_SIZE_T__ == 8 281 : __first_{__v} 282#elif __SIZEOF_SIZE_T__ == 4 283 : __first_{static_cast<__storage_type>(__v), 284 _Size >= 2 * __bits_per_word ? static_cast<__storage_type>(__v >> __bits_per_word) 285 : static_cast<__storage_type>((__v >> __bits_per_word) & (__storage_type(1) << (_Size - __bits_per_word)) - 1)} 286#else 287#error This constructor has not been ported to this platform 288#endif 289#endif 290{ 291#ifdef _LIBCPP_CXX03_LANG 292 __init(__v, integral_constant<bool, sizeof(unsigned long long) == sizeof(__storage_type)>()); 293#endif 294} 295 296template <size_t _N_words, size_t _Size> 297inline 298_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void 299__bitset<_N_words, _Size>::operator&=(const __bitset& __v) _NOEXCEPT 300{ 301 for (size_type __i = 0; __i < _N_words; ++__i) 302 __first_[__i] &= __v.__first_[__i]; 303} 304 305template <size_t _N_words, size_t _Size> 306inline 307_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void 308__bitset<_N_words, _Size>::operator|=(const __bitset& __v) _NOEXCEPT 309{ 310 for (size_type __i = 0; __i < _N_words; ++__i) 311 __first_[__i] |= __v.__first_[__i]; 312} 313 314template <size_t _N_words, size_t _Size> 315inline 316_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void 317__bitset<_N_words, _Size>::operator^=(const __bitset& __v) _NOEXCEPT 318{ 319 for (size_type __i = 0; __i < _N_words; ++__i) 320 __first_[__i] ^= __v.__first_[__i]; 321} 322 323template <size_t _N_words, size_t _Size> 324_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void 325__bitset<_N_words, _Size>::flip() _NOEXCEPT 326{ 327 // do middle whole words 328 size_type __n = _Size; 329 __storage_pointer __p = __first_; 330 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) 331 *__p = ~*__p; 332 // do last partial word 333 if (__n > 0) 334 { 335 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); 336 __storage_type __b = *__p & __m; 337 *__p &= ~__m; 338 *__p |= ~__b & __m; 339 } 340} 341 342template <size_t _N_words, size_t _Size> 343_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long 344__bitset<_N_words, _Size>::to_ulong(false_type) const 345{ 346 const_iterator __e = __make_iter(_Size); 347 const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true); 348 if (__i != __e) 349 __throw_overflow_error("bitset to_ulong overflow error"); 350 351 return __first_[0]; 352} 353 354template <size_t _N_words, size_t _Size> 355inline 356_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long 357__bitset<_N_words, _Size>::to_ulong(true_type) const 358{ 359 return __first_[0]; 360} 361 362template <size_t _N_words, size_t _Size> 363_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long 364__bitset<_N_words, _Size>::to_ullong(false_type) const 365{ 366 const_iterator __e = __make_iter(_Size); 367 const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true); 368 if (__i != __e) 369 __throw_overflow_error("bitset to_ullong overflow error"); 370 371 return to_ullong(true_type()); 372} 373 374template <size_t _N_words, size_t _Size> 375inline 376_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long 377__bitset<_N_words, _Size>::to_ullong(true_type) const 378{ 379 return to_ullong(true_type(), integral_constant<bool, sizeof(__storage_type) < sizeof(unsigned long long)>()); 380} 381 382template <size_t _N_words, size_t _Size> 383inline 384_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long 385__bitset<_N_words, _Size>::to_ullong(true_type, false_type) const 386{ 387 return __first_[0]; 388} 389 390template <size_t _N_words, size_t _Size> 391_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long 392__bitset<_N_words, _Size>::to_ullong(true_type, true_type) const 393{ 394 unsigned long long __r = __first_[0]; 395 for (size_t __i = 1; __i < sizeof(unsigned long long) / sizeof(__storage_type); ++__i) 396 __r |= static_cast<unsigned long long>(__first_[__i]) << (sizeof(__storage_type) * CHAR_BIT); 397 return __r; 398} 399 400template <size_t _N_words, size_t _Size> 401_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool 402__bitset<_N_words, _Size>::all() const _NOEXCEPT 403{ 404 // do middle whole words 405 size_type __n = _Size; 406 __const_storage_pointer __p = __first_; 407 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) 408 if (~*__p) 409 return false; 410 // do last partial word 411 if (__n > 0) 412 { 413 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); 414 if (~*__p & __m) 415 return false; 416 } 417 return true; 418} 419 420template <size_t _N_words, size_t _Size> 421_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool 422__bitset<_N_words, _Size>::any() const _NOEXCEPT 423{ 424 // do middle whole words 425 size_type __n = _Size; 426 __const_storage_pointer __p = __first_; 427 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) 428 if (*__p) 429 return true; 430 // do last partial word 431 if (__n > 0) 432 { 433 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); 434 if (*__p & __m) 435 return true; 436 } 437 return false; 438} 439 440template <size_t _N_words, size_t _Size> 441inline 442size_t 443__bitset<_N_words, _Size>::__hash_code() const _NOEXCEPT 444{ 445 size_t __h = 0; 446 for (size_type __i = 0; __i < _N_words; ++__i) 447 __h ^= __first_[__i]; 448 return __h; 449} 450 451template <size_t _Size> 452class __bitset<1, _Size> 453{ 454public: 455 typedef ptrdiff_t difference_type; 456 typedef size_t size_type; 457 typedef size_type __storage_type; 458protected: 459 typedef __bitset __self; 460 typedef __storage_type* __storage_pointer; 461 typedef const __storage_type* __const_storage_pointer; 462 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); 463 464 friend class __bit_reference<__bitset>; 465 friend class __bit_const_reference<__bitset>; 466 friend class __bit_iterator<__bitset, false>; 467 friend class __bit_iterator<__bitset, true>; 468 friend struct __bit_array<__bitset>; 469 470 __storage_type __first_; 471 472 typedef __bit_reference<__bitset> reference; 473 typedef __bit_const_reference<__bitset> const_reference; 474 typedef __bit_iterator<__bitset, false> iterator; 475 typedef __bit_iterator<__bitset, true> const_iterator; 476 477 _LIBCPP_INLINE_VISIBILITY 478 _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT; 479 _LIBCPP_INLINE_VISIBILITY 480 explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT; 481 482 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 reference __make_ref(size_t __pos) _NOEXCEPT 483 {return reference(&__first_, __storage_type(1) << __pos);} 484 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT 485 {return const_reference(&__first_, __storage_type(1) << __pos);} 486 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 iterator __make_iter(size_t __pos) _NOEXCEPT 487 {return iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);} 488 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 const_iterator __make_iter(size_t __pos) const _NOEXCEPT 489 {return const_iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);} 490 491 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 492 void operator&=(const __bitset& __v) _NOEXCEPT; 493 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 494 void operator|=(const __bitset& __v) _NOEXCEPT; 495 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 496 void operator^=(const __bitset& __v) _NOEXCEPT; 497 498 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 499 void flip() _NOEXCEPT; 500 501 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 502 unsigned long to_ulong() const; 503 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 504 unsigned long long to_ullong() const; 505 506 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 507 bool all() const _NOEXCEPT; 508 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 509 bool any() const _NOEXCEPT; 510 511 _LIBCPP_INLINE_VISIBILITY 512 size_t __hash_code() const _NOEXCEPT; 513}; 514 515template <size_t _Size> 516inline 517_LIBCPP_CONSTEXPR 518__bitset<1, _Size>::__bitset() _NOEXCEPT 519 : __first_(0) 520{ 521} 522 523template <size_t _Size> 524inline 525_LIBCPP_CONSTEXPR 526__bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT 527 : __first_( 528 _Size == __bits_per_word ? static_cast<__storage_type>(__v) 529 : static_cast<__storage_type>(__v) & ((__storage_type(1) << _Size) - 1) 530 ) 531{ 532} 533 534template <size_t _Size> 535inline 536_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void 537__bitset<1, _Size>::operator&=(const __bitset& __v) _NOEXCEPT 538{ 539 __first_ &= __v.__first_; 540} 541 542template <size_t _Size> 543inline 544_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void 545__bitset<1, _Size>::operator|=(const __bitset& __v) _NOEXCEPT 546{ 547 __first_ |= __v.__first_; 548} 549 550template <size_t _Size> 551inline 552_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void 553__bitset<1, _Size>::operator^=(const __bitset& __v) _NOEXCEPT 554{ 555 __first_ ^= __v.__first_; 556} 557 558template <size_t _Size> 559inline 560_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void 561__bitset<1, _Size>::flip() _NOEXCEPT 562{ 563 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size); 564 __first_ = ~__first_; 565 __first_ &= __m; 566} 567 568template <size_t _Size> 569inline 570_LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long 571__bitset<1, _Size>::to_ulong() const 572{ 573 return __first_; 574} 575 576template <size_t _Size> 577inline 578_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long 579__bitset<1, _Size>::to_ullong() const 580{ 581 return __first_; 582} 583 584template <size_t _Size> 585inline 586_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool 587__bitset<1, _Size>::all() const _NOEXCEPT 588{ 589 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size); 590 return !(~__first_ & __m); 591} 592 593template <size_t _Size> 594inline 595_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool 596__bitset<1, _Size>::any() const _NOEXCEPT 597{ 598 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size); 599 return __first_ & __m; 600} 601 602template <size_t _Size> 603inline 604size_t 605__bitset<1, _Size>::__hash_code() const _NOEXCEPT 606{ 607 return __first_; 608} 609 610template <> 611class __bitset<0, 0> 612{ 613public: 614 typedef ptrdiff_t difference_type; 615 typedef size_t size_type; 616 typedef size_type __storage_type; 617protected: 618 typedef __bitset __self; 619 typedef __storage_type* __storage_pointer; 620 typedef const __storage_type* __const_storage_pointer; 621 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); 622 623 friend class __bit_reference<__bitset>; 624 friend class __bit_const_reference<__bitset>; 625 friend class __bit_iterator<__bitset, false>; 626 friend class __bit_iterator<__bitset, true>; 627 friend struct __bit_array<__bitset>; 628 629 typedef __bit_reference<__bitset> reference; 630 typedef __bit_const_reference<__bitset> const_reference; 631 typedef __bit_iterator<__bitset, false> iterator; 632 typedef __bit_iterator<__bitset, true> const_iterator; 633 634 _LIBCPP_INLINE_VISIBILITY 635 _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT; 636 _LIBCPP_INLINE_VISIBILITY 637 explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long) _NOEXCEPT; 638 639 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 reference __make_ref(size_t) _NOEXCEPT 640 {return reference(nullptr, 1);} 641 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t) const _NOEXCEPT 642 {return const_reference(nullptr, 1);} 643 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 iterator __make_iter(size_t) _NOEXCEPT 644 {return iterator(nullptr, 0);} 645 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 const_iterator __make_iter(size_t) const _NOEXCEPT 646 {return const_iterator(nullptr, 0);} 647 648 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator&=(const __bitset&) _NOEXCEPT {} 649 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator|=(const __bitset&) _NOEXCEPT {} 650 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator^=(const __bitset&) _NOEXCEPT {} 651 652 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 void flip() _NOEXCEPT {} 653 654 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong() const {return 0;} 655 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong() const {return 0;} 656 657 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT {return true;} 658 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT {return false;} 659 660 _LIBCPP_INLINE_VISIBILITY size_t __hash_code() const _NOEXCEPT {return 0;} 661}; 662 663inline 664_LIBCPP_CONSTEXPR 665__bitset<0, 0>::__bitset() _NOEXCEPT 666{ 667} 668 669inline 670_LIBCPP_CONSTEXPR 671__bitset<0, 0>::__bitset(unsigned long long) _NOEXCEPT 672{ 673} 674 675template <size_t _Size> class _LIBCPP_TEMPLATE_VIS bitset; 676template <size_t _Size> struct hash<bitset<_Size> >; 677 678template <size_t _Size> 679class _LIBCPP_TEMPLATE_VIS bitset 680 : private __bitset<_Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1, _Size> 681{ 682public: 683 static const unsigned __n_words = _Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1; 684 typedef __bitset<__n_words, _Size> base; 685 686public: 687 typedef typename base::reference reference; 688 typedef typename base::const_reference const_reference; 689 690 // 23.3.5.1 constructors: 691 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bitset() _NOEXCEPT {} 692 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 693 bitset(unsigned long long __v) _NOEXCEPT : base(__v) {} 694 template<class _CharT, class = __enable_if_t<_IsCharLikeType<_CharT>::value> > 695 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 696 explicit bitset(const _CharT* __str, 697 typename basic_string<_CharT>::size_type __n = basic_string<_CharT>::npos, 698 _CharT __zero = _CharT('0'), _CharT __one = _CharT('1')); 699 template<class _CharT, class _Traits, class _Allocator> 700 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 701 explicit bitset(const basic_string<_CharT,_Traits,_Allocator>& __str, 702 typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos = 0, 703 typename basic_string<_CharT,_Traits,_Allocator>::size_type __n = 704 (basic_string<_CharT,_Traits,_Allocator>::npos), 705 _CharT __zero = _CharT('0'), _CharT __one = _CharT('1')); 706 707 // 23.3.5.2 bitset operations: 708 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 709 bitset& operator&=(const bitset& __rhs) _NOEXCEPT; 710 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 711 bitset& operator|=(const bitset& __rhs) _NOEXCEPT; 712 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 713 bitset& operator^=(const bitset& __rhs) _NOEXCEPT; 714 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 715 bitset& operator<<=(size_t __pos) _NOEXCEPT; 716 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 717 bitset& operator>>=(size_t __pos) _NOEXCEPT; 718 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 719 bitset& set() _NOEXCEPT; 720 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 721 bitset& set(size_t __pos, bool __val = true); 722 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 723 bitset& reset() _NOEXCEPT; 724 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 725 bitset& reset(size_t __pos); 726 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 727 bitset operator~() const _NOEXCEPT; 728 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 729 bitset& flip() _NOEXCEPT; 730 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 731 bitset& flip(size_t __pos); 732 733 // element access: 734#ifdef _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL 735 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool operator[](size_t __p) const {return base::__make_ref(__p);} 736#else 737 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference operator[](size_t __p) const {return base::__make_ref(__p);} 738#endif 739 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 reference operator[](size_t __p) {return base::__make_ref(__p);} 740 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 741 unsigned long to_ulong() const; 742 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 743 unsigned long long to_ullong() const; 744 template <class _CharT, class _Traits, class _Allocator> 745 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 746 basic_string<_CharT, _Traits, _Allocator> to_string(_CharT __zero = _CharT('0'), 747 _CharT __one = _CharT('1')) const; 748 template <class _CharT, class _Traits> 749 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 750 basic_string<_CharT, _Traits, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'), 751 _CharT __one = _CharT('1')) const; 752 template <class _CharT> 753 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 754 basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'), 755 _CharT __one = _CharT('1')) const; 756 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 757 basic_string<char, char_traits<char>, allocator<char> > to_string(char __zero = '0', 758 char __one = '1') const; 759 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 760 size_t count() const _NOEXCEPT; 761 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR size_t size() const _NOEXCEPT {return _Size;} 762 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 763 bool operator==(const bitset& __rhs) const _NOEXCEPT; 764 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 765 bool operator!=(const bitset& __rhs) const _NOEXCEPT; 766 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 767 bool test(size_t __pos) const; 768 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 769 bool all() const _NOEXCEPT; 770 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 771 bool any() const _NOEXCEPT; 772 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 bool none() const _NOEXCEPT {return !any();} 773 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 774 bitset operator<<(size_t __pos) const _NOEXCEPT; 775 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 776 bitset operator>>(size_t __pos) const _NOEXCEPT; 777 778private: 779 780 _LIBCPP_INLINE_VISIBILITY 781 size_t __hash_code() const _NOEXCEPT {return base::__hash_code();} 782 783 friend struct hash<bitset>; 784}; 785 786template <size_t _Size> 787template<class _CharT, class> 788_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 789bitset<_Size>::bitset(const _CharT* __str, 790 typename basic_string<_CharT>::size_type __n, 791 _CharT __zero, _CharT __one) 792{ 793 size_t __rlen = _VSTD::min(__n, char_traits<_CharT>::length(__str)); 794 for (size_t __i = 0; __i < __rlen; ++__i) 795 if (__str[__i] != __zero && __str[__i] != __one) 796 __throw_invalid_argument("bitset string ctor has invalid argument"); 797 798 size_t _Mp = _VSTD::min(__rlen, _Size); 799 size_t __i = 0; 800 for (; __i < _Mp; ++__i) 801 { 802 _CharT __c = __str[_Mp - 1 - __i]; 803 (*this)[__i] = (__c == __one); 804 } 805 _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false); 806} 807 808template <size_t _Size> 809template<class _CharT, class _Traits, class _Allocator> 810_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 811bitset<_Size>::bitset(const basic_string<_CharT,_Traits,_Allocator>& __str, 812 typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos, 813 typename basic_string<_CharT,_Traits,_Allocator>::size_type __n, 814 _CharT __zero, _CharT __one) 815{ 816 if (__pos > __str.size()) 817 __throw_out_of_range("bitset string pos out of range"); 818 819 size_t __rlen = _VSTD::min(__n, __str.size() - __pos); 820 for (size_t __i = __pos; __i < __pos + __rlen; ++__i) 821 if (!_Traits::eq(__str[__i], __zero) && !_Traits::eq(__str[__i], __one)) 822 __throw_invalid_argument("bitset string ctor has invalid argument"); 823 824 size_t _Mp = _VSTD::min(__rlen, _Size); 825 size_t __i = 0; 826 for (; __i < _Mp; ++__i) 827 { 828 _CharT __c = __str[__pos + _Mp - 1 - __i]; 829 (*this)[__i] = _Traits::eq(__c, __one); 830 } 831 _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false); 832} 833 834template <size_t _Size> 835inline 836_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 837bitset<_Size>& 838bitset<_Size>::operator&=(const bitset& __rhs) _NOEXCEPT 839{ 840 base::operator&=(__rhs); 841 return *this; 842} 843 844template <size_t _Size> 845inline 846_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 847bitset<_Size>& 848bitset<_Size>::operator|=(const bitset& __rhs) _NOEXCEPT 849{ 850 base::operator|=(__rhs); 851 return *this; 852} 853 854template <size_t _Size> 855inline 856_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 857bitset<_Size>& 858bitset<_Size>::operator^=(const bitset& __rhs) _NOEXCEPT 859{ 860 base::operator^=(__rhs); 861 return *this; 862} 863 864template <size_t _Size> 865_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 866bitset<_Size>& 867bitset<_Size>::operator<<=(size_t __pos) _NOEXCEPT 868{ 869 __pos = _VSTD::min(__pos, _Size); 870 _VSTD::copy_backward(base::__make_iter(0), base::__make_iter(_Size - __pos), base::__make_iter(_Size)); 871 _VSTD::fill_n(base::__make_iter(0), __pos, false); 872 return *this; 873} 874 875template <size_t _Size> 876_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 877bitset<_Size>& 878bitset<_Size>::operator>>=(size_t __pos) _NOEXCEPT 879{ 880 __pos = _VSTD::min(__pos, _Size); 881 _VSTD::copy(base::__make_iter(__pos), base::__make_iter(_Size), base::__make_iter(0)); 882 _VSTD::fill_n(base::__make_iter(_Size - __pos), __pos, false); 883 return *this; 884} 885 886template <size_t _Size> 887inline 888_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 889bitset<_Size>& 890bitset<_Size>::set() _NOEXCEPT 891{ 892 _VSTD::fill_n(base::__make_iter(0), _Size, true); 893 return *this; 894} 895 896template <size_t _Size> 897_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 898bitset<_Size>& 899bitset<_Size>::set(size_t __pos, bool __val) 900{ 901 if (__pos >= _Size) 902 __throw_out_of_range("bitset set argument out of range"); 903 904 (*this)[__pos] = __val; 905 return *this; 906} 907 908template <size_t _Size> 909inline 910_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 911bitset<_Size>& 912bitset<_Size>::reset() _NOEXCEPT 913{ 914 _VSTD::fill_n(base::__make_iter(0), _Size, false); 915 return *this; 916} 917 918template <size_t _Size> 919_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 920bitset<_Size>& 921bitset<_Size>::reset(size_t __pos) 922{ 923 if (__pos >= _Size) 924 __throw_out_of_range("bitset reset argument out of range"); 925 926 (*this)[__pos] = false; 927 return *this; 928} 929 930template <size_t _Size> 931inline 932_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 933bitset<_Size> 934bitset<_Size>::operator~() const _NOEXCEPT 935{ 936 bitset __x(*this); 937 __x.flip(); 938 return __x; 939} 940 941template <size_t _Size> 942inline 943_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 944bitset<_Size>& 945bitset<_Size>::flip() _NOEXCEPT 946{ 947 base::flip(); 948 return *this; 949} 950 951template <size_t _Size> 952_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 953bitset<_Size>& 954bitset<_Size>::flip(size_t __pos) 955{ 956 if (__pos >= _Size) 957 __throw_out_of_range("bitset flip argument out of range"); 958 959 reference r = base::__make_ref(__pos); 960 r = ~r; 961 return *this; 962} 963 964template <size_t _Size> 965inline 966_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 967unsigned long 968bitset<_Size>::to_ulong() const 969{ 970 return base::to_ulong(); 971} 972 973template <size_t _Size> 974inline 975_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 976unsigned long long 977bitset<_Size>::to_ullong() const 978{ 979 return base::to_ullong(); 980} 981 982template <size_t _Size> 983template <class _CharT, class _Traits, class _Allocator> 984_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 985basic_string<_CharT, _Traits, _Allocator> 986bitset<_Size>::to_string(_CharT __zero, _CharT __one) const 987{ 988 basic_string<_CharT, _Traits, _Allocator> __r(_Size, __zero); 989 for (size_t __i = 0; __i != _Size; ++__i) 990 { 991 if ((*this)[__i]) 992 __r[_Size - 1 - __i] = __one; 993 } 994 return __r; 995} 996 997template <size_t _Size> 998template <class _CharT, class _Traits> 999inline 1000_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 1001basic_string<_CharT, _Traits, allocator<_CharT> > 1002bitset<_Size>::to_string(_CharT __zero, _CharT __one) const 1003{ 1004 return to_string<_CharT, _Traits, allocator<_CharT> >(__zero, __one); 1005} 1006 1007template <size_t _Size> 1008template <class _CharT> 1009inline 1010_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 1011basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > 1012bitset<_Size>::to_string(_CharT __zero, _CharT __one) const 1013{ 1014 return to_string<_CharT, char_traits<_CharT>, allocator<_CharT> >(__zero, __one); 1015} 1016 1017template <size_t _Size> 1018inline 1019_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 1020basic_string<char, char_traits<char>, allocator<char> > 1021bitset<_Size>::to_string(char __zero, char __one) const 1022{ 1023 return to_string<char, char_traits<char>, allocator<char> >(__zero, __one); 1024} 1025 1026template <size_t _Size> 1027inline 1028_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 1029size_t 1030bitset<_Size>::count() const _NOEXCEPT 1031{ 1032 return static_cast<size_t>(_VSTD::__count_bool_true(base::__make_iter(0), _Size)); 1033} 1034 1035template <size_t _Size> 1036inline 1037_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 1038bool 1039bitset<_Size>::operator==(const bitset& __rhs) const _NOEXCEPT 1040{ 1041 return _VSTD::equal(base::__make_iter(0), base::__make_iter(_Size), __rhs.__make_iter(0)); 1042} 1043 1044template <size_t _Size> 1045inline 1046_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 1047bool 1048bitset<_Size>::operator!=(const bitset& __rhs) const _NOEXCEPT 1049{ 1050 return !(*this == __rhs); 1051} 1052 1053template <size_t _Size> 1054_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 1055bool 1056bitset<_Size>::test(size_t __pos) const 1057{ 1058 if (__pos >= _Size) 1059 __throw_out_of_range("bitset test argument out of range"); 1060 1061 return (*this)[__pos]; 1062} 1063 1064template <size_t _Size> 1065inline 1066_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 1067bool 1068bitset<_Size>::all() const _NOEXCEPT 1069{ 1070 return base::all(); 1071} 1072 1073template <size_t _Size> 1074inline 1075_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 1076bool 1077bitset<_Size>::any() const _NOEXCEPT 1078{ 1079 return base::any(); 1080} 1081 1082template <size_t _Size> 1083inline 1084_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 1085bitset<_Size> 1086bitset<_Size>::operator<<(size_t __pos) const _NOEXCEPT 1087{ 1088 bitset __r = *this; 1089 __r <<= __pos; 1090 return __r; 1091} 1092 1093template <size_t _Size> 1094inline 1095_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 1096bitset<_Size> 1097bitset<_Size>::operator>>(size_t __pos) const _NOEXCEPT 1098{ 1099 bitset __r = *this; 1100 __r >>= __pos; 1101 return __r; 1102} 1103 1104template <size_t _Size> 1105inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 1106bitset<_Size> 1107operator&(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT 1108{ 1109 bitset<_Size> __r = __x; 1110 __r &= __y; 1111 return __r; 1112} 1113 1114template <size_t _Size> 1115inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 1116bitset<_Size> 1117operator|(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT 1118{ 1119 bitset<_Size> __r = __x; 1120 __r |= __y; 1121 return __r; 1122} 1123 1124template <size_t _Size> 1125inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 1126bitset<_Size> 1127operator^(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT 1128{ 1129 bitset<_Size> __r = __x; 1130 __r ^= __y; 1131 return __r; 1132} 1133 1134template <size_t _Size> 1135struct _LIBCPP_TEMPLATE_VIS hash<bitset<_Size> > 1136 : public __unary_function<bitset<_Size>, size_t> 1137{ 1138 _LIBCPP_INLINE_VISIBILITY 1139 size_t operator()(const bitset<_Size>& __bs) const _NOEXCEPT 1140 {return __bs.__hash_code();} 1141}; 1142 1143template <class _CharT, class _Traits, size_t _Size> 1144_LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>& 1145operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x); 1146 1147template <class _CharT, class _Traits, size_t _Size> 1148_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& 1149operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x); 1150 1151_LIBCPP_END_NAMESPACE_STD 1152 1153_LIBCPP_POP_MACROS 1154 1155#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 1156# include <concepts> 1157#endif 1158 1159#endif // _LIBCPP_BITSET 1160