30 #ifndef _GLIBCXX_TR2_DYNAMIC_BITSET_TCC
31 #define _GLIBCXX_TR2_DYNAMIC_BITSET_TCC 1
33 #pragma GCC system_header
35 namespace std _GLIBCXX_VISIBILITY(default)
39 _GLIBCXX_BEGIN_NAMESPACE_VERSION
42 template<
typename _WordT,
typename _Alloc>
44 __dynamic_bitset_base<_WordT, _Alloc>::_M_do_left_shift(
size_t __shift)
46 if (__builtin_expect(__shift != 0, 1))
48 const size_t __wshift = __shift / _S_bits_per_block;
49 const size_t __offset = __shift % _S_bits_per_block;
52 for (
size_t __n = this->_M_w.size() - 1; __n >= __wshift; --__n)
53 this->_M_w[__n] = this->_M_w[__n - __wshift];
56 const size_t __sub_offset = _S_bits_per_block - __offset;
57 for (
size_t __n = _M_w.size() - 1; __n > __wshift; --__n)
58 this->_M_w[__n] = ((this->_M_w[__n - __wshift] << __offset)
59 | (this->_M_w[__n - __wshift - 1] >> __sub_offset));
60 this->_M_w[__wshift] = this->_M_w[0] << __offset;
68 template<
typename _WordT,
typename _Alloc>
70 __dynamic_bitset_base<_WordT, _Alloc>::_M_do_right_shift(
size_t __shift)
72 if (__builtin_expect(__shift != 0, 1))
74 const size_t __wshift = __shift / _S_bits_per_block;
75 const size_t __offset = __shift % _S_bits_per_block;
76 const size_t __limit = this->_M_w.size() - __wshift - 1;
79 for (
size_t __n = 0; __n <= __limit; ++__n)
80 this->_M_w[__n] = this->_M_w[__n + __wshift];
83 const size_t __sub_offset = (_S_bits_per_block
85 for (
size_t __n = 0; __n < __limit; ++__n)
86 this->_M_w[__n] = ((this->_M_w[__n + __wshift] >> __offset)
87 | (this->_M_w[__n + __wshift + 1] << __sub_offset));
88 this->_M_w[__limit] = this->_M_w[_M_w.size()-1] >> __offset;
96 template<
typename _WordT,
typename _Alloc>
98 __dynamic_bitset_base<_WordT, _Alloc>::_M_do_to_ulong()
const
100 size_t __n =
sizeof(
unsigned long) /
sizeof(block_type);
101 for (
size_t __i = __n; __i < this->_M_w.size(); ++__i)
103 __throw_overflow_error(__N(
"__dynamic_bitset_base::_M_do_to_ulong"));
104 unsigned long __res = 0UL;
105 for (
size_t __i = 0; __i < __n && __i < this->_M_w.size(); ++__i)
106 __res += this->_M_w[__i] << (__i * _S_bits_per_block);
110 template<
typename _WordT,
typename _Alloc>
112 __dynamic_bitset_base<_WordT, _Alloc>::_M_do_to_ullong()
const
114 size_t __n =
sizeof(
unsigned long long) /
sizeof(block_type);
115 for (
size_t __i = __n; __i < this->_M_w.size(); ++__i)
117 __throw_overflow_error(__N(
"__dynamic_bitset_base::_M_do_to_ullong"));
118 unsigned long long __res = 0ULL;
119 for (
size_t __i = 0; __i < __n && __i < this->_M_w.size(); ++__i)
120 __res += this->_M_w[__i] << (__i * _S_bits_per_block);
124 template<
typename _WordT,
typename _Alloc>
126 __dynamic_bitset_base<_WordT, _Alloc>
127 ::_M_do_find_first(
size_t __not_found)
const
129 for (
size_t __i = 0; __i < this->_M_w.size(); ++__i)
131 _WordT __thisword = this->_M_w[__i];
132 if (__thisword != static_cast<_WordT>(0))
133 return (__i * _S_bits_per_block
134 + __builtin_ctzll(__thisword));
140 template<
typename _WordT,
typename _Alloc>
142 __dynamic_bitset_base<_WordT, _Alloc>
143 ::_M_do_find_next(
size_t __prev,
size_t __not_found)
const
149 if (__prev >= this->_M_w.size() * _S_bits_per_block)
153 size_t __i = _S_whichword(__prev);
154 _WordT __thisword = this->_M_w[__i];
157 __thisword &= (~static_cast<_WordT>(0)) << _S_whichbit(__prev);
159 if (__thisword != static_cast<_WordT>(0))
160 return (__i * _S_bits_per_block
161 + __builtin_ctzll(__thisword));
164 for (++__i; __i < this->_M_w.size(); ++__i)
166 __thisword = this->_M_w[__i];
167 if (__thisword != static_cast<_WordT>(0))
168 return (__i * _S_bits_per_block
169 + __builtin_ctzll(__thisword));
176 template<
typename _WordT,
typename _Alloc>
177 template<
typename _CharT,
typename _Traits>
179 dynamic_bitset<_WordT, _Alloc>::
180 _M_copy_from_ptr(
const _CharT* __str,
size_t __len,
181 size_t __pos,
size_t __n, _CharT __zero, _CharT __one)
185 for (
size_t __i = __nbits; __i > 0; --__i)
187 const _CharT __c = __str[__pos + __nbits - __i];
188 if (_Traits::eq(__c, __zero))
190 else if (_Traits::eq(__c, __one))
191 _M_unchecked_set(__i - 1);
193 __throw_invalid_argument(__N(
"dynamic_bitset::_M_copy_from_ptr"));
207 template<
typename _CharT,
typename _Traits,
208 typename _WordT,
typename _Alloc>
211 dynamic_bitset<_WordT, _Alloc>& __x)
213 typedef typename _Traits::char_type char_type;
215 typedef typename __istream_type::ios_base __ios_base;
220 const char_type __zero = __is.
widen(
'0');
221 const char_type __one = __is.
widen(
'1');
223 typename __ios_base::iostate __state = __ios_base::goodbit;
224 typename __istream_type::sentry __sentry(__is);
231 static typename _Traits::int_type __eof = _Traits::eof();
233 typename _Traits::int_type __c1 = __is.
rdbuf()->sbumpc();
234 if (_Traits::eq_int_type(__c1, __eof))
236 __state |= __ios_base::eofbit;
241 const char_type __c2 = _Traits::to_char_type(__c1);
242 if (_Traits::eq(__c2, __zero))
244 else if (_Traits::eq(__c2, __one))
247 eq_int_type(__is.
rdbuf()->sputbackc(__c2),
250 __state |= __ios_base::failbit;
260 __is._M_setstate(__ios_base::badbit);
261 __throw_exception_again;
264 { __is._M_setstate(__ios_base::badbit); }
267 __x.resize(__tmp.
size());
269 if (__tmp.
empty() && __x.size())
270 __state |= __ios_base::failbit;
272 __x._M_copy_from_string(__tmp, static_cast<size_t>(0), __x.
size(),
282 _GLIBCXX_END_NAMESPACE_VERSION
Template class basic_istream.
bitset< _Nb > & reset() noexcept
Sets every bit to false.
void push_back(_CharT __c)
Append a single character.
size_type size() const noexcept
Returns the number of characters in the string, not including any null-termination.
bool empty() const noexcept
basic_streambuf< _CharT, _Traits > * rdbuf() const
Accessing the underlying buffer.
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.
void setstate(iostate __state)
Sets additional flags in the error state.
char_type widen(char __c) const
Widens characters.
bitset< _Nb > operator>>(size_t __position) const noexcept
Self-explanatory.
Managing sequences of characters and character-like objects.
void reserve(size_type __res_arg=0)
Attempt to preallocate enough memory for specified number of characters.