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