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#if __cplusplus >= 201402L
181 if (__builtin_is_constant_evaluated())
183 for (_WordT& __w :
_M_w)
184 __w = ~static_cast<_WordT>(0);;
188 __builtin_memset(
_M_w, 0xFF, _Nw *
sizeof(_WordT));
191 _GLIBCXX14_CONSTEXPR
void
192 _M_do_reset() _GLIBCXX_NOEXCEPT
194#if __cplusplus >= 201402L
195 if (__builtin_is_constant_evaluated())
197 for (_WordT& __w :
_M_w)
202 __builtin_memset(
_M_w, 0, _Nw *
sizeof(_WordT));
205 _GLIBCXX14_CONSTEXPR
bool
206 _M_is_equal(
const _Base_bitset<_Nw>& __x)
const _GLIBCXX_NOEXCEPT
208#if __cplusplus >= 201402L
209 if (__builtin_is_constant_evaluated())
211 for (
size_t __i = 0; __i < _Nw; ++__i)
212 if (
_M_w[__i] != __x._M_w[__i])
217 return !__builtin_memcmp(
_M_w, __x._M_w, _Nw *
sizeof(_WordT));
221 _GLIBCXX14_CONSTEXPR
bool
222 _M_are_all() const _GLIBCXX_NOEXCEPT
224 for (
size_t __i = 0; __i < _Nw - 1; __i++)
225 if (
_M_w[__i] != ~
static_cast<_WordT
>(0))
227 return _M_hiword() == (~static_cast<_WordT>(0)
228 >> (_Nw * _GLIBCXX_BITSET_BITS_PER_WORD
232 _GLIBCXX14_CONSTEXPR
bool
233 _M_is_any() const _GLIBCXX_NOEXCEPT
235 for (
size_t __i = 0; __i < _Nw; __i++)
236 if (
_M_w[__i] !=
static_cast<_WordT
>(0))
241 _GLIBCXX14_CONSTEXPR
size_t
242 _M_do_count() const _GLIBCXX_NOEXCEPT
245 for (
size_t __i = 0; __i < _Nw; __i++)
246 __result += __builtin_popcountl(
_M_w[__i]);
250 _GLIBCXX14_CONSTEXPR
unsigned long
251 _M_do_to_ulong()
const;
253#if __cplusplus >= 201103L
254 _GLIBCXX14_CONSTEXPR
unsigned long long
255 _M_do_to_ullong()
const;
259 _GLIBCXX14_CONSTEXPR
size_t
260 _M_do_find_first(
size_t)
const _GLIBCXX_NOEXCEPT;
263 _GLIBCXX14_CONSTEXPR
size_t
264 _M_do_find_next(
size_t,
size_t)
const _GLIBCXX_NOEXCEPT;
269 _GLIBCXX14_CONSTEXPR
void
270 _Base_bitset<_Nw>::_M_do_left_shift(
size_t __shift) _GLIBCXX_NOEXCEPT
272 if (__builtin_expect(__shift != 0, 1))
274 const size_t __wshift = __shift / _GLIBCXX_BITSET_BITS_PER_WORD;
275 const size_t __offset = __shift % _GLIBCXX_BITSET_BITS_PER_WORD;
278 for (
size_t __n = _Nw - 1; __n >= __wshift; --__n)
279 _M_w[__n] = _M_w[__n - __wshift];
282 const size_t __sub_offset = (_GLIBCXX_BITSET_BITS_PER_WORD
284 for (
size_t __n = _Nw - 1; __n > __wshift; --__n)
285 _M_w[__n] = ((_M_w[__n - __wshift] << __offset)
286 | (_M_w[__n - __wshift - 1] >> __sub_offset));
287 _M_w[__wshift] = _M_w[0] << __offset;
290 std::fill(_M_w + 0, _M_w + __wshift,
static_cast<_WordT
>(0));
295 _GLIBCXX14_CONSTEXPR
void
296 _Base_bitset<_Nw>::_M_do_right_shift(
size_t __shift) _GLIBCXX_NOEXCEPT
298 if (__builtin_expect(__shift != 0, 1))
300 const size_t __wshift = __shift / _GLIBCXX_BITSET_BITS_PER_WORD;
301 const size_t __offset = __shift % _GLIBCXX_BITSET_BITS_PER_WORD;
302 const size_t __limit = _Nw - __wshift - 1;
305 for (
size_t __n = 0; __n <= __limit; ++__n)
306 _M_w[__n] = _M_w[__n + __wshift];
309 const size_t __sub_offset = (_GLIBCXX_BITSET_BITS_PER_WORD
311 for (
size_t __n = 0; __n < __limit; ++__n)
312 _M_w[__n] = ((_M_w[__n + __wshift] >> __offset)
313 | (_M_w[__n + __wshift + 1] << __sub_offset));
314 _M_w[__limit] = _M_w[_Nw-1] >> __offset;
317 std::fill(_M_w + __limit + 1, _M_w + _Nw,
static_cast<_WordT
>(0));
322 _GLIBCXX14_CONSTEXPR
unsigned long
323 _Base_bitset<_Nw>::_M_do_to_ulong()
const
325 for (
size_t __i = 1; __i < _Nw; ++__i)
327 __throw_overflow_error(__N(
"_Base_bitset::_M_do_to_ulong"));
331#if __cplusplus >= 201103L
333 _GLIBCXX14_CONSTEXPR
unsigned long long
334 _Base_bitset<_Nw>::_M_do_to_ullong()
const
336#if __SIZEOF_LONG_LONG__ == __SIZEOF_LONG__
337 return _M_do_to_ulong();
339 for (
size_t __i = 2; __i < _Nw; ++__i)
341 __throw_overflow_error(__N(
"_Base_bitset::_M_do_to_ullong"));
343 return _M_w[0] + (
static_cast<unsigned long long>(_M_w[1])
344 << _GLIBCXX_BITSET_BITS_PER_WORD);
350 _GLIBCXX14_CONSTEXPR
size_t
352 _M_do_find_first(
size_t __not_found)
const _GLIBCXX_NOEXCEPT
354 for (
size_t __i = 0; __i < _Nw; __i++)
356 _WordT __thisword = _M_w[__i];
357 if (__thisword !=
static_cast<_WordT
>(0))
358 return (__i * _GLIBCXX_BITSET_BITS_PER_WORD
359 + __builtin_ctzl(__thisword));
366 _GLIBCXX14_CONSTEXPR
size_t
368 _M_do_find_next(
size_t __prev,
size_t __not_found)
const _GLIBCXX_NOEXCEPT
374 if (__prev >= _Nw * _GLIBCXX_BITSET_BITS_PER_WORD)
378 size_t __i = _S_whichword(__prev);
379 _WordT __thisword = _M_w[__i];
382 __thisword &= (~static_cast<_WordT>(0)) << _S_whichbit(__prev);
384 if (__thisword !=
static_cast<_WordT
>(0))
385 return (__i * _GLIBCXX_BITSET_BITS_PER_WORD
386 + __builtin_ctzl(__thisword));
390 for (; __i < _Nw; __i++)
392 __thisword = _M_w[__i];
393 if (__thisword !=
static_cast<_WordT
>(0))
394 return (__i * _GLIBCXX_BITSET_BITS_PER_WORD
395 + __builtin_ctzl(__thisword));
409 typedef unsigned long _WordT;
416#if __cplusplus >= 201103L
417 constexpr _Base_bitset(
unsigned long long __val)
noexcept
424 static _GLIBCXX_CONSTEXPR
size_t
425 _S_whichword(
size_t __pos) _GLIBCXX_NOEXCEPT
426 {
return __pos / _GLIBCXX_BITSET_BITS_PER_WORD; }
428 static _GLIBCXX_CONSTEXPR
size_t
429 _S_whichbyte(
size_t __pos) _GLIBCXX_NOEXCEPT
430 {
return (__pos % _GLIBCXX_BITSET_BITS_PER_WORD) / __CHAR_BIT__; }
432 static _GLIBCXX_CONSTEXPR
size_t
433 _S_whichbit(
size_t __pos) _GLIBCXX_NOEXCEPT
434 {
return __pos % _GLIBCXX_BITSET_BITS_PER_WORD; }
436 static _GLIBCXX_CONSTEXPR _WordT
437 _S_maskbit(
size_t __pos) _GLIBCXX_NOEXCEPT
438 {
return (
static_cast<_WordT
>(1)) << _S_whichbit(__pos); }
440 _GLIBCXX14_CONSTEXPR _WordT&
441 _M_getword(
size_t) _GLIBCXX_NOEXCEPT
444 _GLIBCXX_CONSTEXPR _WordT
445 _M_getword(
size_t)
const _GLIBCXX_NOEXCEPT
448#if __cplusplus >= 201103L
449 constexpr const _WordT*
450 _M_getdata()
const noexcept
454 _GLIBCXX14_CONSTEXPR _WordT&
455 _M_hiword() _GLIBCXX_NOEXCEPT
458 _GLIBCXX_CONSTEXPR _WordT
459 _M_hiword()
const _GLIBCXX_NOEXCEPT
462 _GLIBCXX14_CONSTEXPR
void
466 _GLIBCXX14_CONSTEXPR
void
470 _GLIBCXX14_CONSTEXPR
void
474 _GLIBCXX14_CONSTEXPR
void
475 _M_do_left_shift(
size_t __shift) _GLIBCXX_NOEXCEPT
476 {
_M_w <<= __shift; }
478 _GLIBCXX14_CONSTEXPR
void
479 _M_do_right_shift(
size_t __shift) _GLIBCXX_NOEXCEPT
480 {
_M_w >>= __shift; }
482 _GLIBCXX14_CONSTEXPR
void
483 _M_do_flip() _GLIBCXX_NOEXCEPT
486 _GLIBCXX14_CONSTEXPR
void
487 _M_do_set() _GLIBCXX_NOEXCEPT
488 {
_M_w = ~static_cast<_WordT>(0); }
490 _GLIBCXX14_CONSTEXPR
void
491 _M_do_reset() _GLIBCXX_NOEXCEPT
494 _GLIBCXX14_CONSTEXPR
bool
499 _GLIBCXX14_CONSTEXPR
bool
500 _M_are_all()
const _GLIBCXX_NOEXCEPT
501 {
return _M_w == (~static_cast<_WordT>(0)
502 >> (_GLIBCXX_BITSET_BITS_PER_WORD - _Nb)); }
504 _GLIBCXX14_CONSTEXPR
bool
505 _M_is_any()
const _GLIBCXX_NOEXCEPT
506 {
return _M_w != 0; }
508 _GLIBCXX14_CONSTEXPR
size_t
509 _M_do_count()
const _GLIBCXX_NOEXCEPT
510 {
return __builtin_popcountl(
_M_w); }
512 _GLIBCXX14_CONSTEXPR
unsigned long
513 _M_do_to_ulong()
const _GLIBCXX_NOEXCEPT
516#if __cplusplus >= 201103L
517 constexpr unsigned long long
518 _M_do_to_ullong()
const noexcept
522 _GLIBCXX14_CONSTEXPR
size_t
523 _M_do_find_first(
size_t __not_found)
const _GLIBCXX_NOEXCEPT
526 return __builtin_ctzl(
_M_w);
532 _GLIBCXX14_CONSTEXPR
size_t
533 _M_do_find_next(
size_t __prev,
size_t __not_found)
const
537 if (__prev >= ((
size_t) _GLIBCXX_BITSET_BITS_PER_WORD))
540 _WordT __x =
_M_w >> __prev;
542 return __builtin_ctzl(__x) + __prev;
556 typedef unsigned long _WordT;
561#if __cplusplus >= 201103L
568 static _GLIBCXX_CONSTEXPR
size_t
569 _S_whichword(
size_t __pos) _GLIBCXX_NOEXCEPT
570 {
return __pos / _GLIBCXX_BITSET_BITS_PER_WORD; }
572 static _GLIBCXX_CONSTEXPR
size_t
573 _S_whichbyte(
size_t __pos) _GLIBCXX_NOEXCEPT
574 {
return (__pos % _GLIBCXX_BITSET_BITS_PER_WORD) / __CHAR_BIT__; }
576 static _GLIBCXX_CONSTEXPR
size_t
577 _S_whichbit(
size_t __pos) _GLIBCXX_NOEXCEPT
578 {
return __pos % _GLIBCXX_BITSET_BITS_PER_WORD; }
580 static _GLIBCXX_CONSTEXPR _WordT
581 _S_maskbit(
size_t __pos) _GLIBCXX_NOEXCEPT
582 {
return (
static_cast<_WordT
>(1)) << _S_whichbit(__pos); }
590 __attribute__((__noreturn__))
592 _M_getword(
size_t) _GLIBCXX_NOEXCEPT
593 { __throw_out_of_range(__N(
"_Base_bitset::_M_getword")); }
595 _GLIBCXX_CONSTEXPR _WordT
596 _M_getword(
size_t)
const _GLIBCXX_NOEXCEPT
599 _GLIBCXX_CONSTEXPR _WordT
600 _M_hiword()
const _GLIBCXX_NOEXCEPT
603 _GLIBCXX14_CONSTEXPR
void
607 _GLIBCXX14_CONSTEXPR
void
611 _GLIBCXX14_CONSTEXPR
void
615 _GLIBCXX14_CONSTEXPR
void
616 _M_do_left_shift(
size_t) _GLIBCXX_NOEXCEPT
619 _GLIBCXX14_CONSTEXPR
void
620 _M_do_right_shift(
size_t) _GLIBCXX_NOEXCEPT
623 _GLIBCXX14_CONSTEXPR
void
624 _M_do_flip() _GLIBCXX_NOEXCEPT
627 _GLIBCXX14_CONSTEXPR
void
628 _M_do_set() _GLIBCXX_NOEXCEPT
631 _GLIBCXX14_CONSTEXPR
void
632 _M_do_reset() _GLIBCXX_NOEXCEPT
638 _GLIBCXX_CONSTEXPR
bool
643 _GLIBCXX_CONSTEXPR
bool
644 _M_are_all()
const _GLIBCXX_NOEXCEPT
647 _GLIBCXX_CONSTEXPR
bool
648 _M_is_any()
const _GLIBCXX_NOEXCEPT
651 _GLIBCXX_CONSTEXPR
size_t
652 _M_do_count()
const _GLIBCXX_NOEXCEPT
655 _GLIBCXX_CONSTEXPR
unsigned long
656 _M_do_to_ulong()
const _GLIBCXX_NOEXCEPT
659#if __cplusplus >= 201103L
660 constexpr unsigned long long
661 _M_do_to_ullong()
const noexcept
667 _GLIBCXX_CONSTEXPR
size_t
668 _M_do_find_first(
size_t)
const _GLIBCXX_NOEXCEPT
671 _GLIBCXX_CONSTEXPR
size_t
672 _M_do_find_next(
size_t,
size_t)
const _GLIBCXX_NOEXCEPT
678 template<
size_t _Extrabits>
681 typedef unsigned long _WordT;
683 static _GLIBCXX14_CONSTEXPR
void
684 _S_do_sanitize(_WordT& __val) _GLIBCXX_NOEXCEPT
685 { __val &= ~((~static_cast<_WordT>(0)) << _Extrabits); }
691 typedef unsigned long _WordT;
693 static _GLIBCXX14_CONSTEXPR
void
694 _S_do_sanitize(_WordT) _GLIBCXX_NOEXCEPT { }
697#if __cplusplus >= 201103L
698 template<
size_t _Nb,
bool = (_Nb < _GLIBCXX_BITSET_BITS_PER_ULL)>
701 static constexpr
unsigned long long
702 _S_do_sanitize_val(
unsigned long long __val)
707 struct _Sanitize_val<_Nb, true>
709 static constexpr unsigned long long
710 _S_do_sanitize_val(
unsigned long long __val)
711 {
return __val & ~((~static_cast<unsigned long long>(0)) << _Nb); }
717 template<
typename _CharT>
720 template<
typename _CharT>
723 using size_type = size_t;
724 static constexpr size_type npos = size_type(-1);
728 static _GLIBCXX14_CONSTEXPR
size_t
729 length(
const _CharT* __s)
noexcept
737 static constexpr bool
738 eq(_CharT __l, _CharT __r)
noexcept
739 {
return __l == __r; }
815 typedef unsigned long _WordT;
818 template<
class _CharT,
class _Traits,
class _Alloc>
822 size_t __position)
const
824 if (__position > __s.
size())
825 __throw_out_of_range_fmt(__N(
"bitset::bitset: __position "
826 "(which is %zu) > __s.size() "
828 __position, __s.
size());
833 void _M_check(
size_t __position,
const char *__s)
const
835 if (__position >= _Nb)
836 __throw_out_of_range_fmt(__N(
"%s: __position (which is %zu) "
837 ">= _Nb (which is %zu)"),
838 __s, __position, _Nb);
843 _M_do_sanitize() _GLIBCXX_NOEXCEPT
845 typedef _Sanitize<_Nb % _GLIBCXX_BITSET_BITS_PER_WORD> __sanitize_type;
846 __sanitize_type::_S_do_sanitize(this->_M_hiword());
849#if __cplusplus >= 201103L
876 _M_wp = &__b._M_getword(__pos);
877 _M_bpos = _Base::_S_whichbit(__pos);
881#if __cplusplus >= 201103L
885#if __cplusplus > 202002L && __cpp_constexpr_dynamic_alloc
894 operator=(
bool __x) _GLIBCXX_NOEXCEPT
897 *_M_wp |= _Base::_S_maskbit(_M_bpos);
899 *_M_wp &=
~_Base::_S_maskbit(_M_bpos);
906 operator=(
const reference& __j) _GLIBCXX_NOEXCEPT
908 if ((*(__j._M_wp) & _Base::_S_maskbit(__j._M_bpos)))
909 *_M_wp |= _Base::_S_maskbit(_M_bpos);
911 *_M_wp &=
~_Base::_S_maskbit(_M_bpos);
918 operator~()
const _GLIBCXX_NOEXCEPT
919 {
return (*(_M_wp) & _Base::_S_maskbit(_M_bpos)) == 0; }
923 operator bool()
const _GLIBCXX_NOEXCEPT
924 {
return (*(_M_wp) & _Base::_S_maskbit(_M_bpos)) != 0; }
929 flip() _GLIBCXX_NOEXCEPT
931 *_M_wp ^= _Base::_S_maskbit(_M_bpos);
939 _GLIBCXX_CONSTEXPR
bitset() _GLIBCXX_NOEXCEPT
943#if __cplusplus >= 201103L
944 constexpr bitset(
unsigned long long __val) noexcept
945 :
_Base(_Sanitize_val<_Nb>::_S_do_sanitize_val(__val)) { }
947 bitset(
unsigned long __val)
949 { _M_do_sanitize(); }
962 template<
class _CharT,
class _Traits,
class _Alloc>
966 size_t __position = 0)
969 _M_check_initial_position(__s, __position);
970 _M_copy_from_string(__s, __position,
972 _CharT(
'0'), _CharT(
'1'));
985 template<
class _CharT,
class _Traits,
class _Alloc>
988 size_t __position,
size_t __n)
991 _M_check_initial_position(__s, __position);
992 _M_copy_from_string(__s, __position, __n, _CharT(
'0'), _CharT(
'1'));
997 template<
class _CharT,
class _Traits,
class _Alloc>
1000 size_t __position,
size_t __n,
1001 _CharT __zero, _CharT __one = _CharT(
'1'))
1004 _M_check_initial_position(__s, __position);
1005 _M_copy_from_string(__s, __position, __n, __zero, __one);
1009#if __cplusplus >= 201103L
1019 template<
typename _CharT>
1020 [[__gnu__::__nonnull__]]
1021 _GLIBCXX23_CONSTEXPR
1024 typename __bitset::__string<_CharT>::size_type __n
1026 _CharT __zero = _CharT(
'0'), _CharT __one = _CharT(
'1'))
1031 __throw_logic_error(__N(
"bitset::bitset(const _CharT*, ...)"));
1033 using _Traits =
typename __bitset::__string<_CharT>::traits_type;
1036 __n = _Traits::length(__str);
1037 _M_copy_from_ptr<_CharT, _Traits>(__str, __n, 0, __n, __zero, __one);
1049 _GLIBCXX23_CONSTEXPR
1053 this->_M_do_and(__rhs);
1057 _GLIBCXX23_CONSTEXPR
1061 this->_M_do_or(__rhs);
1065 _GLIBCXX23_CONSTEXPR
1069 this->_M_do_xor(__rhs);
1081 _GLIBCXX23_CONSTEXPR
1083 operator<<=(
size_t __position) _GLIBCXX_NOEXCEPT
1085 if (__builtin_expect(__position < _Nb, 1))
1087 this->_M_do_left_shift(__position);
1088 this->_M_do_sanitize();
1091 this->_M_do_reset();
1095 _GLIBCXX23_CONSTEXPR
1099 if (__builtin_expect(__position < _Nb, 1))
1100 this->_M_do_right_shift(__position);
1102 this->_M_do_reset();
1113 _GLIBCXX23_CONSTEXPR
1117 this->_M_getword(__pos) |= _Base::_S_maskbit(__pos);
1121 _GLIBCXX23_CONSTEXPR
1126 this->_M_getword(__pos) |= _Base::_S_maskbit(__pos);
1128 this->_M_getword(__pos) &=
~_Base::_S_maskbit(__pos);
1132 _GLIBCXX23_CONSTEXPR
1136 this->_M_getword(__pos) &=
~_Base::_S_maskbit(__pos);
1140 _GLIBCXX23_CONSTEXPR
1144 this->_M_getword(__pos) ^= _Base::_S_maskbit(__pos);
1148 _GLIBCXX_CONSTEXPR
bool
1150 {
return ((this->_M_getword(__pos) & _Base::_S_maskbit(__pos))
1151 !=
static_cast<_WordT
>(0)); }
1158 _GLIBCXX23_CONSTEXPR
1163 this->_M_do_sanitize();
1173 _GLIBCXX23_CONSTEXPR
1175 set(
size_t __position,
bool __val =
true)
1177 this->_M_check(__position, __N(
"bitset::set"));
1178 return _Unchecked_set(__position, __val);
1184 _GLIBCXX23_CONSTEXPR
1188 this->_M_do_reset();
1199 _GLIBCXX23_CONSTEXPR
1203 this->_M_check(__position, __N(
"bitset::reset"));
1204 return _Unchecked_reset(__position);
1210 _GLIBCXX23_CONSTEXPR
1215 this->_M_do_sanitize();
1224 _GLIBCXX23_CONSTEXPR
1228 this->_M_check(__position, __N(
"bitset::flip"));
1229 return _Unchecked_flip(__position);
1233 _GLIBCXX23_CONSTEXPR
1253 _GLIBCXX23_CONSTEXPR
1256 {
return reference(*
this, __position); }
1258 _GLIBCXX_CONSTEXPR
bool
1260 {
return _Unchecked_test(__position); }
1269 _GLIBCXX23_CONSTEXPR
1272 {
return this->_M_do_to_ulong(); }
1274#if __cplusplus >= 201103L
1275 _GLIBCXX23_CONSTEXPR
1278 {
return this->_M_do_to_ullong(); }
1290 template<
class _CharT,
class _Traits,
class _Alloc>
1291 _GLIBCXX23_CONSTEXPR
1296 _M_copy_to_string(__result, _CharT(
'0'), _CharT(
'1'));
1302 template<
class _CharT,
class _Traits,
class _Alloc>
1303 _GLIBCXX23_CONSTEXPR
1305 to_string(_CharT __zero, _CharT __one = _CharT(
'1'))
const
1308 _M_copy_to_string(__result, __zero, __one);
1314 template<
class _CharT,
class _Traits>
1315 _GLIBCXX23_CONSTEXPR
1318 {
return to_string<_CharT, _Traits, std::allocator<_CharT> >(); }
1322 template<
class _CharT,
class _Traits>
1323 _GLIBCXX23_CONSTEXPR
1325 to_string(_CharT __zero, _CharT __one = _CharT(
'1'))
const
1326 {
return to_string<_CharT, _Traits,
1329 template<
class _CharT>
1330 _GLIBCXX23_CONSTEXPR
1335 return to_string<_CharT, std::char_traits<_CharT>,
1339 template<
class _CharT>
1340 _GLIBCXX23_CONSTEXPR
1343 to_string(_CharT __zero, _CharT __one = _CharT(
'1'))
const
1345 return to_string<_CharT, std::char_traits<_CharT>,
1349 _GLIBCXX23_CONSTEXPR
1353 return to_string<char, std::char_traits<char>,
1357 _GLIBCXX23_CONSTEXPR
1359 to_string(
char __zero,
char __one =
'1')
const
1361 return to_string<char, std::char_traits<char>,
1367 _GLIBCXX23_CONSTEXPR
1370 {
return this->_M_do_count(); }
1373 _GLIBCXX_CONSTEXPR
size_t
1379 _GLIBCXX23_CONSTEXPR
1382 {
return this->_M_is_equal(__rhs); }
1384#if __cpp_impl_three_way_comparison < 201907L
1385 _GLIBCXX23_CONSTEXPR
1387 operator!=(
const bitset<_Nb>& __rhs)
const _GLIBCXX_NOEXCEPT
1388 {
return !this->_M_is_equal(__rhs); }
1398 _GLIBCXX23_CONSTEXPR
1402 this->_M_check(__position, __N(
"bitset::test"));
1403 return _Unchecked_test(__position);
1412 _GLIBCXX23_CONSTEXPR
1415 {
return this->
template _M_are_all<_Nb>(); }
1421 _GLIBCXX23_CONSTEXPR
1424 {
return this->_M_is_any(); }
1430 _GLIBCXX23_CONSTEXPR
1433 {
return !this->_M_is_any(); }
1437 _GLIBCXX23_CONSTEXPR
1439 operator<<(
size_t __position)
const _GLIBCXX_NOEXCEPT
1442 _GLIBCXX23_CONSTEXPR
1454 _GLIBCXX23_CONSTEXPR
1457 {
return this->_M_do_find_first(_Nb); }
1466 _GLIBCXX23_CONSTEXPR
1469 {
return this->_M_do_find_next(__prev, _Nb); }
1473 template<
class _CharT,
class _Traits>
1474 _GLIBCXX23_CONSTEXPR
1476 _M_copy_from_ptr(
const _CharT*,
size_t,
size_t,
size_t,
1480 template<
class _CharT,
class _Traits,
class _Alloc>
1481 _GLIBCXX23_CONSTEXPR
1484 _Traits, _Alloc>& __s,
size_t __pos,
size_t __n,
1485 _CharT __zero, _CharT __one)
1486 { _M_copy_from_ptr<_CharT, _Traits>(__s.
data(), __s.
size(), __pos, __n,
1489 template<
class _CharT,
class _Traits,
class _Alloc>
1490 _GLIBCXX23_CONSTEXPR
1493 _CharT, _CharT)
const;
1495 template<
class _CharT,
class _Traits,
size_t _Nb2>
1499 template <
class _CharT,
class _Traits,
size_t _Nb2>
1506 template<
size_t _Nb>
1507 template<
class _CharT,
class _Traits>
1508 _GLIBCXX23_CONSTEXPR
1511 _M_copy_from_ptr(
const _CharT* __s,
size_t __len,
1512 size_t __pos,
size_t __n, _CharT __zero, _CharT __one)
1515 const size_t __nbits =
std::min(_Nb,
std::min(__n,
size_t(__len - __pos)));
1516 for (
size_t __i = __nbits; __i > 0; --__i)
1518 const _CharT __c = __s[__pos + __nbits - __i];
1519 if (_Traits::eq(__c, __zero))
1521 else if (_Traits::eq(__c, __one))
1522 _Unchecked_set(__i - 1);
1524 __throw_invalid_argument(__N(
"bitset::_M_copy_from_ptr"));
1529 template<
size_t _Nb>
1530 template<
class _CharT,
class _Traits,
class _Alloc>
1531 _GLIBCXX23_CONSTEXPR
1535 _CharT __zero, _CharT __one)
const
1538 size_t __n = this->_Find_first();
1541 __s[_Nb - __n - 1] = __one;
1542 __n = _Find_next(__n);
1557 template<
size_t _Nb>
1558 _GLIBCXX23_CONSTEXPR
1567 template<
size_t _Nb>
1568 _GLIBCXX23_CONSTEXPR
1577 template <
size_t _Nb>
1578 _GLIBCXX23_CONSTEXPR
1598 template<
class _CharT,
class _Traits,
size_t _Nb>
1602 typedef typename _Traits::char_type char_type;
1604 typedef typename __istream_type::ios_base __ios_base;
1608 static _GLIBCXX_CONSTEXPR
bool _S_use_alloca() {
return _Nb <= 256; }
1610 explicit _Buffer(_CharT* __p) : _M_ptr(__p) { }
1614 if _GLIBCXX17_CONSTEXPR (!_S_use_alloca())
1618 _CharT*
const _M_ptr;
1621 if _GLIBCXX17_CONSTEXPR (_Buffer::_S_use_alloca())
1622 __ptr = (_CharT*)__builtin_alloca(_Nb);
1624 __ptr =
new _CharT[_Nb];
1625 const _Buffer __buf(__ptr);
1629 const char_type __zero = __is.
widen(
'0');
1630 const char_type __one = __is.
widen(
'1');
1632 typename __ios_base::iostate __state = __ios_base::goodbit;
1633 typename __istream_type::sentry __sentry(__is);
1638 for (
size_t __i = _Nb; __i > 0; --__i)
1640 static typename _Traits::int_type __eof = _Traits::eof();
1642 typename _Traits::int_type __c1 = __is.
rdbuf()->sbumpc();
1643 if (_Traits::eq_int_type(__c1, __eof))
1645 __state |= __ios_base::eofbit;
1650 const char_type __c2 = _Traits::to_char_type(__c1);
1651 if (_Traits::eq(__c2, __zero))
1653 else if (_Traits::eq(__c2, __one))
1656 eq_int_type(__is.
rdbuf()->sputbackc(__c2),
1659 __state |= __ios_base::failbit;
1667 __is._M_setstate(__ios_base::badbit);
1668 __throw_exception_again;
1671 { __is._M_setstate(__ios_base::badbit); }
1674 if _GLIBCXX17_CONSTEXPR (_Nb)
1676 if (
size_t __len = __ptr - __buf._M_ptr)
1677 __x.template _M_copy_from_ptr<_CharT, _Traits>(__buf._M_ptr, __len,
1681 __state |= __ios_base::failbit;
1688 template <
class _CharT,
class _Traits,
size_t _Nb>
1691 const bitset<_Nb>& __x)
1697 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__os.
getloc());
1698 __x._M_copy_to_string(__tmp, __ct.widen(
'0'), __ct.widen(
'1'));
1699 return __os << __tmp;
1704_GLIBCXX_END_NAMESPACE_CONTAINER
1707#undef _GLIBCXX_BITSET_WORDS
1708#undef _GLIBCXX_BITSET_BITS_PER_WORD
1709#undef _GLIBCXX_BITSET_BITS_PER_ULL
1711#if __cplusplus >= 201103L
1713namespace std _GLIBCXX_VISIBILITY(default)
1715_GLIBCXX_BEGIN_NAMESPACE_VERSION
1719 template<
size_t _Nb>
1721 :
public __hash_base<size_t, _GLIBCXX_STD_C::bitset<_Nb>>
1724 operator()(
const _GLIBCXX_STD_C::bitset<_Nb>& __b)
const noexcept
1726 const size_t __clength = (_Nb + __CHAR_BIT__ - 1) / __CHAR_BIT__;
1727 return std::_Hash_impl::hash(__b._M_getdata(), __clength);
1733 :
public __hash_base<size_t, _GLIBCXX_STD_C::bitset<0>>
1736 operator()(
const _GLIBCXX_STD_C::bitset<0>&)
const noexcept
1740_GLIBCXX_END_NAMESPACE_VERSION
1745#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.