42 #ifndef _GLIBCXX_BITSET
43 #define _GLIBCXX_BITSET 1
45 #pragma GCC system_header
53 #define _GLIBCXX_BITSET_BITS_PER_WORD (__CHAR_BIT__ * __SIZEOF_LONG__)
54 #define _GLIBCXX_BITSET_WORDS(__n) \
55 ((__n) / _GLIBCXX_BITSET_BITS_PER_WORD + \
56 ((__n) % _GLIBCXX_BITSET_BITS_PER_WORD == 0 ? 0 : 1))
58 #define _GLIBCXX_BITSET_BITS_PER_ULL (__CHAR_BIT__ * __SIZEOF_LONG_LONG__)
60 namespace std _GLIBCXX_VISIBILITY(default)
62 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
73 typedef unsigned long _WordT;
81 #if __cplusplus >= 201103L
82 constexpr
_Base_bitset(
unsigned long long __val) noexcept
84 #if __SIZEOF_LONG_LONG__ > __SIZEOF_LONG__
85 , _WordT(__val >> _GLIBCXX_BITSET_BITS_PER_WORD)
89 _Base_bitset(
unsigned long __val)
94 static _GLIBCXX_CONSTEXPR
size_t
95 _S_whichword(
size_t __pos) _GLIBCXX_NOEXCEPT
96 {
return __pos / _GLIBCXX_BITSET_BITS_PER_WORD; }
98 static _GLIBCXX_CONSTEXPR
size_t
99 _S_whichbyte(
size_t __pos) _GLIBCXX_NOEXCEPT
100 {
return (__pos % _GLIBCXX_BITSET_BITS_PER_WORD) / __CHAR_BIT__; }
102 static _GLIBCXX_CONSTEXPR
size_t
103 _S_whichbit(
size_t __pos) _GLIBCXX_NOEXCEPT
104 {
return __pos % _GLIBCXX_BITSET_BITS_PER_WORD; }
106 static _GLIBCXX_CONSTEXPR _WordT
107 _S_maskbit(
size_t __pos) _GLIBCXX_NOEXCEPT
108 {
return (static_cast<_WordT>(1)) << _S_whichbit(__pos); }
111 _M_getword(
size_t __pos) _GLIBCXX_NOEXCEPT
112 {
return _M_w[_S_whichword(__pos)]; }
114 _GLIBCXX_CONSTEXPR _WordT
115 _M_getword(
size_t __pos)
const _GLIBCXX_NOEXCEPT
116 {
return _M_w[_S_whichword(__pos)]; }
118 #if __cplusplus >= 201103L
120 _M_getdata() const noexcept
125 _M_hiword() _GLIBCXX_NOEXCEPT
126 {
return _M_w[_Nw - 1]; }
128 _GLIBCXX_CONSTEXPR _WordT
129 _M_hiword() const _GLIBCXX_NOEXCEPT
130 {
return _M_w[_Nw - 1]; }
133 _M_do_and(
const _Base_bitset<_Nw>& __x) _GLIBCXX_NOEXCEPT
135 for (
size_t __i = 0; __i < _Nw; __i++)
136 _M_w[__i] &= __x._M_w[__i];
140 _M_do_or(
const _Base_bitset<_Nw>& __x) _GLIBCXX_NOEXCEPT
142 for (
size_t __i = 0; __i < _Nw; __i++)
143 _M_w[__i] |= __x._M_w[__i];
147 _M_do_xor(
const _Base_bitset<_Nw>& __x) _GLIBCXX_NOEXCEPT
149 for (
size_t __i = 0; __i < _Nw; __i++)
150 _M_w[__i] ^= __x._M_w[__i];
154 _M_do_left_shift(
size_t __shift) _GLIBCXX_NOEXCEPT;
157 _M_do_right_shift(
size_t __shift) _GLIBCXX_NOEXCEPT;
160 _M_do_flip() _GLIBCXX_NOEXCEPT
162 for (
size_t __i = 0; __i < _Nw; __i++)
167 _M_do_set() _GLIBCXX_NOEXCEPT
169 for (
size_t __i = 0; __i < _Nw; __i++)
170 _M_w[__i] = ~static_cast<_WordT>(0);
174 _M_do_reset() _GLIBCXX_NOEXCEPT
175 { __builtin_memset(
_M_w, 0, _Nw *
sizeof(_WordT)); }
178 _M_is_equal(
const _Base_bitset<_Nw>& __x)
const _GLIBCXX_NOEXCEPT
180 for (
size_t __i = 0; __i < _Nw; ++__i)
181 if (
_M_w[__i] != __x._M_w[__i])
188 _M_are_all() const _GLIBCXX_NOEXCEPT
190 for (
size_t __i = 0; __i < _Nw - 1; __i++)
191 if (
_M_w[__i] != ~static_cast<_WordT>(0))
193 return _M_hiword() == (~static_cast<_WordT>(0)
194 >> (_Nw * _GLIBCXX_BITSET_BITS_PER_WORD
199 _M_is_any() const _GLIBCXX_NOEXCEPT
201 for (
size_t __i = 0; __i < _Nw; __i++)
202 if (
_M_w[__i] != static_cast<_WordT>(0))
208 _M_do_count() const _GLIBCXX_NOEXCEPT
211 for (
size_t __i = 0; __i < _Nw; __i++)
212 __result += __builtin_popcountl(
_M_w[__i]);
217 _M_do_to_ulong()
const;
219 #if __cplusplus >= 201103L
221 _M_do_to_ullong()
const;
226 _M_do_find_first(
size_t) const _GLIBCXX_NOEXCEPT;
230 _M_do_find_next(
size_t,
size_t) const _GLIBCXX_NOEXCEPT;
236 _Base_bitset<_Nw>::_M_do_left_shift(
size_t __shift) _GLIBCXX_NOEXCEPT
238 if (__builtin_expect(__shift != 0, 1))
240 const size_t __wshift = __shift / _GLIBCXX_BITSET_BITS_PER_WORD;
241 const size_t __offset = __shift % _GLIBCXX_BITSET_BITS_PER_WORD;
244 for (
size_t __n = _Nw - 1; __n >= __wshift; --__n)
248 const size_t __sub_offset = (_GLIBCXX_BITSET_BITS_PER_WORD
250 for (
size_t __n = _Nw - 1; __n > __wshift; --__n)
251 _M_w[__n] = ((
_M_w[__n - __wshift] << __offset)
252 | (
_M_w[__n - __wshift - 1] >> __sub_offset));
253 _M_w[__wshift] =
_M_w[0] << __offset;
256 std::fill(
_M_w + 0,
_M_w + __wshift, static_cast<_WordT>(0));
262 _Base_bitset<_Nw>::_M_do_right_shift(
size_t __shift) _GLIBCXX_NOEXCEPT
264 if (__builtin_expect(__shift != 0, 1))
266 const size_t __wshift = __shift / _GLIBCXX_BITSET_BITS_PER_WORD;
267 const size_t __offset = __shift % _GLIBCXX_BITSET_BITS_PER_WORD;
268 const size_t __limit = _Nw - __wshift - 1;
271 for (
size_t __n = 0; __n <= __limit; ++__n)
275 const size_t __sub_offset = (_GLIBCXX_BITSET_BITS_PER_WORD
277 for (
size_t __n = 0; __n < __limit; ++__n)
278 _M_w[__n] = ((
_M_w[__n + __wshift] >> __offset)
279 | (
_M_w[__n + __wshift + 1] << __sub_offset));
280 _M_w[__limit] =
_M_w[_Nw-1] >> __offset;
283 std::fill(
_M_w + __limit + 1,
_M_w + _Nw, static_cast<_WordT>(0));
289 _Base_bitset<_Nw>::_M_do_to_ulong()
const
291 for (
size_t __i = 1; __i < _Nw; ++__i)
293 __throw_overflow_error(__N(
"_Base_bitset::_M_do_to_ulong"));
297 #if __cplusplus >= 201103L
300 _Base_bitset<_Nw>::_M_do_to_ullong()
const
302 const bool __dw =
sizeof(
unsigned long long) >
sizeof(
unsigned long);
303 for (
size_t __i = 1 + __dw; __i < _Nw; ++__i)
305 __throw_overflow_error(__N(
"_Base_bitset::_M_do_to_ullong"));
308 return _M_w[0] + (
static_cast<unsigned long long>(
_M_w[1])
309 << _GLIBCXX_BITSET_BITS_PER_WORD);
317 _M_do_find_first(
size_t __not_found)
const _GLIBCXX_NOEXCEPT
319 for (
size_t __i = 0; __i < _Nw; __i++)
321 _WordT __thisword =
_M_w[__i];
322 if (__thisword != static_cast<_WordT>(0))
323 return (__i * _GLIBCXX_BITSET_BITS_PER_WORD
324 + __builtin_ctzl(__thisword));
333 _M_do_find_next(
size_t __prev,
size_t __not_found)
const _GLIBCXX_NOEXCEPT
339 if (__prev >= _Nw * _GLIBCXX_BITSET_BITS_PER_WORD)
343 size_t __i = _S_whichword(__prev);
344 _WordT __thisword =
_M_w[__i];
347 __thisword &= (~static_cast<_WordT>(0)) << _S_whichbit(__prev);
349 if (__thisword != static_cast<_WordT>(0))
350 return (__i * _GLIBCXX_BITSET_BITS_PER_WORD
351 + __builtin_ctzl(__thisword));
355 for (; __i < _Nw; __i++)
357 __thisword =
_M_w[__i];
358 if (__thisword != static_cast<_WordT>(0))
359 return (__i * _GLIBCXX_BITSET_BITS_PER_WORD
360 + __builtin_ctzl(__thisword));
374 typedef unsigned long _WordT;
381 #if __cplusplus >= 201103L
382 constexpr
_Base_bitset(
unsigned long long __val) noexcept
389 static _GLIBCXX_CONSTEXPR
size_t
390 _S_whichword(
size_t __pos) _GLIBCXX_NOEXCEPT
391 {
return __pos / _GLIBCXX_BITSET_BITS_PER_WORD; }
393 static _GLIBCXX_CONSTEXPR
size_t
394 _S_whichbyte(
size_t __pos) _GLIBCXX_NOEXCEPT
395 {
return (__pos % _GLIBCXX_BITSET_BITS_PER_WORD) / __CHAR_BIT__; }
397 static _GLIBCXX_CONSTEXPR
size_t
398 _S_whichbit(
size_t __pos) _GLIBCXX_NOEXCEPT
399 {
return __pos % _GLIBCXX_BITSET_BITS_PER_WORD; }
401 static _GLIBCXX_CONSTEXPR _WordT
402 _S_maskbit(
size_t __pos) _GLIBCXX_NOEXCEPT
403 {
return (static_cast<_WordT>(1)) << _S_whichbit(__pos); }
406 _M_getword(
size_t) _GLIBCXX_NOEXCEPT
409 _GLIBCXX_CONSTEXPR _WordT
410 _M_getword(
size_t)
const _GLIBCXX_NOEXCEPT
413 #if __cplusplus >= 201103L
415 _M_getdata()
const noexcept
420 _M_hiword() _GLIBCXX_NOEXCEPT
423 _GLIBCXX_CONSTEXPR _WordT
424 _M_hiword()
const _GLIBCXX_NOEXCEPT
429 {
_M_w &= __x._M_w; }
433 {
_M_w |= __x._M_w; }
437 {
_M_w ^= __x._M_w; }
440 _M_do_left_shift(
size_t __shift) _GLIBCXX_NOEXCEPT
441 {
_M_w <<= __shift; }
444 _M_do_right_shift(
size_t __shift) _GLIBCXX_NOEXCEPT
445 {
_M_w >>= __shift; }
448 _M_do_flip() _GLIBCXX_NOEXCEPT
452 _M_do_set() _GLIBCXX_NOEXCEPT
453 {
_M_w = ~static_cast<_WordT>(0); }
456 _M_do_reset() _GLIBCXX_NOEXCEPT
461 {
return _M_w == __x._M_w; }
465 _M_are_all()
const _GLIBCXX_NOEXCEPT
466 {
return _M_w == (~static_cast<_WordT>(0)
467 >> (_GLIBCXX_BITSET_BITS_PER_WORD - _Nb)); }
470 _M_is_any()
const _GLIBCXX_NOEXCEPT
471 {
return _M_w != 0; }
474 _M_do_count()
const _GLIBCXX_NOEXCEPT
475 {
return __builtin_popcountl(
_M_w); }
478 _M_do_to_ulong()
const _GLIBCXX_NOEXCEPT
481 #if __cplusplus >= 201103L
483 _M_do_to_ullong()
const noexcept
488 _M_do_find_first(
size_t __not_found)
const _GLIBCXX_NOEXCEPT
491 return __builtin_ctzl(
_M_w);
498 _M_do_find_next(
size_t __prev,
size_t __not_found)
const
502 if (__prev >= ((
size_t) _GLIBCXX_BITSET_BITS_PER_WORD))
505 _WordT __x =
_M_w >> __prev;
507 return __builtin_ctzl(__x) + __prev;
521 typedef unsigned long _WordT;
526 #if __cplusplus >= 201103L
533 static _GLIBCXX_CONSTEXPR
size_t
534 _S_whichword(
size_t __pos) _GLIBCXX_NOEXCEPT
535 {
return __pos / _GLIBCXX_BITSET_BITS_PER_WORD; }
537 static _GLIBCXX_CONSTEXPR
size_t
538 _S_whichbyte(
size_t __pos) _GLIBCXX_NOEXCEPT
539 {
return (__pos % _GLIBCXX_BITSET_BITS_PER_WORD) / __CHAR_BIT__; }
541 static _GLIBCXX_CONSTEXPR
size_t
542 _S_whichbit(
size_t __pos) _GLIBCXX_NOEXCEPT
543 {
return __pos % _GLIBCXX_BITSET_BITS_PER_WORD; }
545 static _GLIBCXX_CONSTEXPR _WordT
546 _S_maskbit(
size_t __pos) _GLIBCXX_NOEXCEPT
547 {
return (static_cast<_WordT>(1)) << _S_whichbit(__pos); }
557 _M_getword(
size_t) _GLIBCXX_NOEXCEPT
559 __throw_out_of_range(__N(
"_Base_bitset::_M_getword"));
563 _GLIBCXX_CONSTEXPR _WordT
564 _M_getword(
size_t __pos)
const _GLIBCXX_NOEXCEPT
567 _GLIBCXX_CONSTEXPR _WordT
568 _M_hiword()
const _GLIBCXX_NOEXCEPT
584 _M_do_left_shift(
size_t) _GLIBCXX_NOEXCEPT
588 _M_do_right_shift(
size_t) _GLIBCXX_NOEXCEPT
592 _M_do_flip() _GLIBCXX_NOEXCEPT
596 _M_do_set() _GLIBCXX_NOEXCEPT
600 _M_do_reset() _GLIBCXX_NOEXCEPT
612 _M_are_all()
const _GLIBCXX_NOEXCEPT
616 _M_is_any()
const _GLIBCXX_NOEXCEPT
620 _M_do_count()
const _GLIBCXX_NOEXCEPT
624 _M_do_to_ulong()
const _GLIBCXX_NOEXCEPT
627 #if __cplusplus >= 201103L
629 _M_do_to_ullong()
const noexcept
636 _M_do_find_first(
size_t)
const _GLIBCXX_NOEXCEPT
640 _M_do_find_next(
size_t,
size_t)
const _GLIBCXX_NOEXCEPT
646 template<
size_t _Extrabits>
649 typedef unsigned long _WordT;
652 _S_do_sanitize(_WordT& __val) _GLIBCXX_NOEXCEPT
653 { __val &= ~((~static_cast<_WordT>(0)) << _Extrabits); }
659 typedef unsigned long _WordT;
662 _S_do_sanitize(_WordT) _GLIBCXX_NOEXCEPT { }
665 #if __cplusplus >= 201103L
666 template<
size_t _Nb,
bool = (_Nb < _GLIBCXX_BITSET_BITS_PER_ULL)>
669 static constexpr
unsigned long long
670 _S_do_sanitize_val(
unsigned long long __val)
675 struct _Sanitize_val<_Nb, true>
677 static constexpr
unsigned long long
678 _S_do_sanitize_val(
unsigned long long __val)
679 {
return __val & ~((~static_cast<
unsigned long long>(0)) << _Nb); }
752 typedef unsigned long _WordT;
754 template<
class _CharT,
class _Traits,
class _Alloc>
757 size_t __position)
const
759 if (__position > __s.
size())
760 __throw_out_of_range_fmt(__N(
"bitset::bitset: __position "
761 "(which is %zu) > __s.size() "
763 __position, __s.
size());
766 void _M_check(
size_t __position,
const char *__s)
const
768 if (__position >= _Nb)
769 __throw_out_of_range_fmt(__N(
"%s: __position (which is %zu) "
770 ">= _Nb (which is %zu)"),
771 __s, __position, _Nb);
775 _M_do_sanitize() _GLIBCXX_NOEXCEPT
777 typedef _Sanitize<_Nb % _GLIBCXX_BITSET_BITS_PER_WORD> __sanitize_type;
778 __sanitize_type::_S_do_sanitize(this->_M_hiword());
781 #if __cplusplus >= 201103L
782 template<
typename>
friend struct hash;
811 _M_wp = &__b._M_getword(__pos);
812 _M_bpos = _Base::_S_whichbit(__pos);
820 operator=(
bool __x) _GLIBCXX_NOEXCEPT
823 *_M_wp |= _Base::_S_maskbit(_M_bpos);
825 *_M_wp &= ~
_Base::_S_maskbit(_M_bpos);
831 operator=(
const reference& __j) _GLIBCXX_NOEXCEPT
833 if ((*(__j._M_wp) & _Base::_S_maskbit(__j._M_bpos)))
834 *_M_wp |= _Base::_S_maskbit(_M_bpos);
836 *_M_wp &= ~
_Base::_S_maskbit(_M_bpos);
842 operator~()
const _GLIBCXX_NOEXCEPT
843 {
return (*(_M_wp) & _Base::_S_maskbit(_M_bpos)) == 0; }
846 operator bool()
const _GLIBCXX_NOEXCEPT
847 {
return (*(_M_wp) & _Base::_S_maskbit(_M_bpos)) != 0; }
851 flip() _GLIBCXX_NOEXCEPT
853 *_M_wp ^= _Base::_S_maskbit(_M_bpos);
861 _GLIBCXX_CONSTEXPR
bitset() _GLIBCXX_NOEXCEPT
865 #if __cplusplus >= 201103L
866 constexpr
bitset(
unsigned long long __val) noexcept
867 :
_Base(_Sanitize_val<_Nb>::_S_do_sanitize_val(__val)) { }
869 bitset(
unsigned long __val)
871 { _M_do_sanitize(); }
883 template<
class _CharT,
class _Traits,
class _Alloc>
886 size_t __position = 0)
889 _M_check_initial_position(__s, __position);
890 _M_copy_from_string(__s, __position,
892 _CharT(
'0'), _CharT(
'1'));
905 template<
class _CharT,
class _Traits,
class _Alloc>
907 size_t __position,
size_t __n)
910 _M_check_initial_position(__s, __position);
911 _M_copy_from_string(__s, __position, __n, _CharT(
'0'), _CharT(
'1'));
916 template<
class _CharT,
class _Traits,
class _Alloc>
918 size_t __position,
size_t __n,
919 _CharT __zero, _CharT __one = _CharT(
'1'))
922 _M_check_initial_position(__s, __position);
923 _M_copy_from_string(__s, __position, __n, __zero, __one);
926 #if __cplusplus >= 201103L
936 template<
typename _CharT>
939 typename std::basic_string<_CharT>::size_type __n
941 _CharT __zero = _CharT(
'0'), _CharT __one = _CharT(
'1'))
945 __throw_logic_error(__N(
"bitset::bitset(const _CharT*, ...)"));
949 _M_copy_from_ptr<_CharT, std::char_traits<_CharT>>(__str, __n, 0,
966 this->_M_do_and(__rhs);
973 this->_M_do_or(__rhs);
980 this->_M_do_xor(__rhs);
993 operator<<=(
size_t __position) _GLIBCXX_NOEXCEPT
995 if (__builtin_expect(__position < _Nb, 1))
997 this->_M_do_left_shift(__position);
998 this->_M_do_sanitize();
1001 this->_M_do_reset();
1008 if (__builtin_expect(__position < _Nb, 1))
1010 this->_M_do_right_shift(__position);
1011 this->_M_do_sanitize();
1014 this->_M_do_reset();
1028 this->_M_getword(__pos) |= _Base::_S_maskbit(__pos);
1036 this->_M_getword(__pos) |= _Base::_S_maskbit(__pos);
1038 this->_M_getword(__pos) &= ~
_Base::_S_maskbit(__pos);
1045 this->_M_getword(__pos) &= ~
_Base::_S_maskbit(__pos);
1052 this->_M_getword(__pos) ^= _Base::_S_maskbit(__pos);
1056 _GLIBCXX_CONSTEXPR
bool
1058 {
return ((this->_M_getword(__pos) & _Base::_S_maskbit(__pos))
1059 != static_cast<_WordT>(0)); }
1070 this->_M_do_sanitize();
1081 set(
size_t __position,
bool __val =
true)
1083 this->_M_check(__position, __N(
"bitset::set"));
1084 return _Unchecked_set(__position, __val);
1093 this->_M_do_reset();
1107 this->_M_check(__position, __N(
"bitset::reset"));
1108 return _Unchecked_reset(__position);
1118 this->_M_do_sanitize();
1130 this->_M_check(__position, __N(
"bitset::flip"));
1131 return _Unchecked_flip(__position);
1156 {
return reference(*
this, __position); }
1158 _GLIBCXX_CONSTEXPR
bool
1160 {
return _Unchecked_test(__position); }
1171 {
return this->_M_do_to_ulong(); }
1173 #if __cplusplus >= 201103L
1176 {
return this->_M_do_to_ullong(); }
1187 template<
class _CharT,
class _Traits,
class _Alloc>
1192 _M_copy_to_string(__result, _CharT(
'0'), _CharT(
'1'));
1198 template<
class _CharT,
class _Traits,
class _Alloc>
1200 to_string(_CharT __zero, _CharT __one = _CharT(
'1'))
const
1203 _M_copy_to_string(__result, __zero, __one);
1209 template<
class _CharT,
class _Traits>
1212 {
return to_string<_CharT, _Traits, std::allocator<_CharT> >(); }
1216 template<
class _CharT,
class _Traits>
1218 to_string(_CharT __zero, _CharT __one = _CharT(
'1'))
const
1219 {
return to_string<_CharT, _Traits,
1222 template<
class _CharT>
1227 return to_string<_CharT, std::char_traits<_CharT>,
1231 template<
class _CharT>
1234 to_string(_CharT __zero, _CharT __one = _CharT(
'1'))
const
1236 return to_string<_CharT, std::char_traits<_CharT>,
1243 return to_string<char, std::char_traits<char>,
1248 to_string(
char __zero,
char __one =
'1')
const
1250 return to_string<char, std::char_traits<char>,
1255 template<
class _CharT,
class _Traits>
1257 _M_copy_from_ptr(
const _CharT*,
size_t,
size_t,
size_t,
1260 template<
class _CharT,
class _Traits,
class _Alloc>
1263 _Traits, _Alloc>& __s,
size_t __pos,
size_t __n,
1264 _CharT __zero, _CharT __one)
1265 { _M_copy_from_ptr<_CharT, _Traits>(__s.
data(), __s.
size(), __pos, __n,
1268 template<
class _CharT,
class _Traits,
class _Alloc>
1271 _CharT, _CharT)
const;
1274 template<
class _CharT,
class _Traits,
class _Alloc>
1277 _Traits, _Alloc>& __s,
size_t __pos,
size_t __n)
1278 { _M_copy_from_string(__s, __pos, __n, _CharT(
'0'), _CharT(
'1')); }
1280 template<
class _CharT,
class _Traits,
class _Alloc>
1283 { _M_copy_to_string(__s, _CharT(
'0'), _CharT(
'1')); }
1288 {
return this->_M_do_count(); }
1291 _GLIBCXX_CONSTEXPR
size_t
1299 {
return this->_M_is_equal(__rhs); }
1303 {
return !this->_M_is_equal(__rhs); }
1315 this->_M_check(__position, __N(
"bitset::test"));
1316 return _Unchecked_test(__position);
1327 {
return this->
template _M_are_all<_Nb>(); }
1335 {
return this->_M_is_any(); }
1343 {
return !this->_M_is_any(); }
1364 {
return this->_M_do_find_first(_Nb); }
1375 {
return this->_M_do_find_next(__prev, _Nb); }
1379 template<
size_t _Nb>
1380 template<
class _CharT,
class _Traits>
1383 _M_copy_from_ptr(
const _CharT* __s,
size_t __len,
1384 size_t __pos,
size_t __n, _CharT __zero, _CharT __one)
1387 const size_t __nbits =
std::min(_Nb,
std::min(__n,
size_t(__len - __pos)));
1388 for (
size_t __i = __nbits; __i > 0; --__i)
1390 const _CharT __c = __s[__pos + __nbits - __i];
1391 if (_Traits::eq(__c, __zero))
1393 else if (_Traits::eq(__c, __one))
1394 _Unchecked_set(__i - 1);
1396 __throw_invalid_argument(__N(
"bitset::_M_copy_from_ptr"));
1400 template<
size_t _Nb>
1401 template<
class _CharT,
class _Traits,
class _Alloc>
1405 _CharT __zero, _CharT __one)
const
1408 for (
size_t __i = _Nb; __i > 0; --__i)
1409 if (_Unchecked_test(__i - 1))
1410 _Traits::assign(__s[_Nb - __i], __one);
1423 template<
size_t _Nb>
1432 template<
size_t _Nb>
1441 template <
size_t _Nb>
1460 template<
class _CharT,
class _Traits,
size_t _Nb>
1464 typedef typename _Traits::char_type char_type;
1466 typedef typename __istream_type::ios_base __ios_base;
1473 const char_type __zero = __is.
widen(
'0');
1474 const char_type __one = __is.
widen(
'1');
1476 typename __ios_base::iostate __state = __ios_base::goodbit;
1477 typename __istream_type::sentry __sentry(__is);
1482 for (
size_t __i = _Nb; __i > 0; --__i)
1484 static typename _Traits::int_type __eof = _Traits::eof();
1486 typename _Traits::int_type __c1 = __is.
rdbuf()->sbumpc();
1487 if (_Traits::eq_int_type(__c1, __eof))
1489 __state |= __ios_base::eofbit;
1494 const char_type __c2 = _Traits::to_char_type(__c1);
1495 if (_Traits::eq(__c2, __zero))
1497 else if (_Traits::eq(__c2, __one))
1500 eq_int_type(__is.
rdbuf()->sputbackc(__c2),
1503 __state |= __ios_base::failbit;
1511 __is._M_setstate(__ios_base::badbit);
1512 __throw_exception_again;
1515 { __is._M_setstate(__ios_base::badbit); }
1518 if (__tmp.
empty() && _Nb)
1519 __state |= __ios_base::failbit;
1521 __x._M_copy_from_string(__tmp, static_cast<size_t>(0), _Nb,
1528 template <
class _CharT,
class _Traits,
size_t _Nb>
1530 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1537 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__os.getloc());
1538 __x._M_copy_to_string(__tmp, __ct.
widen(
'0'), __ct.
widen(
'1'));
1539 return __os << __tmp;
1543 _GLIBCXX_END_NAMESPACE_CONTAINER
1546 #undef _GLIBCXX_BITSET_WORDS
1547 #undef _GLIBCXX_BITSET_BITS_PER_WORD
1548 #undef _GLIBCXX_BITSET_BITS_PER_ULL
1550 #if __cplusplus >= 201103L
1554 namespace std _GLIBCXX_VISIBILITY(default)
1556 _GLIBCXX_BEGIN_NAMESPACE_VERSION
1560 template<
size_t _Nb>
1562 :
public __hash_base<size_t, _GLIBCXX_STD_C::bitset<_Nb>>
1565 operator()(
const _GLIBCXX_STD_C::bitset<_Nb>& __b)
const noexcept
1567 const size_t __clength = (_Nb + __CHAR_BIT__ - 1) / __CHAR_BIT__;
1568 return std::_Hash_impl::hash(__b._M_getdata(), __clength);
1574 :
public __hash_base<size_t, _GLIBCXX_STD_C::bitset<0>>
1577 operator()(
const _GLIBCXX_STD_C::bitset<0>&) const noexcept
1581 _GLIBCXX_END_NAMESPACE_VERSION
1586 #ifdef _GLIBCXX_DEBUG
1590 #ifdef _GLIBCXX_PROFILE
bool operator!=(const bitset< _Nb > &__rhs) const noexcept
These comparisons for equality/inequality are, well, bitwise.
bitset< _Nb > & _Unchecked_set(size_t __pos) noexcept
bitset(const std::basic_string< _CharT, _Traits, _Alloc > &__s, size_t __position=0)
Primary class template hash.
basic_streambuf< _CharT, _Traits > * rdbuf() const
Accessing the underlying buffer.
Managing sequences of characters and character-like objects.
bitset< _Nb > & _Unchecked_flip(size_t __pos) noexcept
bitset< _Nb > operator>>(size_t __position) const noexcept
Self-explanatory.
bitset< _Nb > & _Unchecked_reset(size_t __pos) noexcept
char_type widen(char __c) const
Widen char to char_type.
bitset(const _CharT *__str, typename std::basic_string< _CharT >::size_type __n=std::basic_string< _CharT >::npos, _CharT __zero=_CharT('0'), _CharT __one=_CharT('1'))
bitset< _Nb > & operator|=(const bitset< _Nb > &__rhs) noexcept
bitset< _Nb > operator&(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
constexpr bool _Unchecked_test(size_t __pos) const noexcept
bitset< _Nb > & reset(size_t __position)
Sets a given bit to false.
std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, bitset< _Nb > &__x)
Global I/O operators for bitsets.
Primary class template ctype facet.This template class defines classification and conversion function...
char_type widen(char __c) const
Widens characters.
bitset< _Nb > & operator^=(const bitset< _Nb > &__rhs) noexcept
bitset< _Nb > & flip() noexcept
Toggles every bit to its opposite value.
Thrown as part of forced unwinding.A magic placeholder class that can be caught by reference to recog...
bool any() const noexcept
Tests whether any of the bits are on.
size_t _Find_first() const noexcept
Finds the index of the first "on" bit.
bool none() const noexcept
Tests whether any of the bits are on.
bitset< _Nb > & _Unchecked_set(size_t __pos, int __val) noexcept
std::basic_string< _CharT, _Traits, _Alloc > to_string() const
Returns a character interpretation of the bitset.
_GLIBCXX14_CONSTEXPR const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
reference operator[](size_t __position)
Array-indexing support.
void setstate(iostate __state)
Sets additional flags in the error state.
bitset< _Nb > operator|(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
bool operator==(const bitset< _Nb > &__rhs) const noexcept
These comparisons for equality/inequality are, well, bitwise.
void reserve(size_type __res_arg=0)
Attempt to preallocate enough memory for specified number of characters.
basic_string & assign(const basic_string &__str)
Set value to contents of another string.
bool test(size_t __position) const
Tests the value of a bit.
constexpr bitset() noexcept
All bits set to zero.
bitset< _Nb > & operator&=(const bitset< _Nb > &__rhs) noexcept
bitset(const std::basic_string< _CharT, _Traits, _Alloc > &__s, size_t __position, size_t __n)
const _CharT * data() const noexcept
Return const pointer to contents.
bitset< _Nb > operator~() const noexcept
See the no-argument flip().
Basis for explicit traits specializations.
bitset< _Nb > & set() noexcept
Sets every bit to true.
Template class basic_ostream.
void push_back(_CharT __c)
Append a single character.
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.
bitset< _Nb > & flip(size_t __position)
Toggles a given bit to its opposite value.
constexpr size_t size() const noexcept
Returns the total number of bits.
size_type size() const noexcept
Returns the number of characters in the string, not including any null-termination.
constexpr bitset(unsigned long long __val) noexcept
Initial bits bitwise-copied from a single word (others set to zero).
bitset< _Nb > & operator>>=(size_t __position) noexcept
The bitset class represents a fixed-size sequence of bits.(Note that bitset does not meet the formal ...
bitset< _Nb > & set(size_t __position, bool __val=true)
Sets a given bit to a particular value.
bool empty() const noexcept
std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const bitset< _Nb > &__x)
Global I/O operators for bitsets.
constexpr bool operator[](size_t __position) const
Array-indexing support.
size_t _Find_next(size_t __prev) const noexcept
Finds the index of the next "on" bit after prev.
Template class basic_istream.
bool all() const noexcept
Tests whether all the bits are on.
size_t count() const noexcept
Returns the number of bits which are set.
unsigned long to_ulong() const
Returns a numerical interpretation of the bitset.
bitset< _Nb > & reset() noexcept
Sets every bit to false.
The standard allocator, as per [20.4].