Skip to content

Commit

Permalink
<algorithm>: Relax const-ness requirements on `ranges::_Meow_bound_…
Browse files Browse the repository at this point in the history
…unchecked` (#4927)
  • Loading branch information
frederick-vs-ja committed Sep 4, 2024
1 parent 79206df commit 1a54b61
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
8 changes: 4 additions & 4 deletions stl/inc/algorithm
Original file line number Diff line number Diff line change
Expand Up @@ -7031,9 +7031,9 @@ namespace ranges {

template <class _It, class _Ty, class _Pr, class _Pj>
_NODISCARD constexpr _It _Lower_bound_unchecked(
_It _First, iter_difference_t<_It> _Count, const _Ty& _Val, _Pr _Pred, _Pj _Proj) {
_It _First, iter_difference_t<_It> _Count, _Ty&& _Val, _Pr _Pred, _Pj _Proj) {
_STL_INTERNAL_STATIC_ASSERT(forward_iterator<_It>);
_STL_INTERNAL_STATIC_ASSERT(indirect_strict_weak_order<_Pr, const _Ty*, projected<_It, _Pj>>);
_STL_INTERNAL_STATIC_ASSERT(indirect_strict_weak_order<_Pr, add_pointer_t<_Ty>, projected<_It, _Pj>>);

using _Diff = iter_difference_t<_It>;

Expand Down Expand Up @@ -7082,9 +7082,9 @@ namespace ranges {

template <class _It, class _Ty, class _Pr, class _Pj>
_NODISCARD constexpr _It _Upper_bound_unchecked(
_It _First, iter_difference_t<_It> _Count, const _Ty& _Val, _Pr _Pred, _Pj _Proj) {
_It _First, iter_difference_t<_It> _Count, _Ty&& _Val, _Pr _Pred, _Pj _Proj) {
_STL_INTERNAL_STATIC_ASSERT(forward_iterator<_It>);
_STL_INTERNAL_STATIC_ASSERT(indirect_strict_weak_order<_Pr, const _Ty*, projected<_It, _Pj>>);
_STL_INTERNAL_STATIC_ASSERT(indirect_strict_weak_order<_Pr, add_pointer_t<_Ty>, projected<_It, _Pj>>);

using _Diff = iter_difference_t<_It>;

Expand Down
22 changes: 22 additions & 0 deletions tests/std/tests/P0896R4_ranges_alg_inplace_merge/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
#include <algorithm>
#include <cassert>
#include <concepts>
#include <cstddef>
#include <ranges>
#include <span>
#include <utility>
#include <vector>

#include <range_algorithm_support.hpp>

Expand Down Expand Up @@ -56,6 +58,26 @@ struct instantiator {
}
};

// Test GH-4863: <algorithm>: ranges::inplace_merge doesn't seem to be able to utilize ranges::upper_bound
void test_gh_4863() { // COMPILE-ONLY
{
vector<int> v;
auto cmp = [](int&, int&) { return false; };
ranges::sort(v, cmp);
ranges::inplace_merge(v, v.begin(), cmp);
}
{
struct S {
operator nullptr_t() {
return nullptr;
}
};
vector<int> v;
auto cmp = [](const nullptr_t&, const nullptr_t&) { return false; };
ranges::inplace_merge(v, v.begin(), cmp, [](int) { return S{}; });
}
}

int main() {
test_bidi<instantiator, P>();
}

0 comments on commit 1a54b61

Please sign in to comment.