44 #ifndef _GLIBCXX_BITSET
45 #define _GLIBCXX_BITSET 1
47 #pragma GCC system_header
55 #define _GLIBCXX_BITSET_BITS_PER_WORD (__CHAR_BIT__ * __SIZEOF_LONG__)
56 #define _GLIBCXX_BITSET_WORDS(__n) \
57 ((__n) / _GLIBCXX_BITSET_BITS_PER_WORD + \
58 ((__n) % _GLIBCXX_BITSET_BITS_PER_WORD == 0 ? 0 : 1))
60 #define _GLIBCXX_BITSET_BITS_PER_ULL (__CHAR_BIT__ * __SIZEOF_LONG_LONG__)
62 namespace std _GLIBCXX_VISIBILITY(default)
64 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
75 typedef unsigned long _WordT;
83 #ifdef __GXX_EXPERIMENTAL_CXX0X__
84 constexpr
_Base_bitset(
unsigned long long __val) noexcept
86 #if __SIZEOF_LONG_LONG__ > __SIZEOF_LONG__
87 , _WordT(__val >> _GLIBCXX_BITSET_BITS_PER_WORD)
91 _Base_bitset(
unsigned long __val)
96 static _GLIBCXX_CONSTEXPR
size_t
97 _S_whichword(
size_t __pos) _GLIBCXX_NOEXCEPT
98 {
return __pos / _GLIBCXX_BITSET_BITS_PER_WORD; }
100 static _GLIBCXX_CONSTEXPR
size_t
101 _S_whichbyte(
size_t __pos) _GLIBCXX_NOEXCEPT
102 {
return (__pos % _GLIBCXX_BITSET_BITS_PER_WORD) / __CHAR_BIT__; }
104 static _GLIBCXX_CONSTEXPR
size_t
105 _S_whichbit(
size_t __pos) _GLIBCXX_NOEXCEPT
106 {
return __pos % _GLIBCXX_BITSET_BITS_PER_WORD; }
108 static _GLIBCXX_CONSTEXPR _WordT
109 _S_maskbit(
size_t __pos) _GLIBCXX_NOEXCEPT
110 {
return (static_cast<_WordT>(1)) << _S_whichbit(__pos); }
113 _M_getword(
size_t __pos) _GLIBCXX_NOEXCEPT
114 {
return _M_w[_S_whichword(__pos)]; }
116 _GLIBCXX_CONSTEXPR _WordT
117 _M_getword(
size_t __pos)
const _GLIBCXX_NOEXCEPT
118 {
return _M_w[_S_whichword(__pos)]; }
120 #ifdef __GXX_EXPERIMENTAL_CXX0X__
122 _M_getdata() const noexcept
127 _M_hiword() _GLIBCXX_NOEXCEPT
128 {
return _M_w[_Nw - 1]; }
130 _GLIBCXX_CONSTEXPR _WordT
131 _M_hiword() const _GLIBCXX_NOEXCEPT
132 {
return _M_w[_Nw - 1]; }
135 _M_do_and(
const _Base_bitset<_Nw>& __x) _GLIBCXX_NOEXCEPT
137 for (
size_t __i = 0; __i < _Nw; __i++)
138 _M_w[__i] &= __x._M_w[__i];
142 _M_do_or(
const _Base_bitset<_Nw>& __x) _GLIBCXX_NOEXCEPT
144 for (
size_t __i = 0; __i < _Nw; __i++)
145 _M_w[__i] |= __x._M_w[__i];
149 _M_do_xor(
const _Base_bitset<_Nw>& __x) _GLIBCXX_NOEXCEPT
151 for (
size_t __i = 0; __i < _Nw; __i++)
152 _M_w[__i] ^= __x._M_w[__i];
156 _M_do_left_shift(
size_t __shift) _GLIBCXX_NOEXCEPT;
159 _M_do_right_shift(
size_t __shift) _GLIBCXX_NOEXCEPT;
162 _M_do_flip() _GLIBCXX_NOEXCEPT
164 for (
size_t __i = 0; __i < _Nw; __i++)
169 _M_do_set() _GLIBCXX_NOEXCEPT
171 for (
size_t __i = 0; __i < _Nw; __i++)
172 _M_w[__i] = ~static_cast<_WordT>(0);
176 _M_do_reset() _GLIBCXX_NOEXCEPT
177 { __builtin_memset(
_M_w, 0, _Nw *
sizeof(_WordT)); }
180 _M_is_equal(
const _Base_bitset<_Nw>& __x)
const _GLIBCXX_NOEXCEPT
182 for (
size_t __i = 0; __i < _Nw; ++__i)
183 if (
_M_w[__i] != __x._M_w[__i])
190 _M_are_all() const _GLIBCXX_NOEXCEPT
192 for (
size_t __i = 0; __i < _Nw - 1; __i++)
193 if (
_M_w[__i] != ~static_cast<_WordT>(0))
195 return _M_hiword() == (~static_cast<_WordT>(0)
196 >> (_Nw * _GLIBCXX_BITSET_BITS_PER_WORD
201 _M_is_any() const _GLIBCXX_NOEXCEPT
203 for (
size_t __i = 0; __i < _Nw; __i++)
204 if (
_M_w[__i] != static_cast<_WordT>(0))
210 _M_do_count() const _GLIBCXX_NOEXCEPT
213 for (
size_t __i = 0; __i < _Nw; __i++)
214 __result += __builtin_popcountl(
_M_w[__i]);
219 _M_do_to_ulong()
const;
221 #ifdef __GXX_EXPERIMENTAL_CXX0X__
223 _M_do_to_ullong()
const;
228 _M_do_find_first(
size_t) const _GLIBCXX_NOEXCEPT;
232 _M_do_find_next(
size_t,
size_t) const _GLIBCXX_NOEXCEPT;
238 _Base_bitset<_Nw>::_M_do_left_shift(
size_t __shift) _GLIBCXX_NOEXCEPT
240 if (__builtin_expect(__shift != 0, 1))
242 const size_t __wshift = __shift / _GLIBCXX_BITSET_BITS_PER_WORD;
243 const size_t __offset = __shift % _GLIBCXX_BITSET_BITS_PER_WORD;
246 for (
size_t __n = _Nw - 1; __n >= __wshift; --__n)
250 const size_t __sub_offset = (_GLIBCXX_BITSET_BITS_PER_WORD
252 for (
size_t __n = _Nw - 1; __n > __wshift; --__n)
253 _M_w[__n] = ((
_M_w[__n - __wshift] << __offset)
254 | (
_M_w[__n - __wshift - 1] >> __sub_offset));
255 _M_w[__wshift] =
_M_w[0] << __offset;
258 std::fill(
_M_w + 0,
_M_w + __wshift, static_cast<_WordT>(0));
264 _Base_bitset<_Nw>::_M_do_right_shift(
size_t __shift) _GLIBCXX_NOEXCEPT
266 if (__builtin_expect(__shift != 0, 1))
268 const size_t __wshift = __shift / _GLIBCXX_BITSET_BITS_PER_WORD;
269 const size_t __offset = __shift % _GLIBCXX_BITSET_BITS_PER_WORD;
270 const size_t __limit = _Nw - __wshift - 1;
273 for (
size_t __n = 0; __n <= __limit; ++__n)
277 const size_t __sub_offset = (_GLIBCXX_BITSET_BITS_PER_WORD
279 for (
size_t __n = 0; __n < __limit; ++__n)
280 _M_w[__n] = ((
_M_w[__n + __wshift] >> __offset)
281 | (
_M_w[__n + __wshift + 1] << __sub_offset));
282 _M_w[__limit] =
_M_w[_Nw-1] >> __offset;
285 std::fill(
_M_w + __limit + 1,
_M_w + _Nw, static_cast<_WordT>(0));
291 _Base_bitset<_Nw>::_M_do_to_ulong()
const
293 for (
size_t __i = 1; __i < _Nw; ++__i)
295 __throw_overflow_error(__N(
"_Base_bitset::_M_do_to_ulong"));
299 #ifdef __GXX_EXPERIMENTAL_CXX0X__
302 _Base_bitset<_Nw>::_M_do_to_ullong()
const
304 const bool __dw =
sizeof(
unsigned long long) >
sizeof(
unsigned long);
305 for (
size_t __i = 1 + __dw; __i < _Nw; ++__i)
307 __throw_overflow_error(__N(
"_Base_bitset::_M_do_to_ullong"));
310 return _M_w[0] + (
static_cast<unsigned long long>(
_M_w[1])
311 << _GLIBCXX_BITSET_BITS_PER_WORD);
319 _M_do_find_first(
size_t __not_found)
const _GLIBCXX_NOEXCEPT
321 for (
size_t __i = 0; __i < _Nw; __i++)
323 _WordT __thisword =
_M_w[__i];
324 if (__thisword != static_cast<_WordT>(0))
325 return (__i * _GLIBCXX_BITSET_BITS_PER_WORD
326 + __builtin_ctzl(__thisword));
335 _M_do_find_next(
size_t __prev,
size_t __not_found)
const _GLIBCXX_NOEXCEPT
341 if (__prev >= _Nw * _GLIBCXX_BITSET_BITS_PER_WORD)
345 size_t __i = _S_whichword(__prev);
346 _WordT __thisword =
_M_w[__i];
349 __thisword &= (~static_cast<_WordT>(0)) << _S_whichbit(__prev);
351 if (__thisword != static_cast<_WordT>(0))
352 return (__i * _GLIBCXX_BITSET_BITS_PER_WORD
353 + __builtin_ctzl(__thisword));
357 for (; __i < _Nw; __i++)
359 __thisword =
_M_w[__i];
360 if (__thisword != static_cast<_WordT>(0))
361 return (__i * _GLIBCXX_BITSET_BITS_PER_WORD
362 + __builtin_ctzl(__thisword));
376 typedef unsigned long _WordT;
383 #ifdef __GXX_EXPERIMENTAL_CXX0X__
384 constexpr
_Base_bitset(
unsigned long long __val) noexcept
391 static _GLIBCXX_CONSTEXPR
size_t
392 _S_whichword(
size_t __pos) _GLIBCXX_NOEXCEPT
393 {
return __pos / _GLIBCXX_BITSET_BITS_PER_WORD; }
395 static _GLIBCXX_CONSTEXPR
size_t
396 _S_whichbyte(
size_t __pos) _GLIBCXX_NOEXCEPT
397 {
return (__pos % _GLIBCXX_BITSET_BITS_PER_WORD) / __CHAR_BIT__; }
399 static _GLIBCXX_CONSTEXPR
size_t
400 _S_whichbit(
size_t __pos) _GLIBCXX_NOEXCEPT
401 {
return __pos % _GLIBCXX_BITSET_BITS_PER_WORD; }
403 static _GLIBCXX_CONSTEXPR _WordT
404 _S_maskbit(
size_t __pos) _GLIBCXX_NOEXCEPT
405 {
return (static_cast<_WordT>(1)) << _S_whichbit(__pos); }
408 _M_getword(
size_t) _GLIBCXX_NOEXCEPT
411 _GLIBCXX_CONSTEXPR _WordT
412 _M_getword(
size_t)
const _GLIBCXX_NOEXCEPT
415 #ifdef __GXX_EXPERIMENTAL_CXX0X__
417 _M_getdata()
const noexcept
422 _M_hiword() _GLIBCXX_NOEXCEPT
425 _GLIBCXX_CONSTEXPR _WordT
426 _M_hiword()
const _GLIBCXX_NOEXCEPT
431 {
_M_w &= __x._M_w; }
435 {
_M_w |= __x._M_w; }
439 {
_M_w ^= __x._M_w; }
442 _M_do_left_shift(
size_t __shift) _GLIBCXX_NOEXCEPT
443 {
_M_w <<= __shift; }
446 _M_do_right_shift(
size_t __shift) _GLIBCXX_NOEXCEPT
447 {
_M_w >>= __shift; }
450 _M_do_flip() _GLIBCXX_NOEXCEPT
454 _M_do_set() _GLIBCXX_NOEXCEPT
455 {
_M_w = ~static_cast<_WordT>(0); }
458 _M_do_reset() _GLIBCXX_NOEXCEPT
463 {
return _M_w == __x._M_w; }
467 _M_are_all()
const _GLIBCXX_NOEXCEPT
468 {
return _M_w == (~static_cast<_WordT>(0)
469 >> (_GLIBCXX_BITSET_BITS_PER_WORD - _Nb)); }
472 _M_is_any()
const _GLIBCXX_NOEXCEPT
473 {
return _M_w != 0; }
476 _M_do_count()
const _GLIBCXX_NOEXCEPT
477 {
return __builtin_popcountl(
_M_w); }
480 _M_do_to_ulong()
const _GLIBCXX_NOEXCEPT
483 #ifdef __GXX_EXPERIMENTAL_CXX0X__
485 _M_do_to_ullong()
const noexcept
490 _M_do_find_first(
size_t __not_found)
const _GLIBCXX_NOEXCEPT
493 return __builtin_ctzl(
_M_w);
500 _M_do_find_next(
size_t __prev,
size_t __not_found)
const
504 if (__prev >= ((
size_t) _GLIBCXX_BITSET_BITS_PER_WORD))
507 _WordT __x =
_M_w >> __prev;
509 return __builtin_ctzl(__x) + __prev;
523 typedef unsigned long _WordT;
528 #ifdef __GXX_EXPERIMENTAL_CXX0X__
535 static _GLIBCXX_CONSTEXPR
size_t
536 _S_whichword(
size_t __pos) _GLIBCXX_NOEXCEPT
537 {
return __pos / _GLIBCXX_BITSET_BITS_PER_WORD; }
539 static _GLIBCXX_CONSTEXPR
size_t
540 _S_whichbyte(
size_t __pos) _GLIBCXX_NOEXCEPT
541 {
return (__pos % _GLIBCXX_BITSET_BITS_PER_WORD) / __CHAR_BIT__; }
543 static _GLIBCXX_CONSTEXPR
size_t
544 _S_whichbit(
size_t __pos) _GLIBCXX_NOEXCEPT
545 {
return __pos % _GLIBCXX_BITSET_BITS_PER_WORD; }
547 static _GLIBCXX_CONSTEXPR _WordT
548 _S_maskbit(
size_t __pos) _GLIBCXX_NOEXCEPT
549 {
return (static_cast<_WordT>(1)) << _S_whichbit(__pos); }
559 _M_getword(
size_t) _GLIBCXX_NOEXCEPT
561 __throw_out_of_range(__N(
"_Base_bitset::_M_getword"));
565 _GLIBCXX_CONSTEXPR _WordT
566 _M_getword(
size_t __pos)
const _GLIBCXX_NOEXCEPT
569 _GLIBCXX_CONSTEXPR _WordT
570 _M_hiword()
const _GLIBCXX_NOEXCEPT
586 _M_do_left_shift(
size_t) _GLIBCXX_NOEXCEPT
590 _M_do_right_shift(
size_t) _GLIBCXX_NOEXCEPT
594 _M_do_flip() _GLIBCXX_NOEXCEPT
598 _M_do_set() _GLIBCXX_NOEXCEPT
602 _M_do_reset() _GLIBCXX_NOEXCEPT
614 _M_are_all()
const _GLIBCXX_NOEXCEPT
618 _M_is_any()
const _GLIBCXX_NOEXCEPT
622 _M_do_count()
const _GLIBCXX_NOEXCEPT
626 _M_do_to_ulong()
const _GLIBCXX_NOEXCEPT
629 #ifdef __GXX_EXPERIMENTAL_CXX0X__
631 _M_do_to_ullong()
const noexcept
638 _M_do_find_first(
size_t)
const _GLIBCXX_NOEXCEPT
642 _M_do_find_next(
size_t,
size_t)
const _GLIBCXX_NOEXCEPT
648 template<
size_t _Extrabits>
651 typedef unsigned long _WordT;
654 _S_do_sanitize(_WordT& __val) _GLIBCXX_NOEXCEPT
655 { __val &= ~((~static_cast<_WordT>(0)) << _Extrabits); }
661 typedef unsigned long _WordT;
664 _S_do_sanitize(_WordT) _GLIBCXX_NOEXCEPT { }
667 #ifdef __GXX_EXPERIMENTAL_CXX0X__
668 template<
size_t _Nb,
bool = _Nb < _GLIBCXX_BITSET_BITS_PER_ULL>
671 static constexpr
unsigned long long
672 _S_do_sanitize_val(
unsigned long long __val)
677 struct _Sanitize_val<_Nb, true>
679 static constexpr
unsigned long long
680 _S_do_sanitize_val(
unsigned long long __val)
681 {
return __val & ~((~static_cast<
unsigned long long>(0)) << _Nb); }
751 :
private _Base_bitset<_GLIBCXX_BITSET_WORDS(_Nb)>
754 typedef _Base_bitset<_GLIBCXX_BITSET_WORDS(_Nb)> _Base;
755 typedef unsigned long _WordT;
758 _M_do_sanitize() _GLIBCXX_NOEXCEPT
760 typedef _Sanitize<_Nb % _GLIBCXX_BITSET_BITS_PER_WORD> __sanitize_type;
761 __sanitize_type::_S_do_sanitize(this->_M_hiword());
764 #ifdef __GXX_EXPERIMENTAL_CXX0X__
765 template<
typename>
friend class hash;
792 reference(bitset& __b,
size_t __pos) _GLIBCXX_NOEXCEPT
794 _M_wp = &__b._M_getword(__pos);
795 _M_bpos = _Base::_S_whichbit(__pos);
798 ~reference() _GLIBCXX_NOEXCEPT
803 operator=(
bool __x) _GLIBCXX_NOEXCEPT
806 *_M_wp |= _Base::_S_maskbit(_M_bpos);
808 *_M_wp &= ~_Base::_S_maskbit(_M_bpos);
814 operator=(
const reference& __j) _GLIBCXX_NOEXCEPT
816 if ((*(__j._M_wp) & _Base::_S_maskbit(__j._M_bpos)))
817 *_M_wp |= _Base::_S_maskbit(_M_bpos);
819 *_M_wp &= ~_Base::_S_maskbit(_M_bpos);
826 {
return (*(_M_wp) & _Base::_S_maskbit(_M_bpos)) == 0; }
829 operator bool() const _GLIBCXX_NOEXCEPT
830 {
return (*(_M_wp) & _Base::_S_maskbit(_M_bpos)) != 0; }
834 flip() _GLIBCXX_NOEXCEPT
836 *_M_wp ^= _Base::_S_maskbit(_M_bpos);
840 friend class reference;
844 _GLIBCXX_CONSTEXPR bitset() _GLIBCXX_NOEXCEPT
848 #ifdef __GXX_EXPERIMENTAL_CXX0X__
849 constexpr bitset(
unsigned long long __val) noexcept
850 : _Base(_Sanitize_val<_Nb>::_S_do_sanitize_val(__val)) { }
852 bitset(
unsigned long __val)
854 { _M_do_sanitize(); }
866 template<
class _CharT,
class _Traits,
class _Alloc>
869 size_t __position = 0)
872 if (__position > __s.
size())
873 __throw_out_of_range(__N(
"bitset::bitset initial position "
875 _M_copy_from_string(__s, __position,
877 _CharT(
'0'), _CharT(
'1'));
890 template<
class _CharT,
class _Traits,
class _Alloc>
892 size_t __position,
size_t __n)
895 if (__position > __s.
size())
896 __throw_out_of_range(__N(
"bitset::bitset initial position "
898 _M_copy_from_string(__s, __position, __n, _CharT(
'0'), _CharT(
'1'));
903 template<
class _CharT,
class _Traits,
class _Alloc>
905 size_t __position,
size_t __n,
906 _CharT __zero, _CharT __one = _CharT(
'1'))
909 if (__position > __s.
size())
910 __throw_out_of_range(__N(
"bitset::bitset initial position "
912 _M_copy_from_string(__s, __position, __n, __zero, __one);
915 #ifdef __GXX_EXPERIMENTAL_CXX0X__
925 template<
typename _CharT>
927 bitset(
const _CharT* __str,
928 typename std::basic_string<_CharT>::size_type __n
930 _CharT __zero = _CharT(
'0'), _CharT __one = _CharT(
'1'))
934 __throw_logic_error(__N(
"bitset::bitset(const _CharT*, ...)"));
938 _M_copy_from_ptr<_CharT, std::char_traits<_CharT>>(__str, __n, 0,
953 operator&=(
const bitset<_Nb>& __rhs) _GLIBCXX_NOEXCEPT
955 this->_M_do_and(__rhs);
960 operator|=(
const bitset<_Nb>& __rhs) _GLIBCXX_NOEXCEPT
962 this->_M_do_or(__rhs);
967 operator^=(
const bitset<_Nb>& __rhs) _GLIBCXX_NOEXCEPT
969 this->_M_do_xor(__rhs);
984 if (__builtin_expect(__position < _Nb, 1))
986 this->_M_do_left_shift(__position);
987 this->_M_do_sanitize();
997 if (__builtin_expect(__position < _Nb, 1))
999 this->_M_do_right_shift(__position);
1000 this->_M_do_sanitize();
1003 this->_M_do_reset();
1017 this->_M_getword(__pos) |= _Base::_S_maskbit(__pos);
1025 this->_M_getword(__pos) |= _Base::_S_maskbit(__pos);
1027 this->_M_getword(__pos) &= ~_Base::_S_maskbit(__pos);
1034 this->_M_getword(__pos) &= ~_Base::_S_maskbit(__pos);
1041 this->_M_getword(__pos) ^= _Base::_S_maskbit(__pos);
1045 _GLIBCXX_CONSTEXPR
bool
1047 {
return ((this->_M_getword(__pos) & _Base::_S_maskbit(__pos))
1048 != static_cast<_WordT>(0)); }
1059 this->_M_do_sanitize();
1070 set(
size_t __position,
bool __val =
true)
1072 if (__position >= _Nb)
1073 __throw_out_of_range(__N(
"bitset::set"));
1083 this->_M_do_reset();
1097 if (__position >= _Nb)
1098 __throw_out_of_range(__N(
"bitset::reset"));
1109 this->_M_do_sanitize();
1121 if (__position >= _Nb)
1122 __throw_out_of_range(__N(
"bitset::flip"));
1129 {
return bitset<_Nb>(*this).flip(); }
1148 {
return reference(*
this, __position); }
1150 _GLIBCXX_CONSTEXPR
bool
1163 {
return this->_M_do_to_ulong(); }
1165 #ifdef __GXX_EXPERIMENTAL_CXX0X__
1168 {
return this->_M_do_to_ullong(); }
1179 template<
class _CharT,
class _Traits,
class _Alloc>
1184 _M_copy_to_string(__result, _CharT(
'0'), _CharT(
'1'));
1190 template<
class _CharT,
class _Traits,
class _Alloc>
1192 to_string(_CharT __zero, _CharT __one = _CharT(
'1'))
const
1195 _M_copy_to_string(__result, __zero, __one);
1201 template<
class _CharT,
class _Traits>
1204 {
return to_string<_CharT, _Traits, std::allocator<_CharT> >(); }
1208 template<
class _CharT,
class _Traits>
1210 to_string(_CharT __zero, _CharT __one = _CharT(
'1'))
const
1214 template<
class _CharT>
1219 return to_string<_CharT, std::char_traits<_CharT>,
1223 template<
class _CharT>
1226 to_string(_CharT __zero, _CharT __one = _CharT(
'1'))
const
1228 return to_string<_CharT, std::char_traits<_CharT>,
1235 return to_string<char, std::char_traits<char>,
1240 to_string(
char __zero,
char __one =
'1')
const
1242 return to_string<char, std::char_traits<char>,
1247 template<
class _CharT,
class _Traits>
1249 _M_copy_from_ptr(
const _CharT*,
size_t,
size_t,
size_t,
1252 template<
class _CharT,
class _Traits,
class _Alloc>
1255 _Traits, _Alloc>& __s,
size_t __pos,
size_t __n,
1256 _CharT __zero, _CharT __one)
1257 { _M_copy_from_ptr<_CharT, _Traits>(__s.
data(), __s.
size(), __pos, __n,
1260 template<
class _CharT,
class _Traits,
class _Alloc>
1263 _CharT, _CharT)
const;
1266 template<
class _CharT,
class _Traits,
class _Alloc>
1269 _Traits, _Alloc>& __s,
size_t __pos,
size_t __n)
1270 { _M_copy_from_string(__s, __pos, __n, _CharT(
'0'), _CharT(
'1')); }
1272 template<
class _CharT,
class _Traits,
class _Alloc>
1275 { _M_copy_to_string(__s, _CharT(
'0'), _CharT(
'1')); }
1280 {
return this->_M_do_count(); }
1283 _GLIBCXX_CONSTEXPR
size_t
1291 {
return this->_M_is_equal(__rhs); }
1295 {
return !this->_M_is_equal(__rhs); }
1307 if (__position >= _Nb)
1308 __throw_out_of_range(__N(
"bitset::test"));
1320 {
return this->
template _M_are_all<_Nb>(); }
1328 {
return this->_M_is_any(); }
1336 {
return !this->_M_is_any(); }
1342 {
return bitset<_Nb>(*this) <<= __position; }
1346 {
return bitset<_Nb>(*this) >>= __position; }
1357 {
return this->_M_do_find_first(_Nb); }
1368 {
return this->_M_do_find_next(__prev, _Nb); }
1372 template<
size_t _Nb>
1373 template<
class _CharT,
class _Traits>
1376 _M_copy_from_ptr(
const _CharT* __s,
size_t __len,
1377 size_t __pos,
size_t __n, _CharT __zero, _CharT __one)
1380 const size_t __nbits =
std::min(_Nb,
std::min(__n,
size_t(__len - __pos)));
1381 for (
size_t __i = __nbits; __i > 0; --__i)
1383 const _CharT __c = __s[__pos + __nbits - __i];
1384 if (_Traits::eq(__c, __zero))
1386 else if (_Traits::eq(__c, __one))
1389 __throw_invalid_argument(__N(
"bitset::_M_copy_from_ptr"));
1393 template<
size_t _Nb>
1394 template<
class _CharT,
class _Traits,
class _Alloc>
1398 _CharT __zero, _CharT __one)
const
1401 for (
size_t __i = _Nb; __i > 0; --__i)
1403 _Traits::assign(__s[_Nb - __i], __one);
1416 template<
size_t _Nb>
1418 operator&(
const bitset<_Nb>& __x,
const bitset<_Nb>& __y) _GLIBCXX_NOEXCEPT
1420 bitset<_Nb> __result(__x);
1425 template<
size_t _Nb>
1427 operator|(
const bitset<_Nb>& __x,
const bitset<_Nb>& __y) _GLIBCXX_NOEXCEPT
1429 bitset<_Nb> __result(__x);
1434 template <
size_t _Nb>
1436 operator^(
const bitset<_Nb>& __x,
const bitset<_Nb>& __y) _GLIBCXX_NOEXCEPT
1438 bitset<_Nb> __result(__x);
1453 template<
class _CharT,
class _Traits,
size_t _Nb>
1457 typedef typename _Traits::char_type char_type;
1459 typedef typename __istream_type::ios_base __ios_base;
1466 const char_type __zero = __is.
widen(
'0');
1467 const char_type __one = __is.
widen(
'1');
1469 typename __ios_base::iostate __state = __ios_base::goodbit;
1470 typename __istream_type::sentry __sentry(__is);
1475 for (
size_t __i = _Nb; __i > 0; --__i)
1477 static typename _Traits::int_type __eof = _Traits::eof();
1479 typename _Traits::int_type __c1 = __is.
rdbuf()->sbumpc();
1480 if (_Traits::eq_int_type(__c1, __eof))
1482 __state |= __ios_base::eofbit;
1487 const char_type __c2 = _Traits::to_char_type(__c1);
1488 if (_Traits::eq(__c2, __zero))
1490 else if (_Traits::eq(__c2, __one))
1493 eq_int_type(__is.
rdbuf()->sputbackc(__c2),
1496 __state |= __ios_base::failbit;
1504 __is._M_setstate(__ios_base::badbit);
1505 __throw_exception_again;
1508 { __is._M_setstate(__ios_base::badbit); }
1511 if (__tmp.
empty() && _Nb)
1512 __state |= __ios_base::failbit;
1514 __x._M_copy_from_string(__tmp, static_cast<size_t>(0), _Nb,
1521 template <
class _CharT,
class _Traits,
size_t _Nb>
1523 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1524 const bitset<_Nb>& __x)
1530 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__os.getloc());
1531 __x._M_copy_to_string(__tmp, __ct.
widen(
'0'), __ct.
widen(
'1'));
1532 return __os << __tmp;
1536 _GLIBCXX_END_NAMESPACE_CONTAINER
1539 #undef _GLIBCXX_BITSET_WORDS
1540 #undef _GLIBCXX_BITSET_BITS_PER_WORD
1541 #undef _GLIBCXX_BITSET_BITS_PER_ULL
1543 #ifdef __GXX_EXPERIMENTAL_CXX0X__
1547 namespace std _GLIBCXX_VISIBILITY(default)
1549 _GLIBCXX_BEGIN_NAMESPACE_VERSION
1553 template<
size_t _Nb>
1554 struct hash<_GLIBCXX_STD_C::bitset<_Nb>>
1555 :
public __hash_base<size_t, _GLIBCXX_STD_C::bitset<_Nb>>
1558 operator()(
const _GLIBCXX_STD_C::bitset<_Nb>& __b)
const noexcept
1560 const size_t __clength = (_Nb + __CHAR_BIT__ - 1) / __CHAR_BIT__;
1561 return std::_Hash_impl::hash(__b._M_getdata(), __clength);
1566 struct hash<_GLIBCXX_STD_C::bitset<0>>
1567 :
public __hash_base<size_t, _GLIBCXX_STD_C::bitset<0>>
1570 operator()(
const _GLIBCXX_STD_C::bitset<0>&) const noexcept
1574 _GLIBCXX_END_NAMESPACE_VERSION
1577 #endif // __GXX_EXPERIMENTAL_CXX0X__
1579 #ifdef _GLIBCXX_DEBUG
1583 #ifdef _GLIBCXX_PROFILE
void push_back(_CharT __c)
Append a single character.
bool test(size_t __position) const
Tests the value of a bit.
void setstate(iostate __state)
Sets additional flags in the error state.
bool empty() const _GLIBCXX_NOEXCEPT
The standard allocator, as per [20.4].
Primary class template ctype facet.This template class defines classification and conversion function...
bitset< _Nb > & flip() _GLIBCXX_NOEXCEPT
Toggles every bit to its opposite value.
bitset< _Nb > operator|(const bitset< _Nb > &__x, const bitset< _Nb > &__y) _GLIBCXX_NOEXCEPT
Global bitwise operations on bitsets.
char_type widen(char __c) const
Widens characters.
bitset< _Nb > operator^(const bitset< _Nb > &__x, const bitset< _Nb > &__y) _GLIBCXX_NOEXCEPT
Global bitwise operations on bitsets.
Template class basic_ostream.This is the base class for all output streams. It provides text formatti...
_WordT _M_w[_Nw]
0 is the least significant word.
constexpr bool _Unchecked_test(size_t __pos) const _GLIBCXX_NOEXCEPT
size_type size() const _GLIBCXX_NOEXCEPT
Returns the number of characters in the string, not including any null-termination.
char_type widen(char __c) const
Widen char to char_type.
const _CharT * data() const _GLIBCXX_NOEXCEPT
Return const pointer to contents.
basic_string & assign(const basic_string &__str)
Set value to contents of another string.
std::basic_string< _CharT, _Traits, _Alloc > to_string() const
Returns a character interpretation of the bitset.
bitset< _Nb > operator~() const _GLIBCXX_NOEXCEPT
See the no-argument flip().
size_t count() const _GLIBCXX_NOEXCEPT
Returns the number of bits which are set.
bool operator!=(const bitset< _Nb > &__rhs) const _GLIBCXX_NOEXCEPT
These comparisons for equality/inequality are, well, bitwise.
bitset< _Nb > & _Unchecked_flip(size_t __pos) _GLIBCXX_NOEXCEPT
bool all() const _GLIBCXX_NOEXCEPT
Tests whether all the bits are on.
void reserve(size_type __res_arg=0)
Attempt to preallocate enough memory for specified number of characters.
size_t _Find_next(size_t __prev) const _GLIBCXX_NOEXCEPT
Finds the index of the next "on" bit after prev.
bool none() const _GLIBCXX_NOEXCEPT
Tests whether any of the bits are on.
Thrown as part of forced unwinding.A magic placeholder class that can be caught by reference to recog...
const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
unsigned long to_ulong() const
Returns a numerical interpretation of the bitset.
Template class basic_istream.This is the base class for all input streams. It provides text formattin...
reference operator[](size_t __position)
Array-indexing support.
bitset< _Nb > & operator>>=(size_t __position) _GLIBCXX_NOEXCEPT
Managing sequences of characters and character-like objects.
bitset< _Nb > & reset() _GLIBCXX_NOEXCEPT
Sets every bit to false.
bitset< _Nb > operator<<(size_t __position) const _GLIBCXX_NOEXCEPT
Self-explanatory.
basic_streambuf< _CharT, _Traits > * rdbuf() const
Accessing the underlying buffer.
Basis for explicit traits specializations.
bitset< _Nb > & operator<<=(size_t __position) _GLIBCXX_NOEXCEPT
bool any() const _GLIBCXX_NOEXCEPT
Tests whether any of the bits are on.
bitset< _Nb > & _Unchecked_reset(size_t __pos) _GLIBCXX_NOEXCEPT
size_t _Find_first() const _GLIBCXX_NOEXCEPT
Finds the index of the first "on" bit.
bool operator==(const bitset< _Nb > &__rhs) const _GLIBCXX_NOEXCEPT
These comparisons for equality/inequality are, well, bitwise.
bitset< _Nb > operator>>(size_t __position) const _GLIBCXX_NOEXCEPT
Self-explanatory.
bitset< _Nb > operator&(const bitset< _Nb > &__x, const bitset< _Nb > &__y) _GLIBCXX_NOEXCEPT
Global bitwise operations on bitsets.
bitset< _Nb > & set() _GLIBCXX_NOEXCEPT
Sets every bit to true.
Primary class template hash.
bitset< _Nb > & _Unchecked_set(size_t __pos) _GLIBCXX_NOEXCEPT
constexpr size_t size() const _GLIBCXX_NOEXCEPT
Returns the total number of bits.