42#ifndef _GLIBCXX_BITSET
43#define _GLIBCXX_BITSET 1
45#pragma GCC system_header
57#if __cplusplus >= 201103L
61#define _GLIBCXX_BITSET_BITS_PER_WORD (__CHAR_BIT__ * __SIZEOF_LONG__)
62#define _GLIBCXX_BITSET_WORDS(__n) \
63 ((__n) / _GLIBCXX_BITSET_BITS_PER_WORD + \
64 ((__n) % _GLIBCXX_BITSET_BITS_PER_WORD == 0 ? 0 : 1))
66#define _GLIBCXX_BITSET_BITS_PER_ULL (__CHAR_BIT__ * __SIZEOF_LONG_LONG__)
68namespace std _GLIBCXX_VISIBILITY(default)
70_GLIBCXX_BEGIN_NAMESPACE_CONTAINER
72#if __cplusplus > 202002L && _GLIBCXX_HOSTED
73# define __cpp_lib_constexpr_bitset 202202L
85 typedef unsigned long _WordT;
93#if __cplusplus >= 201103L
94 constexpr _Base_bitset(
unsigned long long __val) noexcept
96#if __SIZEOF_LONG_LONG__ > __SIZEOF_LONG__
97 , _WordT(__val >> _GLIBCXX_BITSET_BITS_PER_WORD)
101 _Base_bitset(
unsigned long __val)
106 static _GLIBCXX_CONSTEXPR
size_t
107 _S_whichword(
size_t __pos) _GLIBCXX_NOEXCEPT
108 {
return __pos / _GLIBCXX_BITSET_BITS_PER_WORD; }
110 static _GLIBCXX_CONSTEXPR
size_t
111 _S_whichbyte(
size_t __pos) _GLIBCXX_NOEXCEPT
112 {
return (__pos % _GLIBCXX_BITSET_BITS_PER_WORD) / __CHAR_BIT__; }
114 static _GLIBCXX_CONSTEXPR
size_t
115 _S_whichbit(
size_t __pos) _GLIBCXX_NOEXCEPT
116 {
return __pos % _GLIBCXX_BITSET_BITS_PER_WORD; }
118 static _GLIBCXX_CONSTEXPR _WordT
119 _S_maskbit(
size_t __pos) _GLIBCXX_NOEXCEPT
120 {
return (
static_cast<_WordT
>(1)) << _S_whichbit(__pos); }
122 _GLIBCXX14_CONSTEXPR _WordT&
123 _M_getword(
size_t __pos) _GLIBCXX_NOEXCEPT
124 {
return _M_w[_S_whichword(__pos)]; }
126 _GLIBCXX_CONSTEXPR _WordT
127 _M_getword(
size_t __pos)
const _GLIBCXX_NOEXCEPT
128 {
return _M_w[_S_whichword(__pos)]; }
130#if __cplusplus >= 201103L
131 constexpr const _WordT*
132 _M_getdata() const noexcept
136 _GLIBCXX23_CONSTEXPR _WordT&
137 _M_hiword() _GLIBCXX_NOEXCEPT
138 {
return _M_w[_Nw - 1]; }
140 _GLIBCXX_CONSTEXPR _WordT
141 _M_hiword() const _GLIBCXX_NOEXCEPT
142 {
return _M_w[_Nw - 1]; }
144 _GLIBCXX23_CONSTEXPR
void
145 _M_do_and(
const _Base_bitset<_Nw>& __x) _GLIBCXX_NOEXCEPT
147 for (
size_t __i = 0; __i < _Nw; __i++)
148 _M_w[__i] &= __x._M_w[__i];
151 _GLIBCXX14_CONSTEXPR
void
152 _M_do_or(
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_xor(
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_left_shift(
size_t __shift) _GLIBCXX_NOEXCEPT;
168 _GLIBCXX14_CONSTEXPR
void
169 _M_do_right_shift(
size_t __shift) _GLIBCXX_NOEXCEPT;
171 _GLIBCXX14_CONSTEXPR
void
172 _M_do_flip() _GLIBCXX_NOEXCEPT
174 for (
size_t __i = 0; __i < _Nw; __i++)
178 _GLIBCXX14_CONSTEXPR
void
179 _M_do_set() _GLIBCXX_NOEXCEPT
181 for (
size_t __i = 0; __i < _Nw; __i++)
182 _M_w[__i] = ~
static_cast<_WordT
>(0);
185 _GLIBCXX14_CONSTEXPR
void
186 _M_do_reset() _GLIBCXX_NOEXCEPT
188#if __cplusplus >= 201402L
189 if (__builtin_is_constant_evaluated())
191 for (_WordT& __w :
_M_w)
196 __builtin_memset(
_M_w, 0, _Nw *
sizeof(_WordT));
199 _GLIBCXX14_CONSTEXPR
bool
200 _M_is_equal(
const _Base_bitset<_Nw>& __x)
const _GLIBCXX_NOEXCEPT
202 for (
size_t __i = 0; __i < _Nw; ++__i)
203 if (
_M_w[__i] != __x._M_w[__i])
209 _GLIBCXX14_CONSTEXPR
bool
210 _M_are_all() const _GLIBCXX_NOEXCEPT
212 for (
size_t __i = 0; __i < _Nw - 1; __i++)
213 if (
_M_w[__i] != ~
static_cast<_WordT
>(0))
215 return _M_hiword() == (~static_cast<_WordT>(0)
216 >> (_Nw * _GLIBCXX_BITSET_BITS_PER_WORD
220 _GLIBCXX14_CONSTEXPR
bool
221 _M_is_any() const _GLIBCXX_NOEXCEPT
223 for (
size_t __i = 0; __i < _Nw; __i++)
224 if (
_M_w[__i] !=
static_cast<_WordT
>(0))
229 _GLIBCXX14_CONSTEXPR
size_t
230 _M_do_count() const _GLIBCXX_NOEXCEPT
233 for (
size_t __i = 0; __i < _Nw; __i++)
234 __result += __builtin_popcountl(
_M_w[__i]);
238 _GLIBCXX14_CONSTEXPR
unsigned long
239 _M_do_to_ulong()
const;
241#if __cplusplus >= 201103L
242 _GLIBCXX14_CONSTEXPR
unsigned long long
243 _M_do_to_ullong()
const;
247 _GLIBCXX14_CONSTEXPR
size_t
248 _M_do_find_first(
size_t)
const _GLIBCXX_NOEXCEPT;
251 _GLIBCXX14_CONSTEXPR
size_t
252 _M_do_find_next(
size_t,
size_t)
const _GLIBCXX_NOEXCEPT;
257 _GLIBCXX14_CONSTEXPR
void
258 _Base_bitset<_Nw>::_M_do_left_shift(
size_t __shift) _GLIBCXX_NOEXCEPT
260 if (__builtin_expect(__shift != 0, 1))
262 const size_t __wshift = __shift / _GLIBCXX_BITSET_BITS_PER_WORD;
263 const size_t __offset = __shift % _GLIBCXX_BITSET_BITS_PER_WORD;
266 for (
size_t __n = _Nw - 1; __n >= __wshift; --__n)
267 _M_w[__n] = _M_w[__n - __wshift];
270 const size_t __sub_offset = (_GLIBCXX_BITSET_BITS_PER_WORD
272 for (
size_t __n = _Nw - 1; __n > __wshift; --__n)
273 _M_w[__n] = ((_M_w[__n - __wshift] << __offset)
274 | (_M_w[__n - __wshift - 1] >> __sub_offset));
275 _M_w[__wshift] = _M_w[0] << __offset;
278 std::fill(_M_w + 0, _M_w + __wshift,
static_cast<_WordT
>(0));
283 _GLIBCXX14_CONSTEXPR
void
284 _Base_bitset<_Nw>::_M_do_right_shift(
size_t __shift) _GLIBCXX_NOEXCEPT
286 if (__builtin_expect(__shift != 0, 1))
288 const size_t __wshift = __shift / _GLIBCXX_BITSET_BITS_PER_WORD;
289 const size_t __offset = __shift % _GLIBCXX_BITSET_BITS_PER_WORD;
290 const size_t __limit = _Nw - __wshift - 1;
293 for (
size_t __n = 0; __n <= __limit; ++__n)
294 _M_w[__n] = _M_w[__n + __wshift];
297 const size_t __sub_offset = (_GLIBCXX_BITSET_BITS_PER_WORD
299 for (
size_t __n = 0; __n < __limit; ++__n)
300 _M_w[__n] = ((_M_w[__n + __wshift] >> __offset)
301 | (_M_w[__n + __wshift + 1] << __sub_offset));
302 _M_w[__limit] = _M_w[_Nw-1] >> __offset;
305 std::fill(_M_w + __limit + 1, _M_w + _Nw,
static_cast<_WordT
>(0));
310 _GLIBCXX14_CONSTEXPR
unsigned long
311 _Base_bitset<_Nw>::_M_do_to_ulong()
const
313 for (
size_t __i = 1; __i < _Nw; ++__i)
315 __throw_overflow_error(__N(
"_Base_bitset::_M_do_to_ulong"));
319#if __cplusplus >= 201103L
321 _GLIBCXX14_CONSTEXPR
unsigned long long
322 _Base_bitset<_Nw>::_M_do_to_ullong()
const
324 const bool __dw =
sizeof(
unsigned long long) >
sizeof(
unsigned long);
325 for (
size_t __i = 1 + __dw; __i < _Nw; ++__i)
327 __throw_overflow_error(__N(
"_Base_bitset::_M_do_to_ullong"));
330 return _M_w[0] + (
static_cast<unsigned long long>(_M_w[1])
331 << _GLIBCXX_BITSET_BITS_PER_WORD);
337 _GLIBCXX14_CONSTEXPR
size_t
339 _M_do_find_first(
size_t __not_found)
const _GLIBCXX_NOEXCEPT
341 for (
size_t __i = 0; __i < _Nw; __i++)
343 _WordT __thisword = _M_w[__i];
344 if (__thisword !=
static_cast<_WordT
>(0))
345 return (__i * _GLIBCXX_BITSET_BITS_PER_WORD
346 + __builtin_ctzl(__thisword));
353 _GLIBCXX14_CONSTEXPR
size_t
355 _M_do_find_next(
size_t __prev,
size_t __not_found)
const _GLIBCXX_NOEXCEPT
361 if (__prev >= _Nw * _GLIBCXX_BITSET_BITS_PER_WORD)
365 size_t __i = _S_whichword(__prev);
366 _WordT __thisword = _M_w[__i];
369 __thisword &= (~static_cast<_WordT>(0)) << _S_whichbit(__prev);
371 if (__thisword !=
static_cast<_WordT
>(0))
372 return (__i * _GLIBCXX_BITSET_BITS_PER_WORD
373 + __builtin_ctzl(__thisword));
377 for (; __i < _Nw; __i++)
379 __thisword = _M_w[__i];
380 if (__thisword !=
static_cast<_WordT
>(0))
381 return (__i * _GLIBCXX_BITSET_BITS_PER_WORD
382 + __builtin_ctzl(__thisword));
396 typedef unsigned long _WordT;
403#if __cplusplus >= 201103L
404 constexpr _Base_bitset(
unsigned long long __val)
noexcept
411 static _GLIBCXX_CONSTEXPR
size_t
412 _S_whichword(
size_t __pos) _GLIBCXX_NOEXCEPT
413 {
return __pos / _GLIBCXX_BITSET_BITS_PER_WORD; }
415 static _GLIBCXX_CONSTEXPR
size_t
416 _S_whichbyte(
size_t __pos) _GLIBCXX_NOEXCEPT
417 {
return (__pos % _GLIBCXX_BITSET_BITS_PER_WORD) / __CHAR_BIT__; }
419 static _GLIBCXX_CONSTEXPR
size_t
420 _S_whichbit(
size_t __pos) _GLIBCXX_NOEXCEPT
421 {
return __pos % _GLIBCXX_BITSET_BITS_PER_WORD; }
423 static _GLIBCXX_CONSTEXPR _WordT
424 _S_maskbit(
size_t __pos) _GLIBCXX_NOEXCEPT
425 {
return (
static_cast<_WordT
>(1)) << _S_whichbit(__pos); }
427 _GLIBCXX14_CONSTEXPR _WordT&
428 _M_getword(
size_t) _GLIBCXX_NOEXCEPT
431 _GLIBCXX_CONSTEXPR _WordT
432 _M_getword(
size_t)
const _GLIBCXX_NOEXCEPT
435#if __cplusplus >= 201103L
436 constexpr const _WordT*
437 _M_getdata()
const noexcept
441 _GLIBCXX14_CONSTEXPR _WordT&
442 _M_hiword() _GLIBCXX_NOEXCEPT
445 _GLIBCXX_CONSTEXPR _WordT
446 _M_hiword()
const _GLIBCXX_NOEXCEPT
449 _GLIBCXX14_CONSTEXPR
void
451 {
_M_w &= __x._M_w; }
453 _GLIBCXX14_CONSTEXPR
void
455 {
_M_w |= __x._M_w; }
457 _GLIBCXX14_CONSTEXPR
void
459 {
_M_w ^= __x._M_w; }
461 _GLIBCXX14_CONSTEXPR
void
462 _M_do_left_shift(
size_t __shift) _GLIBCXX_NOEXCEPT
463 {
_M_w <<= __shift; }
465 _GLIBCXX14_CONSTEXPR
void
466 _M_do_right_shift(
size_t __shift) _GLIBCXX_NOEXCEPT
467 {
_M_w >>= __shift; }
469 _GLIBCXX14_CONSTEXPR
void
470 _M_do_flip() _GLIBCXX_NOEXCEPT
473 _GLIBCXX14_CONSTEXPR
void
474 _M_do_set() _GLIBCXX_NOEXCEPT
475 {
_M_w = ~static_cast<_WordT>(0); }
477 _GLIBCXX14_CONSTEXPR
void
478 _M_do_reset() _GLIBCXX_NOEXCEPT
481 _GLIBCXX14_CONSTEXPR
bool
483 {
return _M_w == __x._M_w; }
486 _GLIBCXX14_CONSTEXPR
bool
487 _M_are_all()
const _GLIBCXX_NOEXCEPT
488 {
return _M_w == (~static_cast<_WordT>(0)
489 >> (_GLIBCXX_BITSET_BITS_PER_WORD - _Nb)); }
491 _GLIBCXX14_CONSTEXPR
bool
492 _M_is_any()
const _GLIBCXX_NOEXCEPT
493 {
return _M_w != 0; }
495 _GLIBCXX14_CONSTEXPR
size_t
496 _M_do_count()
const _GLIBCXX_NOEXCEPT
497 {
return __builtin_popcountl(
_M_w); }
499 _GLIBCXX14_CONSTEXPR
unsigned long
500 _M_do_to_ulong()
const _GLIBCXX_NOEXCEPT
503#if __cplusplus >= 201103L
504 constexpr unsigned long long
505 _M_do_to_ullong()
const noexcept
509 _GLIBCXX14_CONSTEXPR
size_t
510 _M_do_find_first(
size_t __not_found)
const _GLIBCXX_NOEXCEPT
513 return __builtin_ctzl(
_M_w);
519 _GLIBCXX14_CONSTEXPR
size_t
520 _M_do_find_next(
size_t __prev,
size_t __not_found)
const
524 if (__prev >= ((
size_t) _GLIBCXX_BITSET_BITS_PER_WORD))
527 _WordT __x =
_M_w >> __prev;
529 return __builtin_ctzl(__x) + __prev;
543 typedef unsigned long _WordT;
548#if __cplusplus >= 201103L
555 static _GLIBCXX_CONSTEXPR
size_t
556 _S_whichword(
size_t __pos) _GLIBCXX_NOEXCEPT
557 {
return __pos / _GLIBCXX_BITSET_BITS_PER_WORD; }
559 static _GLIBCXX_CONSTEXPR
size_t
560 _S_whichbyte(
size_t __pos) _GLIBCXX_NOEXCEPT
561 {
return (__pos % _GLIBCXX_BITSET_BITS_PER_WORD) / __CHAR_BIT__; }
563 static _GLIBCXX_CONSTEXPR
size_t
564 _S_whichbit(
size_t __pos) _GLIBCXX_NOEXCEPT
565 {
return __pos % _GLIBCXX_BITSET_BITS_PER_WORD; }
567 static _GLIBCXX_CONSTEXPR _WordT
568 _S_maskbit(
size_t __pos) _GLIBCXX_NOEXCEPT
569 {
return (
static_cast<_WordT
>(1)) << _S_whichbit(__pos); }
577 __attribute__((__noreturn__))
579 _M_getword(
size_t) _GLIBCXX_NOEXCEPT
580 { __throw_out_of_range(__N(
"_Base_bitset::_M_getword")); }
582 _GLIBCXX_CONSTEXPR _WordT
583 _M_getword(
size_t)
const _GLIBCXX_NOEXCEPT
586 _GLIBCXX_CONSTEXPR _WordT
587 _M_hiword()
const _GLIBCXX_NOEXCEPT
590 _GLIBCXX14_CONSTEXPR
void
594 _GLIBCXX14_CONSTEXPR
void
598 _GLIBCXX14_CONSTEXPR
void
602 _GLIBCXX14_CONSTEXPR
void
603 _M_do_left_shift(
size_t) _GLIBCXX_NOEXCEPT
606 _GLIBCXX14_CONSTEXPR
void
607 _M_do_right_shift(
size_t) _GLIBCXX_NOEXCEPT
610 _GLIBCXX14_CONSTEXPR
void
611 _M_do_flip() _GLIBCXX_NOEXCEPT
614 _GLIBCXX14_CONSTEXPR
void
615 _M_do_set() _GLIBCXX_NOEXCEPT
618 _GLIBCXX14_CONSTEXPR
void
619 _M_do_reset() _GLIBCXX_NOEXCEPT
625 _GLIBCXX_CONSTEXPR
bool
630 _GLIBCXX_CONSTEXPR
bool
631 _M_are_all()
const _GLIBCXX_NOEXCEPT
634 _GLIBCXX_CONSTEXPR
bool
635 _M_is_any()
const _GLIBCXX_NOEXCEPT
638 _GLIBCXX_CONSTEXPR
size_t
639 _M_do_count()
const _GLIBCXX_NOEXCEPT
642 _GLIBCXX_CONSTEXPR
unsigned long
643 _M_do_to_ulong()
const _GLIBCXX_NOEXCEPT
646#if __cplusplus >= 201103L
647 constexpr unsigned long long
648 _M_do_to_ullong()
const noexcept
654 _GLIBCXX_CONSTEXPR
size_t
655 _M_do_find_first(
size_t)
const _GLIBCXX_NOEXCEPT
658 _GLIBCXX_CONSTEXPR
size_t
659 _M_do_find_next(
size_t,
size_t)
const _GLIBCXX_NOEXCEPT
665 template<
size_t _Extrabits>
668 typedef unsigned long _WordT;
670 static _GLIBCXX14_CONSTEXPR
void
671 _S_do_sanitize(_WordT& __val) _GLIBCXX_NOEXCEPT
672 { __val &= ~((~static_cast<_WordT>(0)) << _Extrabits); }
678 typedef unsigned long _WordT;
680 static _GLIBCXX14_CONSTEXPR
void
681 _S_do_sanitize(_WordT) _GLIBCXX_NOEXCEPT { }
684#if __cplusplus >= 201103L
685 template<
size_t _Nb,
bool = (_Nb < _GLIBCXX_BITSET_BITS_PER_ULL)>
688 static constexpr
unsigned long long
689 _S_do_sanitize_val(
unsigned long long __val)
694 struct _Sanitize_val<_Nb, true>
696 static constexpr unsigned long long
697 _S_do_sanitize_val(
unsigned long long __val)
698 {
return __val & ~((~static_cast<unsigned long long>(0)) << _Nb); }
704 template<
typename _CharT>
707 template<
typename _CharT>
710 using size_type = size_t;
711 static constexpr size_type npos = size_type(-1);
715 static _GLIBCXX14_CONSTEXPR
size_t
716 length(
const _CharT* __s)
noexcept
724 static constexpr bool
725 eq(_CharT __l, _CharT __r)
noexcept
726 {
return __l == __r; }
802 typedef unsigned long _WordT;
805 template<
class _CharT,
class _Traits,
class _Alloc>
809 size_t __position)
const
811 if (__position > __s.
size())
812 __throw_out_of_range_fmt(__N(
"bitset::bitset: __position "
813 "(which is %zu) > __s.size() "
815 __position, __s.
size());
820 void _M_check(
size_t __position,
const char *__s)
const
822 if (__position >= _Nb)
823 __throw_out_of_range_fmt(__N(
"%s: __position (which is %zu) "
824 ">= _Nb (which is %zu)"),
825 __s, __position, _Nb);
830 _M_do_sanitize() _GLIBCXX_NOEXCEPT
832 typedef _Sanitize<_Nb % _GLIBCXX_BITSET_BITS_PER_WORD> __sanitize_type;
833 __sanitize_type::_S_do_sanitize(this->_M_hiword());
836#if __cplusplus >= 201103L
867 _M_wp = &__b._M_getword(__pos);
868 _M_bpos = _Base::_S_whichbit(__pos);
871#if __cplusplus >= 201103L
875#if __cplusplus > 202002L && __cpp_constexpr_dynamic_alloc
884 operator=(
bool __x) _GLIBCXX_NOEXCEPT
887 *_M_wp |= _Base::_S_maskbit(_M_bpos);
889 *_M_wp &=
~_Base::_S_maskbit(_M_bpos);
896 operator=(
const reference& __j) _GLIBCXX_NOEXCEPT
898 if ((*(__j._M_wp) & _Base::_S_maskbit(__j._M_bpos)))
899 *_M_wp |= _Base::_S_maskbit(_M_bpos);
901 *_M_wp &=
~_Base::_S_maskbit(_M_bpos);
908 operator~()
const _GLIBCXX_NOEXCEPT
909 {
return (*(_M_wp) & _Base::_S_maskbit(_M_bpos)) == 0; }
913 operator bool()
const _GLIBCXX_NOEXCEPT
914 {
return (*(_M_wp) & _Base::_S_maskbit(_M_bpos)) != 0; }
919 flip() _GLIBCXX_NOEXCEPT
921 *_M_wp ^= _Base::_S_maskbit(_M_bpos);
929 _GLIBCXX_CONSTEXPR
bitset() _GLIBCXX_NOEXCEPT
933#if __cplusplus >= 201103L
934 constexpr bitset(
unsigned long long __val) noexcept
935 :
_Base(_Sanitize_val<_Nb>::_S_do_sanitize_val(__val)) { }
937 bitset(
unsigned long __val)
939 { _M_do_sanitize(); }
952 template<
class _CharT,
class _Traits,
class _Alloc>
956 size_t __position = 0)
959 _M_check_initial_position(__s, __position);
960 _M_copy_from_string(__s, __position,
962 _CharT(
'0'), _CharT(
'1'));
975 template<
class _CharT,
class _Traits,
class _Alloc>
978 size_t __position,
size_t __n)
981 _M_check_initial_position(__s, __position);
982 _M_copy_from_string(__s, __position, __n, _CharT(
'0'), _CharT(
'1'));
987 template<
class _CharT,
class _Traits,
class _Alloc>
990 size_t __position,
size_t __n,
991 _CharT __zero, _CharT __one = _CharT(
'1'))
994 _M_check_initial_position(__s, __position);
995 _M_copy_from_string(__s, __position, __n, __zero, __one);
999#if __cplusplus >= 201103L
1009 template<
typename _CharT>
1010 [[__gnu__::__nonnull__]]
1011 _GLIBCXX23_CONSTEXPR
1014 typename __bitset::__string<_CharT>::size_type __n
1016 _CharT __zero = _CharT(
'0'), _CharT __one = _CharT(
'1'))
1021 __throw_logic_error(__N(
"bitset::bitset(const _CharT*, ...)"));
1023 using _Traits =
typename __bitset::__string<_CharT>::traits_type;
1026 __n = _Traits::length(__str);
1027 _M_copy_from_ptr<_CharT, _Traits>(__str, __n, 0, __n, __zero, __one);
1039 _GLIBCXX23_CONSTEXPR
1043 this->_M_do_and(__rhs);
1047 _GLIBCXX23_CONSTEXPR
1051 this->_M_do_or(__rhs);
1055 _GLIBCXX23_CONSTEXPR
1059 this->_M_do_xor(__rhs);
1071 _GLIBCXX23_CONSTEXPR
1073 operator<<=(
size_t __position) _GLIBCXX_NOEXCEPT
1075 if (__builtin_expect(__position < _Nb, 1))
1077 this->_M_do_left_shift(__position);
1078 this->_M_do_sanitize();
1081 this->_M_do_reset();
1085 _GLIBCXX23_CONSTEXPR
1089 if (__builtin_expect(__position < _Nb, 1))
1091 this->_M_do_right_shift(__position);
1092 this->_M_do_sanitize();
1095 this->_M_do_reset();
1106 _GLIBCXX23_CONSTEXPR
1110 this->_M_getword(__pos) |= _Base::_S_maskbit(__pos);
1114 _GLIBCXX23_CONSTEXPR
1119 this->_M_getword(__pos) |= _Base::_S_maskbit(__pos);
1121 this->_M_getword(__pos) &=
~_Base::_S_maskbit(__pos);
1125 _GLIBCXX23_CONSTEXPR
1129 this->_M_getword(__pos) &=
~_Base::_S_maskbit(__pos);
1133 _GLIBCXX23_CONSTEXPR
1137 this->_M_getword(__pos) ^= _Base::_S_maskbit(__pos);
1141 _GLIBCXX_CONSTEXPR
bool
1143 {
return ((this->_M_getword(__pos) & _Base::_S_maskbit(__pos))
1144 !=
static_cast<_WordT
>(0)); }
1151 _GLIBCXX23_CONSTEXPR
1156 this->_M_do_sanitize();
1166 _GLIBCXX23_CONSTEXPR
1168 set(
size_t __position,
bool __val =
true)
1170 this->_M_check(__position, __N(
"bitset::set"));
1171 return _Unchecked_set(__position, __val);
1177 _GLIBCXX23_CONSTEXPR
1181 this->_M_do_reset();
1192 _GLIBCXX23_CONSTEXPR
1196 this->_M_check(__position, __N(
"bitset::reset"));
1197 return _Unchecked_reset(__position);
1203 _GLIBCXX23_CONSTEXPR
1208 this->_M_do_sanitize();
1217 _GLIBCXX23_CONSTEXPR
1221 this->_M_check(__position, __N(
"bitset::flip"));
1222 return _Unchecked_flip(__position);
1226 _GLIBCXX23_CONSTEXPR
1246 _GLIBCXX23_CONSTEXPR
1249 {
return reference(*
this, __position); }
1251 _GLIBCXX_CONSTEXPR
bool
1253 {
return _Unchecked_test(__position); }
1262 _GLIBCXX23_CONSTEXPR
1265 {
return this->_M_do_to_ulong(); }
1267#if __cplusplus >= 201103L
1268 _GLIBCXX23_CONSTEXPR
1271 {
return this->_M_do_to_ullong(); }
1283 template<
class _CharT,
class _Traits,
class _Alloc>
1284 _GLIBCXX23_CONSTEXPR
1289 _M_copy_to_string(__result, _CharT(
'0'), _CharT(
'1'));
1295 template<
class _CharT,
class _Traits,
class _Alloc>
1296 _GLIBCXX23_CONSTEXPR
1298 to_string(_CharT __zero, _CharT __one = _CharT(
'1'))
const
1301 _M_copy_to_string(__result, __zero, __one);
1307 template<
class _CharT,
class _Traits>
1308 _GLIBCXX23_CONSTEXPR
1311 {
return to_string<_CharT, _Traits, std::allocator<_CharT> >(); }
1315 template<
class _CharT,
class _Traits>
1316 _GLIBCXX23_CONSTEXPR
1318 to_string(_CharT __zero, _CharT __one = _CharT(
'1'))
const
1319 {
return to_string<_CharT, _Traits,
1322 template<
class _CharT>
1323 _GLIBCXX23_CONSTEXPR
1328 return to_string<_CharT, std::char_traits<_CharT>,
1332 template<
class _CharT>
1333 _GLIBCXX23_CONSTEXPR
1336 to_string(_CharT __zero, _CharT __one = _CharT(
'1'))
const
1338 return to_string<_CharT, std::char_traits<_CharT>,
1342 _GLIBCXX23_CONSTEXPR
1346 return to_string<char, std::char_traits<char>,
1350 _GLIBCXX23_CONSTEXPR
1352 to_string(
char __zero,
char __one =
'1')
const
1354 return to_string<char, std::char_traits<char>,
1360 _GLIBCXX23_CONSTEXPR
1363 {
return this->_M_do_count(); }
1366 _GLIBCXX_CONSTEXPR
size_t
1372 _GLIBCXX23_CONSTEXPR
1375 {
return this->_M_is_equal(__rhs); }
1377#if __cpp_impl_three_way_comparison < 201907L
1378 _GLIBCXX23_CONSTEXPR
1380 operator!=(
const bitset<_Nb>& __rhs)
const _GLIBCXX_NOEXCEPT
1381 {
return !this->_M_is_equal(__rhs); }
1391 _GLIBCXX23_CONSTEXPR
1395 this->_M_check(__position, __N(
"bitset::test"));
1396 return _Unchecked_test(__position);
1405 _GLIBCXX23_CONSTEXPR
1408 {
return this->
template _M_are_all<_Nb>(); }
1414 _GLIBCXX23_CONSTEXPR
1417 {
return this->_M_is_any(); }
1423 _GLIBCXX23_CONSTEXPR
1426 {
return !this->_M_is_any(); }
1430 _GLIBCXX23_CONSTEXPR
1432 operator<<(
size_t __position)
const _GLIBCXX_NOEXCEPT
1435 _GLIBCXX23_CONSTEXPR
1447 _GLIBCXX23_CONSTEXPR
1450 {
return this->_M_do_find_first(_Nb); }
1459 _GLIBCXX23_CONSTEXPR
1462 {
return this->_M_do_find_next(__prev, _Nb); }
1466 template<
class _CharT,
class _Traits>
1467 _GLIBCXX23_CONSTEXPR
1469 _M_copy_from_ptr(
const _CharT*,
size_t,
size_t,
size_t,
1473 template<
class _CharT,
class _Traits,
class _Alloc>
1474 _GLIBCXX23_CONSTEXPR
1477 _Traits, _Alloc>& __s,
size_t __pos,
size_t __n,
1478 _CharT __zero, _CharT __one)
1479 { _M_copy_from_ptr<_CharT, _Traits>(__s.
data(), __s.
size(), __pos, __n,
1482 template<
class _CharT,
class _Traits,
class _Alloc>
1483 _GLIBCXX23_CONSTEXPR
1486 _CharT, _CharT)
const;
1488 template<
class _CharT,
class _Traits,
size_t _Nb2>
1492 template <
class _CharT,
class _Traits,
size_t _Nb2>
1499 template<
size_t _Nb>
1500 template<
class _CharT,
class _Traits>
1501 _GLIBCXX23_CONSTEXPR
1504 _M_copy_from_ptr(
const _CharT* __s,
size_t __len,
1505 size_t __pos,
size_t __n, _CharT __zero, _CharT __one)
1508 const size_t __nbits =
std::min(_Nb,
std::min(__n,
size_t(__len - __pos)));
1509 for (
size_t __i = __nbits; __i > 0; --__i)
1511 const _CharT __c = __s[__pos + __nbits - __i];
1512 if (_Traits::eq(__c, __zero))
1514 else if (_Traits::eq(__c, __one))
1515 _Unchecked_set(__i - 1);
1519 __throw_invalid_argument(__N(
"bitset::_M_copy_from_ptr"));
1528 template<
size_t _Nb>
1529 template<
class _CharT,
class _Traits,
class _Alloc>
1530 _GLIBCXX23_CONSTEXPR
1534 _CharT __zero, _CharT __one)
const
1537 size_t __n = this->_Find_first();
1540 __s[_Nb - __n - 1] = __one;
1541 __n = _Find_next(__n);
1556 template<
size_t _Nb>
1557 _GLIBCXX23_CONSTEXPR
1566 template<
size_t _Nb>
1567 _GLIBCXX23_CONSTEXPR
1576 template <
size_t _Nb>
1577 _GLIBCXX23_CONSTEXPR
1597 template<
class _CharT,
class _Traits,
size_t _Nb>
1601 typedef typename _Traits::char_type char_type;
1603 typedef typename __istream_type::ios_base __ios_base;
1608 : _M_base(_Nb > 256 ?
new _CharT[_Nb] : (_CharT*)__builtin_alloca(_Nb))
1613 if _GLIBCXX17_CONSTEXPR (_Nb > 256)
1617 _CharT*
const _M_base;
1620 _CharT* __ptr = __buf._M_base;
1624 const char_type __zero = __is.
widen(
'0');
1625 const char_type __one = __is.
widen(
'1');
1627 typename __ios_base::iostate __state = __ios_base::goodbit;
1628 typename __istream_type::sentry __sentry(__is);
1633 for (
size_t __i = _Nb; __i > 0; --__i)
1635 static typename _Traits::int_type __eof = _Traits::eof();
1637 typename _Traits::int_type __c1 = __is.
rdbuf()->sbumpc();
1638 if (_Traits::eq_int_type(__c1, __eof))
1640 __state |= __ios_base::eofbit;
1645 const char_type __c2 = _Traits::to_char_type(__c1);
1646 if (_Traits::eq(__c2, __zero))
1648 else if (_Traits::eq(__c2, __one))
1651 eq_int_type(__is.
rdbuf()->sputbackc(__c2),
1654 __state |= __ios_base::failbit;
1662 __is._M_setstate(__ios_base::badbit);
1663 __throw_exception_again;
1666 { __is._M_setstate(__ios_base::badbit); }
1669 if _GLIBCXX17_CONSTEXPR (_Nb)
1671 if (
size_t __len = __ptr - __buf._M_base)
1672 __x.template _M_copy_from_ptr<_CharT, _Traits>(__buf._M_base, __len,
1676 __state |= __ios_base::failbit;
1683 template <
class _CharT,
class _Traits,
size_t _Nb>
1686 const bitset<_Nb>& __x)
1692 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__os.
getloc());
1693 __x._M_copy_to_string(__tmp, __ct.widen(
'0'), __ct.widen(
'1'));
1694 return __os << __tmp;
1699_GLIBCXX_END_NAMESPACE_CONTAINER
1702#undef _GLIBCXX_BITSET_WORDS
1703#undef _GLIBCXX_BITSET_BITS_PER_WORD
1704#undef _GLIBCXX_BITSET_BITS_PER_ULL
1706#if __cplusplus >= 201103L
1708namespace std _GLIBCXX_VISIBILITY(default)
1710_GLIBCXX_BEGIN_NAMESPACE_VERSION
1714 template<
size_t _Nb>
1716 :
public __hash_base<size_t, _GLIBCXX_STD_C::bitset<_Nb>>
1719 operator()(
const _GLIBCXX_STD_C::bitset<_Nb>& __b)
const noexcept
1721 const size_t __clength = (_Nb + __CHAR_BIT__ - 1) / __CHAR_BIT__;
1722 return std::_Hash_impl::hash(__b._M_getdata(), __clength);
1728 :
public __hash_base<size_t, _GLIBCXX_STD_C::bitset<0>>
1731 operator()(
const _GLIBCXX_STD_C::bitset<0>&)
const noexcept
1735_GLIBCXX_END_NAMESPACE_VERSION
1740#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].
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.