Skip to content

Commit

Permalink
Make operator* and operator-> const in all iterators.
Browse files Browse the repository at this point in the history
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](ryanhaining#91).

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`](https://en.cppreference.com/w/cpp/named_req/ForwardIterator)). 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.
  • Loading branch information
Thomas Weidner committed Feb 25, 2023
1 parent 8d93422 commit 242cc42
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
bazel-*
build
.vscode

0 comments on commit 242cc42

Please sign in to comment.