Skip to content

<algorithm>: ranges::inplace_merge doesn't seem to be able to utilize ranges::upper_bound #4863

Description

@hewillk
#include <algorithm>
#include <vector>

int main() {
  std::vector<int> v;
  auto cmp = [](int&, int&) { return true; };
  std::ranges::sort(v, cmp);
  std::ranges::inplace_merge(v, v.begin(), cmp); // hard error
}

https://godbolt.org/z/soe8sa75q

The above code is rejected by libstdc++, libc++, and MSVC-STL, which shouldn't be because ranges::inplace_merge has the same constraint signature as ranges::sort.
The root cause is that inplace_merge uses upper_bound, which then requires Compare to satisfy indirect_strict_weak_order<const T*, I> (note the const here), which is not guaranteed by the constraints of inplace_merge.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixedSomething works now, yay!rangesC++20/23 ranges

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions