cppitertools icon indicating copy to clipboard operation
cppitertools copied to clipboard

Make operator* and operator-> const in all iterators.

Open thomas001 opened this issue 2 years ago • 0 comments

C++ iterators basically model pointers. Hence a const pointer can still be dereferenced to a mutable object (T * const not const T*). This is not true for many iterators in itertools since they only have non-const versions of operator*. This also violates C++ iterator concepts, see the github issue.

This change basically replaces all non-const dereference operators with const ones. This was straight forward in most cases:

  • Some iterators own the data they return (note: that probably violates LegacyForwardIterator). So those data fields were changed to mutable.
  • GroupBy advances the group while dereferencing. This does not work when the iterator is constant. Moved the advancing to the constructor and increment operators. This is the only real behavior change, please review carefully.

Fixes #91 .

thomas001 avatar Feb 25 '23 12:02 thomas001