From dabb0796f27cc52f2b2e7c9bcb5db3ddc637ca91 Mon Sep 17 00:00:00 2001 From: Jakub Mazurkiewicz Date: Thu, 9 Mar 2023 11:19:02 +0100 Subject: [PATCH 1/6] Test `views::istream` --- tests/std/tests/P0896R4_istream_view/test.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/std/tests/P0896R4_istream_view/test.cpp b/tests/std/tests/P0896R4_istream_view/test.cpp index db9a35a1d0..086bd56932 100644 --- a/tests/std/tests/P0896R4_istream_view/test.cpp +++ b/tests/std/tests/P0896R4_istream_view/test.cpp @@ -119,6 +119,23 @@ void test_one_type() { static_assert(noexcept(views::istream(wintstream))); assert(ranges::equal(input, expected_vals)); } +#if _HAS_CXX23 + { // Using ranges::istream_view with const iterators + istringstream intstream{"0 1 2 3"}; + T input[] = {-1, -1, -1, -1, -1}; + auto v = ranges::istream_view(intstream); + ranges::copy(v.cbegin(), v.cend(), input); + assert(ranges::equal(input, expected_vals)); + } + + { // Using ranges::wistream_view with const iterators + wistringstream wintstream{L"0 1 2 3"}; + T input[] = {-1, -1, -1, -1, -1}; + auto v = ranges::wistream_view(wintstream); + ranges::copy(v.cbegin(), v.cend(), input); + assert(ranges::equal(input, expected_vals)); + } +#endif // _HAS_CXX23 } istringstream some_stream{"42"}; From 871b875e76a10506904531a80980a64c7b80e8f3 Mon Sep 17 00:00:00 2001 From: Jakub Mazurkiewicz Date: Thu, 9 Mar 2023 11:38:04 +0100 Subject: [PATCH 2/6] Test `views::empty` --- tests/std/tests/P0896R4_views_empty/test.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/std/tests/P0896R4_views_empty/test.cpp b/tests/std/tests/P0896R4_views_empty/test.cpp index 5f6a2338b7..c7412bd016 100644 --- a/tests/std/tests/P0896R4_views_empty/test.cpp +++ b/tests/std/tests/P0896R4_views_empty/test.cpp @@ -20,7 +20,7 @@ constexpr bool test_one_type() { static_assert(ranges::view && ranges::contiguous_range && ranges::sized_range && ranges::common_range); static_assert(ranges::borrowed_range); static_assert(same_as)>); - auto& r = views::empty; + constexpr auto& r = views::empty; // validate member size static_assert(same_as); @@ -50,6 +50,15 @@ constexpr bool test_one_type() { static_assert(noexcept(R::empty())); static_assert(noexcept(ranges::empty(r))); +#if _HAS_CXX23 + // validate cbegin, and cend + static_assert(same_as>); + static_assert(r.cbegin() == nullptr); + + static_assert(same_as>); + static_assert(r.cend() == nullptr); +#endif // _HAS_CXX23 + // validate members inherited from view_interface assert(!r); From 0ee6a0ba5dc1c04114e7d59d8c22a0bd3cb5c96a Mon Sep 17 00:00:00 2001 From: Jakub Mazurkiewicz Date: Thu, 9 Mar 2023 11:43:03 +0100 Subject: [PATCH 3/6] Test `views::iota` --- tests/std/tests/P0896R4_views_iota/test.cpp | 23 +++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/std/tests/P0896R4_views_iota/test.cpp b/tests/std/tests/P0896R4_views_iota/test.cpp index a0fee3aff0..a4e530846f 100644 --- a/tests/std/tests/P0896R4_views_iota/test.cpp +++ b/tests/std/tests/P0896R4_views_iota/test.cpp @@ -197,6 +197,14 @@ constexpr void test_integral() { static_assert(noexcept(first != last)); // strengthened assert(last - first == 8); static_assert(noexcept(last - first)); // strengthened + +#if _HAS_CXX23 + const same_as> auto cfirst = rng.cbegin(); + assert(cfirst == first); + const same_as> auto clast = rng.cend(); + assert(clast == last); + assert(clast - cfirst == 8); +#endif // _HAS_CXX23 } { @@ -234,6 +242,21 @@ constexpr void test_integral() { } static_assert(!CanSize>); + +#if _HAS_CXX23 + { + const same_as auto rng = views::iota(low); + const ranges::subrange crng{rng.cbegin(), rng.cend()}; + + auto i = low; + for (const auto& e : crng) { + assert(e == i); + if (++i == high) { + break; + } + } + } +#endif // _HAS_CXX23 } } From 24d4b202aa3c072f457e52fb513a1055dd199833 Mon Sep 17 00:00:00 2001 From: Jakub Mazurkiewicz Date: Thu, 9 Mar 2023 11:48:29 +0100 Subject: [PATCH 4/6] Test `views::single` --- tests/std/tests/P0896R4_views_single/test.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/std/tests/P0896R4_views_single/test.cpp b/tests/std/tests/P0896R4_views_single/test.cpp index 18149b0566..54fc7abfb7 100644 --- a/tests/std/tests/P0896R4_views_single/test.cpp +++ b/tests/std/tests/P0896R4_views_single/test.cpp @@ -94,6 +94,23 @@ constexpr bool test_one_type(T value, Args&&... args) { static_assert(noexcept(cr0.end())); static_assert(noexcept(ranges::end(cr0))); +#if _HAS_CXX23 + // validate members cbegin and cend + static_assert(same_as); + assert(*r0.cbegin() == value); + assert(r0.cbegin() == ptr); + + static_assert(same_as); + assert(r0.cend() == ptr + 1); + + static_assert(same_as); + assert(*cr0.cbegin() == value); + assert(cr0.cbegin() == cptr); + + static_assert(same_as); + assert(cr0.cend() == cptr + 1); +#endif // _HAS_CXX23 + // validate CTAD and T&& constructor const same_as auto cr1 = ranges::single_view{move(value)}; assert(cr1.data() != nullptr); From 9e9db3309d9f3aa653c340bb7ef25ae30943ebf6 Mon Sep 17 00:00:00 2001 From: Jakub Mazurkiewicz Date: Thu, 9 Mar 2023 11:55:57 +0100 Subject: [PATCH 5/6] Test `views::repeat` --- tests/std/tests/P2474R2_views_repeat/test.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/std/tests/P2474R2_views_repeat/test.cpp b/tests/std/tests/P2474R2_views_repeat/test.cpp index 4c360593b1..ba1f542495 100644 --- a/tests/std/tests/P2474R2_views_repeat/test.cpp +++ b/tests/std/tests/P2474R2_views_repeat/test.cpp @@ -252,6 +252,16 @@ constexpr void test_common(T val, B bound = unreachable_sentinel) { assert(cmp_equal(last - first, rng.size())); static_assert(noexcept(last - first)); // strengthened } + + const same_as> auto cfirst = rng.cbegin(); + assert(cfirst == first); + const same_as> auto clast = rng.cend(); + if constexpr (ranges::common_range) { + assert(clast == last); + assert(cmp_equal(clast - cfirst, rng.size())); + } else { + static_assert(same_as, unreachable_sentinel_t>); + } } struct move_tester { From b3c333c7c1c1304a7ea71b78824ea7032c85f415 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Thu, 9 Mar 2023 11:17:25 -0800 Subject: [PATCH 6/6] Code review feedback. --- tests/std/tests/P0896R4_istream_view/test.cpp | 4 ++-- tests/std/tests/P0896R4_views_empty/test.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/std/tests/P0896R4_istream_view/test.cpp b/tests/std/tests/P0896R4_istream_view/test.cpp index 086bd56932..d007d86c83 100644 --- a/tests/std/tests/P0896R4_istream_view/test.cpp +++ b/tests/std/tests/P0896R4_istream_view/test.cpp @@ -123,7 +123,7 @@ void test_one_type() { { // Using ranges::istream_view with const iterators istringstream intstream{"0 1 2 3"}; T input[] = {-1, -1, -1, -1, -1}; - auto v = ranges::istream_view(intstream); + ranges::istream_view v(intstream); ranges::copy(v.cbegin(), v.cend(), input); assert(ranges::equal(input, expected_vals)); } @@ -131,7 +131,7 @@ void test_one_type() { { // Using ranges::wistream_view with const iterators wistringstream wintstream{L"0 1 2 3"}; T input[] = {-1, -1, -1, -1, -1}; - auto v = ranges::wistream_view(wintstream); + ranges::wistream_view v(wintstream); ranges::copy(v.cbegin(), v.cend(), input); assert(ranges::equal(input, expected_vals)); } diff --git a/tests/std/tests/P0896R4_views_empty/test.cpp b/tests/std/tests/P0896R4_views_empty/test.cpp index c7412bd016..252fb5141e 100644 --- a/tests/std/tests/P0896R4_views_empty/test.cpp +++ b/tests/std/tests/P0896R4_views_empty/test.cpp @@ -51,7 +51,7 @@ constexpr bool test_one_type() { static_assert(noexcept(ranges::empty(r))); #if _HAS_CXX23 - // validate cbegin, and cend + // validate members cbegin and cend inherited from view_interface static_assert(same_as>); static_assert(r.cbegin() == nullptr); @@ -59,7 +59,7 @@ constexpr bool test_one_type() { static_assert(r.cend() == nullptr); #endif // _HAS_CXX23 - // validate members inherited from view_interface + // validate other members inherited from view_interface assert(!r); return true;