diff --git a/stl/inc/ranges b/stl/inc/ranges index f163e8d799b..e70042d44f0 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 c381dc9d4d8..66fa630e975 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) { @@ -392,6 +392,19 @@ 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); // 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); // strengthened + assert(*b2.begin() == *begin(*begin(expected))); + return true; }