42 #ifndef _GLIBCXX_BITSET 43 #define _GLIBCXX_BITSET 1 45 #pragma GCC system_header 53 #if __cplusplus >= 201103L 57 #define _GLIBCXX_BITSET_BITS_PER_WORD (__CHAR_BIT__ * __SIZEOF_LONG__) 58 #define _GLIBCXX_BITSET_WORDS(__n) \ 59 ((__n) / _GLIBCXX_BITSET_BITS_PER_WORD + \ 60 ((__n) % _GLIBCXX_BITSET_BITS_PER_WORD == 0 ? 0 : 1)) 62 #define _GLIBCXX_BITSET_BITS_PER_ULL (__CHAR_BIT__ * __SIZEOF_LONG_LONG__) 64 namespace std _GLIBCXX_VISIBILITY(default)
66 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
77 typedef unsigned long _WordT;
85 #if __cplusplus >= 201103L 86 constexpr
_Base_bitset(
unsigned long long __val) noexcept
88 #if __SIZEOF_LONG_LONG__ > __SIZEOF_LONG__ 89 , _WordT(__val >> _GLIBCXX_BITSET_BITS_PER_WORD)
98 static _GLIBCXX_CONSTEXPR
size_t 99 _S_whichword(
size_t __pos) _GLIBCXX_NOEXCEPT
100 {
return __pos / _GLIBCXX_BITSET_BITS_PER_WORD; }
102 static _GLIBCXX_CONSTEXPR
size_t 103 _S_whichbyte(
size_t __pos) _GLIBCXX_NOEXCEPT
104 {
return (__pos % _GLIBCXX_BITSET_BITS_PER_WORD) / __CHAR_BIT__; }
106 static _GLIBCXX_CONSTEXPR
size_t 107 _S_whichbit(
size_t __pos) _GLIBCXX_NOEXCEPT
108 {
return __pos % _GLIBCXX_BITSET_BITS_PER_WORD; }
110 static _GLIBCXX_CONSTEXPR _WordT
111 _S_maskbit(
size_t __pos) _GLIBCXX_NOEXCEPT
112 {
return (static_cast<_WordT>(1)) << _S_whichbit(__pos); }
115 _M_getword(
size_t __pos) _GLIBCXX_NOEXCEPT
116 {
return _M_w[_S_whichword(__pos)]; }
118 _GLIBCXX_CONSTEXPR _WordT
119 _M_getword(
size_t __pos)
const _GLIBCXX_NOEXCEPT
120 {
return _M_w[_S_whichword(__pos)]; }
122 #if __cplusplus >= 201103L 124 _M_getdata()
const noexcept
129 _M_hiword() _GLIBCXX_NOEXCEPT
130 {
return _M_w[_Nw - 1]; }
132 _GLIBCXX_CONSTEXPR _WordT
133 _M_hiword()
const _GLIBCXX_NOEXCEPT
134 {
return _M_w[_Nw - 1]; }
139 for (
size_t __i = 0; __i < _Nw; __i++)
140 _M_w[__i] &= __x.
_M_w[__i];
146 for (
size_t __i = 0; __i < _Nw; __i++)
147 _M_w[__i] |= __x.
_M_w[__i];
153 for (
size_t __i = 0; __i < _Nw; __i++)
154 _M_w[__i] ^= __x.
_M_w[__i];
158 _M_do_left_shift(
size_t __shift) _GLIBCXX_NOEXCEPT;
161 _M_do_right_shift(
size_t __shift) _GLIBCXX_NOEXCEPT;
164 _M_do_flip() _GLIBCXX_NOEXCEPT
166 for (
size_t __i = 0; __i < _Nw; __i++)
167 _M_w[__i] = ~_M_w[__i];
171 _M_do_set() _GLIBCXX_NOEXCEPT
173 for (
size_t __i = 0; __i < _Nw; __i++)
174 _M_w[__i] = ~static_cast<_WordT>(0);
178 _M_do_reset() _GLIBCXX_NOEXCEPT
179 { __builtin_memset(_M_w, 0, _Nw *
sizeof(_WordT)); }
184 for (
size_t __i = 0; __i < _Nw; ++__i)
185 if (_M_w[__i] != __x.
_M_w[__i])
192 _M_are_all()
const _GLIBCXX_NOEXCEPT
194 for (
size_t __i = 0; __i < _Nw - 1; __i++)
195 if (_M_w[__i] != ~static_cast<_WordT>(0))
197 return _M_hiword() == (~static_cast<_WordT>(0)
198 >> (_Nw * _GLIBCXX_BITSET_BITS_PER_WORD
203 _M_is_any()
const _GLIBCXX_NOEXCEPT
205 for (
size_t __i = 0; __i < _Nw; __i++)
206 if (_M_w[__i] != static_cast<_WordT>(0))
212 _M_do_count()
const _GLIBCXX_NOEXCEPT
215 for (
size_t __i = 0; __i < _Nw; __i++)
216 __result += __builtin_popcountl(_M_w[__i]);
221 _M_do_to_ulong()
const;
223 #if __cplusplus >= 201103L 225 _M_do_to_ullong()
const;
230 _M_do_find_first(
size_t)
const _GLIBCXX_NOEXCEPT;
234 _M_do_find_next(
size_t,
size_t)
const _GLIBCXX_NOEXCEPT;
242 if (__builtin_expect(__shift != 0, 1))
244 const size_t __wshift = __shift / _GLIBCXX_BITSET_BITS_PER_WORD;
245 const size_t __offset = __shift % _GLIBCXX_BITSET_BITS_PER_WORD;
248 for (
size_t __n = _Nw - 1; __n >= __wshift; --__n)
252 const size_t __sub_offset = (_GLIBCXX_BITSET_BITS_PER_WORD
254 for (
size_t __n = _Nw - 1; __n > __wshift; --__n)
255 _M_w[__n] = ((
_M_w[__n - __wshift] << __offset)
256 | (
_M_w[__n - __wshift - 1] >> __sub_offset));
257 _M_w[__wshift] =
_M_w[0] << __offset;
260 std::fill(
_M_w + 0,
_M_w + __wshift, static_cast<_WordT>(0));
268 if (__builtin_expect(__shift != 0, 1))
270 const size_t __wshift = __shift / _GLIBCXX_BITSET_BITS_PER_WORD;
271 const size_t __offset = __shift % _GLIBCXX_BITSET_BITS_PER_WORD;
272 const size_t __limit = _Nw - __wshift - 1;
275 for (
size_t __n = 0; __n <= __limit; ++__n)
279 const size_t __sub_offset = (_GLIBCXX_BITSET_BITS_PER_WORD
281 for (
size_t __n = 0; __n < __limit; ++__n)
282 _M_w[__n] = ((
_M_w[__n + __wshift] >> __offset)
283 | (
_M_w[__n + __wshift + 1] << __sub_offset));
284 _M_w[__limit] =
_M_w[_Nw-1] >> __offset;
287 std::fill(
_M_w + __limit + 1,
_M_w + _Nw, static_cast<_WordT>(0));
295 for (
size_t __i = 1; __i < _Nw; ++__i)
297 __throw_overflow_error(__N(
"_Base_bitset::_M_do_to_ulong"));
301 #if __cplusplus >= 201103L 306 const bool __dw =
sizeof(
unsigned long long) >
sizeof(
unsigned long);
307 for (
size_t __i = 1 + __dw; __i < _Nw; ++__i)
309 __throw_overflow_error(__N(
"_Base_bitset::_M_do_to_ullong"));
312 return _M_w[0] + (
static_cast<unsigned long long>(
_M_w[1])
313 << _GLIBCXX_BITSET_BITS_PER_WORD);
323 for (
size_t __i = 0; __i < _Nw; __i++)
325 _WordT __thisword =
_M_w[__i];
326 if (__thisword != static_cast<_WordT>(0))
327 return (__i * _GLIBCXX_BITSET_BITS_PER_WORD
328 + __builtin_ctzl(__thisword));
337 _M_do_find_next(
size_t __prev,
size_t __not_found)
const _GLIBCXX_NOEXCEPT
343 if (__prev >= _Nw * _GLIBCXX_BITSET_BITS_PER_WORD)
347 size_t __i = _S_whichword(__prev);
348 _WordT __thisword =
_M_w[__i];
351 __thisword &= (~static_cast<_WordT>(0)) << _S_whichbit(__prev);
353 if (__thisword != static_cast<_WordT>(0))
354 return (__i * _GLIBCXX_BITSET_BITS_PER_WORD
355 + __builtin_ctzl(__thisword));
359 for (; __i < _Nw; __i++)
361 __thisword =
_M_w[__i];
362 if (__thisword != static_cast<_WordT>(0))
363 return (__i * _GLIBCXX_BITSET_BITS_PER_WORD
364 + __builtin_ctzl(__thisword));
378 typedef unsigned long _WordT;
385 #if __cplusplus >= 201103L 386 constexpr
_Base_bitset(
unsigned long long __val) noexcept
393 static _GLIBCXX_CONSTEXPR
size_t 394 _S_whichword(
size_t __pos) _GLIBCXX_NOEXCEPT
395 {
return __pos / _GLIBCXX_BITSET_BITS_PER_WORD; }
397 static _GLIBCXX_CONSTEXPR
size_t 398 _S_whichbyte(
size_t __pos) _GLIBCXX_NOEXCEPT
399 {
return (__pos % _GLIBCXX_BITSET_BITS_PER_WORD) / __CHAR_BIT__; }
401 static _GLIBCXX_CONSTEXPR
size_t 402 _S_whichbit(
size_t __pos) _GLIBCXX_NOEXCEPT
403 {
return __pos % _GLIBCXX_BITSET_BITS_PER_WORD; }
405 static _GLIBCXX_CONSTEXPR _WordT
406 _S_maskbit(
size_t __pos) _GLIBCXX_NOEXCEPT
407 {
return (static_cast<_WordT>(1)) << _S_whichbit(__pos); }
410 _M_getword(
size_t) _GLIBCXX_NOEXCEPT
413 _GLIBCXX_CONSTEXPR _WordT
414 _M_getword(
size_t)
const _GLIBCXX_NOEXCEPT
417 #if __cplusplus >= 201103L 419 _M_getdata()
const noexcept
424 _M_hiword() _GLIBCXX_NOEXCEPT
427 _GLIBCXX_CONSTEXPR _WordT
428 _M_hiword()
const _GLIBCXX_NOEXCEPT
433 { _M_w &= __x._M_w; }
437 { _M_w |= __x._M_w; }
441 { _M_w ^= __x._M_w; }
444 _M_do_left_shift(
size_t __shift) _GLIBCXX_NOEXCEPT
445 { _M_w <<= __shift; }
448 _M_do_right_shift(
size_t __shift) _GLIBCXX_NOEXCEPT
449 { _M_w >>= __shift; }
452 _M_do_flip() _GLIBCXX_NOEXCEPT
456 _M_do_set() _GLIBCXX_NOEXCEPT
457 { _M_w = ~static_cast<_WordT>(0); }
460 _M_do_reset() _GLIBCXX_NOEXCEPT
465 {
return _M_w == __x._M_w; }
469 _M_are_all()
const _GLIBCXX_NOEXCEPT
470 {
return _M_w == (~static_cast<_WordT>(0)
471 >> (_GLIBCXX_BITSET_BITS_PER_WORD - _Nb)); }
474 _M_is_any()
const _GLIBCXX_NOEXCEPT
475 {
return _M_w != 0; }
478 _M_do_count()
const _GLIBCXX_NOEXCEPT
479 {
return __builtin_popcountl(_M_w); }
482 _M_do_to_ulong()
const _GLIBCXX_NOEXCEPT
485 #if __cplusplus >= 201103L 487 _M_do_to_ullong()
const noexcept
492 _M_do_find_first(
size_t __not_found)
const _GLIBCXX_NOEXCEPT
495 return __builtin_ctzl(_M_w);
502 _M_do_find_next(
size_t __prev,
size_t __not_found)
const 506 if (__prev >= ((
size_t) _GLIBCXX_BITSET_BITS_PER_WORD))
509 _WordT __x = _M_w >> __prev;
511 return __builtin_ctzl(__x) + __prev;
525 typedef unsigned long _WordT;
530 #if __cplusplus >= 201103L 537 static _GLIBCXX_CONSTEXPR
size_t 538 _S_whichword(
size_t __pos) _GLIBCXX_NOEXCEPT
539 {
return __pos / _GLIBCXX_BITSET_BITS_PER_WORD; }
541 static _GLIBCXX_CONSTEXPR
size_t 542 _S_whichbyte(
size_t __pos) _GLIBCXX_NOEXCEPT
543 {
return (__pos % _GLIBCXX_BITSET_BITS_PER_WORD) / __CHAR_BIT__; }
545 static _GLIBCXX_CONSTEXPR
size_t 546 _S_whichbit(
size_t __pos) _GLIBCXX_NOEXCEPT
547 {
return __pos % _GLIBCXX_BITSET_BITS_PER_WORD; }
549 static _GLIBCXX_CONSTEXPR _WordT
550 _S_maskbit(
size_t __pos) _GLIBCXX_NOEXCEPT
551 {
return (static_cast<_WordT>(1)) << _S_whichbit(__pos); }
561 _M_getword(
size_t) _GLIBCXX_NOEXCEPT
563 __throw_out_of_range(__N(
"_Base_bitset::_M_getword"));
567 _GLIBCXX_CONSTEXPR _WordT
568 _M_getword(
size_t)
const _GLIBCXX_NOEXCEPT
571 _GLIBCXX_CONSTEXPR _WordT
572 _M_hiword()
const _GLIBCXX_NOEXCEPT
588 _M_do_left_shift(
size_t) _GLIBCXX_NOEXCEPT
592 _M_do_right_shift(
size_t) _GLIBCXX_NOEXCEPT
596 _M_do_flip() _GLIBCXX_NOEXCEPT
600 _M_do_set() _GLIBCXX_NOEXCEPT
604 _M_do_reset() _GLIBCXX_NOEXCEPT
616 _M_are_all()
const _GLIBCXX_NOEXCEPT
620 _M_is_any()
const _GLIBCXX_NOEXCEPT
624 _M_do_count()
const _GLIBCXX_NOEXCEPT
628 _M_do_to_ulong()
const _GLIBCXX_NOEXCEPT
631 #if __cplusplus >= 201103L 633 _M_do_to_ullong()
const noexcept
640 _M_do_find_first(
size_t)
const _GLIBCXX_NOEXCEPT
644 _M_do_find_next(
size_t,
size_t)
const _GLIBCXX_NOEXCEPT
650 template<
size_t _Extrabits>
653 typedef unsigned long _WordT;
656 _S_do_sanitize(_WordT& __val) _GLIBCXX_NOEXCEPT
657 { __val &= ~((~static_cast<_WordT>(0)) << _Extrabits); }
663 typedef unsigned long _WordT;
666 _S_do_sanitize(_WordT) _GLIBCXX_NOEXCEPT { }
669 #if __cplusplus >= 201103L 670 template<
size_t _Nb,
bool = (_Nb < _GLIBCXX_BITSET_BITS_PER_ULL)>
673 static constexpr
unsigned long long 674 _S_do_sanitize_val(
unsigned long long __val)
679 struct _Sanitize_val<_Nb, true>
681 static constexpr
unsigned long long 682 _S_do_sanitize_val(
unsigned long long __val)
683 {
return __val & ~((~static_cast<
unsigned long long>(0)) << _Nb); }
756 typedef unsigned long _WordT;
758 template<
class _CharT,
class _Traits,
class _Alloc>
761 size_t __position)
const 763 if (__position > __s.
size())
764 __throw_out_of_range_fmt(__N(
"bitset::bitset: __position " 765 "(which is %zu) > __s.size() " 767 __position, __s.
size());
770 void _M_check(
size_t __position,
const char *__s)
const 772 if (__position >= _Nb)
773 __throw_out_of_range_fmt(__N(
"%s: __position (which is %zu) " 774 ">= _Nb (which is %zu)"),
775 __s, __position, _Nb);
779 _M_do_sanitize() _GLIBCXX_NOEXCEPT
781 typedef _Sanitize<_Nb % _GLIBCXX_BITSET_BITS_PER_WORD> __sanitize_type;
782 __sanitize_type::_S_do_sanitize(this->_M_hiword());
785 #if __cplusplus >= 201103L 813 reference(bitset& __b,
size_t __pos) _GLIBCXX_NOEXCEPT
815 _M_wp = &__b._M_getword(__pos);
816 _M_bpos = _Base::_S_whichbit(__pos);
819 #if __cplusplus >= 201103L 828 operator=(
bool __x) _GLIBCXX_NOEXCEPT
831 *_M_wp |= _Base::_S_maskbit(_M_bpos);
833 *_M_wp &= ~_Base::_S_maskbit(_M_bpos);
839 operator=(
const reference& __j) _GLIBCXX_NOEXCEPT
841 if ((*(__j._M_wp) & _Base::_S_maskbit(__j._M_bpos)))
842 *_M_wp |= _Base::_S_maskbit(_M_bpos);
844 *_M_wp &= ~_Base::_S_maskbit(_M_bpos);
850 operator~()
const _GLIBCXX_NOEXCEPT
851 {
return (*(_M_wp) & _Base::_S_maskbit(_M_bpos)) == 0; }
854 operator bool()
const _GLIBCXX_NOEXCEPT
855 {
return (*(_M_wp) & _Base::_S_maskbit(_M_bpos)) != 0; }
859 flip() _GLIBCXX_NOEXCEPT
861 *_M_wp ^= _Base::_S_maskbit(_M_bpos);
869 _GLIBCXX_CONSTEXPR
bitset() _GLIBCXX_NOEXCEPT
873 #if __cplusplus >= 201103L 874 constexpr
bitset(
unsigned long long __val) noexcept
875 : _Base(_Sanitize_val<_Nb>::_S_do_sanitize_val(__val)) { }
877 bitset(
unsigned long __val)
879 { _M_do_sanitize(); }
891 template<
class _CharT,
class _Traits,
class _Alloc>
894 size_t __position = 0)
897 _M_check_initial_position(__s, __position);
898 _M_copy_from_string(__s, __position,
900 _CharT(
'0'), _CharT(
'1'));
913 template<
class _CharT,
class _Traits,
class _Alloc>
915 size_t __position,
size_t __n)
918 _M_check_initial_position(__s, __position);
919 _M_copy_from_string(__s, __position, __n, _CharT(
'0'), _CharT(
'1'));
924 template<
class _CharT,
class _Traits,
class _Alloc>
926 size_t __position,
size_t __n,
927 _CharT __zero, _CharT __one = _CharT(
'1'))
930 _M_check_initial_position(__s, __position);
931 _M_copy_from_string(__s, __position, __n, __zero, __one);
934 #if __cplusplus >= 201103L 944 template<
typename _CharT>
947 typename std::basic_string<_CharT>::size_type __n
949 _CharT __zero = _CharT(
'0'), _CharT __one = _CharT(
'1'))
953 __throw_logic_error(__N(
"bitset::bitset(const _CharT*, ...)"));
957 _M_copy_from_ptr<_CharT, std::char_traits<_CharT>>(__str, __n, 0,
974 this->_M_do_and(__rhs);
981 this->_M_do_or(__rhs);
988 this->_M_do_xor(__rhs);
1001 operator<<=(
size_t __position) _GLIBCXX_NOEXCEPT
1003 if (__builtin_expect(__position < _Nb, 1))
1005 this->_M_do_left_shift(__position);
1006 this->_M_do_sanitize();
1009 this->_M_do_reset();
1016 if (__builtin_expect(__position < _Nb, 1))
1018 this->_M_do_right_shift(__position);
1019 this->_M_do_sanitize();
1022 this->_M_do_reset();
1036 this->_M_getword(__pos) |= _Base::_S_maskbit(__pos);
1044 this->_M_getword(__pos) |= _Base::_S_maskbit(__pos);
1046 this->_M_getword(__pos) &= ~_Base::_S_maskbit(__pos);
1053 this->_M_getword(__pos) &= ~_Base::_S_maskbit(__pos);
1060 this->_M_getword(__pos) ^= _Base::_S_maskbit(__pos);
1064 _GLIBCXX_CONSTEXPR
bool 1066 {
return ((this->_M_getword(__pos) & _Base::_S_maskbit(__pos))
1067 != static_cast<_WordT>(0)); }
1075 set() _GLIBCXX_NOEXCEPT
1078 this->_M_do_sanitize();
1089 set(
size_t __position,
bool __val =
true)
1091 this->_M_check(__position, __N(
"bitset::set"));
1092 return _Unchecked_set(__position, __val);
1101 this->_M_do_reset();
1115 this->_M_check(__position, __N(
"bitset::reset"));
1116 return _Unchecked_reset(__position);
1126 this->_M_do_sanitize();
1138 this->_M_check(__position, __N(
"bitset::flip"));
1139 return _Unchecked_flip(__position);
1164 {
return reference(*
this, __position); }
1166 _GLIBCXX_CONSTEXPR
bool 1168 {
return _Unchecked_test(__position); }
1179 {
return this->_M_do_to_ulong(); }
1181 #if __cplusplus >= 201103L 1184 {
return this->_M_do_to_ullong(); }
1195 template<
class _CharT,
class _Traits,
class _Alloc>
1200 _M_copy_to_string(__result, _CharT(
'0'), _CharT(
'1'));
1206 template<
class _CharT,
class _Traits,
class _Alloc>
1208 to_string(_CharT __zero, _CharT __one = _CharT(
'1'))
const 1211 _M_copy_to_string(__result, __zero, __one);
1217 template<
class _CharT,
class _Traits>
1220 {
return to_string<_CharT, _Traits, std::allocator<_CharT> >(); }
1224 template<
class _CharT,
class _Traits>
1226 to_string(_CharT __zero, _CharT __one = _CharT(
'1'))
const 1227 {
return to_string<_CharT, _Traits,
1230 template<
class _CharT>
1235 return to_string<_CharT, std::char_traits<_CharT>,
1239 template<
class _CharT>
1240 std::basic_string<_CharT, std::char_traits<_CharT>,
1242 to_string(_CharT __zero, _CharT __one = _CharT(
'1'))
const 1244 return to_string<_CharT, std::char_traits<_CharT>,
1251 return to_string<char, std::char_traits<char>,
1256 to_string(
char __zero,
char __one =
'1')
const 1258 return to_string<char, std::char_traits<char>,
1263 template<
class _CharT,
class _Traits>
1265 _M_copy_from_ptr(
const _CharT*,
size_t,
size_t,
size_t,
1268 template<
class _CharT,
class _Traits,
class _Alloc>
1271 _Traits, _Alloc>& __s,
size_t __pos,
size_t __n,
1272 _CharT __zero, _CharT __one)
1273 { _M_copy_from_ptr<_CharT, _Traits>(__s.
data(), __s.
size(), __pos, __n,
1276 template<
class _CharT,
class _Traits,
class _Alloc>
1279 _CharT, _CharT)
const;
1282 template<
class _CharT,
class _Traits,
class _Alloc>
1285 _Traits, _Alloc>& __s,
size_t __pos,
size_t __n)
1286 { _M_copy_from_string(__s, __pos, __n, _CharT(
'0'), _CharT(
'1')); }
1288 template<
class _CharT,
class _Traits,
class _Alloc>
1291 { _M_copy_to_string(__s, _CharT(
'0'), _CharT(
'1')); }
1296 {
return this->_M_do_count(); }
1299 _GLIBCXX_CONSTEXPR
size_t 1307 {
return this->_M_is_equal(__rhs); }
1311 {
return !this->_M_is_equal(__rhs); }
1323 this->_M_check(__position, __N(
"bitset::test"));
1324 return _Unchecked_test(__position);
1335 {
return this->
template _M_are_all<_Nb>(); }
1343 {
return this->_M_is_any(); }
1351 {
return !this->_M_is_any(); }
1372 {
return this->_M_do_find_first(_Nb); }
1383 {
return this->_M_do_find_next(__prev, _Nb); }
1387 template<
size_t _Nb>
1388 template<
class _CharT,
class _Traits>
1392 size_t __pos,
size_t __n, _CharT __zero, _CharT __one)
1395 const size_t __nbits =
std::min(_Nb,
std::min(__n,
size_t(__len - __pos)));
1396 for (
size_t __i = __nbits; __i > 0; --__i)
1398 const _CharT __c = __s[__pos + __nbits - __i];
1399 if (_Traits::eq(__c, __zero))
1401 else if (_Traits::eq(__c, __one))
1402 _Unchecked_set(__i - 1);
1404 __throw_invalid_argument(__N(
"bitset::_M_copy_from_ptr"));
1408 template<
size_t _Nb>
1409 template<
class _CharT,
class _Traits,
class _Alloc>
1413 _CharT __zero, _CharT __one)
const 1416 for (
size_t __i = _Nb; __i > 0; --__i)
1417 if (_Unchecked_test(__i - 1))
1418 _Traits::assign(__s[_Nb - __i], __one);
1431 template<
size_t _Nb>
1440 template<
size_t _Nb>
1449 template <
size_t _Nb>
1468 template<
class _CharT,
class _Traits,
size_t _Nb>
1472 typedef typename _Traits::char_type char_type;
1474 typedef typename __istream_type::ios_base __ios_base;
1481 const char_type __zero = __is.
widen(
'0');
1482 const char_type __one = __is.
widen(
'1');
1484 typename __ios_base::iostate __state = __ios_base::goodbit;
1485 typename __istream_type::sentry __sentry(__is);
1490 for (
size_t __i = _Nb; __i > 0; --__i)
1492 static typename _Traits::int_type __eof = _Traits::eof();
1494 typename _Traits::int_type __c1 = __is.
rdbuf()->sbumpc();
1495 if (_Traits::eq_int_type(__c1, __eof))
1497 __state |= __ios_base::eofbit;
1502 const char_type __c2 = _Traits::to_char_type(__c1);
1503 if (_Traits::eq(__c2, __zero))
1505 else if (_Traits::eq(__c2, __one))
1508 eq_int_type(__is.
rdbuf()->sputbackc(__c2),
1511 __state |= __ios_base::failbit;
1519 __is._M_setstate(__ios_base::badbit);
1520 __throw_exception_again;
1523 { __is._M_setstate(__ios_base::badbit); }
1526 if (__tmp.
empty() && _Nb)
1527 __state |= __ios_base::failbit;
1529 __x._M_copy_from_string(__tmp, static_cast<size_t>(0), _Nb,
1536 template <
class _CharT,
class _Traits,
size_t _Nb>
1538 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1545 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__os.getloc());
1546 __x._M_copy_to_string(__tmp, __ct.
widen(
'0'), __ct.
widen(
'1'));
1547 return __os << __tmp;
1551 _GLIBCXX_END_NAMESPACE_CONTAINER
1554 #undef _GLIBCXX_BITSET_WORDS 1555 #undef _GLIBCXX_BITSET_BITS_PER_WORD 1556 #undef _GLIBCXX_BITSET_BITS_PER_ULL 1558 #if __cplusplus >= 201103L 1560 namespace std _GLIBCXX_VISIBILITY(default)
1562 _GLIBCXX_BEGIN_NAMESPACE_VERSION
1566 template<
size_t _Nb>
1567 struct hash<_GLIBCXX_STD_C::bitset<_Nb>>
1568 :
public __hash_base<size_t, _GLIBCXX_STD_C::bitset<_Nb>>
1571 operator()(
const _GLIBCXX_STD_C::bitset<_Nb>& __b)
const noexcept
1573 const size_t __clength = (_Nb + __CHAR_BIT__ - 1) / __CHAR_BIT__;
1574 return std::_Hash_impl::hash(__b._M_getdata(), __clength);
1579 struct hash<_GLIBCXX_STD_C::bitset<0>>
1580 :
public __hash_base<size_t, _GLIBCXX_STD_C::bitset<0>>
1583 operator()(
const _GLIBCXX_STD_C::bitset<0>&)
const noexcept
1587 _GLIBCXX_END_NAMESPACE_VERSION
1592 #ifdef _GLIBCXX_DEBUG 1596 #ifdef _GLIBCXX_PROFILE bool any() const noexcept
Tests whether any of the bits are on.
bitset< _Nb > & operator|=(const bitset< _Nb > &__rhs) noexcept
ISO C++ entities toplevel namespace is std.
bitset< _Nb > & reset(size_t __position)
Sets a given bit to false.
bitset< _Nb > & _Unchecked_reset(size_t __pos) noexcept
constexpr size_t size() const noexcept
Returns the total number of bits.
bitset< _Nb > operator^(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
bitset< _Nb > & _Unchecked_set(size_t __pos) noexcept
const _CharT * data() const noexcept
Return const pointer to contents.
bool test(size_t __position) const
Tests the value of a bit.
_WordT _M_w[_Nw]
0 is the least significant word.
constexpr bitset(unsigned long long __val) noexcept
Initial bits bitwise-copied from a single word (others set to zero).
Thrown as part of forced unwinding.A magic placeholder class that can be caught by reference to recog...
Template class basic_ostream.
bitset< _Nb > & operator>>=(size_t __position) noexcept
std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const bitset< _Nb > &__x)
Global I/O operators for bitsets.
The bitset class represents a fixed-size sequence of bits.(Note that bitset does not meet the formal ...
bitset< _Nb > operator~() const noexcept
See the no-argument flip().
bitset< _Nb > & _Unchecked_set(size_t __pos, int __val) noexcept
The standard allocator, as per [20.4].
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 > & flip(size_t __position)
Toggles a given bit to its opposite value.
bitset< _Nb > operator &(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
void push_back(_CharT __c)
Append a single character.
constexpr bool _Unchecked_test(size_t __pos) const noexcept
basic_streambuf< _CharT, _Traits > * rdbuf() const
Accessing the underlying buffer.
_GLIBCXX_NODISCARD bool empty() const noexcept
reference operator[](size_t __position)
Array-indexing support.
Template class basic_istream.
Primary class template hash.
char_type widen(char __c) const
Widens characters.
bitset< _Nb > & _Unchecked_flip(size_t __pos) noexcept
size_t _Find_next(size_t __prev) const noexcept
Finds the index of the next "on" bit after prev.
std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, bitset< _Nb > &__x)
Global I/O operators for bitsets.
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.
bitset(const std::basic_string< _CharT, _Traits, _Alloc > &__s, size_t __position, size_t __n)
constexpr bool operator[](size_t __position) const
Array-indexing support.
bitset< _Nb > operator>>(size_t __position) const noexcept
Self-explanatory.
bitset(const std::basic_string< _CharT, _Traits, _Alloc > &__s, size_t __position=0)
bitset< _Nb > & flip() noexcept
Toggles every bit to its opposite value.
bool none() const noexcept
Tests whether any of the bits are on.
size_t _Find_first() const noexcept
Finds the index of the first "on" bit.
_GLIBCXX14_CONSTEXPR const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
bitset< _Nb > & reset() noexcept
Sets every bit to false.
char_type widen(char __c) const
Widen char to char_type.
size_t count() const noexcept
Returns the number of bits which are set.
std::basic_string< _CharT, _Traits, _Alloc > to_string() const
Returns a character interpretation of the bitset.
void setstate(iostate __state)
Sets additional flags in the error state.
bool all() const noexcept
Tests whether all the bits are on.
Primary class template ctype facet.This template class defines classification and conversion function...
Basis for explicit traits specializations.
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.
Managing sequences of characters and character-like objects.
unsigned long to_ulong() const
Returns a numerical interpretation of the bitset.
basic_string & assign(const basic_string &__str)
Set value to contents of another string.
constexpr bitset() noexcept
All bits set to zero.
size_type size() const noexcept
Returns the number of characters in the string, not including any null-termination.