42#ifndef _GLIBCXX_BITSET
43#define _GLIBCXX_BITSET 1
46#pragma GCC system_header
59#if __cplusplus >= 201103L
63#define __glibcxx_want_constexpr_bitset
64#define __glibcxx_want_bitset
65#define __glibcxx_want_hardened_bitset
68#ifdef __cpp_lib_bitset
72#define _GLIBCXX_BITSET_BITS_PER_WORD (__CHAR_BIT__ * __SIZEOF_LONG__)
73#define _GLIBCXX_BITSET_WORDS(__n) \
74 ((__n) / _GLIBCXX_BITSET_BITS_PER_WORD + \
75 ((__n) % _GLIBCXX_BITSET_BITS_PER_WORD == 0 ? 0 : 1))
77#define _GLIBCXX_BITSET_BITS_PER_ULL (__CHAR_BIT__ * __SIZEOF_LONG_LONG__)
79namespace std _GLIBCXX_VISIBILITY(default)
81_GLIBCXX_BEGIN_NAMESPACE_CONTAINER
92 typedef unsigned long _WordT;
97 _GLIBCXX_CONSTEXPR _Base_bitset() _GLIBCXX_NOEXCEPT
100#if __cplusplus >= 201103L
101 constexpr _Base_bitset(
unsigned long long __val) noexcept
102 :
_M_w{ _WordT(__val)
103#if __SIZEOF_LONG_LONG__ > __SIZEOF_LONG__
104 , _WordT(__val >> _GLIBCXX_BITSET_BITS_PER_WORD)
108 _Base_bitset(
unsigned long __val)
113 static _GLIBCXX_CONSTEXPR
size_t
114 _S_whichword(
size_t __pos) _GLIBCXX_NOEXCEPT
115 {
return __pos / _GLIBCXX_BITSET_BITS_PER_WORD; }
117 static _GLIBCXX_CONSTEXPR
size_t
118 _S_whichbyte(
size_t __pos) _GLIBCXX_NOEXCEPT
119 {
return (__pos % _GLIBCXX_BITSET_BITS_PER_WORD) / __CHAR_BIT__; }
121 static _GLIBCXX_CONSTEXPR
size_t
122 _S_whichbit(
size_t __pos) _GLIBCXX_NOEXCEPT
123 {
return __pos % _GLIBCXX_BITSET_BITS_PER_WORD; }
125 static _GLIBCXX_CONSTEXPR _WordT
126 _S_maskbit(
size_t __pos) _GLIBCXX_NOEXCEPT
127 {
return (
static_cast<_WordT
>(1)) << _S_whichbit(__pos); }
129 _GLIBCXX14_CONSTEXPR _WordT&
130 _M_getword(
size_t __pos) _GLIBCXX_NOEXCEPT
131 {
return _M_w[_S_whichword(__pos)]; }
133 _GLIBCXX_CONSTEXPR _WordT
134 _M_getword(
size_t __pos)
const _GLIBCXX_NOEXCEPT
135 {
return _M_w[_S_whichword(__pos)]; }
137#if __cplusplus >= 201103L
138 constexpr const _WordT*
139 _M_getdata() const noexcept
143 _GLIBCXX23_CONSTEXPR _WordT&
144 _M_hiword() _GLIBCXX_NOEXCEPT
145 {
return _M_w[_Nw - 1]; }
147 _GLIBCXX_CONSTEXPR _WordT
148 _M_hiword() const _GLIBCXX_NOEXCEPT
149 {
return _M_w[_Nw - 1]; }
151 _GLIBCXX23_CONSTEXPR
void
152 _M_do_and(
const _Base_bitset<_Nw>& __x) _GLIBCXX_NOEXCEPT
154 for (
size_t __i = 0; __i < _Nw; __i++)
155 _M_w[__i] &= __x._M_w[__i];
158 _GLIBCXX14_CONSTEXPR
void
159 _M_do_or(
const _Base_bitset<_Nw>& __x) _GLIBCXX_NOEXCEPT
161 for (
size_t __i = 0; __i < _Nw; __i++)
162 _M_w[__i] |= __x._M_w[__i];
165 _GLIBCXX14_CONSTEXPR
void
166 _M_do_xor(
const _Base_bitset<_Nw>& __x) _GLIBCXX_NOEXCEPT
168 for (
size_t __i = 0; __i < _Nw; __i++)
169 _M_w[__i] ^= __x._M_w[__i];
172 _GLIBCXX14_CONSTEXPR
void
173 _M_do_left_shift(
size_t __shift) _GLIBCXX_NOEXCEPT;
175 _GLIBCXX14_CONSTEXPR
void
176 _M_do_right_shift(
size_t __shift) _GLIBCXX_NOEXCEPT;
178 _GLIBCXX14_CONSTEXPR
void
179 _M_do_flip() _GLIBCXX_NOEXCEPT
181 for (
size_t __i = 0; __i < _Nw; __i++)
185 _GLIBCXX14_CONSTEXPR
void
186 _M_do_set() _GLIBCXX_NOEXCEPT
188#if __cplusplus >= 201402L
189 if (__builtin_is_constant_evaluated())
191 for (_WordT& __w :
_M_w)
192 __w = ~static_cast<_WordT>(0);;
196 __builtin_memset(
_M_w, 0xFF, _Nw *
sizeof(_WordT));
199 _GLIBCXX14_CONSTEXPR
void
200 _M_do_reset() _GLIBCXX_NOEXCEPT
202#if __cplusplus >= 201402L
203 if (__builtin_is_constant_evaluated())
205 for (_WordT& __w :
_M_w)
210 __builtin_memset(
_M_w, 0, _Nw *
sizeof(_WordT));
213 _GLIBCXX14_CONSTEXPR
bool
214 _M_is_equal(
const _Base_bitset<_Nw>& __x)
const _GLIBCXX_NOEXCEPT
216#if __cplusplus >= 201402L
217 if (__builtin_is_constant_evaluated())
219 for (
size_t __i = 0; __i < _Nw; ++__i)
220 if (
_M_w[__i] != __x._M_w[__i])
225 return !__builtin_memcmp(
_M_w, __x._M_w, _Nw *
sizeof(_WordT));
229 _GLIBCXX14_CONSTEXPR
bool
230 _M_are_all() const _GLIBCXX_NOEXCEPT
232 for (
size_t __i = 0; __i < _Nw - 1; __i++)
233 if (
_M_w[__i] != ~
static_cast<_WordT
>(0))
235 return _M_hiword() == (~static_cast<_WordT>(0)
236 >> (_Nw * _GLIBCXX_BITSET_BITS_PER_WORD
240 _GLIBCXX14_CONSTEXPR
bool
241 _M_is_any() const _GLIBCXX_NOEXCEPT
243 for (
size_t __i = 0; __i < _Nw; __i++)
244 if (
_M_w[__i] !=
static_cast<_WordT
>(0))
249 _GLIBCXX14_CONSTEXPR
size_t
250 _M_do_count() const _GLIBCXX_NOEXCEPT
253 for (
size_t __i = 0; __i < _Nw; __i++)
254 __result += __builtin_popcountl(
_M_w[__i]);
258 _GLIBCXX14_CONSTEXPR
unsigned long
259 _M_do_to_ulong()
const;
261#if __cplusplus >= 201103L
262 _GLIBCXX14_CONSTEXPR
unsigned long long
263 _M_do_to_ullong()
const;
267 _GLIBCXX14_CONSTEXPR
size_t
268 _M_do_find_first(
size_t)
const _GLIBCXX_NOEXCEPT;
271 _GLIBCXX14_CONSTEXPR
size_t
272 _M_do_find_next(
size_t,
size_t)
const _GLIBCXX_NOEXCEPT;
277 _GLIBCXX14_CONSTEXPR
void
278 _Base_bitset<_Nw>::_M_do_left_shift(
size_t __shift) _GLIBCXX_NOEXCEPT
280 if (__builtin_expect(__shift != 0, 1))
282 const size_t __wshift = __shift / _GLIBCXX_BITSET_BITS_PER_WORD;
283 const size_t __offset = __shift % _GLIBCXX_BITSET_BITS_PER_WORD;
286 for (
size_t __n = _Nw - 1; __n >= __wshift; --__n)
287 _M_w[__n] = _M_w[__n - __wshift];
290 const size_t __sub_offset = (_GLIBCXX_BITSET_BITS_PER_WORD
292 for (
size_t __n = _Nw - 1; __n > __wshift; --__n)
293 _M_w[__n] = ((_M_w[__n - __wshift] << __offset)
294 | (_M_w[__n - __wshift - 1] >> __sub_offset));
295 _M_w[__wshift] = _M_w[0] << __offset;
298 std::fill(_M_w + 0, _M_w + __wshift,
static_cast<_WordT
>(0));
303 _GLIBCXX14_CONSTEXPR
void
304 _Base_bitset<_Nw>::_M_do_right_shift(
size_t __shift) _GLIBCXX_NOEXCEPT
306 if (__builtin_expect(__shift != 0, 1))
308 const size_t __wshift = __shift / _GLIBCXX_BITSET_BITS_PER_WORD;
309 const size_t __offset = __shift % _GLIBCXX_BITSET_BITS_PER_WORD;
310 const size_t __limit = _Nw - __wshift - 1;
313 for (
size_t __n = 0; __n <= __limit; ++__n)
314 _M_w[__n] = _M_w[__n + __wshift];
317 const size_t __sub_offset = (_GLIBCXX_BITSET_BITS_PER_WORD
319 for (
size_t __n = 0; __n < __limit; ++__n)
320 _M_w[__n] = ((_M_w[__n + __wshift] >> __offset)
321 | (_M_w[__n + __wshift + 1] << __sub_offset));
322 _M_w[__limit] = _M_w[_Nw-1] >> __offset;
325 std::fill(_M_w + __limit + 1, _M_w + _Nw,
static_cast<_WordT
>(0));
330 _GLIBCXX14_CONSTEXPR
unsigned long
331 _Base_bitset<_Nw>::_M_do_to_ulong()
const
333 for (
size_t __i = 1; __i < _Nw; ++__i)
335 __throw_overflow_error(__N(
"_Base_bitset::_M_do_to_ulong"));
339#if __cplusplus >= 201103L
341 _GLIBCXX14_CONSTEXPR
unsigned long long
342 _Base_bitset<_Nw>::_M_do_to_ullong()
const
344#if __SIZEOF_LONG_LONG__ == __SIZEOF_LONG__
345 return _M_do_to_ulong();
347 for (
size_t __i = 2; __i < _Nw; ++__i)
349 __throw_overflow_error(__N(
"_Base_bitset::_M_do_to_ullong"));
351 return _M_w[0] + (
static_cast<unsigned long long>(_M_w[1])
352 << _GLIBCXX_BITSET_BITS_PER_WORD);
358 _GLIBCXX14_CONSTEXPR
size_t
362 for (
size_t __i = 0; __i < _Nw; __i++)
364 _WordT __thisword = _M_w[__i];
365 if (__thisword !=
static_cast<_WordT
>(0))
366 return (__i * _GLIBCXX_BITSET_BITS_PER_WORD
367 + __builtin_ctzl(__thisword));
374 _GLIBCXX14_CONSTEXPR
size_t
376 _M_do_find_next(
size_t __prev,
size_t __not_found)
const _GLIBCXX_NOEXCEPT
382 if (__prev >= _Nw * _GLIBCXX_BITSET_BITS_PER_WORD)
386 size_t __i = _S_whichword(__prev);
387 _WordT __thisword = _M_w[__i];
390 __thisword &= (~static_cast<_WordT>(0)) << _S_whichbit(__prev);
392 if (__thisword !=
static_cast<_WordT
>(0))
393 return (__i * _GLIBCXX_BITSET_BITS_PER_WORD
394 + __builtin_ctzl(__thisword));
398 for (; __i < _Nw; __i++)
400 __thisword = _M_w[__i];
401 if (__thisword !=
static_cast<_WordT
>(0))
402 return (__i * _GLIBCXX_BITSET_BITS_PER_WORD
403 + __builtin_ctzl(__thisword));
415 struct _Base_bitset<1>
417 typedef unsigned long _WordT;
420 _GLIBCXX_CONSTEXPR _Base_bitset() _GLIBCXX_NOEXCEPT
424#if __cplusplus >= 201103L
425 constexpr _Base_bitset(
unsigned long long __val)
noexcept
427 _Base_bitset(
unsigned long __val)
432 static _GLIBCXX_CONSTEXPR
size_t
433 _S_whichword(
size_t __pos) _GLIBCXX_NOEXCEPT
434 {
return __pos / _GLIBCXX_BITSET_BITS_PER_WORD; }
436 static _GLIBCXX_CONSTEXPR
size_t
437 _S_whichbyte(
size_t __pos) _GLIBCXX_NOEXCEPT
438 {
return (__pos % _GLIBCXX_BITSET_BITS_PER_WORD) / __CHAR_BIT__; }
440 static _GLIBCXX_CONSTEXPR
size_t
441 _S_whichbit(
size_t __pos) _GLIBCXX_NOEXCEPT
442 {
return __pos % _GLIBCXX_BITSET_BITS_PER_WORD; }
444 static _GLIBCXX_CONSTEXPR _WordT
445 _S_maskbit(
size_t __pos) _GLIBCXX_NOEXCEPT
446 {
return (
static_cast<_WordT
>(1)) << _S_whichbit(__pos); }
448 _GLIBCXX14_CONSTEXPR _WordT&
449 _M_getword(
size_t) _GLIBCXX_NOEXCEPT
452 _GLIBCXX_CONSTEXPR _WordT
453 _M_getword(
size_t)
const _GLIBCXX_NOEXCEPT
456#if __cplusplus >= 201103L
457 constexpr const _WordT*
458 _M_getdata()
const noexcept
462 _GLIBCXX14_CONSTEXPR _WordT&
463 _M_hiword() _GLIBCXX_NOEXCEPT
466 _GLIBCXX_CONSTEXPR _WordT
467 _M_hiword()
const _GLIBCXX_NOEXCEPT
470 _GLIBCXX14_CONSTEXPR
void
471 _M_do_and(
const _Base_bitset<1>& __x) _GLIBCXX_NOEXCEPT
472 { _M_w &= __x.
_M_w; }
474 _GLIBCXX14_CONSTEXPR
void
475 _M_do_or(
const _Base_bitset<1>& __x) _GLIBCXX_NOEXCEPT
476 { _M_w |= __x.
_M_w; }
478 _GLIBCXX14_CONSTEXPR
void
479 _M_do_xor(
const _Base_bitset<1>& __x) _GLIBCXX_NOEXCEPT
480 { _M_w ^= __x.
_M_w; }
482 _GLIBCXX14_CONSTEXPR
void
483 _M_do_left_shift(
size_t __shift) _GLIBCXX_NOEXCEPT
484 { _M_w <<= __shift; }
486 _GLIBCXX14_CONSTEXPR
void
487 _M_do_right_shift(
size_t __shift) _GLIBCXX_NOEXCEPT
488 { _M_w >>= __shift; }
490 _GLIBCXX14_CONSTEXPR
void
491 _M_do_flip() _GLIBCXX_NOEXCEPT
494 _GLIBCXX14_CONSTEXPR
void
495 _M_do_set() _GLIBCXX_NOEXCEPT
496 { _M_w = ~static_cast<_WordT>(0); }
498 _GLIBCXX14_CONSTEXPR
void
499 _M_do_reset() _GLIBCXX_NOEXCEPT
502 _GLIBCXX14_CONSTEXPR
bool
503 _M_is_equal(
const _Base_bitset<1>& __x)
const _GLIBCXX_NOEXCEPT
504 {
return _M_w == __x.
_M_w; }
507 _GLIBCXX14_CONSTEXPR
bool
508 _M_are_all()
const _GLIBCXX_NOEXCEPT
509 {
return _M_w == (~static_cast<_WordT>(0)
510 >> (_GLIBCXX_BITSET_BITS_PER_WORD - _Nb)); }
512 _GLIBCXX14_CONSTEXPR
bool
513 _M_is_any()
const _GLIBCXX_NOEXCEPT
514 {
return _M_w != 0; }
516 _GLIBCXX14_CONSTEXPR
size_t
517 _M_do_count()
const _GLIBCXX_NOEXCEPT
518 {
return __builtin_popcountl(_M_w); }
520 _GLIBCXX14_CONSTEXPR
unsigned long
521 _M_do_to_ulong()
const _GLIBCXX_NOEXCEPT
524#if __cplusplus >= 201103L
525 constexpr unsigned long long
526 _M_do_to_ullong()
const noexcept
530 _GLIBCXX14_CONSTEXPR
size_t
531 _M_do_find_first(
size_t __not_found)
const _GLIBCXX_NOEXCEPT
534 return __builtin_ctzl(_M_w);
540 _GLIBCXX14_CONSTEXPR
size_t
541 _M_do_find_next(
size_t __prev,
size_t __not_found)
const
545 if (__prev >= ((
size_t) _GLIBCXX_BITSET_BITS_PER_WORD))
548 _WordT __x = _M_w >> __prev;
550 return __builtin_ctzl(__x) + __prev;
562 struct _Base_bitset<0>
564 typedef unsigned long _WordT;
566 _GLIBCXX_CONSTEXPR _Base_bitset() _GLIBCXX_NOEXCEPT
569#if __cplusplus >= 201103L
570 constexpr _Base_bitset(
unsigned long long)
noexcept
572 _Base_bitset(
unsigned long)
576 static _GLIBCXX_CONSTEXPR
size_t
577 _S_whichword(
size_t __pos) _GLIBCXX_NOEXCEPT
578 {
return __pos / _GLIBCXX_BITSET_BITS_PER_WORD; }
580 static _GLIBCXX_CONSTEXPR
size_t
581 _S_whichbyte(
size_t __pos) _GLIBCXX_NOEXCEPT
582 {
return (__pos % _GLIBCXX_BITSET_BITS_PER_WORD) / __CHAR_BIT__; }
584 static _GLIBCXX_CONSTEXPR
size_t
585 _S_whichbit(
size_t __pos) _GLIBCXX_NOEXCEPT
586 {
return __pos % _GLIBCXX_BITSET_BITS_PER_WORD; }
588 static _GLIBCXX_CONSTEXPR _WordT
589 _S_maskbit(
size_t __pos) _GLIBCXX_NOEXCEPT
590 {
return (
static_cast<_WordT
>(1)) << _S_whichbit(__pos); }
598 __attribute__((__noreturn__))
600 _M_getword(
size_t) _GLIBCXX_NOEXCEPT
601 { __throw_out_of_range(__N(
"_Base_bitset::_M_getword")); }
603 _GLIBCXX_CONSTEXPR _WordT
604 _M_getword(
size_t)
const _GLIBCXX_NOEXCEPT
607 _GLIBCXX_CONSTEXPR _WordT
608 _M_hiword()
const _GLIBCXX_NOEXCEPT
611 _GLIBCXX14_CONSTEXPR
void
612 _M_do_and(
const _Base_bitset<0>&) _GLIBCXX_NOEXCEPT
615 _GLIBCXX14_CONSTEXPR
void
616 _M_do_or(
const _Base_bitset<0>&) _GLIBCXX_NOEXCEPT
619 _GLIBCXX14_CONSTEXPR
void
620 _M_do_xor(
const _Base_bitset<0>&) _GLIBCXX_NOEXCEPT
623 _GLIBCXX14_CONSTEXPR
void
624 _M_do_left_shift(
size_t) _GLIBCXX_NOEXCEPT
627 _GLIBCXX14_CONSTEXPR
void
628 _M_do_right_shift(
size_t) _GLIBCXX_NOEXCEPT
631 _GLIBCXX14_CONSTEXPR
void
632 _M_do_flip() _GLIBCXX_NOEXCEPT
635 _GLIBCXX14_CONSTEXPR
void
636 _M_do_set() _GLIBCXX_NOEXCEPT
639 _GLIBCXX14_CONSTEXPR
void
640 _M_do_reset() _GLIBCXX_NOEXCEPT
646 _GLIBCXX_CONSTEXPR
bool
647 _M_is_equal(
const _Base_bitset<0>&)
const _GLIBCXX_NOEXCEPT
651 _GLIBCXX_CONSTEXPR
bool
652 _M_are_all()
const _GLIBCXX_NOEXCEPT
655 _GLIBCXX_CONSTEXPR
bool
656 _M_is_any()
const _GLIBCXX_NOEXCEPT
659 _GLIBCXX_CONSTEXPR
size_t
660 _M_do_count()
const _GLIBCXX_NOEXCEPT
663 _GLIBCXX_CONSTEXPR
unsigned long
664 _M_do_to_ulong()
const _GLIBCXX_NOEXCEPT
667#if __cplusplus >= 201103L
668 constexpr unsigned long long
669 _M_do_to_ullong()
const noexcept
675 _GLIBCXX_CONSTEXPR
size_t
676 _M_do_find_first(
size_t)
const _GLIBCXX_NOEXCEPT
679 _GLIBCXX_CONSTEXPR
size_t
680 _M_do_find_next(
size_t,
size_t)
const _GLIBCXX_NOEXCEPT
686 template<
size_t _Extrabits>
689 typedef unsigned long _WordT;
691 static _GLIBCXX14_CONSTEXPR
void
692 _S_do_sanitize(_WordT& __val) _GLIBCXX_NOEXCEPT
693 { __val &= ~((~static_cast<_WordT>(0)) << _Extrabits); }
699 typedef unsigned long _WordT;
701 static _GLIBCXX14_CONSTEXPR
void
702 _S_do_sanitize(_WordT) _GLIBCXX_NOEXCEPT { }
705#if __cplusplus >= 201103L
706 template<
size_t _Nb,
bool = (_Nb < _GLIBCXX_BITSET_BITS_PER_ULL)>
709 static constexpr
unsigned long long
710 _S_do_sanitize_val(
unsigned long long __val)
715 struct _Sanitize_val<_Nb, true>
717 static constexpr unsigned long long
718 _S_do_sanitize_val(
unsigned long long __val)
719 {
return __val & ~((~static_cast<unsigned long long>(0)) << _Nb); }
724#ifdef __cpp_lib_bitset
725 template<
typename _CharT>
726 using __string = std::basic_string_view<_CharT>;
728 template<
typename _CharT>
729 using __string = std::basic_string<_CharT>;
731 template<
typename _CharT>
739 static _GLIBCXX14_CONSTEXPR
size_t
740 length(
const _CharT* __s)
noexcept
748 static constexpr bool
749 eq(_CharT __l, _CharT __r)
noexcept
750 {
return __l == __r; }
822 :
private _Base_bitset<_GLIBCXX_BITSET_WORDS(_Nb)>
825 typedef _Base_bitset<_GLIBCXX_BITSET_WORDS(_Nb)> _Base;
826 typedef unsigned long _WordT;
829 _GLIBCXX23_CONSTEXPR
void
830 _M_check_initial_position(
831 const _Str& __s,
typename _Str::size_type __position)
const
833 if (__position > __s.size())
834 __throw_out_of_range_fmt(
835 __N(
"bitset::bitset:"
836 " __position (which is %zu) > __s.size() (which is %zu)"),
837 size_t(__position),
size_t(__s.size()));
841 void _M_check(
size_t __position,
const char *__s)
const
843 if (__position >= _Nb)
844 __throw_out_of_range_fmt(
845 __N(
"%s: __position (which is %zu) >= _Nb (which is %zu)"),
846 __s,
size_t(__position),
size_t(_Nb));
851 _M_do_sanitize() _GLIBCXX_NOEXCEPT
853 typedef _Sanitize<_Nb % _GLIBCXX_BITSET_BITS_PER_WORD> __sanitize_type;
854 __sanitize_type::_S_do_sanitize(this->_M_hiword());
857#if __cplusplus >= 201103L
882 reference(bitset& __b,
size_t __pos) _GLIBCXX_NOEXCEPT
884 _M_wp = &__b._M_getword(__pos);
885 _M_bpos = _Base::_S_whichbit(__pos);
889#if __cplusplus >= 201103L
890 reference(
const reference&) =
default;
893#if __cplusplus > 202002L && __cpp_constexpr_dynamic_alloc
896 ~reference() _GLIBCXX_NOEXCEPT
902 operator=(
bool __x) _GLIBCXX_NOEXCEPT
905 *_M_wp |= _Base::_S_maskbit(_M_bpos);
907 *_M_wp &= ~_Base::_S_maskbit(_M_bpos);
914 operator=(
const reference& __j) _GLIBCXX_NOEXCEPT
916 if ((*(__j._M_wp) & _Base::_S_maskbit(__j._M_bpos)))
917 *_M_wp |= _Base::_S_maskbit(_M_bpos);
919 *_M_wp &= ~_Base::_S_maskbit(_M_bpos);
926 operator~()
const _GLIBCXX_NOEXCEPT
927 {
return (*(_M_wp) & _Base::_S_maskbit(_M_bpos)) == 0; }
931 operator bool()
const _GLIBCXX_NOEXCEPT
932 {
return (*(_M_wp) & _Base::_S_maskbit(_M_bpos)) != 0; }
937 flip() _GLIBCXX_NOEXCEPT
939 *_M_wp ^= _Base::_S_maskbit(_M_bpos);
947 _GLIBCXX_CONSTEXPR
bitset() _GLIBCXX_NOEXCEPT
951#if __cplusplus >= 201103L
952 constexpr bitset(
unsigned long long __val) noexcept
953 : _Base(_Sanitize_val<_Nb>::_S_do_sanitize_val(__val)) { }
955 bitset(
unsigned long __val)
957 { _M_do_sanitize(); }
970 template<
class _CharT,
class _Traits,
class _Alloc>
974 size_t __position = 0)
977 _M_check_initial_position(__s, __position);
978 _M_copy_from_string(__s, __position,
980 _CharT(
'0'), _CharT(
'1'));
992 template<
class _CharT,
class _Traits,
class _Alloc>
995 size_t __position,
size_t __n)
998 _M_check_initial_position(__s, __position);
999 _M_copy_from_string(__s, __position, __n, _CharT(
'0'), _CharT(
'1'));
1004 template<
class _CharT,
class _Traits,
class _Alloc>
1005 _GLIBCXX23_CONSTEXPR
1007 size_t __position,
size_t __n,
1008 _CharT __zero, _CharT __one = _CharT(
'1'))
1011 _M_check_initial_position(__s, __position);
1012 _M_copy_from_string(__s, __position, __n, __zero, __one);
1016#ifdef __cpp_lib_bitset
1028 template<
class _CharT,
class _Traits>
1030 bitset(basic_string_view<_CharT, _Traits> __s,
1031 basic_string_view<_CharT, _Traits>::size_type __position = 0,
1032 basic_string_view<_CharT, _Traits>::size_type __n =
1033 basic_string_view<_CharT, _Traits>::npos,
1034 _CharT __zero = _CharT(
'0'), _CharT __one = _CharT(
'1'))
1037 _M_check_initial_position(__s, __position);
1038 _M_copy_from_ptr<_CharT, _Traits>(
1039 __s.data(), __s.size(), __position, __n, __zero, __one);
1043#if __cplusplus >= 201103L
1055 template<
typename _CharT,
1056 typename = _Require<is_trivially_copyable<_CharT>,
1059 __not_<is_array<_CharT>>>>
1060 [[__gnu__::__nonnull__]]
1061 _GLIBCXX23_CONSTEXPR
1064 typename __bitset::__string<_CharT>::size_type __n
1066 _CharT __zero = _CharT(
'0'), _CharT __one = _CharT(
'1'))
1070 __throw_logic_error(__N(
"bitset::bitset(const _CharT*, ...)"));
1071 using _Traits =
typename __bitset::__string<_CharT>::traits_type;
1074 __n = _Traits::length(__str);
1075 _M_copy_from_ptr<_CharT, _Traits>(__str, __n, 0, __n, __zero, __one);
1087 _GLIBCXX23_CONSTEXPR
1091 this->_M_do_and(__rhs);
1095 _GLIBCXX23_CONSTEXPR
1099 this->_M_do_or(__rhs);
1103 _GLIBCXX23_CONSTEXPR
1107 this->_M_do_xor(__rhs);
1119 _GLIBCXX23_CONSTEXPR
1123 if (__builtin_expect(__position < _Nb, 1))
1125 this->_M_do_left_shift(__position);
1126 this->_M_do_sanitize();
1129 this->_M_do_reset();
1133 _GLIBCXX23_CONSTEXPR
1137 if (__builtin_expect(__position < _Nb, 1))
1138 this->_M_do_right_shift(__position);
1140 this->_M_do_reset();
1151 _GLIBCXX23_CONSTEXPR
1155 this->_M_getword(__pos) |= _Base::_S_maskbit(__pos);
1159 _GLIBCXX23_CONSTEXPR
1164 this->_M_getword(__pos) |= _Base::_S_maskbit(__pos);
1166 this->_M_getword(__pos) &= ~_Base::_S_maskbit(__pos);
1170 _GLIBCXX23_CONSTEXPR
1174 this->_M_getword(__pos) &= ~_Base::_S_maskbit(__pos);
1178 _GLIBCXX23_CONSTEXPR
1182 this->_M_getword(__pos) ^= _Base::_S_maskbit(__pos);
1186 _GLIBCXX_CONSTEXPR
bool
1188 {
return ((this->_M_getword(__pos) & _Base::_S_maskbit(__pos))
1189 !=
static_cast<_WordT
>(0)); }
1196 _GLIBCXX23_CONSTEXPR
1201 this->_M_do_sanitize();
1211 _GLIBCXX23_CONSTEXPR
1213 set(
size_t __position,
bool __val =
true)
1215 this->_M_check(__position, __N(
"bitset::set"));
1222 _GLIBCXX23_CONSTEXPR
1226 this->_M_do_reset();
1237 _GLIBCXX23_CONSTEXPR
1241 this->_M_check(__position, __N(
"bitset::reset"));
1248 _GLIBCXX23_CONSTEXPR
1253 this->_M_do_sanitize();
1262 _GLIBCXX23_CONSTEXPR
1266 this->_M_check(__position, __N(
"bitset::flip"));
1271 _GLIBCXX23_CONSTEXPR
1291 _GLIBCXX23_CONSTEXPR
1295 __glibcxx_assert(__position < _Nb);
1299 _GLIBCXX_CONSTEXPR
bool
1302#if __cplusplus != 201103L
1303 __glibcxx_assert(__position < _Nb);
1305#elif defined(_GLIBCXX_ASSERTIONS)
1308 : (__builtin_trap(),
false);
1321 _GLIBCXX23_CONSTEXPR
1324 {
return this->_M_do_to_ulong(); }
1326#if __cplusplus >= 201103L
1327 _GLIBCXX23_CONSTEXPR
1330 {
return this->_M_do_to_ullong(); }
1342 template<
class _CharT,
class _Traits,
class _Alloc>
1343 _GLIBCXX23_CONSTEXPR
1348 _M_copy_to_string(__result, _CharT(
'0'), _CharT(
'1'));
1354 template<
class _CharT,
class _Traits,
class _Alloc>
1355 _GLIBCXX23_CONSTEXPR
1357 to_string(_CharT __zero, _CharT __one = _CharT(
'1'))
const
1360 _M_copy_to_string(__result, __zero, __one);
1366 template<
class _CharT,
class _Traits>
1367 _GLIBCXX23_CONSTEXPR
1370 {
return to_string<_CharT, _Traits, std::allocator<_CharT> >(); }
1374 template<
class _CharT,
class _Traits>
1375 _GLIBCXX23_CONSTEXPR
1376 std::basic_string<_CharT, _Traits, std::allocator<_CharT> >
1377 to_string(_CharT __zero, _CharT __one = _CharT(
'1'))
const
1378 {
return to_string<_CharT, _Traits,
1379 std::allocator<_CharT> >(__zero, __one); }
1381 template<
class _CharT>
1382 _GLIBCXX23_CONSTEXPR
1383 std::basic_string<_CharT, std::char_traits<_CharT>,
1384 std::allocator<_CharT> >
1387 return to_string<_CharT, std::char_traits<_CharT>,
1388 std::allocator<_CharT> >();
1391 template<
class _CharT>
1392 _GLIBCXX23_CONSTEXPR
1393 std::basic_string<_CharT, std::char_traits<_CharT>,
1394 std::allocator<_CharT> >
1395 to_string(_CharT __zero, _CharT __one = _CharT(
'1'))
const
1397 return to_string<_CharT, std::char_traits<_CharT>,
1398 std::allocator<_CharT> >(__zero, __one);
1401 _GLIBCXX23_CONSTEXPR
1402 std::basic_string<char, std::char_traits<char>, std::allocator<char> >
1405 return to_string<char, std::char_traits<char>,
1406 std::allocator<char> >();
1409 _GLIBCXX23_CONSTEXPR
1410 std::basic_string<char, std::char_traits<char>, std::allocator<char> >
1411 to_string(
char __zero,
char __one =
'1')
const
1413 return to_string<char, std::char_traits<char>,
1414 std::allocator<char> >(__zero, __one);
1419 _GLIBCXX23_CONSTEXPR
1422 {
return this->_M_do_count(); }
1425 _GLIBCXX_CONSTEXPR
size_t
1431 _GLIBCXX23_CONSTEXPR
1434 {
return this->_M_is_equal(__rhs); }
1436#if __cpp_impl_three_way_comparison < 201907L
1437 _GLIBCXX23_CONSTEXPR
1439 operator!=(
const bitset<_Nb>& __rhs)
const _GLIBCXX_NOEXCEPT
1440 {
return !this->_M_is_equal(__rhs); }
1450 _GLIBCXX23_CONSTEXPR
1454 this->_M_check(__position, __N(
"bitset::test"));
1464 _GLIBCXX23_CONSTEXPR
1467 {
return this->
template _M_are_all<_Nb>(); }
1473 _GLIBCXX23_CONSTEXPR
1476 {
return this->_M_is_any(); }
1482 _GLIBCXX23_CONSTEXPR
1485 {
return !this->_M_is_any(); }
1489 _GLIBCXX23_CONSTEXPR
1491 operator<<(
size_t __position)
const _GLIBCXX_NOEXCEPT
1494 _GLIBCXX23_CONSTEXPR
1506 _GLIBCXX23_CONSTEXPR
1509 {
return this->_M_do_find_first(_Nb); }
1518 _GLIBCXX23_CONSTEXPR
1521 {
return this->_M_do_find_next(__prev, _Nb); }
1525 template<
class _CharT,
class _Traits>
1526 _GLIBCXX23_CONSTEXPR
1528 _M_copy_from_ptr(
const _CharT*,
size_t,
size_t,
size_t,
1532 template<
class _CharT,
class _Traits,
class _Alloc>
1533 _GLIBCXX23_CONSTEXPR
1536 _Traits, _Alloc>& __s,
size_t __pos,
size_t __n,
1537 _CharT __zero, _CharT __one)
1538 { _M_copy_from_ptr<_CharT, _Traits>(__s.data(), __s.size(), __pos, __n,
1541 template<
class _CharT,
class _Traits,
class _Alloc>
1542 _GLIBCXX23_CONSTEXPR
1545 _CharT, _CharT)
const;
1547 template<
class _CharT,
class _Traits,
size_t _Nb2>
1551 template <
class _CharT,
class _Traits,
size_t _Nb2>
1558 template<
size_t _Nb>
1559 template<
class _CharT,
class _Traits>
1560 _GLIBCXX23_CONSTEXPR
1564 size_t __pos,
size_t __n, _CharT __zero, _CharT __one)
1567 const size_t __rlen =
std::min(__n,
size_t(__len - __pos));
1568 const size_t __nbits =
std::min(_Nb, __rlen);
1569 for (
size_t __i = __rlen - __nbits; __i > 0; --__i)
1571 const _CharT __c = __s[__pos + __rlen - __i];
1572 if (!_Traits::eq(__c, __zero) && !_Traits::eq(__c, __one))
1573 __throw_invalid_argument(__N(
"bitset::_M_copy_from_ptr"));
1575 for (
size_t __i = __nbits; __i > 0; --__i)
1577 const _CharT __c = __s[__pos + __nbits - __i];
1578 if (_Traits::eq(__c, __zero))
1580 else if (_Traits::eq(__c, __one))
1581 _Unchecked_set(__i - 1);
1583 __throw_invalid_argument(__N(
"bitset::_M_copy_from_ptr"));
1588 template<
size_t _Nb>
1589 template<
class _CharT,
class _Traits,
class _Alloc>
1590 _GLIBCXX23_CONSTEXPR
1594 _CharT __zero, _CharT __one)
const
1597 size_t __n = this->_Find_first();
1600 __s[_Nb - __n - 1] = __one;
1601 __n = _Find_next(__n);
1616 template<
size_t _Nb>
1617 _GLIBCXX23_CONSTEXPR
1626 template<
size_t _Nb>
1627 _GLIBCXX23_CONSTEXPR
1636 template <
size_t _Nb>
1637 _GLIBCXX23_CONSTEXPR
1657 template<
class _CharT,
class _Traits,
size_t _Nb>
1661 typedef typename _Traits::char_type char_type;
1663 typedef typename __istream_type::ios_base __ios_base;
1665#pragma GCC diagnostic push
1666#pragma GCC diagnostic ignored "-Wc++17-extensions"
1669 static _GLIBCXX_CONSTEXPR
bool _S_use_alloca() {
return _Nb <= 256; }
1671 explicit _Buffer(_CharT* __p) : _M_ptr(__p) { }
1675 if _GLIBCXX_CONSTEXPR (!_S_use_alloca())
1679 _CharT*
const _M_ptr;
1682 if _GLIBCXX_CONSTEXPR (_Buffer::_S_use_alloca())
1683 __ptr = (_CharT*)__builtin_alloca(_Nb);
1685 __ptr =
new _CharT[_Nb];
1686 const _Buffer __buf(__ptr);
1687#pragma GCC diagnostic pop
1691 const char_type __zero = __is.
widen(
'0');
1692 const char_type __one = __is.
widen(
'1');
1694 typename __ios_base::iostate __state = __ios_base::goodbit;
1695 typename __istream_type::sentry __sentry(__is);
1700 for (
size_t __i = _Nb; __i > 0; --__i)
1702 static typename _Traits::int_type __eof = _Traits::eof();
1704 typename _Traits::int_type __c1 = __is.
rdbuf()->sbumpc();
1705 if (_Traits::eq_int_type(__c1, __eof))
1707 __state |= __ios_base::eofbit;
1712 const char_type __c2 = _Traits::to_char_type(__c1);
1713 if (_Traits::eq(__c2, __zero))
1715 else if (_Traits::eq(__c2, __one))
1718 eq_int_type(__is.
rdbuf()->sputbackc(__c2),
1721 __state |= __ios_base::failbit;
1729 __is._M_setstate(__ios_base::badbit);
1730 __throw_exception_again;
1733 { __is._M_setstate(__ios_base::badbit); }
1736#pragma GCC diagnostic push
1737#pragma GCC diagnostic ignored "-Wc++17-extensions"
1738 if _GLIBCXX_CONSTEXPR (_Nb)
1740 if (
size_t __len = __ptr - __buf._M_ptr)
1741 __x.template _M_copy_from_ptr<_CharT, _Traits>(__buf._M_ptr, __len,
1745 __state |= __ios_base::failbit;
1747#pragma GCC diagnostic pop
1753 template <
class _CharT,
class _Traits,
size_t _Nb>
1756 const bitset<_Nb>& __x)
1763 __x._M_copy_to_string(__tmp, __ct.widen(
'0'), __ct.widen(
'1'));
1764 return __os << __tmp;
1769_GLIBCXX_END_NAMESPACE_CONTAINER
1772#undef _GLIBCXX_BITSET_WORDS
1773#undef _GLIBCXX_BITSET_BITS_PER_WORD
1774#undef _GLIBCXX_BITSET_BITS_PER_ULL
1776#if __cplusplus >= 201103L
1778namespace std _GLIBCXX_VISIBILITY(default)
1780_GLIBCXX_BEGIN_NAMESPACE_VERSION
1784 template<
size_t _Nb>
1786 :
public __hash_base<size_t, _GLIBCXX_STD_C::bitset<_Nb>>
1789 operator()(
const _GLIBCXX_STD_C::bitset<_Nb>& __b)
const noexcept
1791 const size_t __clength = (_Nb + __CHAR_BIT__ - 1) / __CHAR_BIT__;
1792 return std::_Hash_impl::hash(__b._M_getdata(), __clength);
1798 :
public __hash_base<size_t, _GLIBCXX_STD_C::bitset<0>>
1801 operator()(
const _GLIBCXX_STD_C::bitset<0>&)
const noexcept
1805_GLIBCXX_END_NAMESPACE_VERSION
1810#if defined _GLIBCXX_DEBUG && _GLIBCXX_HOSTED
constexpr bitset< _Nb > & _Unchecked_reset(size_t __pos) noexcept
constexpr bitset< _Nb > & _Unchecked_flip(size_t __pos) noexcept
constexpr size_t _Find_first() const noexcept
Finds the index of the first "on" bit.
constexpr bool _Unchecked_test(size_t __pos) const noexcept
constexpr bitset< _Nb > & _Unchecked_set(size_t __pos) noexcept
constexpr bitset< _Nb > & _Unchecked_set(size_t __pos, int __val) noexcept
constexpr size_t _Find_next(size_t __prev) const noexcept
Finds the index of the next "on" bit after prev.
constexpr const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
const _Facet & use_facet(const locale &__loc)
Return a facet.
ISO C++ entities toplevel namespace is std.
constexpr bitset< _Nb > operator^(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, bitset< _Nb > &__x)
Global I/O operators for bitsets.
std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const bitset< _Nb > &__x)
Global I/O operators for bitsets.
constexpr bitset< _Nb > operator|(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
constexpr bitset< _Nb > operator&(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
The bitset class represents a fixed-size sequence of bits.
constexpr reference operator[](size_t __position)
Array-indexing support.
constexpr bitset< _Nb > & operator>>=(size_t __position) noexcept
constexpr bitset< _Nb > & flip() noexcept
Toggles every bit to its opposite value.
constexpr bitset< _Nb > & operator&=(const bitset< _Nb > &__rhs) noexcept
constexpr bitset(const _CharT *__str, typename __bitset::__string< _CharT >::size_type __n=__bitset::__string< _CharT >::npos, _CharT __zero=_CharT('0'), _CharT __one=_CharT('1'))
constexpr bitset< _Nb > operator>>(size_t __position) const noexcept
Self-explanatory.
constexpr unsigned long to_ulong() const
Returns a numerical interpretation of the bitset.
constexpr bool any() const noexcept
Tests whether any of the bits are on.
constexpr bitset() noexcept
All bits set to zero.
constexpr bitset< _Nb > & operator^=(const bitset< _Nb > &__rhs) noexcept
constexpr bool test(size_t __position) const
Tests the value of a bit.
constexpr bitset< _Nb > operator~() const noexcept
See the no-argument flip().
constexpr bitset< _Nb > & operator|=(const bitset< _Nb > &__rhs) noexcept
constexpr bitset< _Nb > & set(size_t __position, bool __val=true)
Sets a given bit to a particular value.
constexpr size_t count() const noexcept
Returns the number of bits which are set.
constexpr bitset< _Nb > & operator<<=(size_t __position) noexcept
constexpr std::basic_string< _CharT, _Traits, _Alloc > to_string() const
Returns a character interpretation of the bitset.
constexpr bitset< _Nb > & reset() noexcept
Sets every bit to false.
constexpr bitset< _Nb > & set() noexcept
Sets every bit to true.
constexpr bitset(const std::basic_string< _CharT, _Traits, _Alloc > &__s, size_t __position=0)
constexpr bitset(const std::basic_string< _CharT, _Traits, _Alloc > &__s, size_t __position, size_t __n)
constexpr bitset(unsigned long long __val) noexcept
Initial bits bitwise-copied from a single word (others set to zero).
constexpr size_t size() const noexcept
Returns the total number of bits.
constexpr bool all() const noexcept
Tests whether all the bits are on.
constexpr bitset< _Nb > & reset(size_t __position)
Sets a given bit to false.
constexpr bool none() const noexcept
Tests whether any of the bits are on.
constexpr bool operator==(const bitset< _Nb > &__rhs) const noexcept
These comparisons for equality/inequality are, well, bitwise.
constexpr bool operator[](size_t __position) const
Array-indexing support.
constexpr bitset< _Nb > & flip(size_t __position)
Toggles a given bit to its opposite value.
Template class basic_istream.
Primary class template hash.
is_trivially_default_constructible
void setstate(iostate __state)
Sets additional flags in the error state.
char_type widen(char __c) const
Widens characters.
basic_streambuf< _CharT, _Traits > * rdbuf() const
Accessing the underlying buffer.
Managing sequences of characters and character-like objects.
constexpr basic_string & assign(const basic_string &__str)
Set value to contents of another string.
static const size_type npos
Value returned by various member functions when they fail.
Thrown as part of forced unwinding.
locale getloc() const
Locale access.
Template class basic_ostream.