Skip to content

Commit

Permalink
LWG-3848: slide_view missing base accessor (#3410)
Browse files Browse the repository at this point in the history
Co-authored-by: Stephan T. Lavavej <stl@nuwen.net>
  • Loading branch information
JMazurkiewicz and StephanTLavavej authored Feb 14, 2023
1 parent 5b29686 commit aee02b5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
10 changes: 10 additions & 0 deletions stl/inc/ranges
Original file line number Diff line number Diff line change
Expand Up @@ -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<const _Vw>) ) {
// clang-format on
Expand Down
17 changes: 15 additions & 2 deletions tests/std/tests/P2442R1_views_slide/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,14 @@ constexpr bool test_one(Rng&& rng, Expected&& expected) {
if constexpr (CanMemberSize<R>) {
same_as<_Make_unsigned_like_t<ranges::range_difference_t<V>>> 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<const R> == sized_range<const V>);
if constexpr (CanMemberSize<const R>) {
same_as<_Make_unsigned_like_t<ranges::range_difference_t<const V>>> 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) {
Expand Down Expand Up @@ -392,6 +392,19 @@ constexpr bool test_one(Rng&& rng, Expected&& expected) {
}
}

// Validate slide_view::base() const&
STATIC_ASSERT(CanMemberBase<const R&> == copy_constructible<V>);
if constexpr (copy_constructible<V>) {
same_as<V> auto b1 = as_const(r).base();
STATIC_ASSERT(noexcept(as_const(r).base()) == is_nothrow_copy_constructible_v<V>); // strengthened
assert(*b1.begin() == *begin(*begin(expected)));
}

// Validate slide_view::base() &&
same_as<V> auto b2 = move(r).base();
STATIC_ASSERT(noexcept(move(r).base()) == is_nothrow_move_constructible_v<V>); // strengthened
assert(*b2.begin() == *begin(*begin(expected)));

return true;
}

Expand Down

0 comments on commit aee02b5

Please sign in to comment.