Debian Codegraph @

llvm-project/libcxx/include/bitset

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