ericniebler / range-v3

Range library for C++14/17/20, basis for C++20's std::ranges
Other
4.11k stars 442 forks source link

basic_iterator comparison operators are not symmetric, thus not equality comparable #1606

Open slymz opened 3 years ago

slymz commented 3 years ago

Here is the issue in detail: https://godbolt.org/z/Ehsc36

In summary:

 bool b1{constantIter == mutableIter};  // ok: expected goodness.
 bool b2{mutableIter == constantIter};  // fails to compile

where constantIter and mutableIter is otherwise compatible iterators into const and non-const views of the same range, respectively.

This can be reproduced with any other custom view adaptor, where the adaptor allows for conversion, and provide correct assignment semantics, but fail to provide symmetric comparison. E.g.: https://godbolt.org/z/19qGGM

For context, I ran into this issue while upgrading our in-house Boost.Range (v2) iterators and ranges to range-v3. This was a showstopper. Here is the same example as above with Boost.Range fwiw: https://godbolt.org/z/MKKvWY

Is there a workaround?

JohelEGP commented 3 years ago

Using C++20, with its rewriting of comparison operators, is a workaround.