`<algorithm>`: `ranges::reverse_copy` and `ranges::search` missing `difference_type` casting for `contiguous_iterator` operations
Open
Nobody has claimed this yet.
bug
ranges
- Dominant language
- C++
- Stars
- 11.2k
- Forks
- 1.7k
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 22
Description
The lhs type is _Out, while the rhs is iter_difference_t<_It>.
The same goes for ranges::search.
#include <algorithm>
int* p;
struct O {
using iterator_category = std::contiguous_iterator_tag;
using difference_type = int;
using element_type = int;
element_type& operator*() const;
O& operator++();
O operator++(int);
O& operator--();
O operator--(int);
O& operator+=(difference_type);
O& operator-=(difference_type);
element_type* operator->() const;
element_type& operator[](difference_type) const;
friend O operator+(O, difference_type);
friend O operator+(difference_type, O);
friend O operator-(O, difference_type);
friend difference_type operator-(O, O);
auto operator<=>(const O&) const = default;
void operator+=(decltype(p - p)) = delete;
};
int main() {
std::ranges::reverse_copy(p, p, O{});
std::ranges::search(O{}, O{}, p, p);
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read the linked operations in stl/inc/algorithm and stl/inc/xutility, focusing on the contiguous_iterator paths for ranges::reverse_copy and ranges::search. Compile the provided reproducer to observe the type mismatch, then check the relevant algorithm tests and add coverage showing both calls work with the custom iterator. Done means the reproducer compiles and the regression tests pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100