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 for (
size_t __i = 0; __i < _Nw; ++__i)
209 if (
_M_w[__i] != __x._M_w[__i])
215 _GLIBCXX14_CONSTEXPR
bool
216 _M_are_all() const _GLIBCXX_NOEXCEPT
218 for (
size_t __i = 0; __i < _Nw - 1; __i++)
219 if (
_M_w[__i] != ~
static_cast<_WordT
>(0))
221 return _M_hiword() == (~static_cast<_WordT>(0)
222 >> (_Nw * _GLIBCXX_BITSET_BITS_PER_WORD
226 _GLIBCXX14_CONSTEXPR
bool
227 _M_is_any() const _GLIBCXX_NOEXCEPT
229 for (
size_t __i = 0; __i < _Nw; __i++)
230 if (
_M_w[__i] !=
static_cast<_WordT
>(0))
235 _GLIBCXX14_CONSTEXPR
size_t
236 _M_do_count() const _GLIBCXX_NOEXCEPT
239 for (
size_t __i = 0; __i < _Nw; __i++)
240 __result += __builtin_popcountl(
_M_w[__i]);
244 _GLIBCXX14_CONSTEXPR
unsigned long
245 _M_do_to_ulong()
const;
247#if __cplusplus >= 201103L
248 _GLIBCXX14_CONSTEXPR
unsigned long long
249 _M_do_to_ullong()
const;
253 _GLIBCXX14_CONSTEXPR
size_t
254 _M_do_find_first(
size_t)
const _GLIBCXX_NOEXCEPT;
257 _GLIBCXX14_CONSTEXPR
size_t
258 _M_do_find_next(
size_t,
size_t)
const _GLIBCXX_NOEXCEPT;
263 _GLIBCXX14_CONSTEXPR
void
264 _Base_bitset<_Nw>::_M_do_left_shift(
size_t __shift) _GLIBCXX_NOEXCEPT
266 if (__builtin_expect(__shift != 0, 1))
268 const size_t __wshift = __shift / _GLIBCXX_BITSET_BITS_PER_WORD;
269 const size_t __offset = __shift % _GLIBCXX_BITSET_BITS_PER_WORD;
272 for (
size_t __n = _Nw - 1; __n >= __wshift; --__n)
273 _M_w[__n] = _M_w[__n - __wshift];
276 const size_t __sub_offset = (_GLIBCXX_BITSET_BITS_PER_WORD
278 for (
size_t __n = _Nw - 1; __n > __wshift; --__n)
279 _M_w[__n] = ((_M_w[__n - __wshift] << __offset)
280 | (_M_w[__n - __wshift - 1] >> __sub_offset));
281 _M_w[__wshift] = _M_w[0] << __offset;
284 std::fill(_M_w + 0, _M_w + __wshift,
static_cast<_WordT
>(0));
289 _GLIBCXX14_CONSTEXPR
void
290 _Base_bitset<_Nw>::_M_do_right_shift(
size_t __shift) _GLIBCXX_NOEXCEPT
292 if (__builtin_expect(__shift != 0, 1))
294 const size_t __wshift = __shift / _GLIBCXX_BITSET_BITS_PER_WORD;
295 const size_t __offset = __shift % _GLIBCXX_BITSET_BITS_PER_WORD;
296 const size_t __limit = _Nw - __wshift - 1;
299 for (
size_t __n = 0; __n <= __limit; ++__n)
300 _M_w[__n] = _M_w[__n + __wshift];
303 const size_t __sub_offset = (_GLIBCXX_BITSET_BITS_PER_WORD
305 for (
size_t __n = 0; __n < __limit; ++__n)
306 _M_w[__n] = ((_M_w[__n + __wshift] >> __offset)
307 | (_M_w[__n + __wshift + 1] << __sub_offset));
308 _M_w[__limit] = _M_w[_Nw-1] >> __offset;
311 std::fill(_M_w + __limit + 1, _M_w + _Nw,
static_cast<_WordT
>(0));
316 _GLIBCXX14_CONSTEXPR
unsigned long
317 _Base_bitset<_Nw>::_M_do_to_ulong()
const
319 for (
size_t __i = 1; __i < _Nw; ++__i)
321 __throw_overflow_error(__N(
"_Base_bitset::_M_do_to_ulong"));
325#if __cplusplus >= 201103L
327 _GLIBCXX14_CONSTEXPR
unsigned long long
328 _Base_bitset<_Nw>::_M_do_to_ullong()
const
330#if __SIZEOF_LONG_LONG__ == __SIZEOF_LONG__
331 return _M_do_to_ulong();
333 for (
size_t __i = 2; __i < _Nw; ++__i)
335 __throw_overflow_error(__N(
"_Base_bitset::_M_do_to_ullong"));
337 return _M_w[0] + (
static_cast<unsigned long long>(_M_w[1])
338 << _GLIBCXX_BITSET_BITS_PER_WORD);
344 _GLIBCXX14_CONSTEXPR
size_t
346 _M_do_find_first(
size_t __not_found)
const _GLIBCXX_NOEXCEPT
348 for (
size_t __i = 0; __i < _Nw; __i++)
350 _WordT __thisword = _M_w[__i];
351 if (__thisword !=
static_cast<_WordT
>(0))
352 return (__i * _GLIBCXX_BITSET_BITS_PER_WORD
353 + __builtin_ctzl(__thisword));
360 _GLIBCXX14_CONSTEXPR
size_t
362 _M_do_find_next(
size_t __prev,
size_t __not_found)
const _GLIBCXX_NOEXCEPT
368 if (__prev >= _Nw * _GLIBCXX_BITSET_BITS_PER_WORD)
372 size_t __i = _S_whichword(__prev);
373 _WordT __thisword = _M_w[__i];
376 __thisword &= (~static_cast<_WordT>(0)) << _S_whichbit(__prev);
378 if (__thisword !=
static_cast<_WordT
>(0))
379 return (__i * _GLIBCXX_BITSET_BITS_PER_WORD
380 + __builtin_ctzl(__thisword));
384 for (; __i < _Nw; __i++)
386 __thisword = _M_w[__i];
387 if (__thisword !=
static_cast<_WordT
>(0))
388 return (__i * _GLIBCXX_BITSET_BITS_PER_WORD
389 + __builtin_ctzl(__thisword));
403 typedef unsigned long _WordT;
410#if __cplusplus >= 201103L
411 constexpr _Base_bitset(
unsigned long long __val)
noexcept
418 static _GLIBCXX_CONSTEXPR
size_t
419 _S_whichword(
size_t __pos) _GLIBCXX_NOEXCEPT
420 {
return __pos / _GLIBCXX_BITSET_BITS_PER_WORD; }
422 static _GLIBCXX_CONSTEXPR
size_t
423 _S_whichbyte(
size_t __pos) _GLIBCXX_NOEXCEPT
424 {
return (__pos % _GLIBCXX_BITSET_BITS_PER_WORD) / __CHAR_BIT__; }
426 static _GLIBCXX_CONSTEXPR
size_t
427 _S_whichbit(
size_t __pos) _GLIBCXX_NOEXCEPT
428 {
return __pos % _GLIBCXX_BITSET_BITS_PER_WORD; }
430 static _GLIBCXX_CONSTEXPR _WordT
431 _S_maskbit(
size_t __pos) _GLIBCXX_NOEXCEPT
432 {
return (
static_cast<_WordT
>(1)) << _S_whichbit(__pos); }
434 _GLIBCXX14_CONSTEXPR _WordT&
435 _M_getword(
size_t) _GLIBCXX_NOEXCEPT
438 _GLIBCXX_CONSTEXPR _WordT
439 _M_getword(
size_t)
const _GLIBCXX_NOEXCEPT
442#if __cplusplus >= 201103L
443 constexpr const _WordT*
444 _M_getdata()
const noexcept
448 _GLIBCXX14_CONSTEXPR _WordT&
449 _M_hiword() _GLIBCXX_NOEXCEPT
452 _GLIBCXX_CONSTEXPR _WordT
453 _M_hiword()
const _GLIBCXX_NOEXCEPT
456 _GLIBCXX14_CONSTEXPR
void
460 _GLIBCXX14_CONSTEXPR
void
464 _GLIBCXX14_CONSTEXPR
void
468 _GLIBCXX14_CONSTEXPR
void
469 _M_do_left_shift(
size_t __shift) _GLIBCXX_NOEXCEPT
470 {
_M_w <<= __shift; }
472 _GLIBCXX14_CONSTEXPR
void
473 _M_do_right_shift(
size_t __shift) _GLIBCXX_NOEXCEPT
474 {
_M_w >>= __shift; }
476 _GLIBCXX14_CONSTEXPR
void
477 _M_do_flip() _GLIBCXX_NOEXCEPT
480 _GLIBCXX14_CONSTEXPR
void
481 _M_do_set() _GLIBCXX_NOEXCEPT
482 {
_M_w = ~static_cast<_WordT>(0); }
484 _GLIBCXX14_CONSTEXPR
void
485 _M_do_reset() _GLIBCXX_NOEXCEPT
488 _GLIBCXX14_CONSTEXPR
bool
493 _GLIBCXX14_CONSTEXPR
bool
494 _M_are_all()
const _GLIBCXX_NOEXCEPT
495 {
return _M_w == (~static_cast<_WordT>(0)
496 >> (_GLIBCXX_BITSET_BITS_PER_WORD - _Nb)); }
498 _GLIBCXX14_CONSTEXPR
bool
499 _M_is_any()
const _GLIBCXX_NOEXCEPT
500 {
return _M_w != 0; }
502 _GLIBCXX14_CONSTEXPR
size_t
503 _M_do_count()
const _GLIBCXX_NOEXCEPT
504 {
return __builtin_popcountl(
_M_w); }
506 _GLIBCXX14_CONSTEXPR
unsigned long
507 _M_do_to_ulong()
const _GLIBCXX_NOEXCEPT
510#if __cplusplus >= 201103L
511 constexpr unsigned long long
512 _M_do_to_ullong()
const noexcept
516 _GLIBCXX14_CONSTEXPR
size_t
517 _M_do_find_first(
size_t __not_found)
const _GLIBCXX_NOEXCEPT
520 return __builtin_ctzl(
_M_w);
526 _GLIBCXX14_CONSTEXPR
size_t
527 _M_do_find_next(
size_t __prev,
size_t __not_found)
const
531 if (__prev >= ((
size_t) _GLIBCXX_BITSET_BITS_PER_WORD))
534 _WordT __x =
_M_w >> __prev;
536 return __builtin_ctzl(__x) + __prev;
550 typedef unsigned long _WordT;
555#if __cplusplus >= 201103L
562 static _GLIBCXX_CONSTEXPR
size_t
563 _S_whichword(
size_t __pos) _GLIBCXX_NOEXCEPT
564 {
return __pos / _GLIBCXX_BITSET_BITS_PER_WORD; }
566 static _GLIBCXX_CONSTEXPR
size_t
567 _S_whichbyte(
size_t __pos) _GLIBCXX_NOEXCEPT
568 {
return (__pos % _GLIBCXX_BITSET_BITS_PER_WORD) / __CHAR_BIT__; }
570 static _GLIBCXX_CONSTEXPR
size_t
571 _S_whichbit(
size_t __pos) _GLIBCXX_NOEXCEPT
572 {
return __pos % _GLIBCXX_BITSET_BITS_PER_WORD; }
574 static _GLIBCXX_CONSTEXPR _WordT
575 _S_maskbit(
size_t __pos) _GLIBCXX_NOEXCEPT
576 {
return (
static_cast<_WordT
>(1)) << _S_whichbit(__pos); }
584 __attribute__((__noreturn__))
586 _M_getword(
size_t) _GLIBCXX_NOEXCEPT
587 { __throw_out_of_range(__N(
"_Base_bitset::_M_getword")); }
589 _GLIBCXX_CONSTEXPR _WordT
590 _M_getword(
size_t)
const _GLIBCXX_NOEXCEPT
593 _GLIBCXX_CONSTEXPR _WordT
594 _M_hiword()
const _GLIBCXX_NOEXCEPT
597 _GLIBCXX14_CONSTEXPR
void
601 _GLIBCXX14_CONSTEXPR
void
605 _GLIBCXX14_CONSTEXPR
void
609 _GLIBCXX14_CONSTEXPR
void
610 _M_do_left_shift(
size_t) _GLIBCXX_NOEXCEPT
613 _GLIBCXX14_CONSTEXPR
void
614 _M_do_right_shift(
size_t) _GLIBCXX_NOEXCEPT
617 _GLIBCXX14_CONSTEXPR
void
618 _M_do_flip() _GLIBCXX_NOEXCEPT
621 _GLIBCXX14_CONSTEXPR
void
622 _M_do_set() _GLIBCXX_NOEXCEPT
625 _GLIBCXX14_CONSTEXPR
void
626 _M_do_reset() _GLIBCXX_NOEXCEPT
632 _GLIBCXX_CONSTEXPR
bool
637 _GLIBCXX_CONSTEXPR
bool
638 _M_are_all()
const _GLIBCXX_NOEXCEPT
641 _GLIBCXX_CONSTEXPR
bool
642 _M_is_any()
const _GLIBCXX_NOEXCEPT
645 _GLIBCXX_CONSTEXPR
size_t
646 _M_do_count()
const _GLIBCXX_NOEXCEPT
649 _GLIBCXX_CONSTEXPR
unsigned long
650 _M_do_to_ulong()
const _GLIBCXX_NOEXCEPT
653#if __cplusplus >= 201103L
654 constexpr unsigned long long
655 _M_do_to_ullong()
const noexcept
661 _GLIBCXX_CONSTEXPR
size_t
662 _M_do_find_first(
size_t)
const _GLIBCXX_NOEXCEPT
665 _GLIBCXX_CONSTEXPR
size_t
666 _M_do_find_next(
size_t,
size_t)
const _GLIBCXX_NOEXCEPT
672 template<
size_t _Extrabits>
675 typedef unsigned long _WordT;
677 static _GLIBCXX14_CONSTEXPR
void
678 _S_do_sanitize(_WordT& __val) _GLIBCXX_NOEXCEPT
679 { __val &= ~((~static_cast<_WordT>(0)) << _Extrabits); }
685 typedef unsigned long _WordT;
687 static _GLIBCXX14_CONSTEXPR
void
688 _S_do_sanitize(_WordT) _GLIBCXX_NOEXCEPT { }
691#if __cplusplus >= 201103L
692 template<
size_t _Nb,
bool = (_Nb < _GLIBCXX_BITSET_BITS_PER_ULL)>
695 static constexpr
unsigned long long
696 _S_do_sanitize_val(
unsigned long long __val)
701 struct _Sanitize_val<_Nb, true>
703 static constexpr unsigned long long
704 _S_do_sanitize_val(
unsigned long long __val)
705 {
return __val & ~((~static_cast<unsigned long long>(0)) << _Nb); }
711 template<
typename _CharT>
714 template<
typename _CharT>
717 using size_type = size_t;
718 static constexpr size_type npos = size_type(-1);
722 static _GLIBCXX14_CONSTEXPR
size_t
723 length(
const _CharT* __s)
noexcept
731 static constexpr bool
732 eq(_CharT __l, _CharT __r)
noexcept
733 {
return __l == __r; }
809 typedef unsigned long _WordT;
812 template<
class _CharT,
class _Traits,
class _Alloc>
816 size_t __position)
const
818 if (__position > __s.
size())
819 __throw_out_of_range_fmt(__N(
"bitset::bitset: __position "
820 "(which is %zu) > __s.size() "
822 __position, __s.
size());
827 void _M_check(
size_t __position,
const char *__s)
const
829 if (__position >= _Nb)
830 __throw_out_of_range_fmt(__N(
"%s: __position (which is %zu) "
831 ">= _Nb (which is %zu)"),
832 __s, __position, _Nb);
837 _M_do_sanitize() _GLIBCXX_NOEXCEPT
839 typedef _Sanitize<_Nb % _GLIBCXX_BITSET_BITS_PER_WORD> __sanitize_type;
840 __sanitize_type::_S_do_sanitize(this->_M_hiword());
843#if __cplusplus >= 201103L
874 _M_wp = &__b._M_getword(__pos);
875 _M_bpos = _Base::_S_whichbit(__pos);
878#if __cplusplus >= 201103L
882#if __cplusplus > 202002L && __cpp_constexpr_dynamic_alloc
891 operator=(
bool __x) _GLIBCXX_NOEXCEPT
894 *_M_wp |= _Base::_S_maskbit(_M_bpos);
896 *_M_wp &=
~_Base::_S_maskbit(_M_bpos);
903 operator=(
const reference& __j) _GLIBCXX_NOEXCEPT
905 if ((*(__j._M_wp) & _Base::_S_maskbit(__j._M_bpos)))
906 *_M_wp |= _Base::_S_maskbit(_M_bpos);
908 *_M_wp &=
~_Base::_S_maskbit(_M_bpos);
915 operator~()
const _GLIBCXX_NOEXCEPT
916 {
return (*(_M_wp) & _Base::_S_maskbit(_M_bpos)) == 0; }
920 operator bool()
const _GLIBCXX_NOEXCEPT
921 {
return (*(_M_wp) & _Base::_S_maskbit(_M_bpos)) != 0; }
926 flip() _GLIBCXX_NOEXCEPT
928 *_M_wp ^= _Base::_S_maskbit(_M_bpos);
936 _GLIBCXX_CONSTEXPR
bitset() _GLIBCXX_NOEXCEPT
940#if __cplusplus >= 201103L
941 constexpr bitset(
unsigned long long __val) noexcept
942 :
_Base(_Sanitize_val<_Nb>::_S_do_sanitize_val(__val)) { }
944 bitset(
unsigned long __val)
946 { _M_do_sanitize(); }
959 template<
class _CharT,
class _Traits,
class _Alloc>
963 size_t __position = 0)
966 _M_check_initial_position(__s, __position);
967 _M_copy_from_string(__s, __position,
969 _CharT(
'0'), _CharT(
'1'));
982 template<
class _CharT,
class _Traits,
class _Alloc>
985 size_t __position,
size_t __n)
988 _M_check_initial_position(__s, __position);
989 _M_copy_from_string(__s, __position, __n, _CharT(
'0'), _CharT(
'1'));
994 template<
class _CharT,
class _Traits,
class _Alloc>
997 size_t __position,
size_t __n,
998 _CharT __zero, _CharT __one = _CharT(
'1'))
1001 _M_check_initial_position(__s, __position);
1002 _M_copy_from_string(__s, __position, __n, __zero, __one);
1006#if __cplusplus >= 201103L
1016 template<
typename _CharT>
1017 [[__gnu__::__nonnull__]]
1018 _GLIBCXX23_CONSTEXPR
1021 typename __bitset::__string<_CharT>::size_type __n
1023 _CharT __zero = _CharT(
'0'), _CharT __one = _CharT(
'1'))
1028 __throw_logic_error(__N(
"bitset::bitset(const _CharT*, ...)"));
1030 using _Traits =
typename __bitset::__string<_CharT>::traits_type;
1033 __n = _Traits::length(__str);
1034 _M_copy_from_ptr<_CharT, _Traits>(__str, __n, 0, __n, __zero, __one);
1046 _GLIBCXX23_CONSTEXPR
1050 this->_M_do_and(__rhs);
1054 _GLIBCXX23_CONSTEXPR
1058 this->_M_do_or(__rhs);
1062 _GLIBCXX23_CONSTEXPR
1066 this->_M_do_xor(__rhs);
1078 _GLIBCXX23_CONSTEXPR
1080 operator<<=(
size_t __position) _GLIBCXX_NOEXCEPT
1082 if (__builtin_expect(__position < _Nb, 1))
1084 this->_M_do_left_shift(__position);
1085 this->_M_do_sanitize();
1088 this->_M_do_reset();
1092 _GLIBCXX23_CONSTEXPR
1096 if (__builtin_expect(__position < _Nb, 1))
1097 this->_M_do_right_shift(__position);
1099 this->_M_do_reset();
1110 _GLIBCXX23_CONSTEXPR
1114 this->_M_getword(__pos) |= _Base::_S_maskbit(__pos);
1118 _GLIBCXX23_CONSTEXPR
1123 this->_M_getword(__pos) |= _Base::_S_maskbit(__pos);
1125 this->_M_getword(__pos) &=
~_Base::_S_maskbit(__pos);
1129 _GLIBCXX23_CONSTEXPR
1133 this->_M_getword(__pos) &=
~_Base::_S_maskbit(__pos);
1137 _GLIBCXX23_CONSTEXPR
1141 this->_M_getword(__pos) ^= _Base::_S_maskbit(__pos);
1145 _GLIBCXX_CONSTEXPR
bool
1147 {
return ((this->_M_getword(__pos) & _Base::_S_maskbit(__pos))
1148 !=
static_cast<_WordT
>(0)); }
1155 _GLIBCXX23_CONSTEXPR
1160 this->_M_do_sanitize();
1170 _GLIBCXX23_CONSTEXPR
1172 set(
size_t __position,
bool __val =
true)
1174 this->_M_check(__position, __N(
"bitset::set"));
1175 return _Unchecked_set(__position, __val);
1181 _GLIBCXX23_CONSTEXPR
1185 this->_M_do_reset();
1196 _GLIBCXX23_CONSTEXPR
1200 this->_M_check(__position, __N(
"bitset::reset"));
1201 return _Unchecked_reset(__position);
1207 _GLIBCXX23_CONSTEXPR
1212 this->_M_do_sanitize();
1221 _GLIBCXX23_CONSTEXPR
1225 this->_M_check(__position, __N(
"bitset::flip"));
1226 return _Unchecked_flip(__position);
1230 _GLIBCXX23_CONSTEXPR
1250 _GLIBCXX23_CONSTEXPR
1253 {
return reference(*
this, __position); }
1255 _GLIBCXX_CONSTEXPR
bool
1257 {
return _Unchecked_test(__position); }
1266 _GLIBCXX23_CONSTEXPR
1269 {
return this->_M_do_to_ulong(); }
1271#if __cplusplus >= 201103L
1272 _GLIBCXX23_CONSTEXPR
1275 {
return this->_M_do_to_ullong(); }
1287 template<
class _CharT,
class _Traits,
class _Alloc>
1288 _GLIBCXX23_CONSTEXPR
1293 _M_copy_to_string(__result, _CharT(
'0'), _CharT(
'1'));
1299 template<
class _CharT,
class _Traits,
class _Alloc>
1300 _GLIBCXX23_CONSTEXPR
1302 to_string(_CharT __zero, _CharT __one = _CharT(
'1'))
const
1305 _M_copy_to_string(__result, __zero, __one);
1311 template<
class _CharT,
class _Traits>
1312 _GLIBCXX23_CONSTEXPR
1315 {
return to_string<_CharT, _Traits, std::allocator<_CharT> >(); }
1319 template<
class _CharT,
class _Traits>
1320 _GLIBCXX23_CONSTEXPR
1322 to_string(_CharT __zero, _CharT __one = _CharT(
'1'))
const
1323 {
return to_string<_CharT, _Traits,
1326 template<
class _CharT>
1327 _GLIBCXX23_CONSTEXPR
1332 return to_string<_CharT, std::char_traits<_CharT>,
1336 template<
class _CharT>
1337 _GLIBCXX23_CONSTEXPR
1340 to_string(_CharT __zero, _CharT __one = _CharT(
'1'))
const
1342 return to_string<_CharT, std::char_traits<_CharT>,
1346 _GLIBCXX23_CONSTEXPR
1350 return to_string<char, std::char_traits<char>,
1354 _GLIBCXX23_CONSTEXPR
1356 to_string(
char __zero,
char __one =
'1')
const
1358 return to_string<char, std::char_traits<char>,
1364 _GLIBCXX23_CONSTEXPR
1367 {
return this->_M_do_count(); }
1370 _GLIBCXX_CONSTEXPR
size_t
1376 _GLIBCXX23_CONSTEXPR
1379 {
return this->_M_is_equal(__rhs); }
1381#if __cpp_impl_three_way_comparison < 201907L
1382 _GLIBCXX23_CONSTEXPR
1384 operator!=(
const bitset<_Nb>& __rhs)
const _GLIBCXX_NOEXCEPT
1385 {
return !this->_M_is_equal(__rhs); }
1395 _GLIBCXX23_CONSTEXPR
1399 this->_M_check(__position, __N(
"bitset::test"));
1400 return _Unchecked_test(__position);
1409 _GLIBCXX23_CONSTEXPR
1412 {
return this->
template _M_are_all<_Nb>(); }
1418 _GLIBCXX23_CONSTEXPR
1421 {
return this->_M_is_any(); }
1427 _GLIBCXX23_CONSTEXPR
1430 {
return !this->_M_is_any(); }
1434 _GLIBCXX23_CONSTEXPR
1436 operator<<(
size_t __position)
const _GLIBCXX_NOEXCEPT
1439 _GLIBCXX23_CONSTEXPR
1451 _GLIBCXX23_CONSTEXPR
1454 {
return this->_M_do_find_first(_Nb); }
1463 _GLIBCXX23_CONSTEXPR
1466 {
return this->_M_do_find_next(__prev, _Nb); }
1470 template<
class _CharT,
class _Traits>
1471 _GLIBCXX23_CONSTEXPR
1473 _M_copy_from_ptr(
const _CharT*,
size_t,
size_t,
size_t,
1477 template<
class _CharT,
class _Traits,
class _Alloc>
1478 _GLIBCXX23_CONSTEXPR
1481 _Traits, _Alloc>& __s,
size_t __pos,
size_t __n,
1482 _CharT __zero, _CharT __one)
1483 { _M_copy_from_ptr<_CharT, _Traits>(__s.
data(), __s.
size(), __pos, __n,
1486 template<
class _CharT,
class _Traits,
class _Alloc>
1487 _GLIBCXX23_CONSTEXPR
1490 _CharT, _CharT)
const;
1492 template<
class _CharT,
class _Traits,
size_t _Nb2>
1496 template <
class _CharT,
class _Traits,
size_t _Nb2>
1503 template<
size_t _Nb>
1504 template<
class _CharT,
class _Traits>
1505 _GLIBCXX23_CONSTEXPR
1508 _M_copy_from_ptr(
const _CharT* __s,
size_t __len,
1509 size_t __pos,
size_t __n, _CharT __zero, _CharT __one)
1512 const size_t __nbits =
std::min(_Nb,
std::min(__n,
size_t(__len - __pos)));
1513 for (
size_t __i = __nbits; __i > 0; --__i)
1515 const _CharT __c = __s[__pos + __nbits - __i];
1516 if (_Traits::eq(__c, __zero))
1518 else if (_Traits::eq(__c, __one))
1519 _Unchecked_set(__i - 1);
1521 __throw_invalid_argument(__N(
"bitset::_M_copy_from_ptr"));
1526 template<
size_t _Nb>
1527 template<
class _CharT,
class _Traits,
class _Alloc>
1528 _GLIBCXX23_CONSTEXPR
1532 _CharT __zero, _CharT __one)
const
1535 size_t __n = this->_Find_first();
1538 __s[_Nb - __n - 1] = __one;
1539 __n = _Find_next(__n);
1554 template<
size_t _Nb>
1555 _GLIBCXX23_CONSTEXPR
1564 template<
size_t _Nb>
1565 _GLIBCXX23_CONSTEXPR
1574 template <
size_t _Nb>
1575 _GLIBCXX23_CONSTEXPR
1595 template<
class _CharT,
class _Traits,
size_t _Nb>
1599 typedef typename _Traits::char_type char_type;
1601 typedef typename __istream_type::ios_base __ios_base;
1605 static _GLIBCXX_CONSTEXPR
bool _S_use_alloca() {
return _Nb <= 256; }
1607 explicit _Buffer(_CharT* __p) : _M_ptr(__p) { }
1611 if _GLIBCXX17_CONSTEXPR (!_S_use_alloca())
1615 _CharT*
const _M_ptr;
1618 if _GLIBCXX17_CONSTEXPR (_Buffer::_S_use_alloca())
1619 __ptr = (_CharT*)__builtin_alloca(_Nb);
1621 __ptr =
new _CharT[_Nb];
1622 const _Buffer __buf(__ptr);
1626 const char_type __zero = __is.
widen(
'0');
1627 const char_type __one = __is.
widen(
'1');
1629 typename __ios_base::iostate __state = __ios_base::goodbit;
1630 typename __istream_type::sentry __sentry(__is);
1635 for (
size_t __i = _Nb; __i > 0; --__i)
1637 static typename _Traits::int_type __eof = _Traits::eof();
1639 typename _Traits::int_type __c1 = __is.
rdbuf()->sbumpc();
1640 if (_Traits::eq_int_type(__c1, __eof))
1642 __state |= __ios_base::eofbit;
1647 const char_type __c2 = _Traits::to_char_type(__c1);
1648 if (_Traits::eq(__c2, __zero))
1650 else if (_Traits::eq(__c2, __one))
1653 eq_int_type(__is.
rdbuf()->sputbackc(__c2),
1656 __state |= __ios_base::failbit;
1664 __is._M_setstate(__ios_base::badbit);
1665 __throw_exception_again;
1668 { __is._M_setstate(__ios_base::badbit); }
1671 if _GLIBCXX17_CONSTEXPR (_Nb)
1673 if (
size_t __len = __ptr - __buf._M_ptr)
1674 __x.template _M_copy_from_ptr<_CharT, _Traits>(__buf._M_ptr, __len,
1678 __state |= __ios_base::failbit;
1685 template <
class _CharT,
class _Traits,
size_t _Nb>
1688 const bitset<_Nb>& __x)
1694 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__os.
getloc());
1695 __x._M_copy_to_string(__tmp, __ct.widen(
'0'), __ct.widen(
'1'));
1696 return __os << __tmp;
1701_GLIBCXX_END_NAMESPACE_CONTAINER
1704#undef _GLIBCXX_BITSET_WORDS
1705#undef _GLIBCXX_BITSET_BITS_PER_WORD
1706#undef _GLIBCXX_BITSET_BITS_PER_ULL
1708#if __cplusplus >= 201103L
1710namespace std _GLIBCXX_VISIBILITY(default)
1712_GLIBCXX_BEGIN_NAMESPACE_VERSION
1716 template<
size_t _Nb>
1718 :
public __hash_base<size_t, _GLIBCXX_STD_C::bitset<_Nb>>
1721 operator()(
const _GLIBCXX_STD_C::bitset<_Nb>& __b)
const noexcept
1723 const size_t __clength = (_Nb + __CHAR_BIT__ - 1) / __CHAR_BIT__;
1724 return std::_Hash_impl::hash(__b._M_getdata(), __clength);
1730 :
public __hash_base<size_t, _GLIBCXX_STD_C::bitset<0>>
1733 operator()(
const _GLIBCXX_STD_C::bitset<0>&)
const noexcept
1737_GLIBCXX_END_NAMESPACE_VERSION
1742#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.