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
88 #if __SIZEOF_LONG_LONG__ > __SIZEOF_LONG__
89 , _WordT(__val >> _GLIBCXX_BITSET_BITS_PER_WORD)
93 _Base_bitset(
unsigned long __val)
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
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]; }
137 _M_do_and(
const _Base_bitset<_Nw>& __x) _GLIBCXX_NOEXCEPT
139 for (
size_t __i = 0; __i < _Nw; __i++)
140 _M_w[__i] &= __x._M_w[__i];
144 _M_do_or(
const _Base_bitset<_Nw>& __x) _GLIBCXX_NOEXCEPT
146 for (
size_t __i = 0; __i < _Nw; __i++)
147 _M_w[__i] |= __x._M_w[__i];
151 _M_do_xor(
const _Base_bitset<_Nw>& __x) _GLIBCXX_NOEXCEPT
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++)
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)); }
182 _M_is_equal(
const _Base_bitset<_Nw>& __x)
const _GLIBCXX_NOEXCEPT
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;
240 _Base_bitset<_Nw>::_M_do_left_shift(
size_t __shift) _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));
266 _Base_bitset<_Nw>::_M_do_right_shift(
size_t __shift) _GLIBCXX_NOEXCEPT
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));
293 _Base_bitset<_Nw>::_M_do_to_ulong()
const
295 for (
size_t __i = 1; __i < _Nw; ++__i)
297 __throw_overflow_error(__N(
"_Base_bitset::_M_do_to_ulong"));
301 #if __cplusplus >= 201103L
304 _Base_bitset<_Nw>::_M_do_to_ullong()
const
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);
321 _M_do_find_first(
size_t __not_found)
const _GLIBCXX_NOEXCEPT
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
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
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
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
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);
824 operator=(
bool __x) _GLIBCXX_NOEXCEPT
827 *_M_wp |= _Base::_S_maskbit(_M_bpos);
829 *_M_wp &= ~
_Base::_S_maskbit(_M_bpos);
835 operator=(
const reference& __j) _GLIBCXX_NOEXCEPT
837 if ((*(__j._M_wp) & _Base::_S_maskbit(__j._M_bpos)))
838 *_M_wp |= _Base::_S_maskbit(_M_bpos);
840 *_M_wp &= ~
_Base::_S_maskbit(_M_bpos);
846 operator~()
const _GLIBCXX_NOEXCEPT
847 {
return (*(_M_wp) & _Base::_S_maskbit(_M_bpos)) == 0; }
850 operator bool()
const _GLIBCXX_NOEXCEPT
851 {
return (*(_M_wp) & _Base::_S_maskbit(_M_bpos)) != 0; }
855 flip() _GLIBCXX_NOEXCEPT
857 *_M_wp ^= _Base::_S_maskbit(_M_bpos);
865 _GLIBCXX_CONSTEXPR
bitset() _GLIBCXX_NOEXCEPT
869 #if __cplusplus >= 201103L
871 :
_Base(_Sanitize_val<_Nb>::_S_do_sanitize_val(__val)) { }
873 bitset(
unsigned long __val)
875 { _M_do_sanitize(); }
887 template<
class _CharT,
class _Traits,
class _Alloc>
890 size_t __position = 0)
893 _M_check_initial_position(__s, __position);
894 _M_copy_from_string(__s, __position,
896 _CharT(
'0'), _CharT(
'1'));
909 template<
class _CharT,
class _Traits,
class _Alloc>
911 size_t __position,
size_t __n)
914 _M_check_initial_position(__s, __position);
915 _M_copy_from_string(__s, __position, __n, _CharT(
'0'), _CharT(
'1'));
920 template<
class _CharT,
class _Traits,
class _Alloc>
922 size_t __position,
size_t __n,
923 _CharT __zero, _CharT __one = _CharT(
'1'))
926 _M_check_initial_position(__s, __position);
927 _M_copy_from_string(__s, __position, __n, __zero, __one);
930 #if __cplusplus >= 201103L
940 template<
typename _CharT>
943 typename std::basic_string<_CharT>::size_type __n
945 _CharT __zero = _CharT(
'0'), _CharT __one = _CharT(
'1'))
949 __throw_logic_error(__N(
"bitset::bitset(const _CharT*, ...)"));
953 _M_copy_from_ptr<_CharT, std::char_traits<_CharT>>(__str, __n, 0,
970 this->_M_do_and(__rhs);
977 this->_M_do_or(__rhs);
984 this->_M_do_xor(__rhs);
997 operator<<=(
size_t __position) _GLIBCXX_NOEXCEPT
999 if (__builtin_expect(__position < _Nb, 1))
1001 this->_M_do_left_shift(__position);
1002 this->_M_do_sanitize();
1005 this->_M_do_reset();
1012 if (__builtin_expect(__position < _Nb, 1))
1014 this->_M_do_right_shift(__position);
1015 this->_M_do_sanitize();
1018 this->_M_do_reset();
1032 this->_M_getword(__pos) |= _Base::_S_maskbit(__pos);
1040 this->_M_getword(__pos) |= _Base::_S_maskbit(__pos);
1042 this->_M_getword(__pos) &= ~
_Base::_S_maskbit(__pos);
1049 this->_M_getword(__pos) &= ~
_Base::_S_maskbit(__pos);
1056 this->_M_getword(__pos) ^= _Base::_S_maskbit(__pos);
1060 _GLIBCXX_CONSTEXPR
bool
1062 {
return ((this->_M_getword(__pos) & _Base::_S_maskbit(__pos))
1063 != static_cast<_WordT>(0)); }
1074 this->_M_do_sanitize();
1085 set(
size_t __position,
bool __val =
true)
1087 this->_M_check(__position, __N(
"bitset::set"));
1088 return _Unchecked_set(__position, __val);
1097 this->_M_do_reset();
1111 this->_M_check(__position, __N(
"bitset::reset"));
1112 return _Unchecked_reset(__position);
1122 this->_M_do_sanitize();
1134 this->_M_check(__position, __N(
"bitset::flip"));
1135 return _Unchecked_flip(__position);
1160 {
return reference(*
this, __position); }
1162 _GLIBCXX_CONSTEXPR
bool
1164 {
return _Unchecked_test(__position); }
1175 {
return this->_M_do_to_ulong(); }
1177 #if __cplusplus >= 201103L
1180 {
return this->_M_do_to_ullong(); }
1191 template<
class _CharT,
class _Traits,
class _Alloc>
1196 _M_copy_to_string(__result, _CharT(
'0'), _CharT(
'1'));
1202 template<
class _CharT,
class _Traits,
class _Alloc>
1204 to_string(_CharT __zero, _CharT __one = _CharT(
'1'))
const
1207 _M_copy_to_string(__result, __zero, __one);
1213 template<
class _CharT,
class _Traits>
1216 {
return to_string<_CharT, _Traits, std::allocator<_CharT> >(); }
1220 template<
class _CharT,
class _Traits>
1222 to_string(_CharT __zero, _CharT __one = _CharT(
'1'))
const
1223 {
return to_string<_CharT, _Traits,
1226 template<
class _CharT>
1231 return to_string<_CharT, std::char_traits<_CharT>,
1235 template<
class _CharT>
1238 to_string(_CharT __zero, _CharT __one = _CharT(
'1'))
const
1240 return to_string<_CharT, std::char_traits<_CharT>,
1247 return to_string<char, std::char_traits<char>,
1252 to_string(
char __zero,
char __one =
'1')
const
1254 return to_string<char, std::char_traits<char>,
1259 template<
class _CharT,
class _Traits>
1261 _M_copy_from_ptr(
const _CharT*,
size_t,
size_t,
size_t,
1264 template<
class _CharT,
class _Traits,
class _Alloc>
1267 _Traits, _Alloc>& __s,
size_t __pos,
size_t __n,
1268 _CharT __zero, _CharT __one)
1269 { _M_copy_from_ptr<_CharT, _Traits>(__s.
data(), __s.
size(), __pos, __n,
1272 template<
class _CharT,
class _Traits,
class _Alloc>
1275 _CharT, _CharT)
const;
1278 template<
class _CharT,
class _Traits,
class _Alloc>
1281 _Traits, _Alloc>& __s,
size_t __pos,
size_t __n)
1282 { _M_copy_from_string(__s, __pos, __n, _CharT(
'0'), _CharT(
'1')); }
1284 template<
class _CharT,
class _Traits,
class _Alloc>
1287 { _M_copy_to_string(__s, _CharT(
'0'), _CharT(
'1')); }
1292 {
return this->_M_do_count(); }
1295 _GLIBCXX_CONSTEXPR
size_t
1303 {
return this->_M_is_equal(__rhs); }
1307 {
return !this->_M_is_equal(__rhs); }
1319 this->_M_check(__position, __N(
"bitset::test"));
1320 return _Unchecked_test(__position);
1331 {
return this->
template _M_are_all<_Nb>(); }
1339 {
return this->_M_is_any(); }
1347 {
return !this->_M_is_any(); }
1368 {
return this->_M_do_find_first(_Nb); }
1379 {
return this->_M_do_find_next(__prev, _Nb); }
1383 template<
size_t _Nb>
1384 template<
class _CharT,
class _Traits>
1387 _M_copy_from_ptr(
const _CharT* __s,
size_t __len,
1388 size_t __pos,
size_t __n, _CharT __zero, _CharT __one)
1391 const size_t __nbits =
std::min(_Nb,
std::min(__n,
size_t(__len - __pos)));
1392 for (
size_t __i = __nbits; __i > 0; --__i)
1394 const _CharT __c = __s[__pos + __nbits - __i];
1395 if (_Traits::eq(__c, __zero))
1397 else if (_Traits::eq(__c, __one))
1398 _Unchecked_set(__i - 1);
1400 __throw_invalid_argument(__N(
"bitset::_M_copy_from_ptr"));
1404 template<
size_t _Nb>
1405 template<
class _CharT,
class _Traits,
class _Alloc>
1409 _CharT __zero, _CharT __one)
const
1412 for (
size_t __i = _Nb; __i > 0; --__i)
1413 if (_Unchecked_test(__i - 1))
1414 _Traits::assign(__s[_Nb - __i], __one);
1427 template<
size_t _Nb>
1436 template<
size_t _Nb>
1445 template <
size_t _Nb>
1464 template<
class _CharT,
class _Traits,
size_t _Nb>
1468 typedef typename _Traits::char_type char_type;
1470 typedef typename __istream_type::ios_base __ios_base;
1477 const char_type __zero = __is.
widen(
'0');
1478 const char_type __one = __is.
widen(
'1');
1480 typename __ios_base::iostate __state = __ios_base::goodbit;
1481 typename __istream_type::sentry __sentry(__is);
1486 for (
size_t __i = _Nb; __i > 0; --__i)
1488 static typename _Traits::int_type __eof = _Traits::eof();
1490 typename _Traits::int_type __c1 = __is.
rdbuf()->sbumpc();
1491 if (_Traits::eq_int_type(__c1, __eof))
1493 __state |= __ios_base::eofbit;
1498 const char_type __c2 = _Traits::to_char_type(__c1);
1499 if (_Traits::eq(__c2, __zero))
1501 else if (_Traits::eq(__c2, __one))
1504 eq_int_type(__is.
rdbuf()->sputbackc(__c2),
1507 __state |= __ios_base::failbit;
1515 __is._M_setstate(__ios_base::badbit);
1516 __throw_exception_again;
1519 { __is._M_setstate(__ios_base::badbit); }
1522 if (__tmp.
empty() && _Nb)
1523 __state |= __ios_base::failbit;
1525 __x._M_copy_from_string(__tmp, static_cast<size_t>(0), _Nb,
1532 template <
class _CharT,
class _Traits,
size_t _Nb>
1534 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1541 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__os.getloc());
1542 __x._M_copy_to_string(__tmp, __ct.
widen(
'0'), __ct.
widen(
'1'));
1543 return __os << __tmp;
1547 _GLIBCXX_END_NAMESPACE_CONTAINER
1550 #undef _GLIBCXX_BITSET_WORDS
1551 #undef _GLIBCXX_BITSET_BITS_PER_WORD
1552 #undef _GLIBCXX_BITSET_BITS_PER_ULL
1554 #if __cplusplus >= 201103L
1556 namespace std _GLIBCXX_VISIBILITY(default)
1558 _GLIBCXX_BEGIN_NAMESPACE_VERSION
1562 template<
size_t _Nb>
1563 struct hash<_GLIBCXX_STD_C::bitset<_Nb>>
1564 :
public __hash_base<size_t, _GLIBCXX_STD_C::bitset<_Nb>>
1567 operator()(
const _GLIBCXX_STD_C::bitset<_Nb>& __b)
const noexcept
1569 const size_t __clength = (_Nb + __CHAR_BIT__ - 1) / __CHAR_BIT__;
1570 return std::_Hash_impl::hash(__b._M_getdata(), __clength);
1575 struct hash<_GLIBCXX_STD_C::bitset<0>>
1576 :
public __hash_base<size_t, _GLIBCXX_STD_C::bitset<0>>
1579 operator()(
const _GLIBCXX_STD_C::bitset<0>&) const
noexcept
1583 _GLIBCXX_END_NAMESPACE_VERSION
1588 #ifdef _GLIBCXX_DEBUG
1592 #ifdef _GLIBCXX_PROFILE
bool empty() const noexcept
Primary class template ctype facet.This template class defines classification and conversion function...
void reserve(size_type __res_arg=0)
Attempt to preallocate enough memory for specified number of characters.
constexpr size_t size() const noexcept
Returns the total number of bits.
std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, bitset< _Nb > &__x)
Global I/O operators for bitsets.
bitset< _Nb > & _Unchecked_set(size_t __pos) noexcept
bitset< _Nb > operator&(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
bitset< _Nb > & set(size_t __position, bool __val=true)
Sets a given bit to a particular value.
bitset< _Nb > & operator&=(const bitset< _Nb > &__rhs) noexcept
std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const bitset< _Nb > &__x)
Global I/O operators for bitsets.
bitset< _Nb > & _Unchecked_flip(size_t __pos) noexcept
basic_streambuf< _CharT, _Traits > * rdbuf() const
Accessing the underlying buffer.
bool any() const noexcept
Tests whether any of the bits are on.
size_type size() const noexcept
Returns the number of characters in the string, not including any null-termination.
enable_if< ::__array_traits< _Tp, _Nm >::_Is_swappable::value >::type noexcept(noexcept(__one.swap(__two)))
swap
bitset< _Nb > operator>>(size_t __position) const noexcept
Self-explanatory.
std::basic_string< _CharT, _Traits, _Alloc > to_string() const
Returns a character interpretation of the bitset.
Template class basic_ostream.
bitset< _Nb > & operator|=(const bitset< _Nb > &__rhs) noexcept
bitset< _Nb > & _Unchecked_set(size_t __pos, int __val) noexcept
size_t _Find_first() const noexcept
Finds the index of the first "on" bit.
const _CharT * data() const noexcept
Return const pointer to contents.
bitset< _Nb > & reset(size_t __position)
Sets a given bit to false.
bool test(size_t __position) const
Tests the value of a bit.
constexpr bitset() noexcept
All bits set to zero.
The standard allocator, as per [20.4].
basic_string & assign(const basic_string &__str)
Set value to contents of another string.
bitset< _Nb > & flip() noexcept
Toggles every bit to its opposite value.
bitset< _Nb > & _Unchecked_reset(size_t __pos) noexcept
bitset< _Nb > & operator>>=(size_t __position) noexcept
bitset< _Nb > & operator^=(const bitset< _Nb > &__rhs) noexcept
reference operator[](size_t __position)
Array-indexing support.
bitset< _Nb > & flip(size_t __position)
Toggles a given bit to its opposite value.
bitset< _Nb > operator~() const noexcept
See the no-argument flip().
bool none() const noexcept
Tests whether any of the bits are on.
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(const std::basic_string< _CharT, _Traits, _Alloc > &__s, size_t __position=0)
Template class basic_istream.
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.
char_type widen(char __c) const
Widen char to char_type.
bool operator!=(const bitset< _Nb > &__rhs) const noexcept
These comparisons for equality/inequality are, well, bitwise.
_WordT _M_w[_Nw]
0 is the least significant word.
unsigned long to_ulong() const
Returns a numerical interpretation of the bitset.
Managing sequences of characters and character-like objects.
bool operator==(const bitset< _Nb > &__rhs) const noexcept
These comparisons for equality/inequality are, well, bitwise.
Primary class template hash.
void setstate(iostate __state)
Sets additional flags in the error state.
Thrown as part of forced unwinding.A magic placeholder class that can be caught by reference to recog...
char_type widen(char __c) const
Widens characters.
_GLIBCXX14_CONSTEXPR const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
Basis for explicit traits specializations.
constexpr bool _Unchecked_test(size_t __pos) const noexcept
bitset< _Nb > operator^(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
bitset< _Nb > & reset() noexcept
Sets every bit to false.
bitset< _Nb > operator|(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
bool all() const noexcept
Tests whether all the bits are on.
size_t count() const noexcept
Returns the number of bits which are set.
size_t _Find_next(size_t __prev) const noexcept
Finds the index of the next "on" bit after prev.
constexpr bitset(unsigned long long __val) noexcept
Initial bits bitwise-copied from a single word (others set to zero).
bitset< _Nb > & set() noexcept
Sets every bit to true.
The bitset class represents a fixed-size sequence of bits.(Note that bitset does not meet the formal ...
void push_back(_CharT __c)
Append a single character.