xref: /freebsd/contrib/llvm-project/libcxx/include/bitset (revision 9bc300465e48e19d794d88d0c158a2adb92c7197)
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#include <__algorithm/count.h>
130#include <__algorithm/fill.h>
131#include <__algorithm/find.h>
132#include <__assert> // all public C++ headers provide the assertion handler
133#include <__bit_reference>
134#include <__config>
135#include <__functional/hash.h>
136#include <__functional/unary_function.h>
137#include <__type_traits/is_char_like_type.h>
138#include <climits>
139#include <cstddef>
140#include <stdexcept>
141#include <string_view>
142#include <version>
143
144// standard-mandated includes
145
146// [bitset.syn]
147#include <iosfwd>
148#include <string>
149
150#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
151#  pragma GCC system_header
152#endif
153
154_LIBCPP_PUSH_MACROS
155#include <__undef_macros>
156
157_LIBCPP_BEGIN_NAMESPACE_STD
158
159template <size_t _N_words, size_t _Size>
160class __bitset;
161
162template <size_t _N_words, size_t _Size>
163struct __has_storage_type<__bitset<_N_words, _Size> > {
164  static const bool value = true;
165};
166
167template <size_t _N_words, size_t _Size>
168class __bitset {
169public:
170  typedef ptrdiff_t difference_type;
171  typedef size_t size_type;
172  typedef size_type __storage_type;
173
174protected:
175  typedef __bitset __self;
176  typedef __storage_type* __storage_pointer;
177  typedef const __storage_type* __const_storage_pointer;
178  static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
179
180  friend class __bit_reference<__bitset>;
181  friend class __bit_const_reference<__bitset>;
182  friend class __bit_iterator<__bitset, false>;
183  friend class __bit_iterator<__bitset, true>;
184  friend struct __bit_array<__bitset>;
185
186  __storage_type __first_[_N_words];
187
188  typedef __bit_reference<__bitset> reference;
189  typedef __bit_const_reference<__bitset> const_reference;
190  typedef __bit_iterator<__bitset, false> iterator;
191  typedef __bit_iterator<__bitset, true> const_iterator;
192
193  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
194  _LIBCPP_HIDE_FROM_ABI explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT;
195
196  _LIBCPP_HIDE_FROM_ABI _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  }
199  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT {
200    return const_reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);
201  }
202  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 iterator __make_iter(size_t __pos) _NOEXCEPT {
203    return iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);
204  }
205  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 const_iterator __make_iter(size_t __pos) const _NOEXCEPT {
206    return const_iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);
207  }
208
209  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator&=(const __bitset& __v) _NOEXCEPT;
210  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator|=(const __bitset& __v) _NOEXCEPT;
211  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator^=(const __bitset& __v) _NOEXCEPT;
212
213  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void flip() _NOEXCEPT;
214  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong() const {
215    return to_ulong(integral_constant < bool, _Size< sizeof(unsigned long) * CHAR_BIT>());
216  }
217  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong() const {
218    return to_ullong(integral_constant < bool, _Size< sizeof(unsigned long long) * CHAR_BIT>());
219  }
220
221  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT;
222  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT;
223  _LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT;
224
225private:
226#ifdef _LIBCPP_CXX03_LANG
227  void __init(unsigned long long __v, false_type) _NOEXCEPT;
228  _LIBCPP_HIDE_FROM_ABI void __init(unsigned long long __v, true_type) _NOEXCEPT;
229#endif // _LIBCPP_CXX03_LANG
230  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong(false_type) const;
231  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong(true_type) const;
232  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong(false_type) const;
233  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong(true_type) const;
234  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong(true_type, false_type) const;
235  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong(true_type, true_type) const;
236};
237
238template <size_t _N_words, size_t _Size>
239inline _LIBCPP_CONSTEXPR __bitset<_N_words, _Size>::__bitset() _NOEXCEPT
240#ifndef _LIBCPP_CXX03_LANG
241    : __first_{0}
242#endif
243{
244#ifdef _LIBCPP_CXX03_LANG
245  std::fill_n(__first_, _N_words, __storage_type(0));
246#endif
247}
248
249#ifdef _LIBCPP_CXX03_LANG
250
251template <size_t _N_words, size_t _Size>
252void __bitset<_N_words, _Size>::__init(unsigned long long __v, false_type) _NOEXCEPT {
253  __storage_type __t[sizeof(unsigned long long) / sizeof(__storage_type)];
254  size_t __sz = _Size;
255  for (size_t __i = 0; __i < sizeof(__t) / sizeof(__t[0]); ++__i, __v >>= __bits_per_word, __sz -= __bits_per_word)
256    if (__sz < __bits_per_word)
257      __t[__i] = static_cast<__storage_type>(__v) & (1ULL << __sz) - 1;
258    else
259      __t[__i] = static_cast<__storage_type>(__v);
260
261  std::copy(__t, __t + sizeof(__t) / sizeof(__t[0]), __first_);
262  std::fill(
263      __first_ + sizeof(__t) / sizeof(__t[0]), __first_ + sizeof(__first_) / sizeof(__first_[0]), __storage_type(0));
264}
265
266template <size_t _N_words, size_t _Size>
267inline _LIBCPP_HIDE_FROM_ABI void __bitset<_N_words, _Size>::__init(unsigned long long __v, true_type) _NOEXCEPT {
268  __first_[0] = __v;
269  if (_Size < __bits_per_word)
270    __first_[0] &= (1ULL << _Size) - 1;
271
272  std::fill(__first_ + 1, __first_ + sizeof(__first_) / sizeof(__first_[0]), __storage_type(0));
273}
274
275#endif // _LIBCPP_CXX03_LANG
276
277template <size_t _N_words, size_t _Size>
278inline _LIBCPP_CONSTEXPR __bitset<_N_words, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
279#ifndef _LIBCPP_CXX03_LANG
280#  if __SIZEOF_SIZE_T__ == 8
281    : __first_{__v}
282#  elif __SIZEOF_SIZE_T__ == 4
283    : __first_{static_cast<__storage_type>(__v),
284               _Size >= 2 * __bits_per_word
285                   ? static_cast<__storage_type>(__v >> __bits_per_word)
286                   : static_cast<__storage_type>((__v >> __bits_per_word) &
287                                                 (__storage_type(1) << (_Size - __bits_per_word)) - 1)}
288#  else
289#    error This constructor has not been ported to this platform
290#  endif
291#endif
292{
293#ifdef _LIBCPP_CXX03_LANG
294  __init(__v, integral_constant<bool, sizeof(unsigned long long) == sizeof(__storage_type)>());
295#endif
296}
297
298template <size_t _N_words, size_t _Size>
299inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void
300__bitset<_N_words, _Size>::operator&=(const __bitset& __v) _NOEXCEPT {
301  for (size_type __i = 0; __i < _N_words; ++__i)
302    __first_[__i] &= __v.__first_[__i];
303}
304
305template <size_t _N_words, size_t _Size>
306inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void
307__bitset<_N_words, _Size>::operator|=(const __bitset& __v) _NOEXCEPT {
308  for (size_type __i = 0; __i < _N_words; ++__i)
309    __first_[__i] |= __v.__first_[__i];
310}
311
312template <size_t _N_words, size_t _Size>
313inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void
314__bitset<_N_words, _Size>::operator^=(const __bitset& __v) _NOEXCEPT {
315  for (size_type __i = 0; __i < _N_words; ++__i)
316    __first_[__i] ^= __v.__first_[__i];
317}
318
319template <size_t _N_words, size_t _Size>
320_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void __bitset<_N_words, _Size>::flip() _NOEXCEPT {
321  // do middle whole words
322  size_type __n         = _Size;
323  __storage_pointer __p = __first_;
324  for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
325    *__p = ~*__p;
326  // do last partial word
327  if (__n > 0) {
328    __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
329    __storage_type __b = *__p & __m;
330    *__p &= ~__m;
331    *__p |= ~__b & __m;
332  }
333}
334
335template <size_t _N_words, size_t _Size>
336_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long
337__bitset<_N_words, _Size>::to_ulong(false_type) const {
338  const_iterator __e = __make_iter(_Size);
339  const_iterator __i = std::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true);
340  if (__i != __e)
341    __throw_overflow_error("bitset to_ulong overflow error");
342
343  return __first_[0];
344}
345
346template <size_t _N_words, size_t _Size>
347inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long
348__bitset<_N_words, _Size>::to_ulong(true_type) const {
349  return __first_[0];
350}
351
352template <size_t _N_words, size_t _Size>
353_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long
354__bitset<_N_words, _Size>::to_ullong(false_type) const {
355  const_iterator __e = __make_iter(_Size);
356  const_iterator __i = std::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true);
357  if (__i != __e)
358    __throw_overflow_error("bitset to_ullong overflow error");
359
360  return to_ullong(true_type());
361}
362
363template <size_t _N_words, size_t _Size>
364inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long
365__bitset<_N_words, _Size>::to_ullong(true_type) const {
366  return to_ullong(true_type(), integral_constant<bool, sizeof(__storage_type) < sizeof(unsigned long long)>());
367}
368
369template <size_t _N_words, size_t _Size>
370inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long
371__bitset<_N_words, _Size>::to_ullong(true_type, false_type) const {
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(true_type, true_type) const {
378  unsigned long long __r = __first_[0];
379  _LIBCPP_DIAGNOSTIC_PUSH
380  _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wshift-count-overflow")
381  for (size_t __i = 1; __i < sizeof(unsigned long long) / sizeof(__storage_type); ++__i)
382    __r |= static_cast<unsigned long long>(__first_[__i]) << (sizeof(__storage_type) * CHAR_BIT);
383  _LIBCPP_DIAGNOSTIC_POP
384  return __r;
385}
386
387template <size_t _N_words, size_t _Size>
388_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool __bitset<_N_words, _Size>::all() const _NOEXCEPT {
389  // do middle whole words
390  size_type __n               = _Size;
391  __const_storage_pointer __p = __first_;
392  for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
393    if (~*__p)
394      return false;
395  // do last partial word
396  if (__n > 0) {
397    __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
398    if (~*__p & __m)
399      return false;
400  }
401  return true;
402}
403
404template <size_t _N_words, size_t _Size>
405_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool __bitset<_N_words, _Size>::any() const _NOEXCEPT {
406  // do middle whole words
407  size_type __n               = _Size;
408  __const_storage_pointer __p = __first_;
409  for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
410    if (*__p)
411      return true;
412  // do last partial word
413  if (__n > 0) {
414    __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
415    if (*__p & __m)
416      return true;
417  }
418  return false;
419}
420
421template <size_t _N_words, size_t _Size>
422inline size_t __bitset<_N_words, _Size>::__hash_code() const _NOEXCEPT {
423  size_t __h = 0;
424  for (size_type __i = 0; __i < _N_words; ++__i)
425    __h ^= __first_[__i];
426  return __h;
427}
428
429template <size_t _Size>
430class __bitset<1, _Size> {
431public:
432  typedef ptrdiff_t difference_type;
433  typedef size_t size_type;
434  typedef size_type __storage_type;
435
436protected:
437  typedef __bitset __self;
438  typedef __storage_type* __storage_pointer;
439  typedef const __storage_type* __const_storage_pointer;
440  static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
441
442  friend class __bit_reference<__bitset>;
443  friend class __bit_const_reference<__bitset>;
444  friend class __bit_iterator<__bitset, false>;
445  friend class __bit_iterator<__bitset, true>;
446  friend struct __bit_array<__bitset>;
447
448  __storage_type __first_;
449
450  typedef __bit_reference<__bitset> reference;
451  typedef __bit_const_reference<__bitset> const_reference;
452  typedef __bit_iterator<__bitset, false> iterator;
453  typedef __bit_iterator<__bitset, true> const_iterator;
454
455  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
456  _LIBCPP_HIDE_FROM_ABI explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT;
457
458  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 reference __make_ref(size_t __pos) _NOEXCEPT {
459    return reference(&__first_, __storage_type(1) << __pos);
460  }
461  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT {
462    return const_reference(&__first_, __storage_type(1) << __pos);
463  }
464  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 iterator __make_iter(size_t __pos) _NOEXCEPT {
465    return iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);
466  }
467  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 const_iterator __make_iter(size_t __pos) const _NOEXCEPT {
468    return const_iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);
469  }
470
471  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator&=(const __bitset& __v) _NOEXCEPT;
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
475  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void flip() _NOEXCEPT;
476
477  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong() const;
478  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong() const;
479
480  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT;
481  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT;
482
483  _LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT;
484};
485
486template <size_t _Size>
487inline _LIBCPP_CONSTEXPR __bitset<1, _Size>::__bitset() _NOEXCEPT : __first_(0) {}
488
489template <size_t _Size>
490inline _LIBCPP_CONSTEXPR __bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
491    : __first_(_Size == __bits_per_word ? static_cast<__storage_type>(__v)
492                                        : static_cast<__storage_type>(__v) & ((__storage_type(1) << _Size) - 1)) {}
493
494template <size_t _Size>
495inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void
496__bitset<1, _Size>::operator&=(const __bitset& __v) _NOEXCEPT {
497  __first_ &= __v.__first_;
498}
499
500template <size_t _Size>
501inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void
502__bitset<1, _Size>::operator|=(const __bitset& __v) _NOEXCEPT {
503  __first_ |= __v.__first_;
504}
505
506template <size_t _Size>
507inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void
508__bitset<1, _Size>::operator^=(const __bitset& __v) _NOEXCEPT {
509  __first_ ^= __v.__first_;
510}
511
512template <size_t _Size>
513inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void __bitset<1, _Size>::flip() _NOEXCEPT {
514  __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
515  __first_           = ~__first_;
516  __first_ &= __m;
517}
518
519template <size_t _Size>
520inline _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long __bitset<1, _Size>::to_ulong() const {
521  return __first_;
522}
523
524template <size_t _Size>
525inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long __bitset<1, _Size>::to_ullong() const {
526  return __first_;
527}
528
529template <size_t _Size>
530inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool __bitset<1, _Size>::all() const _NOEXCEPT {
531  __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
532  return !(~__first_ & __m);
533}
534
535template <size_t _Size>
536inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool __bitset<1, _Size>::any() const _NOEXCEPT {
537  __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
538  return __first_ & __m;
539}
540
541template <size_t _Size>
542inline size_t __bitset<1, _Size>::__hash_code() const _NOEXCEPT {
543  return __first_;
544}
545
546template <>
547class __bitset<0, 0> {
548public:
549  typedef ptrdiff_t difference_type;
550  typedef size_t size_type;
551  typedef size_type __storage_type;
552
553protected:
554  typedef __bitset __self;
555  typedef __storage_type* __storage_pointer;
556  typedef const __storage_type* __const_storage_pointer;
557  static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
558
559  friend class __bit_reference<__bitset>;
560  friend class __bit_const_reference<__bitset>;
561  friend class __bit_iterator<__bitset, false>;
562  friend class __bit_iterator<__bitset, true>;
563  friend struct __bit_array<__bitset>;
564
565  typedef __bit_reference<__bitset> reference;
566  typedef __bit_const_reference<__bitset> const_reference;
567  typedef __bit_iterator<__bitset, false> iterator;
568  typedef __bit_iterator<__bitset, true> const_iterator;
569
570  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
571  _LIBCPP_HIDE_FROM_ABI explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long) _NOEXCEPT;
572
573  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 reference __make_ref(size_t) _NOEXCEPT {
574    return reference(nullptr, 1);
575  }
576  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference __make_ref(size_t) const _NOEXCEPT {
577    return const_reference(nullptr, 1);
578  }
579  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 iterator __make_iter(size_t) _NOEXCEPT {
580    return iterator(nullptr, 0);
581  }
582  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 const_iterator __make_iter(size_t) const _NOEXCEPT {
583    return const_iterator(nullptr, 0);
584  }
585
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  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator^=(const __bitset&) _NOEXCEPT {}
589
590  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void flip() _NOEXCEPT {}
591
592  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong() const { return 0; }
593  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong() const { return 0; }
594
595  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT { return true; }
596  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT { return false; }
597
598  _LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT { return 0; }
599};
600
601inline _LIBCPP_CONSTEXPR __bitset<0, 0>::__bitset() _NOEXCEPT {}
602
603inline _LIBCPP_CONSTEXPR __bitset<0, 0>::__bitset(unsigned long long) _NOEXCEPT {}
604
605template <size_t _Size>
606class _LIBCPP_TEMPLATE_VIS bitset;
607template <size_t _Size>
608struct hash<bitset<_Size> >;
609
610template <size_t _Size>
611class _LIBCPP_TEMPLATE_VIS bitset
612    : private __bitset<_Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1, _Size> {
613public:
614  static const unsigned __n_words = _Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1;
615  typedef __bitset<__n_words, _Size> base;
616
617public:
618  typedef typename base::reference reference;
619  typedef typename base::const_reference const_reference;
620
621  // 23.3.5.1 constructors:
622  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bitset() _NOEXCEPT {}
623  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bitset(unsigned long long __v) _NOEXCEPT : base(__v) {}
624  template <class _CharT, class = __enable_if_t<_IsCharLikeType<_CharT>::value> >
625  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit bitset(
626      const _CharT* __str,
627#if _LIBCPP_STD_VER >= 26
628      typename basic_string_view<_CharT>::size_type __n = basic_string_view<_CharT>::npos,
629#else
630      typename basic_string<_CharT>::size_type __n = basic_string<_CharT>::npos,
631#endif
632      _CharT __zero = _CharT('0'),
633      _CharT __one  = _CharT('1')) {
634
635    size_t __rlen = std::min(__n, char_traits<_CharT>::length(__str));
636    __init_from_string_view(basic_string_view<_CharT>(__str, __rlen), __zero, __one);
637  }
638#if _LIBCPP_STD_VER >= 26
639  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      __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#endif
653  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_BOOL
684  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool operator[](size_t __p) const { return base::__make_ref(__p); }
685#else
686  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference operator[](size_t __p) const { return base::__make_ref(__p); }
687#endif
688  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 reference operator[](size_t __p) { return base::__make_ref(__p); }
689  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong() const;
690  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong() const;
691  template <class _CharT, class _Traits, class _Allocator>
692  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, _Traits, _Allocator>
693  to_string(_CharT __zero = _CharT('0'), _CharT __one = _CharT('1')) const;
694  template <class _CharT, class _Traits>
695  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, _Traits, allocator<_CharT> >
696  to_string(_CharT __zero = _CharT('0'), _CharT __one = _CharT('1')) const;
697  template <class _CharT>
698  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> >
699  to_string(_CharT __zero = _CharT('0'), _CharT __one = _CharT('1')) const;
700  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<char, char_traits<char>, allocator<char> >
701  to_string(char __zero = '0', char __one = '1') const;
702  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 size_t count() const _NOEXCEPT;
703  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR size_t size() const _NOEXCEPT { return _Size; }
704  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool operator==(const bitset& __rhs) const _NOEXCEPT;
705#if _LIBCPP_STD_VER <= 17
706  _LIBCPP_HIDE_FROM_ABI bool operator!=(const bitset& __rhs) const _NOEXCEPT;
707#endif
708  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool test(size_t __pos) const;
709  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT;
710  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT;
711  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool none() const _NOEXCEPT { return !any(); }
712  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset operator<<(size_t __pos) const _NOEXCEPT;
713  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset operator>>(size_t __pos) const _NOEXCEPT;
714
715private:
716  template <class _CharT, class _Traits>
717  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void
718  __init_from_string_view(basic_string_view<_CharT, _Traits> __str, _CharT __zero, _CharT __one) {
719    for (size_t __i = 0; __i < __str.size(); ++__i)
720      if (!_Traits::eq(__str[__i], __zero) && !_Traits::eq(__str[__i], __one))
721        std::__throw_invalid_argument("bitset string ctor has invalid argument");
722
723    size_t __mp = std::min(__str.size(), _Size);
724    size_t __i  = 0;
725    for (; __i < __mp; ++__i) {
726      _CharT __c   = __str[__mp - 1 - __i];
727      (*this)[__i] = _Traits::eq(__c, __one);
728    }
729    std::fill(base::__make_iter(__i), base::__make_iter(_Size), false);
730  }
731
732  _LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT { return base::__hash_code(); }
733
734  friend struct hash<bitset>;
735};
736
737template <size_t _Size>
738inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>&
739bitset<_Size>::operator&=(const bitset& __rhs) _NOEXCEPT {
740  base::operator&=(__rhs);
741  return *this;
742}
743
744template <size_t _Size>
745inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>&
746bitset<_Size>::operator|=(const bitset& __rhs) _NOEXCEPT {
747  base::operator|=(__rhs);
748  return *this;
749}
750
751template <size_t _Size>
752inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>&
753bitset<_Size>::operator^=(const bitset& __rhs) _NOEXCEPT {
754  base::operator^=(__rhs);
755  return *this;
756}
757
758template <size_t _Size>
759_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::operator<<=(size_t __pos) _NOEXCEPT {
760  __pos = std::min(__pos, _Size);
761  std::copy_backward(base::__make_iter(0), base::__make_iter(_Size - __pos), base::__make_iter(_Size));
762  std::fill_n(base::__make_iter(0), __pos, false);
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(base::__make_iter(__pos), base::__make_iter(_Size), base::__make_iter(0));
770  std::fill_n(base::__make_iter(_Size - __pos), __pos, false);
771  return *this;
772}
773
774template <size_t _Size>
775inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::set() _NOEXCEPT {
776  std::fill_n(base::__make_iter(0), _Size, true);
777  return *this;
778}
779
780template <size_t _Size>
781_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::set(size_t __pos, bool __val) {
782  if (__pos >= _Size)
783    __throw_out_of_range("bitset set argument out of range");
784
785  (*this)[__pos] = __val;
786  return *this;
787}
788
789template <size_t _Size>
790inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::reset() _NOEXCEPT {
791  std::fill_n(base::__make_iter(0), _Size, false);
792  return *this;
793}
794
795template <size_t _Size>
796_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::reset(size_t __pos) {
797  if (__pos >= _Size)
798    __throw_out_of_range("bitset reset argument out of range");
799
800  (*this)[__pos] = false;
801  return *this;
802}
803
804template <size_t _Size>
805inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size> bitset<_Size>::operator~() const _NOEXCEPT {
806  bitset __x(*this);
807  __x.flip();
808  return __x;
809}
810
811template <size_t _Size>
812inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::flip() _NOEXCEPT {
813  base::flip();
814  return *this;
815}
816
817template <size_t _Size>
818_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::flip(size_t __pos) {
819  if (__pos >= _Size)
820    __throw_out_of_range("bitset flip argument out of range");
821
822  reference __r = base::__make_ref(__pos);
823  __r           = ~__r;
824  return *this;
825}
826
827template <size_t _Size>
828inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long bitset<_Size>::to_ulong() const {
829  return base::to_ulong();
830}
831
832template <size_t _Size>
833inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long bitset<_Size>::to_ullong() const {
834  return base::to_ullong();
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  basic_string<_CharT, _Traits, _Allocator> __r(_Size, __zero);
842  for (size_t __i = 0; __i != _Size; ++__i) {
843    if ((*this)[__i])
844      __r[_Size - 1 - __i] = __one;
845  }
846  return __r;
847}
848
849template <size_t _Size>
850template <class _CharT, class _Traits>
851inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, _Traits, allocator<_CharT> >
852bitset<_Size>::to_string(_CharT __zero, _CharT __one) const {
853  return to_string<_CharT, _Traits, allocator<_CharT> >(__zero, __one);
854}
855
856template <size_t _Size>
857template <class _CharT>
858inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> >
859bitset<_Size>::to_string(_CharT __zero, _CharT __one) const {
860  return to_string<_CharT, char_traits<_CharT>, allocator<_CharT> >(__zero, __one);
861}
862
863template <size_t _Size>
864inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<char, char_traits<char>, allocator<char> >
865bitset<_Size>::to_string(char __zero, char __one) const {
866  return to_string<char, char_traits<char>, allocator<char> >(__zero, __one);
867}
868
869template <size_t _Size>
870inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 size_t bitset<_Size>::count() const _NOEXCEPT {
871  return static_cast<size_t>(std::count(base::__make_iter(0), base::__make_iter(_Size), true));
872}
873
874template <size_t _Size>
875inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool
876bitset<_Size>::operator==(const bitset& __rhs) const _NOEXCEPT {
877  return std::equal(base::__make_iter(0), base::__make_iter(_Size), __rhs.__make_iter(0));
878}
879
880#if _LIBCPP_STD_VER <= 17
881
882template <size_t _Size>
883inline _LIBCPP_HIDE_FROM_ABI bool bitset<_Size>::operator!=(const bitset& __rhs) const _NOEXCEPT {
884  return !(*this == __rhs);
885}
886
887#endif
888
889template <size_t _Size>
890_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool bitset<_Size>::test(size_t __pos) const {
891  if (__pos >= _Size)
892    __throw_out_of_range("bitset test argument out of range");
893
894  return (*this)[__pos];
895}
896
897template <size_t _Size>
898inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool bitset<_Size>::all() const _NOEXCEPT {
899  return base::all();
900}
901
902template <size_t _Size>
903inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool bitset<_Size>::any() const _NOEXCEPT {
904  return base::any();
905}
906
907template <size_t _Size>
908inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>
909bitset<_Size>::operator<<(size_t __pos) const _NOEXCEPT {
910  bitset __r = *this;
911  __r <<= __pos;
912  return __r;
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>
925operator&(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT {
926  bitset<_Size> __r = __x;
927  __r &= __y;
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>
948struct _LIBCPP_TEMPLATE_VIS hash<bitset<_Size> > : public __unary_function<bitset<_Size>, size_t> {
949  _LIBCPP_HIDE_FROM_ABI size_t operator()(const bitset<_Size>& __bs) const _NOEXCEPT { return __bs.__hash_code(); }
950};
951
952template <class _CharT, class _Traits, size_t _Size>
953_LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
954operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x);
955
956template <class _CharT, class _Traits, size_t _Size>
957_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
958operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x);
959
960_LIBCPP_END_NAMESPACE_STD
961
962_LIBCPP_POP_MACROS
963
964#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
965#  include <concepts>
966#  include <cstdlib>
967#  include <type_traits>
968#endif
969
970#endif // _LIBCPP_BITSET
971