From 1a54b610d60aaa22f2c488f0e599873f9a6f9104 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Wed, 4 Sep 2024 12:59:03 +0800 Subject: [PATCH] ``: Relax const-ness requirements on `ranges::_Meow_bound_unchecked` (#4927) --- stl/inc/algorithm | 8 +++---- .../P0896R4_ranges_alg_inplace_merge/test.cpp | 22 +++++++++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/stl/inc/algorithm b/stl/inc/algorithm index c0b1c0e84a..3f54cd75ef 100644 --- a/stl/inc/algorithm +++ b/stl/inc/algorithm @@ -7031,9 +7031,9 @@ namespace ranges { template _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>; @@ -7082,9 +7082,9 @@ namespace ranges { template _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>; diff --git a/tests/std/tests/P0896R4_ranges_alg_inplace_merge/test.cpp b/tests/std/tests/P0896R4_ranges_alg_inplace_merge/test.cpp index bb0314722b..3a9f6a495a 100644 --- a/tests/std/tests/P0896R4_ranges_alg_inplace_merge/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_inplace_merge/test.cpp @@ -4,9 +4,11 @@ #include #include #include +#include #include #include #include +#include #include @@ -56,6 +58,26 @@ struct instantiator { } }; +// Test GH-4863: : ranges::inplace_merge doesn't seem to be able to utilize ranges::upper_bound +void test_gh_4863() { // COMPILE-ONLY + { + vector 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 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(); }