File tree Expand file tree Collapse file tree 1 file changed +16
-2
lines changed
include/bitlib/bit-iterator Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -270,14 +270,28 @@ constexpr bit_iterator<Iterator> bit_iterator<Iterator>::operator-(difference_ty
270270// Increments the iterator by several bits and returns it
271271template <class Iterator >
272272constexpr bit_iterator<Iterator>& bit_iterator<Iterator>::operator +=(difference_type n) {
273- *this = *this + n;
273+ constexpr difference_type digits = binary_digits<word_type>::value;
274+ const difference_type sum = _position + n;
275+ difference_type diff = sum / digits;
276+ if (sum < 0 && diff * digits != sum) {
277+ --diff;
278+ }
279+ _current = std::next (_current, diff);
280+ _position = (sum - diff * digits);
274281 return *this ;
275282}
276283
277284// Decrements the iterator by several bits and returns it
278285template <class Iterator >
279286constexpr bit_iterator<Iterator>& bit_iterator<Iterator>::operator -=(difference_type n) {
280- *this = *this - n;
287+ constexpr difference_type digits = binary_digits<word_type>::value;
288+ const difference_type sum = _position - n;
289+ difference_type diff = sum / digits;
290+ if (sum < 0 && diff * digits != sum) {
291+ --diff;
292+ }
293+ _current = std::next (_current, diff);
294+ _position = (sum - diff * digits);
281295 return *this ;
282296}
283297// -------------------------------------------------------------------------- //
You can’t perform that action at this time.
0 commit comments