From e659d478350d98433d4b86bce4ad96b5c7b95118 Mon Sep 17 00:00:00 2001 From: Jakub Mazurkiewicz Date: Sun, 12 Feb 2023 00:57:30 +0100 Subject: [PATCH 1/3] Implement LWG-3848 --- stl/inc/ranges | 10 ++++++++++ tests/std/tests/P2442R1_views_slide/test.cpp | 15 +++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/stl/inc/ranges b/stl/inc/ranges index f163e8d799..e70042d44f 100644 --- a/stl/inc/ranges +++ b/stl/inc/ranges @@ -6753,6 +6753,16 @@ namespace ranges { #endif // _CONTAINER_DEBUG_LEVEL > 0 } + _NODISCARD constexpr _Vw base() const& noexcept(is_nothrow_copy_constructible_v<_Vw>) // strengthened + requires copy_constructible<_Vw> + { + return _Range; + } + + _NODISCARD constexpr _Vw base() && noexcept(is_nothrow_move_constructible_v<_Vw>) /* strengthened */ { + return _STD move(_Range); + } + // clang-format off _NODISCARD constexpr auto begin() requires (!(_Simple_view<_Vw> && _Slide_caches_nothing) ) { // clang-format on diff --git a/tests/std/tests/P2442R1_views_slide/test.cpp b/tests/std/tests/P2442R1_views_slide/test.cpp index c381dc9d4d..7c9763f85b 100644 --- a/tests/std/tests/P2442R1_views_slide/test.cpp +++ b/tests/std/tests/P2442R1_views_slide/test.cpp @@ -392,6 +392,21 @@ constexpr bool test_one(Rng&& rng, Expected&& expected) { } } + // Validate slide_view::base() const& + STATIC_ASSERT(CanMemberBase == copy_constructible); + if constexpr (copy_constructible) { + same_as auto b1 = as_const(r).base(); + STATIC_ASSERT(noexcept(as_const(r).base()) == is_nothrow_copy_constructible_v); + assert(*b1.begin() == *begin(*begin(expected))); + } + + // Validate slide_view::base() && + same_as auto b2 = move(r).base(); + STATIC_ASSERT(noexcept(move(r).base()) == is_nothrow_move_constructible_v); + if (!is_empty) { + assert(*b2.begin() == *begin(*begin(expected))); + } + return true; } From 2a7c5cca7e084742bdb278299e6e9589e561423d Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Sun, 12 Feb 2023 10:53:48 -0800 Subject: [PATCH 2/3] Not empty. --- tests/std/tests/P2442R1_views_slide/test.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/std/tests/P2442R1_views_slide/test.cpp b/tests/std/tests/P2442R1_views_slide/test.cpp index 7c9763f85b..6838c9dc46 100644 --- a/tests/std/tests/P2442R1_views_slide/test.cpp +++ b/tests/std/tests/P2442R1_views_slide/test.cpp @@ -403,9 +403,7 @@ constexpr bool test_one(Rng&& rng, Expected&& expected) { // Validate slide_view::base() && same_as auto b2 = move(r).base(); STATIC_ASSERT(noexcept(move(r).base()) == is_nothrow_move_constructible_v); - if (!is_empty) { - assert(*b2.begin() == *begin(*begin(expected))); - } + assert(*b2.begin() == *begin(*begin(expected))); return true; } From d8d0bbd520daad4dde50e437ec21b5166723ab3b Mon Sep 17 00:00:00 2001 From: Jakub Mazurkiewicz Date: Sun, 12 Feb 2023 23:30:19 +0100 Subject: [PATCH 3/3] strengthened! --- tests/std/tests/P2442R1_views_slide/test.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/std/tests/P2442R1_views_slide/test.cpp b/tests/std/tests/P2442R1_views_slide/test.cpp index 6838c9dc46..66fa630e97 100644 --- a/tests/std/tests/P2442R1_views_slide/test.cpp +++ b/tests/std/tests/P2442R1_views_slide/test.cpp @@ -201,14 +201,14 @@ constexpr bool test_one(Rng&& rng, Expected&& expected) { if constexpr (CanMemberSize) { same_as<_Make_unsigned_like_t>> auto s = r.size(); assert(s == ranges::size(expected)); - STATIC_ASSERT(noexcept(r.size())); + STATIC_ASSERT(noexcept(r.size()) == noexcept(ranges::size(rng))); // strengthened } STATIC_ASSERT(CanMemberSize == sized_range); if constexpr (CanMemberSize) { same_as<_Make_unsigned_like_t>> auto s = as_const(r).size(); assert(s == ranges::size(expected)); - STATIC_ASSERT(noexcept(as_const(r).size())); + STATIC_ASSERT(noexcept(as_const(r).size()) == noexcept(ranges::size(rng))); // strengthened } if (is_empty) { @@ -396,13 +396,13 @@ constexpr bool test_one(Rng&& rng, Expected&& expected) { STATIC_ASSERT(CanMemberBase == copy_constructible); if constexpr (copy_constructible) { same_as auto b1 = as_const(r).base(); - STATIC_ASSERT(noexcept(as_const(r).base()) == is_nothrow_copy_constructible_v); + STATIC_ASSERT(noexcept(as_const(r).base()) == is_nothrow_copy_constructible_v); // strengthened assert(*b1.begin() == *begin(*begin(expected))); } // Validate slide_view::base() && same_as auto b2 = move(r).base(); - STATIC_ASSERT(noexcept(move(r).base()) == is_nothrow_move_constructible_v); + STATIC_ASSERT(noexcept(move(r).base()) == is_nothrow_move_constructible_v); // strengthened assert(*b2.begin() == *begin(*begin(expected))); return true;