use of boost::reversed_iterator within boost::reversed_range adaptor
- Dominant language
- C++
- Stars
- 45
- Forks
- 104
- PR merge metrics
- No merged PRs in 30d
Description
We use custom `span` class template, and it works incorrectly with boost::adapters::reverse. Link to reproduce:
https://godbolt.org/z/1Yxvqvj4r
Executable compiled with clang prints incorrect value, with gcc - exits with nonzero code, and msvc compiler emits a warning. I believe godbolt doesn't support sanitizers ATM. Non-const span is provided and works fine.
I believe the problem is that iterator_range::operator[] returns by reference and uses boost::reverse_iterator::operator[], but the latter reserved a right to return by value. According to docs ( https://www.boost.org/doc/libs/1_79_0/libs/iterator/doc/reverse_iterator.html ) it is "Random Access Iterator", and according to other docs ( https://www.boost.org/doc/libs/1_79_0/libs/iterator/doc/new-iter-concepts.html#design ), "operator[] is only required to return something convertible to the value_type (for a Readable Iterator)", which reverse_iterator does ( https://www.boost.org/doc/libs/1_79_0/libs/iterator/doc/new-iter-concepts.html#random-access-traversal-iterators-lib-random-access-traversal-iterators ): "`a[n]` has return type `convertible to T`" (for random access iterator as defined in now quite old "New Iterator Concepts").
Note that some std::reverse_iterator implementations return by reference in `const T` case too and could work with `boost::iterator_range`.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.