brintos

brintos / llvm-project-archived public Read only

0
0
Text · 40.7 KiB · 3453c2f Raw
971 lines · plain
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-exception7//8//===----------------------------------------------------------------------===//9 10#ifndef _LIBCPP_BITSET11#define _LIBCPP_BITSET12 13// clang-format off14 15/*16    bitset synopsis17 18namespace std19{20 21namespace std {22 23template <size_t N>24class bitset25{26public:27    // bit reference:28    class reference29    {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 bit37        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++2348    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++2652    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++2658    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++2364 65    // 23.3.5.2 bitset operations:66    bitset& operator&=(const bitset& rhs) noexcept; // constexpr since C++2367    bitset& operator|=(const bitset& rhs) noexcept; // constexpr since C++2368    bitset& operator^=(const bitset& rhs) noexcept; // constexpr since C++2369    bitset& operator<<=(size_t pos) noexcept;       // constexpr since C++2370    bitset& operator>>=(size_t pos) noexcept;       // constexpr since C++2371    bitset& set() noexcept;                         // constexpr since C++2372    bitset& set(size_t pos, bool val = true);       // constexpr since C++2373    bitset& reset() noexcept;                       // constexpr since C++2374    bitset& reset(size_t pos);                      // constexpr since C++2375    bitset operator~() const noexcept;              // constexpr since C++2376    bitset& flip() noexcept;                        // constexpr since C++2377    bitset& flip(size_t pos);                       // constexpr since C++2378 79    // element access:80    constexpr bool operator[](size_t pos) const;81    reference operator[](size_t pos);            // constexpr since C++2382    unsigned long to_ulong() const;              // constexpr since C++2383    unsigned long long to_ullong() const;        // constexpr since C++2384    template <class charT, class traits, class Allocator> // constexpr since C++2385        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++2387        basic_string<charT, traits, allocator<charT> > to_string(charT zero = charT('0'), charT one = charT('1')) const;88    template <class charT> // constexpr since C++2389        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++2391    size_t count() const noexcept;                     // constexpr since C++2392    constexpr size_t size() const noexcept;            // constexpr since C++2393    bool operator==(const bitset& rhs) const noexcept; // constexpr since C++2394    bool operator!=(const bitset& rhs) const noexcept; // removed in C++2095    bool test(size_t pos) const;                       // constexpr since C++2396    bool all() const noexcept;                         // constexpr since C++2397    bool any() const noexcept;                         // constexpr since C++2398    bool none() const noexcept;                        // constexpr since C++2399    bitset<N> operator<<(size_t pos) const noexcept;   // constexpr since C++23100    bitset<N> operator>>(size_t pos) const noexcept;   // constexpr since C++23101};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++23106 107template <size_t N>108bitset<N> operator|(const bitset<N>&, const bitset<N>&) noexcept; // constexpr since C++23109 110template <size_t N>111bitset<N> operator^(const bitset<N>&, const bitset<N>&) noexcept; // constexpr since C++23112 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}  // std124 125*/126 127// clang-format on128 129#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)130#  include <__cxx03/bitset>131#else132#  include <__algorithm/copy.h>133#  include <__algorithm/copy_backward.h>134#  include <__algorithm/count.h>135#  include <__algorithm/equal.h>136#  include <__algorithm/fill.h>137#  include <__algorithm/fill_n.h>138#  include <__algorithm/find.h>139#  include <__algorithm/min.h>140#  include <__assert>141#  include <__bit/countr.h>142#  include <__bit/invert_if.h>143#  include <__bit_reference>144#  include <__config>145#  include <__cstddef/ptrdiff_t.h>146#  include <__cstddef/size_t.h>147#  include <__functional/hash.h>148#  include <__functional/identity.h>149#  include <__functional/unary_function.h>150#  include <__type_traits/enable_if.h>151#  include <__type_traits/integral_constant.h>152#  include <__type_traits/is_char_like_type.h>153#  include <__utility/integer_sequence.h>154#  include <climits>155#  include <stdexcept>156#  include <string_view>157#  include <version>158 159// standard-mandated includes160 161// [bitset.syn]162#  include <iosfwd>163#  include <string>164 165#  if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)166#    pragma GCC system_header167#  endif168 169_LIBCPP_PUSH_MACROS170#  include <__undef_macros>171 172_LIBCPP_BEGIN_NAMESPACE_STD173 174template <size_t _N_words, size_t _Size>175class __bitset;176 177template <size_t _N_words, size_t _Size>178struct __has_storage_type<__bitset<_N_words, _Size> > {179  static const bool value = true;180};181 182template <size_t _N_words, size_t _Size>183class __bitset {184public:185  typedef size_t __storage_type;186 187protected:188  typedef __bitset __self;189  typedef __storage_type* __storage_pointer;190  typedef const __storage_type* __const_storage_pointer;191  static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);192 193  friend class __bit_reference<__bitset>;194  friend class __bit_const_reference<__bitset>;195  friend class __bit_iterator<__bitset, false>;196  friend class __bit_iterator<__bitset, true>;197  friend struct __bit_array<__bitset>;198 199  __storage_type __first_[_N_words];200 201  typedef __bit_reference<__bitset> reference;202  typedef __bit_const_reference<__bitset> __const_reference;203  typedef __bit_iterator<__bitset, false> __iterator;204  typedef __bit_iterator<__bitset, true> __const_iterator;205 206  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;207  _LIBCPP_HIDE_FROM_ABI explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT;208 209  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 reference __make_ref(size_t __pos) _NOEXCEPT {210    return reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);211  }212  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __const_reference __make_ref(size_t __pos) const _NOEXCEPT {213    return __const_reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);214  }215  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 __iterator __make_iter(size_t __pos) _NOEXCEPT {216    return __iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);217  }218  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 __const_iterator __make_iter(size_t __pos) const _NOEXCEPT {219    return __const_iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);220  }221 222  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator&=(const __bitset& __v) _NOEXCEPT;223  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator|=(const __bitset& __v) _NOEXCEPT;224  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator^=(const __bitset& __v) _NOEXCEPT;225 226  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void flip() _NOEXCEPT;227 228  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong() const {229    if _LIBCPP_CONSTEXPR (_Size > sizeof(unsigned long) * CHAR_BIT) {230      if (auto __e = __make_iter(_Size); std::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true) != __e)231        std::__throw_overflow_error("__bitset<_N_words, _Size>::to_ulong overflow error");232    }233 234    static_assert(sizeof(__storage_type) >= sizeof(unsigned long),235                  "libc++ only supports platforms where sizeof(size_t) >= sizeof(unsigned long), such as 32-bit and "236                  "64-bit platforms. If you're interested in supporting a platform where that is not the case, please "237                  "contact the libc++ developers.");238    return static_cast<unsigned long>(__first_[0]);239  }240 241  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong() const {242    // Check for overflow if _Size does not fit in unsigned long long243    if _LIBCPP_CONSTEXPR (_Size > sizeof(unsigned long long) * CHAR_BIT) {244      if (auto __e = __make_iter(_Size);245          std::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true) != __e)246        std::__throw_overflow_error("__bitset<_N_words, _Size>::to_ullong overflow error");247    }248 249    // At this point, the effective bitset size (excluding leading zeros) fits in unsigned long long250 251    if _LIBCPP_CONSTEXPR (sizeof(__storage_type) >= sizeof(unsigned long long)) {252      // If __storage_type is at least as large as unsigned long long, the result spans only one word253      return static_cast<unsigned long long>(__first_[0]);254    } else {255      // Otherwise, the result spans multiple words which are concatenated256      const size_t __ull_words = (sizeof(unsigned long long) - 1) / sizeof(__storage_type) + 1;257      const size_t __n_words   = _N_words < __ull_words ? _N_words : __ull_words;258      unsigned long long __r   = static_cast<unsigned long long>(__first_[0]);259      for (size_t __i = 1; __i < __n_words; ++__i)260        __r |= static_cast<unsigned long long>(__first_[__i]) << (__bits_per_word * __i);261      return __r;262    }263  }264 265  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT { return !__scan_bits(__bit_not()); }266  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT {267    return __scan_bits(std::__identity());268  }269  _LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT;270 271  template <bool _Sparse, class _CharT, class _Traits, class _Allocator>272  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, _Traits, _Allocator>273  __to_string(_CharT __zero, _CharT __one) const {274    basic_string<_CharT, _Traits, _Allocator> __r(_Size, _Sparse ? __zero : __one);275    for (size_t __i = 0, __bits = 0; __i < _N_words; ++__i, __bits += __bits_per_word) {276      __storage_type __word = std::__invert_if<!_Sparse>(__first_[__i]);277      if (__i == _N_words - 1 && _Size - __bits < __bits_per_word)278        __word &= (__storage_type(1) << (_Size - __bits)) - 1;279      for (; __word; __word &= (__word - 1))280        __r[_Size - 1 - (__bits + std::__countr_zero(__word))] = _Sparse ? __one : __zero;281    }282 283    return __r;284  }285 286private:287  struct __bit_not {288    template <class _Tp>289    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp operator()(const _Tp& __x) const _NOEXCEPT {290      return ~__x;291    }292  };293 294  template <typename _Proj>295  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool __scan_bits(_Proj __proj) const _NOEXCEPT {296    size_t __n                  = _Size;297    __const_storage_pointer __p = __first_;298    // do middle whole words299    for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)300      if (__proj(*__p))301        return true;302    // do last partial word303    if (__n > 0) {304      __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);305      if (__proj(*__p) & __m)306        return true;307    }308    return false;309  }310 311#  ifdef _LIBCPP_CXX03_LANG312  void __init(unsigned long long __v, false_type) _NOEXCEPT;313  _LIBCPP_HIDE_FROM_ABI void __init(unsigned long long __v, true_type) _NOEXCEPT;314#  else315  template <size_t... _Indices>316  _LIBCPP_HIDE_FROM_ABI constexpr __bitset(unsigned long long __v, __index_sequence<_Indices...>) _NOEXCEPT317      : __first_{static_cast<__storage_type>(__v >> (_Indices * __bits_per_word))...} {}318#  endif // _LIBCPP_CXX03_LANG319};320 321template <size_t _N_words, size_t _Size>322inline _LIBCPP_CONSTEXPR __bitset<_N_words, _Size>::__bitset() _NOEXCEPT323#  ifndef _LIBCPP_CXX03_LANG324    : __first_{0}325#  endif326{327#  ifdef _LIBCPP_CXX03_LANG328  std::fill_n(__first_, _N_words, __storage_type(0));329#  endif330}331 332#  ifdef _LIBCPP_CXX03_LANG333 334template <size_t _N_words, size_t _Size>335void __bitset<_N_words, _Size>::__init(unsigned long long __v, false_type) _NOEXCEPT {336  const size_t __n_words = std::min((sizeof(unsigned long long) - 1) / sizeof(__storage_type) + 1, _N_words);337  for (size_t __i = 0; __i < __n_words; ++__i, __v >>= __bits_per_word)338    __first_[__i] = static_cast<__storage_type>(__v);339  std::fill(__first_ + __n_words, __first_ + _N_words, __storage_type(0));340}341 342template <size_t _N_words, size_t _Size>343inline _LIBCPP_HIDE_FROM_ABI void __bitset<_N_words, _Size>::__init(unsigned long long __v, true_type) _NOEXCEPT {344  __first_[0] = __v;345  std::fill(__first_ + 1, __first_ + _N_words, __storage_type(0));346}347 348#  endif // _LIBCPP_CXX03_LANG349 350template <size_t _N_words, size_t _Size>351inline _LIBCPP_CONSTEXPR __bitset<_N_words, _Size>::__bitset(unsigned long long __v) _NOEXCEPT352#  ifndef _LIBCPP_CXX03_LANG353    : __bitset(__v,354               __make_index_sequence<(_N_words < (sizeof(unsigned long long) - 1) / sizeof(__storage_type) + 1)355                                         ? _N_words356                                         : (sizeof(unsigned long long) - 1) / sizeof(__storage_type) + 1>())357#  endif358{359#  ifdef _LIBCPP_CXX03_LANG360  __init(__v, _BoolConstant<sizeof(unsigned long long) <= sizeof(__storage_type)>());361#  endif362}363 364template <size_t _N_words, size_t _Size>365inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void366__bitset<_N_words, _Size>::operator&=(const __bitset& __v) _NOEXCEPT {367  for (size_t __i = 0; __i < _N_words; ++__i)368    __first_[__i] &= __v.__first_[__i];369}370 371template <size_t _N_words, size_t _Size>372inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void373__bitset<_N_words, _Size>::operator|=(const __bitset& __v) _NOEXCEPT {374  for (size_t __i = 0; __i < _N_words; ++__i)375    __first_[__i] |= __v.__first_[__i];376}377 378template <size_t _N_words, size_t _Size>379inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void380__bitset<_N_words, _Size>::operator^=(const __bitset& __v) _NOEXCEPT {381  for (size_t __i = 0; __i < _N_words; ++__i)382    __first_[__i] ^= __v.__first_[__i];383}384 385template <size_t _N_words, size_t _Size>386_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void __bitset<_N_words, _Size>::flip() _NOEXCEPT {387  // do middle whole words388  size_t __n            = _Size;389  __storage_pointer __p = __first_;390  for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)391    *__p = ~*__p;392  // do last partial word393  // Ensure trailing padding bits are zeroed as part of the ABI for consistent hashing behavior. std::hash<bitset>394  // assumes trailing bits are zeroed; otherwise, identical bitsets could hash differently.395  if (__n > 0)396    *__p ^= (__storage_type(1) << __n) - 1;397}398 399template <size_t _N_words, size_t _Size>400inline size_t __bitset<_N_words, _Size>::__hash_code() const _NOEXCEPT {401  size_t __h = 0;402  for (size_t __i = 0; __i < _N_words; ++__i)403    __h ^= __first_[__i];404  return __h;405}406 407template <size_t _Size>408class __bitset<1, _Size> {409public:410  typedef size_t __storage_type;411 412protected:413  typedef __bitset __self;414  typedef __storage_type* __storage_pointer;415  typedef const __storage_type* __const_storage_pointer;416  static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);417 418  friend class __bit_reference<__bitset>;419  friend class __bit_const_reference<__bitset>;420  friend class __bit_iterator<__bitset, false>;421  friend class __bit_iterator<__bitset, true>;422  friend struct __bit_array<__bitset>;423 424  __storage_type __first_;425 426  typedef __bit_reference<__bitset> reference;427  typedef __bit_const_reference<__bitset> __const_reference;428  typedef __bit_iterator<__bitset, false> __iterator;429  typedef __bit_iterator<__bitset, true> __const_iterator;430 431  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;432  _LIBCPP_HIDE_FROM_ABI explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT;433 434  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 reference __make_ref(size_t __pos) _NOEXCEPT {435    return reference(&__first_, __storage_type(1) << __pos);436  }437  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __const_reference __make_ref(size_t __pos) const _NOEXCEPT {438    return __const_reference(&__first_, __storage_type(1) << __pos);439  }440  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 __iterator __make_iter(size_t __pos) _NOEXCEPT {441    // Allow the == case to accommodate the past-the-end iterator.442    _LIBCPP_ASSERT_INTERNAL(__pos <= __bits_per_word, "Out of bounds access in the single-word bitset implementation.");443    return __pos != __bits_per_word ? __iterator(&__first_, __pos) : __iterator(&__first_ + 1, 0);444  }445  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 __const_iterator __make_iter(size_t __pos) const _NOEXCEPT {446    // Allow the == case to accommodate the past-the-end iterator.447    _LIBCPP_ASSERT_INTERNAL(__pos <= __bits_per_word, "Out of bounds access in the single-word bitset implementation.");448    return __pos != __bits_per_word ? __const_iterator(&__first_, __pos) : __const_iterator(&__first_ + 1, 0);449  }450 451  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator&=(const __bitset& __v) _NOEXCEPT;452  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator|=(const __bitset& __v) _NOEXCEPT;453  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator^=(const __bitset& __v) _NOEXCEPT;454 455  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void flip() _NOEXCEPT;456 457  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong() const {458    if _LIBCPP_CONSTEXPR (_Size > sizeof(unsigned long) * CHAR_BIT) {459      if (auto __e = __make_iter(_Size); std::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true) != __e)460        __throw_overflow_error("__bitset<1, _Size>::to_ulong overflow error");461    }462    return static_cast<unsigned long>(__first_);463  }464 465  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong() const {466    // If _Size exceeds the size of unsigned long long, check for overflow467    if _LIBCPP_CONSTEXPR (_Size > sizeof(unsigned long long) * CHAR_BIT) {468      if (auto __e = __make_iter(_Size);469          std::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true) != __e)470        __throw_overflow_error("__bitset<1, _Size>::to_ullong overflow error");471    }472 473    // If _Size fits or no overflow, directly cast to unsigned long long474    return static_cast<unsigned long long>(__first_);475  }476 477  template <bool _Sparse, class _CharT, class _Traits, class _Allocator>478  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, _Traits, _Allocator>479  __to_string(_CharT __zero, _CharT __one) const {480    basic_string<_CharT, _Traits, _Allocator> __r(_Size, _Sparse ? __zero : __one);481    __storage_type __word = std::__invert_if<!_Sparse>(__first_);482    if (_Size < __bits_per_word)483      __word &= (__storage_type(1) << _Size) - 1;484    for (; __word; __word &= (__word - 1)) {485      size_t __pos           = std::__countr_zero(__word);486      __r[_Size - 1 - __pos] = _Sparse ? __one : __zero;487    }488    return __r;489  }490 491  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT;492  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT;493 494  _LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT;495};496 497template <size_t _Size>498inline _LIBCPP_CONSTEXPR __bitset<1, _Size>::__bitset() _NOEXCEPT : __first_(0) {}499 500template <size_t _Size>501inline _LIBCPP_CONSTEXPR __bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT502    // TODO: We must refer to __bits_per_word in order to work around an issue with the GDB pretty-printers.503    //       Without it, the pretty-printers complain about a missing __bits_per_word member. This needs to504    //       be investigated further.505    : __first_(_Size == __bits_per_word ? static_cast<__storage_type>(__v) : static_cast<__storage_type>(__v)) {}506 507template <size_t _Size>508inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void509__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 void515__bitset<1, _Size>::operator|=(const __bitset& __v) _NOEXCEPT {516  __first_ |= __v.__first_;517}518 519template <size_t _Size>520inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void521__bitset<1, _Size>::operator^=(const __bitset& __v) _NOEXCEPT {522  __first_ ^= __v.__first_;523}524 525template <size_t _Size>526inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void __bitset<1, _Size>::flip() _NOEXCEPT {527  __first_ ^= ~__storage_type(0) >> (__bits_per_word - _Size);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  template <bool _Sparse, class _CharT, class _Traits, class _Allocator>595  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, _Traits, _Allocator>596  __to_string(_CharT, _CharT) const {597    return basic_string<_CharT, _Traits, _Allocator>();598  }599 600  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT { return true; }601  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT { return false; }602 603  _LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT { return 0; }604};605 606inline _LIBCPP_CONSTEXPR __bitset<0, 0>::__bitset() _NOEXCEPT {}607 608inline _LIBCPP_CONSTEXPR __bitset<0, 0>::__bitset(unsigned long long) _NOEXCEPT {}609 610template <size_t _Size>611class bitset;612template <size_t _Size>613struct hash<bitset<_Size> >;614 615template <size_t _Size>616class bitset : private __bitset<_Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1, _Size> {617public:618  static const unsigned __n_words = _Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1;619  typedef __bitset<__n_words, _Size> __base;620  typedef typename __base::reference reference;621  typedef typename __base::__const_reference __const_reference;622 623  // 23.3.5.1 constructors:624  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bitset() _NOEXCEPT {}625  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bitset(unsigned long long __v) _NOEXCEPT626      : __base(sizeof(unsigned long long) * CHAR_BIT <= _Size ? __v : __v & ((1ULL << _Size) - 1)) {}627  template <class _CharT, __enable_if_t<_IsCharLikeType<_CharT>::value, int> = 0>628  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit bitset(629      const _CharT* __str,630      size_t __n    = basic_string<_CharT>::npos,631      _CharT __zero = _CharT('0'),632      _CharT __one  = _CharT('1')) {633    if (__n == basic_string<_CharT>::npos)634      __init_from_string_view(basic_string_view<_CharT>(__str), __zero, __one);635    else636      __init_from_string_view(basic_string_view<_CharT>(__str, __n), __zero, __one);637  }638#  if _LIBCPP_STD_VER >= 26639  template <class _CharT, class _Traits>640  _LIBCPP_HIDE_FROM_ABI constexpr explicit bitset(641      basic_string_view<_CharT, _Traits> __str,642      typename basic_string_view<_CharT, _Traits>::size_type __pos = 0,643      typename basic_string_view<_CharT, _Traits>::size_type __n   = basic_string_view<_CharT, _Traits>::npos,644      _CharT __zero                                                = _CharT('0'),645      _CharT __one                                                 = _CharT('1')) {646    if (__pos > __str.size())647      std::__throw_out_of_range("bitset string pos out of range");648 649    size_t __rlen = std::min(__n, __str.size() - __pos);650    __init_from_string_view(basic_string_view<_CharT, _Traits>(__str.data() + __pos, __rlen), __zero, __one);651  }652#  endif653  template <class _CharT, class _Traits, class _Allocator>654  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit bitset(655      const basic_string<_CharT, _Traits, _Allocator>& __str,656      typename basic_string<_CharT, _Traits, _Allocator>::size_type __pos = 0,657      typename basic_string<_CharT, _Traits, _Allocator>::size_type __n =658          basic_string<_CharT, _Traits, _Allocator>::npos,659      _CharT __zero = _CharT('0'),660      _CharT __one  = _CharT('1')) {661    if (__pos > __str.size())662      std::__throw_out_of_range("bitset string pos out of range");663 664    size_t __rlen = std::min(__n, __str.size() - __pos);665    __init_from_string_view(basic_string_view<_CharT, _Traits>(__str.data() + __pos, __rlen), __zero, __one);666  }667 668  // 23.3.5.2 bitset operations: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^=(const bitset& __rhs) _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& operator>>=(size_t __pos) _NOEXCEPT;674  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& set() _NOEXCEPT;675  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& set(size_t __pos, bool __val = true);676  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& reset() _NOEXCEPT;677  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& reset(size_t __pos);678  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset operator~() const _NOEXCEPT;679  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& flip() _NOEXCEPT;680  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& flip(size_t __pos);681 682  // element access:683#  ifdef _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL684  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool operator[](size_t __p) const {685    _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__p < _Size, "bitset::operator[] index out of bounds");686    return __base::__make_ref(__p);687  }688#  else689  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __const_reference operator[](size_t __p) const {690    _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__p < _Size, "bitset::operator[] index out of bounds");691    return __base::__make_ref(__p);692  }693#  endif694  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 reference operator[](size_t __p) {695    _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__p < _Size, "bitset::operator[] index out of bounds");696    return __base::__make_ref(__p);697  }698  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong() const { return __base::to_ulong(); }699  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong() const {700    return __base::to_ullong();701  }702  template <class _CharT, class _Traits, class _Allocator>703  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, _Traits, _Allocator>704  to_string(_CharT __zero = _CharT('0'), _CharT __one = _CharT('1')) const;705  template <class _CharT, class _Traits>706  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, _Traits, allocator<_CharT> >707  to_string(_CharT __zero = _CharT('0'), _CharT __one = _CharT('1')) const;708  template <class _CharT>709  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> >710  to_string(_CharT __zero = _CharT('0'), _CharT __one = _CharT('1')) const;711  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<char, char_traits<char>, allocator<char> >712  to_string(char __zero = '0', char __one = '1') const;713  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 size_t count() const _NOEXCEPT;714  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR size_t size() const _NOEXCEPT { return _Size; }715  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool operator==(const bitset& __rhs) const _NOEXCEPT;716#  if _LIBCPP_STD_VER <= 17717  _LIBCPP_HIDE_FROM_ABI bool operator!=(const bitset& __rhs) const _NOEXCEPT;718#  endif719  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool test(size_t __pos) const;720  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT { return __base::all(); }721  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT { return __base::any(); }722  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool none() const _NOEXCEPT { return !any(); }723  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset operator<<(size_t __pos) const _NOEXCEPT;724  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset operator>>(size_t __pos) const _NOEXCEPT;725 726private:727  template <class _CharT, class _Traits>728  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void729  __init_from_string_view(basic_string_view<_CharT, _Traits> __str, _CharT __zero, _CharT __one) {730    for (size_t __i = 0; __i < __str.size(); ++__i)731      if (!_Traits::eq(__str[__i], __zero) && !_Traits::eq(__str[__i], __one))732        std::__throw_invalid_argument("bitset string ctor has invalid argument");733 734    size_t __mp = std::min(__str.size(), _Size);735    size_t __i  = 0;736    for (; __i < __mp; ++__i) {737      _CharT __c   = __str[__mp - 1 - __i];738      (*this)[__i] = _Traits::eq(__c, __one);739    }740  }741 742  _LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT { return __base::__hash_code(); }743 744  friend struct hash<bitset>;745};746 747template <size_t _Size>748inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>&749bitset<_Size>::operator&=(const bitset& __rhs) _NOEXCEPT {750  __base::operator&=(__rhs);751  return *this;752}753 754template <size_t _Size>755inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>&756bitset<_Size>::operator|=(const bitset& __rhs) _NOEXCEPT {757  __base::operator|=(__rhs);758  return *this;759}760 761template <size_t _Size>762inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>&763bitset<_Size>::operator^=(const bitset& __rhs) _NOEXCEPT {764  __base::operator^=(__rhs);765  return *this;766}767 768template <size_t _Size>769_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::operator<<=(size_t __pos) _NOEXCEPT {770  __pos = std::min(__pos, _Size);771  std::copy_backward(__base::__make_iter(0), __base::__make_iter(_Size - __pos), __base::__make_iter(_Size));772  std::fill_n(__base::__make_iter(0), __pos, false);773  return *this;774}775 776template <size_t _Size>777_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::operator>>=(size_t __pos) _NOEXCEPT {778  __pos = std::min(__pos, _Size);779  std::copy(__base::__make_iter(__pos), __base::__make_iter(_Size), __base::__make_iter(0));780  std::fill_n(__base::__make_iter(_Size - __pos), __pos, false);781  return *this;782}783 784template <size_t _Size>785inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::set() _NOEXCEPT {786  std::fill_n(__base::__make_iter(0), _Size, true);787  return *this;788}789 790template <size_t _Size>791_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::set(size_t __pos, bool __val) {792  if (__pos >= _Size)793    std::__throw_out_of_range("bitset set argument out of range");794 795  (*this)[__pos] = __val;796  return *this;797}798 799template <size_t _Size>800inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::reset() _NOEXCEPT {801  std::fill_n(__base::__make_iter(0), _Size, false);802  return *this;803}804 805template <size_t _Size>806_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::reset(size_t __pos) {807  if (__pos >= _Size)808    std::__throw_out_of_range("bitset reset argument out of range");809 810  (*this)[__pos] = false;811  return *this;812}813 814template <size_t _Size>815inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size> bitset<_Size>::operator~() const _NOEXCEPT {816  bitset __x(*this);817  __x.flip();818  return __x;819}820 821template <size_t _Size>822inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::flip() _NOEXCEPT {823  __base::flip();824  return *this;825}826 827template <size_t _Size>828_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::flip(size_t __pos) {829  if (__pos >= _Size)830    std::__throw_out_of_range("bitset flip argument out of range");831 832  reference __r = __base::__make_ref(__pos);833  __r           = ~__r;834  return *this;835}836 837template <size_t _Size>838template <class _CharT, class _Traits, class _Allocator>839_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, _Traits, _Allocator>840bitset<_Size>::to_string(_CharT __zero, _CharT __one) const {841  bool __sparse = size_t(std::count(__base::__make_iter(0), __base::__make_iter(_Size), true)) < _Size / 2;842  if (__sparse)843    return __base::template __to_string<true, _CharT, _Traits, _Allocator>(__zero, __one);844  else845    return __base::template __to_string<false, _CharT, _Traits, _Allocator>(__zero, __one);846}847 848template <size_t _Size>849template <class _CharT, class _Traits>850inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, _Traits, allocator<_CharT> >851bitset<_Size>::to_string(_CharT __zero, _CharT __one) const {852  return to_string<_CharT, _Traits, allocator<_CharT> >(__zero, __one);853}854 855template <size_t _Size>856template <class _CharT>857inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> >858bitset<_Size>::to_string(_CharT __zero, _CharT __one) const {859  return to_string<_CharT, char_traits<_CharT>, allocator<_CharT> >(__zero, __one);860}861 862template <size_t _Size>863inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<char, char_traits<char>, allocator<char> >864bitset<_Size>::to_string(char __zero, char __one) const {865  return to_string<char, char_traits<char>, allocator<char> >(__zero, __one);866}867 868template <size_t _Size>869inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 size_t bitset<_Size>::count() const _NOEXCEPT {870#  if defined(_LIBCPP_COMPILER_CLANG_BASED) && !defined(_LIBCPP_CXX03_LANG)871  if constexpr (_Size == 0) {872    return 0;873  } else if constexpr (_Size <= __base::__bits_per_word) {874    return __builtin_popcountg(static_cast<unsigned _BitInt(_Size)>(__base::__first_));875  } else876#  endif877  {878    return static_cast<size_t>(std::count(__base::__make_iter(0), __base::__make_iter(_Size), true));879  }880}881 882template <size_t _Size>883inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool884bitset<_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 <= 17889 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#  endif896 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    std::__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 bitset<_Size>907bitset<_Size>::operator<<(size_t __pos) const _NOEXCEPT {908  bitset __r = *this;909  __r <<= __pos;910  return __r;911}912 913template <size_t _Size>914inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>915bitset<_Size>::operator>>(size_t __pos) const _NOEXCEPT {916  bitset __r = *this;917  __r >>= __pos;918  return __r;919}920 921template <size_t _Size>922inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>923operator&(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT {924  bitset<_Size> __r = __x;925  __r &= __y;926  return __r;927}928 929template <size_t _Size>930inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>931operator|(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT {932  bitset<_Size> __r = __x;933  __r |= __y;934  return __r;935}936 937template <size_t _Size>938inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>939operator^(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT {940  bitset<_Size> __r = __x;941  __r ^= __y;942  return __r;943}944 945template <size_t _Size>946struct hash<bitset<_Size> > : public __unary_function<bitset<_Size>, size_t> {947  _LIBCPP_HIDE_FROM_ABI size_t operator()(const bitset<_Size>& __bs) const _NOEXCEPT { return __bs.__hash_code(); }948};949 950template <class _CharT, class _Traits, size_t _Size>951_LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&952operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x);953 954template <class _CharT, class _Traits, size_t _Size>955_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&956operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x);957 958_LIBCPP_END_NAMESPACE_STD959 960_LIBCPP_POP_MACROS961 962#  if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20963#    include <concepts>964#    include <cstdlib>965#    include <optional>966#    include <type_traits>967#  endif968#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)969 970#endif // _LIBCPP_BITSET971