Skip to content

Commit 1a54b61

Browse files
<algorithm>: Relax const-ness requirements on ranges::_Meow_bound_unchecked (#4927)
1 parent 79206df commit 1a54b61

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

stl/inc/algorithm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7031,9 +7031,9 @@ namespace ranges {
70317031

70327032
template <class _It, class _Ty, class _Pr, class _Pj>
70337033
_NODISCARD constexpr _It _Lower_bound_unchecked(
7034-
_It _First, iter_difference_t<_It> _Count, const _Ty& _Val, _Pr _Pred, _Pj _Proj) {
7034+
_It _First, iter_difference_t<_It> _Count, _Ty&& _Val, _Pr _Pred, _Pj _Proj) {
70357035
_STL_INTERNAL_STATIC_ASSERT(forward_iterator<_It>);
7036-
_STL_INTERNAL_STATIC_ASSERT(indirect_strict_weak_order<_Pr, const _Ty*, projected<_It, _Pj>>);
7036+
_STL_INTERNAL_STATIC_ASSERT(indirect_strict_weak_order<_Pr, add_pointer_t<_Ty>, projected<_It, _Pj>>);
70377037

70387038
using _Diff = iter_difference_t<_It>;
70397039

@@ -7082,9 +7082,9 @@ namespace ranges {
70827082

70837083
template <class _It, class _Ty, class _Pr, class _Pj>
70847084
_NODISCARD constexpr _It _Upper_bound_unchecked(
7085-
_It _First, iter_difference_t<_It> _Count, const _Ty& _Val, _Pr _Pred, _Pj _Proj) {
7085+
_It _First, iter_difference_t<_It> _Count, _Ty&& _Val, _Pr _Pred, _Pj _Proj) {
70867086
_STL_INTERNAL_STATIC_ASSERT(forward_iterator<_It>);
7087-
_STL_INTERNAL_STATIC_ASSERT(indirect_strict_weak_order<_Pr, const _Ty*, projected<_It, _Pj>>);
7087+
_STL_INTERNAL_STATIC_ASSERT(indirect_strict_weak_order<_Pr, add_pointer_t<_Ty>, projected<_It, _Pj>>);
70887088

70897089
using _Diff = iter_difference_t<_It>;
70907090

tests/std/tests/P0896R4_ranges_alg_inplace_merge/test.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
#include <algorithm>
55
#include <cassert>
66
#include <concepts>
7+
#include <cstddef>
78
#include <ranges>
89
#include <span>
910
#include <utility>
11+
#include <vector>
1012

1113
#include <range_algorithm_support.hpp>
1214

@@ -56,6 +58,26 @@ struct instantiator {
5658
}
5759
};
5860

61+
// Test GH-4863: <algorithm>: ranges::inplace_merge doesn't seem to be able to utilize ranges::upper_bound
62+
void test_gh_4863() { // COMPILE-ONLY
63+
{
64+
vector<int> v;
65+
auto cmp = [](int&, int&) { return false; };
66+
ranges::sort(v, cmp);
67+
ranges::inplace_merge(v, v.begin(), cmp);
68+
}
69+
{
70+
struct S {
71+
operator nullptr_t() {
72+
return nullptr;
73+
}
74+
};
75+
vector<int> v;
76+
auto cmp = [](const nullptr_t&, const nullptr_t&) { return false; };
77+
ranges::inplace_merge(v, v.begin(), cmp, [](int) { return S{}; });
78+
}
79+
}
80+
5981
int main() {
6082
test_bidi<instantiator, P>();
6183
}

0 commit comments

Comments
 (0)