42#ifndef _GLIBCXX_BITSET
43#define _GLIBCXX_BITSET 1
45#pragma GCC system_header
57#if __cplusplus >= 201103L
61#define __glibcxx_want_constexpr_bitset
64#define _GLIBCXX_BITSET_BITS_PER_WORD (__CHAR_BIT__ * __SIZEOF_LONG__)
65#define _GLIBCXX_BITSET_WORDS(__n) \
66 ((__n) / _GLIBCXX_BITSET_BITS_PER_WORD + \
67 ((__n) % _GLIBCXX_BITSET_BITS_PER_WORD == 0 ? 0 : 1))
69#define _GLIBCXX_BITSET_BITS_PER_ULL (__CHAR_BIT__ * __SIZEOF_LONG_LONG__)
71namespace std _GLIBCXX_VISIBILITY(default)
73_GLIBCXX_BEGIN_NAMESPACE_CONTAINER
84 typedef unsigned long _WordT;
92#if __cplusplus >= 201103L
93 constexpr _Base_bitset(
unsigned long long __val) noexcept
95#if __SIZEOF_LONG_LONG__ > __SIZEOF_LONG__
96 , _WordT(__val >> _GLIBCXX_BITSET_BITS_PER_WORD)
100 _Base_bitset(
unsigned long __val)
105 static _GLIBCXX_CONSTEXPR
size_t
106 _S_whichword(
size_t __pos) _GLIBCXX_NOEXCEPT
107 {
return __pos / _GLIBCXX_BITSET_BITS_PER_WORD; }
109 static _GLIBCXX_CONSTEXPR
size_t
110 _S_whichbyte(
size_t __pos) _GLIBCXX_NOEXCEPT
111 {
return (__pos % _GLIBCXX_BITSET_BITS_PER_WORD) / __CHAR_BIT__; }
113 static _GLIBCXX_CONSTEXPR
size_t
114 _S_whichbit(
size_t __pos) _GLIBCXX_NOEXCEPT
115 {
return __pos % _GLIBCXX_BITSET_BITS_PER_WORD; }
117 static _GLIBCXX_CONSTEXPR _WordT
118 _S_maskbit(
size_t __pos) _GLIBCXX_NOEXCEPT
119 {
return (
static_cast<_WordT
>(1)) << _S_whichbit(__pos); }
121 _GLIBCXX14_CONSTEXPR _WordT&
122 _M_getword(
size_t __pos) _GLIBCXX_NOEXCEPT
123 {
return _M_w[_S_whichword(__pos)]; }
125 _GLIBCXX_CONSTEXPR _WordT
126 _M_getword(
size_t __pos)
const _GLIBCXX_NOEXCEPT
127 {
return _M_w[_S_whichword(__pos)]; }
129#if __cplusplus >= 201103L
130 constexpr const _WordT*
131 _M_getdata() const noexcept
135 _GLIBCXX23_CONSTEXPR _WordT&
136 _M_hiword() _GLIBCXX_NOEXCEPT
137 {
return _M_w[_Nw - 1]; }
139 _GLIBCXX_CONSTEXPR _WordT
140 _M_hiword() const _GLIBCXX_NOEXCEPT
141 {
return _M_w[_Nw - 1]; }
143 _GLIBCXX23_CONSTEXPR
void
144 _M_do_and(
const _Base_bitset<_Nw>& __x) _GLIBCXX_NOEXCEPT
146 for (
size_t __i = 0; __i < _Nw; __i++)
147 _M_w[__i] &= __x._M_w[__i];
150 _GLIBCXX14_CONSTEXPR
void
151 _M_do_or(
const _Base_bitset<_Nw>& __x) _GLIBCXX_NOEXCEPT
153 for (
size_t __i = 0; __i < _Nw; __i++)
154 _M_w[__i] |= __x._M_w[__i];
157 _GLIBCXX14_CONSTEXPR
void
158 _M_do_xor(
const _Base_bitset<_Nw>& __x) _GLIBCXX_NOEXCEPT
160 for (
size_t __i = 0; __i < _Nw; __i++)
161 _M_w[__i] ^= __x._M_w[__i];
164 _GLIBCXX14_CONSTEXPR
void
165 _M_do_left_shift(
size_t __shift) _GLIBCXX_NOEXCEPT;
167 _GLIBCXX14_CONSTEXPR
void
168 _M_do_right_shift(
size_t __shift) _GLIBCXX_NOEXCEPT;
170 _GLIBCXX14_CONSTEXPR
void
171 _M_do_flip() _GLIBCXX_NOEXCEPT
173 for (
size_t __i = 0; __i < _Nw; __i++)
177 _GLIBCXX14_CONSTEXPR
void
178 _M_do_set() _GLIBCXX_NOEXCEPT
180 for (
size_t __i = 0; __i < _Nw; __i++)
181 _M_w[__i] = ~
static_cast<_WordT
>(0);
184 _GLIBCXX14_CONSTEXPR
void
185 _M_do_reset() _GLIBCXX_NOEXCEPT
187#if __cplusplus >= 201402L
188 if (__builtin_is_constant_evaluated())
190 for (_WordT& __w :
_M_w)
195 __builtin_memset(
_M_w, 0, _Nw *
sizeof(_WordT));
198 _GLIBCXX14_CONSTEXPR
bool
199 _M_is_equal(
const _Base_bitset<_Nw>& __x)
const _GLIBCXX_NOEXCEPT
201 for (
size_t __i = 0; __i < _Nw; ++__i)
202 if (
_M_w[__i] != __x._M_w[__i])
208 _GLIBCXX14_CONSTEXPR
bool
209 _M_are_all() const _GLIBCXX_NOEXCEPT
211 for (
size_t __i = 0; __i < _Nw - 1; __i++)
212 if (
_M_w[__i] != ~
static_cast<_WordT
>(0))
214 return _M_hiword() == (~static_cast<_WordT>(0)
215 >> (_Nw * _GLIBCXX_BITSET_BITS_PER_WORD
219 _GLIBCXX14_CONSTEXPR
bool
220 _M_is_any() const _GLIBCXX_NOEXCEPT
222 for (
size_t __i = 0; __i < _Nw; __i++)
223 if (
_M_w[__i] !=
static_cast<_WordT
>(0))
228 _GLIBCXX14_CONSTEXPR
size_t
229 _M_do_count() const _GLIBCXX_NOEXCEPT
232 for (
size_t __i = 0; __i < _Nw; __i++)
233 __result += __builtin_popcountl(
_M_w[__i]);
237 _GLIBCXX14_CONSTEXPR
unsigned long
238 _M_do_to_ulong()
const;
240#if __cplusplus >= 201103L
241 _GLIBCXX14_CONSTEXPR
unsigned long long
242 _M_do_to_ullong()
const;
246 _GLIBCXX14_CONSTEXPR
size_t
247 _M_do_find_first(
size_t)
const _GLIBCXX_NOEXCEPT;
250 _GLIBCXX14_CONSTEXPR
size_t
251 _M_do_find_next(
size_t,
size_t)
const _GLIBCXX_NOEXCEPT;
256 _GLIBCXX14_CONSTEXPR
void
257 _Base_bitset<_Nw>::_M_do_left_shift(
size_t __shift) _GLIBCXX_NOEXCEPT
259 if (__builtin_expect(__shift != 0, 1))
261 const size_t __wshift = __shift / _GLIBCXX_BITSET_BITS_PER_WORD;
262 const size_t __offset = __shift % _GLIBCXX_BITSET_BITS_PER_WORD;
265 for (
size_t __n = _Nw - 1; __n >= __wshift; --__n)
266 _M_w[__n] = _M_w[__n - __wshift];
269 const size_t __sub_offset = (_GLIBCXX_BITSET_BITS_PER_WORD
271 for (
size_t __n = _Nw - 1; __n > __wshift; --__n)
272 _M_w[__n] = ((_M_w[__n - __wshift] << __offset)
273 | (_M_w[__n - __wshift - 1] >> __sub_offset));
274 _M_w[__wshift] = _M_w[0] << __offset;
277 std::fill(_M_w + 0, _M_w + __wshift,
static_cast<_WordT
>(0));
282 _GLIBCXX14_CONSTEXPR
void
283 _Base_bitset<_Nw>::_M_do_right_shift(
size_t __shift) _GLIBCXX_NOEXCEPT
285 if (__builtin_expect(__shift != 0, 1))
287 const size_t __wshift = __shift / _GLIBCXX_BITSET_BITS_PER_WORD;
288 const size_t __offset = __shift % _GLIBCXX_BITSET_BITS_PER_WORD;
289 const size_t __limit = _Nw - __wshift - 1;
292 for (
size_t __n = 0; __n <= __limit; ++__n)
293 _M_w[__n] = _M_w[__n + __wshift];
296 const size_t __sub_offset = (_GLIBCXX_BITSET_BITS_PER_WORD
298 for (
size_t __n = 0; __n < __limit; ++__n)
299 _M_w[__n] = ((_M_w[__n + __wshift] >> __offset)
300 | (_M_w[__n + __wshift + 1] << __sub_offset));
301 _M_w[__limit] = _M_w[_Nw-1] >> __offset;
304 std::fill(_M_w + __limit + 1, _M_w + _Nw,
static_cast<_WordT
>(0));
309 _GLIBCXX14_CONSTEXPR
unsigned long
310 _Base_bitset<_Nw>::_M_do_to_ulong()
const
312 for (
size_t __i = 1; __i < _Nw; ++__i)
314 __throw_overflow_error(__N(
"_Base_bitset::_M_do_to_ulong"));
318#if __cplusplus >= 201103L
320 _GLIBCXX14_CONSTEXPR
unsigned long long
321 _Base_bitset<_Nw>::_M_do_to_ullong()
const
323 const bool __dw =
sizeof(
unsigned long long) >
sizeof(
unsigned long);
324 for (
size_t __i = 1 + __dw; __i < _Nw; ++__i)
326 __throw_overflow_error(__N(
"_Base_bitset::_M_do_to_ullong"));
329 return _M_w[0] + (
static_cast<unsigned long long>(_M_w[1])
330 << _GLIBCXX_BITSET_BITS_PER_WORD);
336 _GLIBCXX14_CONSTEXPR
size_t
338 _M_do_find_first(
size_t __not_found)
const _GLIBCXX_NOEXCEPT
340 for (
size_t __i = 0; __i < _Nw; __i++)
342 _WordT __thisword = _M_w[__i];
343 if (__thisword !=
static_cast<_WordT
>(0))
344 return (__i * _GLIBCXX_BITSET_BITS_PER_WORD
345 + __builtin_ctzl(__thisword));
352 _GLIBCXX14_CONSTEXPR
size_t
354 _M_do_find_next(
size_t __prev,
size_t __not_found)
const _GLIBCXX_NOEXCEPT
360 if (__prev >= _Nw * _GLIBCXX_BITSET_BITS_PER_WORD)
364 size_t __i = _S_whichword(__prev);
365 _WordT __thisword = _M_w[__i];
368 __thisword &= (~static_cast<_WordT>(0)) << _S_whichbit(__prev);
370 if (__thisword !=
static_cast<_WordT
>(0))
371 return (__i * _GLIBCXX_BITSET_BITS_PER_WORD
372 + __builtin_ctzl(__thisword));
376 for (; __i < _Nw; __i++)
378 __thisword = _M_w[__i];
379 if (__thisword !=
static_cast<_WordT
>(0))
380 return (__i * _GLIBCXX_BITSET_BITS_PER_WORD
381 + __builtin_ctzl(__thisword));
395 typedef unsigned long _WordT;
402#if __cplusplus >= 201103L
403 constexpr _Base_bitset(
unsigned long long __val)
noexcept
410 static _GLIBCXX_CONSTEXPR
size_t
411 _S_whichword(
size_t __pos) _GLIBCXX_NOEXCEPT
412 {
return __pos / _GLIBCXX_BITSET_BITS_PER_WORD; }
414 static _GLIBCXX_CONSTEXPR
size_t
415 _S_whichbyte(
size_t __pos) _GLIBCXX_NOEXCEPT
416 {
return (__pos % _GLIBCXX_BITSET_BITS_PER_WORD) / __CHAR_BIT__; }
418 static _GLIBCXX_CONSTEXPR
size_t
419 _S_whichbit(
size_t __pos) _GLIBCXX_NOEXCEPT
420 {
return __pos % _GLIBCXX_BITSET_BITS_PER_WORD; }
422 static _GLIBCXX_CONSTEXPR _WordT
423 _S_maskbit(
size_t __pos) _GLIBCXX_NOEXCEPT
424 {
return (
static_cast<_WordT
>(1)) << _S_whichbit(__pos); }
426 _GLIBCXX14_CONSTEXPR _WordT&
427 _M_getword(
size_t) _GLIBCXX_NOEXCEPT
430 _GLIBCXX_CONSTEXPR _WordT
431 _M_getword(
size_t)
const _GLIBCXX_NOEXCEPT
434#if __cplusplus >= 201103L
435 constexpr const _WordT*
436 _M_getdata()
const noexcept
440 _GLIBCXX14_CONSTEXPR _WordT&
441 _M_hiword() _GLIBCXX_NOEXCEPT
444 _GLIBCXX_CONSTEXPR _WordT
445 _M_hiword()
const _GLIBCXX_NOEXCEPT
448 _GLIBCXX14_CONSTEXPR
void
452 _GLIBCXX14_CONSTEXPR
void
456 _GLIBCXX14_CONSTEXPR
void
460 _GLIBCXX14_CONSTEXPR
void
461 _M_do_left_shift(
size_t __shift) _GLIBCXX_NOEXCEPT
462 {
_M_w <<= __shift; }
464 _GLIBCXX14_CONSTEXPR
void
465 _M_do_right_shift(
size_t __shift) _GLIBCXX_NOEXCEPT
466 {
_M_w >>= __shift; }
468 _GLIBCXX14_CONSTEXPR
void
469 _M_do_flip() _GLIBCXX_NOEXCEPT
472 _GLIBCXX14_CONSTEXPR
void
473 _M_do_set() _GLIBCXX_NOEXCEPT
474 {
_M_w = ~static_cast<_WordT>(0); }
476 _GLIBCXX14_CONSTEXPR
void
477 _M_do_reset() _GLIBCXX_NOEXCEPT
480 _GLIBCXX14_CONSTEXPR
bool
485 _GLIBCXX14_CONSTEXPR
bool
486 _M_are_all()
const _GLIBCXX_NOEXCEPT
487 {
return _M_w == (~static_cast<_WordT>(0)
488 >> (_GLIBCXX_BITSET_BITS_PER_WORD - _Nb)); }
490 _GLIBCXX14_CONSTEXPR
bool
491 _M_is_any()
const _GLIBCXX_NOEXCEPT
492 {
return _M_w != 0; }
494 _GLIBCXX14_CONSTEXPR
size_t
495 _M_do_count()
const _GLIBCXX_NOEXCEPT
496 {
return __builtin_popcountl(
_M_w); }
498 _GLIBCXX14_CONSTEXPR
unsigned long
499 _M_do_to_ulong()
const _GLIBCXX_NOEXCEPT
502#if __cplusplus >= 201103L
503 constexpr unsigned long long
504 _M_do_to_ullong()
const noexcept
508 _GLIBCXX14_CONSTEXPR
size_t
509 _M_do_find_first(
size_t __not_found)
const _GLIBCXX_NOEXCEPT
512 return __builtin_ctzl(
_M_w);
518 _GLIBCXX14_CONSTEXPR
size_t
519 _M_do_find_next(
size_t __prev,
size_t __not_found)
const
523 if (__prev >= ((
size_t) _GLIBCXX_BITSET_BITS_PER_WORD))
526 _WordT __x =
_M_w >> __prev;
528 return __builtin_ctzl(__x) + __prev;
542 typedef unsigned long _WordT;
547#if __cplusplus >= 201103L
554 static _GLIBCXX_CONSTEXPR
size_t
555 _S_whichword(
size_t __pos) _GLIBCXX_NOEXCEPT
556 {
return __pos / _GLIBCXX_BITSET_BITS_PER_WORD; }
558 static _GLIBCXX_CONSTEXPR
size_t
559 _S_whichbyte(
size_t __pos) _GLIBCXX_NOEXCEPT
560 {
return (__pos % _GLIBCXX_BITSET_BITS_PER_WORD) / __CHAR_BIT__; }
562 static _GLIBCXX_CONSTEXPR
size_t
563 _S_whichbit(
size_t __pos) _GLIBCXX_NOEXCEPT
564 {
return __pos % _GLIBCXX_BITSET_BITS_PER_WORD; }
566 static _GLIBCXX_CONSTEXPR _WordT
567 _S_maskbit(
size_t __pos) _GLIBCXX_NOEXCEPT
568 {
return (
static_cast<_WordT
>(1)) << _S_whichbit(__pos); }
576 __attribute__((__noreturn__))
578 _M_getword(
size_t) _GLIBCXX_NOEXCEPT
579 { __throw_out_of_range(__N(
"_Base_bitset::_M_getword")); }
581 _GLIBCXX_CONSTEXPR _WordT
582 _M_getword(
size_t)
const _GLIBCXX_NOEXCEPT
585 _GLIBCXX_CONSTEXPR _WordT
586 _M_hiword()
const _GLIBCXX_NOEXCEPT
589 _GLIBCXX14_CONSTEXPR
void
593 _GLIBCXX14_CONSTEXPR
void
597 _GLIBCXX14_CONSTEXPR
void
601 _GLIBCXX14_CONSTEXPR
void
602 _M_do_left_shift(
size_t) _GLIBCXX_NOEXCEPT
605 _GLIBCXX14_CONSTEXPR
void
606 _M_do_right_shift(
size_t) _GLIBCXX_NOEXCEPT
609 _GLIBCXX14_CONSTEXPR
void
610 _M_do_flip() _GLIBCXX_NOEXCEPT
613 _GLIBCXX14_CONSTEXPR
void
614 _M_do_set() _GLIBCXX_NOEXCEPT
617 _GLIBCXX14_CONSTEXPR
void
618 _M_do_reset() _GLIBCXX_NOEXCEPT
624 _GLIBCXX_CONSTEXPR
bool
629 _GLIBCXX_CONSTEXPR
bool
630 _M_are_all()
const _GLIBCXX_NOEXCEPT
633 _GLIBCXX_CONSTEXPR
bool
634 _M_is_any()
const _GLIBCXX_NOEXCEPT
637 _GLIBCXX_CONSTEXPR
size_t
638 _M_do_count()
const _GLIBCXX_NOEXCEPT
641 _GLIBCXX_CONSTEXPR
unsigned long
642 _M_do_to_ulong()
const _GLIBCXX_NOEXCEPT
645#if __cplusplus >= 201103L
646 constexpr unsigned long long
647 _M_do_to_ullong()
const noexcept
653 _GLIBCXX_CONSTEXPR
size_t
654 _M_do_find_first(
size_t)
const _GLIBCXX_NOEXCEPT
657 _GLIBCXX_CONSTEXPR
size_t
658 _M_do_find_next(
size_t,
size_t)
const _GLIBCXX_NOEXCEPT
664 template<
size_t _Extrabits>
667 typedef unsigned long _WordT;
669 static _GLIBCXX14_CONSTEXPR
void
670 _S_do_sanitize(_WordT& __val) _GLIBCXX_NOEXCEPT
671 { __val &= ~((~static_cast<_WordT>(0)) << _Extrabits); }
677 typedef unsigned long _WordT;
679 static _GLIBCXX14_CONSTEXPR
void
680 _S_do_sanitize(_WordT) _GLIBCXX_NOEXCEPT { }
683#if __cplusplus >= 201103L
684 template<
size_t _Nb,
bool = (_Nb < _GLIBCXX_BITSET_BITS_PER_ULL)>
687 static constexpr
unsigned long long
688 _S_do_sanitize_val(
unsigned long long __val)
693 struct _Sanitize_val<_Nb, true>
695 static constexpr unsigned long long
696 _S_do_sanitize_val(
unsigned long long __val)
697 {
return __val & ~((~static_cast<unsigned long long>(0)) << _Nb); }
703 template<
typename _CharT>
706 template<
typename _CharT>
709 using size_type = size_t;
710 static constexpr size_type npos = size_type(-1);
714 static _GLIBCXX14_CONSTEXPR
size_t
715 length(
const _CharT* __s)
noexcept
723 static constexpr bool
724 eq(_CharT __l, _CharT __r)
noexcept
725 {
return __l == __r; }
801 typedef unsigned long _WordT;
804 template<
class _CharT,
class _Traits,
class _Alloc>
808 size_t __position)
const
810 if (__position > __s.
size())
811 __throw_out_of_range_fmt(__N(
"bitset::bitset: __position "
812 "(which is %zu) > __s.size() "
814 __position, __s.
size());
819 void _M_check(
size_t __position,
const char *__s)
const
821 if (__position >= _Nb)
822 __throw_out_of_range_fmt(__N(
"%s: __position (which is %zu) "
823 ">= _Nb (which is %zu)"),
824 __s, __position, _Nb);
829 _M_do_sanitize() _GLIBCXX_NOEXCEPT
831 typedef _Sanitize<_Nb % _GLIBCXX_BITSET_BITS_PER_WORD> __sanitize_type;
832 __sanitize_type::_S_do_sanitize(this->_M_hiword());
835#if __cplusplus >= 201103L
866 _M_wp = &__b._M_getword(__pos);
867 _M_bpos = _Base::_S_whichbit(__pos);
870#if __cplusplus >= 201103L
874#if __cplusplus > 202002L && __cpp_constexpr_dynamic_alloc
883 operator=(
bool __x) _GLIBCXX_NOEXCEPT
886 *_M_wp |= _Base::_S_maskbit(_M_bpos);
888 *_M_wp &=
~_Base::_S_maskbit(_M_bpos);
895 operator=(
const reference& __j) _GLIBCXX_NOEXCEPT
897 if ((*(__j._M_wp) & _Base::_S_maskbit(__j._M_bpos)))
898 *_M_wp |= _Base::_S_maskbit(_M_bpos);
900 *_M_wp &=
~_Base::_S_maskbit(_M_bpos);
907 operator~()
const _GLIBCXX_NOEXCEPT
908 {
return (*(_M_wp) & _Base::_S_maskbit(_M_bpos)) == 0; }
912 operator bool()
const _GLIBCXX_NOEXCEPT
913 {
return (*(_M_wp) & _Base::_S_maskbit(_M_bpos)) != 0; }
918 flip() _GLIBCXX_NOEXCEPT
920 *_M_wp ^= _Base::_S_maskbit(_M_bpos);
928 _GLIBCXX_CONSTEXPR
bitset() _GLIBCXX_NOEXCEPT
932#if __cplusplus >= 201103L
933 constexpr bitset(
unsigned long long __val) noexcept
934 :
_Base(_Sanitize_val<_Nb>::_S_do_sanitize_val(__val)) { }
936 bitset(
unsigned long __val)
938 { _M_do_sanitize(); }
951 template<
class _CharT,
class _Traits,
class _Alloc>
955 size_t __position = 0)
958 _M_check_initial_position(__s, __position);
959 _M_copy_from_string(__s, __position,
961 _CharT(
'0'), _CharT(
'1'));
974 template<
class _CharT,
class _Traits,
class _Alloc>
977 size_t __position,
size_t __n)
980 _M_check_initial_position(__s, __position);
981 _M_copy_from_string(__s, __position, __n, _CharT(
'0'), _CharT(
'1'));
986 template<
class _CharT,
class _Traits,
class _Alloc>
989 size_t __position,
size_t __n,
990 _CharT __zero, _CharT __one = _CharT(
'1'))
993 _M_check_initial_position(__s, __position);
994 _M_copy_from_string(__s, __position, __n, __zero, __one);
998#if __cplusplus >= 201103L
1008 template<
typename _CharT>
1009 [[__gnu__::__nonnull__]]
1010 _GLIBCXX23_CONSTEXPR
1013 typename __bitset::__string<_CharT>::size_type __n
1015 _CharT __zero = _CharT(
'0'), _CharT __one = _CharT(
'1'))
1020 __throw_logic_error(__N(
"bitset::bitset(const _CharT*, ...)"));
1022 using _Traits =
typename __bitset::__string<_CharT>::traits_type;
1025 __n = _Traits::length(__str);
1026 _M_copy_from_ptr<_CharT, _Traits>(__str, __n, 0, __n, __zero, __one);
1038 _GLIBCXX23_CONSTEXPR
1042 this->_M_do_and(__rhs);
1046 _GLIBCXX23_CONSTEXPR
1050 this->_M_do_or(__rhs);
1054 _GLIBCXX23_CONSTEXPR
1058 this->_M_do_xor(__rhs);
1070 _GLIBCXX23_CONSTEXPR
1072 operator<<=(
size_t __position) _GLIBCXX_NOEXCEPT
1074 if (__builtin_expect(__position < _Nb, 1))
1076 this->_M_do_left_shift(__position);
1077 this->_M_do_sanitize();
1080 this->_M_do_reset();
1084 _GLIBCXX23_CONSTEXPR
1088 if (__builtin_expect(__position < _Nb, 1))
1090 this->_M_do_right_shift(__position);
1091 this->_M_do_sanitize();
1094 this->_M_do_reset();
1105 _GLIBCXX23_CONSTEXPR
1109 this->_M_getword(__pos) |= _Base::_S_maskbit(__pos);
1113 _GLIBCXX23_CONSTEXPR
1118 this->_M_getword(__pos) |= _Base::_S_maskbit(__pos);
1120 this->_M_getword(__pos) &=
~_Base::_S_maskbit(__pos);
1124 _GLIBCXX23_CONSTEXPR
1128 this->_M_getword(__pos) &=
~_Base::_S_maskbit(__pos);
1132 _GLIBCXX23_CONSTEXPR
1136 this->_M_getword(__pos) ^= _Base::_S_maskbit(__pos);
1140 _GLIBCXX_CONSTEXPR
bool
1142 {
return ((this->_M_getword(__pos) & _Base::_S_maskbit(__pos))
1143 !=
static_cast<_WordT
>(0)); }
1150 _GLIBCXX23_CONSTEXPR
1155 this->_M_do_sanitize();
1165 _GLIBCXX23_CONSTEXPR
1167 set(
size_t __position,
bool __val =
true)
1169 this->_M_check(__position, __N(
"bitset::set"));
1170 return _Unchecked_set(__position, __val);
1176 _GLIBCXX23_CONSTEXPR
1180 this->_M_do_reset();
1191 _GLIBCXX23_CONSTEXPR
1195 this->_M_check(__position, __N(
"bitset::reset"));
1196 return _Unchecked_reset(__position);
1202 _GLIBCXX23_CONSTEXPR
1207 this->_M_do_sanitize();
1216 _GLIBCXX23_CONSTEXPR
1220 this->_M_check(__position, __N(
"bitset::flip"));
1221 return _Unchecked_flip(__position);
1225 _GLIBCXX23_CONSTEXPR
1245 _GLIBCXX23_CONSTEXPR
1248 {
return reference(*
this, __position); }
1250 _GLIBCXX_CONSTEXPR
bool
1252 {
return _Unchecked_test(__position); }
1261 _GLIBCXX23_CONSTEXPR
1264 {
return this->_M_do_to_ulong(); }
1266#if __cplusplus >= 201103L
1267 _GLIBCXX23_CONSTEXPR
1270 {
return this->_M_do_to_ullong(); }
1282 template<
class _CharT,
class _Traits,
class _Alloc>
1283 _GLIBCXX23_CONSTEXPR
1288 _M_copy_to_string(__result, _CharT(
'0'), _CharT(
'1'));
1294 template<
class _CharT,
class _Traits,
class _Alloc>
1295 _GLIBCXX23_CONSTEXPR
1297 to_string(_CharT __zero, _CharT __one = _CharT(
'1'))
const
1300 _M_copy_to_string(__result, __zero, __one);
1306 template<
class _CharT,
class _Traits>
1307 _GLIBCXX23_CONSTEXPR
1310 {
return to_string<_CharT, _Traits, std::allocator<_CharT> >(); }
1314 template<
class _CharT,
class _Traits>
1315 _GLIBCXX23_CONSTEXPR
1317 to_string(_CharT __zero, _CharT __one = _CharT(
'1'))
const
1318 {
return to_string<_CharT, _Traits,
1321 template<
class _CharT>
1322 _GLIBCXX23_CONSTEXPR
1327 return to_string<_CharT, std::char_traits<_CharT>,
1331 template<
class _CharT>
1332 _GLIBCXX23_CONSTEXPR
1335 to_string(_CharT __zero, _CharT __one = _CharT(
'1'))
const
1337 return to_string<_CharT, std::char_traits<_CharT>,
1341 _GLIBCXX23_CONSTEXPR
1345 return to_string<char, std::char_traits<char>,
1349 _GLIBCXX23_CONSTEXPR
1351 to_string(
char __zero,
char __one =
'1')
const
1353 return to_string<char, std::char_traits<char>,
1359 _GLIBCXX23_CONSTEXPR
1362 {
return this->_M_do_count(); }
1365 _GLIBCXX_CONSTEXPR
size_t
1371 _GLIBCXX23_CONSTEXPR
1374 {
return this->_M_is_equal(__rhs); }
1376#if __cpp_impl_three_way_comparison < 201907L
1377 _GLIBCXX23_CONSTEXPR
1379 operator!=(
const bitset<_Nb>& __rhs)
const _GLIBCXX_NOEXCEPT
1380 {
return !this->_M_is_equal(__rhs); }
1390 _GLIBCXX23_CONSTEXPR
1394 this->_M_check(__position, __N(
"bitset::test"));
1395 return _Unchecked_test(__position);
1404 _GLIBCXX23_CONSTEXPR
1407 {
return this->
template _M_are_all<_Nb>(); }
1413 _GLIBCXX23_CONSTEXPR
1416 {
return this->_M_is_any(); }
1422 _GLIBCXX23_CONSTEXPR
1425 {
return !this->_M_is_any(); }
1429 _GLIBCXX23_CONSTEXPR
1431 operator<<(
size_t __position)
const _GLIBCXX_NOEXCEPT
1434 _GLIBCXX23_CONSTEXPR
1446 _GLIBCXX23_CONSTEXPR
1449 {
return this->_M_do_find_first(_Nb); }
1458 _GLIBCXX23_CONSTEXPR
1461 {
return this->_M_do_find_next(__prev, _Nb); }
1465 template<
class _CharT,
class _Traits>
1466 _GLIBCXX23_CONSTEXPR
1468 _M_copy_from_ptr(
const _CharT*,
size_t,
size_t,
size_t,
1472 template<
class _CharT,
class _Traits,
class _Alloc>
1473 _GLIBCXX23_CONSTEXPR
1476 _Traits, _Alloc>& __s,
size_t __pos,
size_t __n,
1477 _CharT __zero, _CharT __one)
1478 { _M_copy_from_ptr<_CharT, _Traits>(__s.
data(), __s.
size(), __pos, __n,
1481 template<
class _CharT,
class _Traits,
class _Alloc>
1482 _GLIBCXX23_CONSTEXPR
1485 _CharT, _CharT)
const;
1487 template<
class _CharT,
class _Traits,
size_t _Nb2>
1491 template <
class _CharT,
class _Traits,
size_t _Nb2>
1498 template<
size_t _Nb>
1499 template<
class _CharT,
class _Traits>
1500 _GLIBCXX23_CONSTEXPR
1503 _M_copy_from_ptr(
const _CharT* __s,
size_t __len,
1504 size_t __pos,
size_t __n, _CharT __zero, _CharT __one)
1507 const size_t __nbits =
std::min(_Nb,
std::min(__n,
size_t(__len - __pos)));
1508 for (
size_t __i = __nbits; __i > 0; --__i)
1510 const _CharT __c = __s[__pos + __nbits - __i];
1511 if (_Traits::eq(__c, __zero))
1513 else if (_Traits::eq(__c, __one))
1514 _Unchecked_set(__i - 1);
1516 __throw_invalid_argument(__N(
"bitset::_M_copy_from_ptr"));
1521 template<
size_t _Nb>
1522 template<
class _CharT,
class _Traits,
class _Alloc>
1523 _GLIBCXX23_CONSTEXPR
1527 _CharT __zero, _CharT __one)
const
1530 size_t __n = this->_Find_first();
1533 __s[_Nb - __n - 1] = __one;
1534 __n = _Find_next(__n);
1549 template<
size_t _Nb>
1550 _GLIBCXX23_CONSTEXPR
1559 template<
size_t _Nb>
1560 _GLIBCXX23_CONSTEXPR
1569 template <
size_t _Nb>
1570 _GLIBCXX23_CONSTEXPR
1590 template<
class _CharT,
class _Traits,
size_t _Nb>
1594 typedef typename _Traits::char_type char_type;
1596 typedef typename __istream_type::ios_base __ios_base;
1600 static _GLIBCXX_CONSTEXPR
bool _S_use_alloca() {
return _Nb <= 256; }
1602 explicit _Buffer(_CharT* __p) : _M_ptr(__p) { }
1606 if _GLIBCXX17_CONSTEXPR (!_S_use_alloca())
1610 _CharT*
const _M_ptr;
1613 if _GLIBCXX17_CONSTEXPR (_Buffer::_S_use_alloca())
1614 __ptr = (_CharT*)__builtin_alloca(_Nb);
1616 __ptr =
new _CharT[_Nb];
1617 const _Buffer __buf(__ptr);
1621 const char_type __zero = __is.
widen(
'0');
1622 const char_type __one = __is.
widen(
'1');
1624 typename __ios_base::iostate __state = __ios_base::goodbit;
1625 typename __istream_type::sentry __sentry(__is);
1630 for (
size_t __i = _Nb; __i > 0; --__i)
1632 static typename _Traits::int_type __eof = _Traits::eof();
1634 typename _Traits::int_type __c1 = __is.
rdbuf()->sbumpc();
1635 if (_Traits::eq_int_type(__c1, __eof))
1637 __state |= __ios_base::eofbit;
1642 const char_type __c2 = _Traits::to_char_type(__c1);
1643 if (_Traits::eq(__c2, __zero))
1645 else if (_Traits::eq(__c2, __one))
1648 eq_int_type(__is.
rdbuf()->sputbackc(__c2),
1651 __state |= __ios_base::failbit;
1659 __is._M_setstate(__ios_base::badbit);
1660 __throw_exception_again;
1663 { __is._M_setstate(__ios_base::badbit); }
1666 if _GLIBCXX17_CONSTEXPR (_Nb)
1668 if (
size_t __len = __ptr - __buf._M_ptr)
1669 __x.template _M_copy_from_ptr<_CharT, _Traits>(__buf._M_ptr, __len,
1673 __state |= __ios_base::failbit;
1680 template <
class _CharT,
class _Traits,
size_t _Nb>
1683 const bitset<_Nb>& __x)
1689 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__os.
getloc());
1690 __x._M_copy_to_string(__tmp, __ct.widen(
'0'), __ct.widen(
'1'));
1691 return __os << __tmp;
1696_GLIBCXX_END_NAMESPACE_CONTAINER
1699#undef _GLIBCXX_BITSET_WORDS
1700#undef _GLIBCXX_BITSET_BITS_PER_WORD
1701#undef _GLIBCXX_BITSET_BITS_PER_ULL
1703#if __cplusplus >= 201103L
1705namespace std _GLIBCXX_VISIBILITY(default)
1707_GLIBCXX_BEGIN_NAMESPACE_VERSION
1711 template<
size_t _Nb>
1713 :
public __hash_base<size_t, _GLIBCXX_STD_C::bitset<_Nb>>
1716 operator()(
const _GLIBCXX_STD_C::bitset<_Nb>& __b)
const noexcept
1718 const size_t __clength = (_Nb + __CHAR_BIT__ - 1) / __CHAR_BIT__;
1719 return std::_Hash_impl::hash(__b._M_getdata(), __clength);
1725 :
public __hash_base<size_t, _GLIBCXX_STD_C::bitset<0>>
1728 operator()(
const _GLIBCXX_STD_C::bitset<0>&)
const noexcept
1732_GLIBCXX_END_NAMESPACE_VERSION
1737#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.
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.
_WordT _M_w[_Nw]
0 is the least significant word.
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< _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 std::basic_string< _CharT, _Traits, _Alloc > to_string() const
Returns a character interpretation of the bitset.
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 > & 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.
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.
Template class basic_istream.
Template class basic_ostream.
Primary class template hash.
The standard allocator, as per C++03 [20.4.1].
Managing sequences of characters and character-like objects.
const _CharT * data() const noexcept
Return const pointer to contents.
basic_string & assign(const basic_string &__str)
Set value to contents of another string.
size_type size() const noexcept
Returns the number of characters in the string, not including any null-termination.
Thrown as part of forced unwinding.
locale getloc() const
Locale access.