-
Notifications
You must be signed in to change notification settings - Fork 119
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
*i
andi->m
should be valid expressions giveni
andj
, values of typeIt
orconst It
Note the inclusion of
const It
here. -
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
*in
vor 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.