-
Notifications
You must be signed in to change notification settings - Fork 122
Description
Currently a lot iterators have only non-const operator* or operator-> (for example in groupby).
This is not correct according to the legacy and C++20 iterator concepts:
-
LegacyInputIterator states that
*iandi->mshould be valid expressions giveniandj, values of typeItorconst ItNote the inclusion of
const Ithere. -
std::indirectly_readable(which is required bystd::input_iterator) hasrequires(const In in) { // ... { *in } -> std::same_as<std::iter_reference_t<In>>; // .... } &&
Note that the concept requires
*invor values ofconst In.
Since iterators are copyable, one can always work around this by copying a const itertools iterator and dereferencing the copy. Yet, this might be inefficient for some iterators. Also, itertools iterators not implementing c++20 iterator concepts will probably make them much less useful in the future. Finally, there are other range and iterator adapter libraries out there which might assume a const iterator is dereferenceable.
For some iterators in itertools the fix seems to be straightforward by adding const to the operators. Others, like groupby, seem to require more changes.