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