Skip to content

<algorithm>: ranges::reverse_copy and ranges::search missing difference_type casting for contiguous_iterator operations #2892

Open
@hewillk

Description

@hewillk

_Result += _Last - _First;

The lhs type is _Out, while the rhs is iter_difference_t<_It>.

_First1 += (_Last2 - _First2);

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);
}

https://godbolt.org/z/osEE96695

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingrangesC++20/23 ranges

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions