From 2398f5ccad53c434724d3c43570203e0db63b0f8 Mon Sep 17 00:00:00 2001 From: Jakub Mazurkiewicz Date: Wed, 7 Jun 2023 14:36:49 +0200 Subject: [PATCH] Make `P2415R2_owning_view\test.cpp` test something --- tests/std/include/range_algorithm_support.hpp | 2 + tests/std/tests/P2415R2_owning_view/test.cpp | 351 ++++++++++-------- 2 files changed, 192 insertions(+), 161 deletions(-) diff --git a/tests/std/include/range_algorithm_support.hpp b/tests/std/include/range_algorithm_support.hpp index 6769cb2477..3d2de06d40 100644 --- a/tests/std/include/range_algorithm_support.hpp +++ b/tests/std/include/range_algorithm_support.hpp @@ -915,6 +915,8 @@ namespace test { public: using I = iterator; using S = conditional_t>; + using RebindAsMoveOnly = range; using detail::range_base::range_base; diff --git a/tests/std/tests/P2415R2_owning_view/test.cpp b/tests/std/tests/P2415R2_owning_view/test.cpp index 8355ca854e..61ef347074 100644 --- a/tests/std/tests/P2415R2_owning_view/test.cpp +++ b/tests/std/tests/P2415R2_owning_view/test.cpp @@ -10,224 +10,253 @@ #include #include + using namespace std; struct instantiator { - template + template static constexpr void call() { - if constexpr (move_constructible) { - using ranges::owning_view, ranges::begin, ranges::end, ranges::bidirectional_range, ranges::common_range, - ranges::contiguous_range, ranges::forward_range, ranges::input_range, ranges::random_access_range; - int input[3] = {0, 1, 2}; - - // properties - STATIC_ASSERT(ranges::enable_borrowed_range> == ranges::enable_borrowed_range); - - STATIC_ASSERT(ranges::view>); - STATIC_ASSERT(input_range>); - STATIC_ASSERT(forward_range> == forward_range); - STATIC_ASSERT(bidirectional_range> == bidirectional_range); - STATIC_ASSERT(random_access_range> == random_access_range); - STATIC_ASSERT(contiguous_range> == contiguous_range); - - { // constructors and assignment operators - STATIC_ASSERT(constructible_from, R>); - STATIC_ASSERT(!constructible_from, R&>); - STATIC_ASSERT(!constructible_from, const R&>); - STATIC_ASSERT(!constructible_from, const R>); - - STATIC_ASSERT(default_initializable> == default_initializable); - STATIC_ASSERT( - is_nothrow_default_constructible_v> == is_nothrow_default_constructible_v); - if constexpr (default_initializable) { - [[maybe_unused]] owning_view default_constructed; - } + using R = ImmobileR::RebindAsMoveOnly; + using ranges::owning_view, ranges::begin, ranges::end, ranges::bidirectional_range, ranges::common_range, + ranges::contiguous_range, ranges::forward_range, ranges::input_range, ranges::random_access_range; + int input[3] = {0, 1, 2}; + + // properties + STATIC_ASSERT(ranges::enable_borrowed_range> == ranges::enable_borrowed_range); + + STATIC_ASSERT(ranges::view>); + STATIC_ASSERT(input_range>); + STATIC_ASSERT(forward_range> == forward_range); + STATIC_ASSERT(bidirectional_range> == bidirectional_range); + STATIC_ASSERT(random_access_range> == random_access_range); + STATIC_ASSERT(contiguous_range> == contiguous_range); + + { // constructors and assignment operators + STATIC_ASSERT(constructible_from, R>); + STATIC_ASSERT(!constructible_from, R&>); + STATIC_ASSERT(!constructible_from, const R&>); + STATIC_ASSERT(!constructible_from, const R>); + + STATIC_ASSERT(default_initializable> == default_initializable); + STATIC_ASSERT(is_nothrow_default_constructible_v> == is_nothrow_default_constructible_v); + if constexpr (default_initializable) { + [[maybe_unused]] owning_view default_constructed; + } + + owning_view converted{R{input}}; + STATIC_ASSERT(is_nothrow_constructible_v, R> == is_nothrow_move_constructible_v); - owning_view converted{R{input}}; - STATIC_ASSERT(is_nothrow_constructible_v, R> == is_nothrow_move_constructible_v); + owning_view move_constructed = move(converted); + if constexpr (forward_range) { + assert(move_constructed.begin().peek() == begin(input)); + } + assert(move_constructed.end().peek() == end(input)); - owning_view move_constructed = move(converted); + if constexpr (movable) { + int other_data[3] = {4, 5, 6}; + owning_view move_assigned{R{other_data}}; + move_assigned = move(move_constructed); if constexpr (forward_range) { - assert(move_constructed.begin().peek() == begin(input)); - } - assert(move_constructed.end().peek() == end(input)); - - if constexpr (movable) { - int other_data[3] = {4, 5, 6}; - owning_view move_assigned{R{other_data}}; - move_assigned = move(move_constructed); - if constexpr (forward_range) { - assert(move_assigned.begin().peek() == begin(input)); - } - assert(move_assigned.end().peek() == end(input)); + assert(move_assigned.begin().peek() == begin(input)); } + assert(move_assigned.end().peek() == end(input)); } + } + + { // access + owning_view test_view{R{input}}; + same_as auto& base = test_view.base(); + STATIC_ASSERT(noexcept(test_view.base())); + assert(addressof(base) != nullptr); + + same_as auto& cbase = as_const(test_view).base(); + STATIC_ASSERT(noexcept(as_const(test_view).base())); + assert(addressof(cbase) == addressof(base)); + + same_as auto&& rbase = move(test_view).base(); + STATIC_ASSERT(noexcept(move(test_view).base())); + assert(addressof(rbase) == addressof(base)); - { // access + same_as auto&& crbase = move(as_const(test_view)).base(); + STATIC_ASSERT(noexcept(move(as_const(test_view)).base())); + assert(addressof(crbase) == addressof(base)); + } + + { // iterators + { owning_view test_view{R{input}}; - same_as auto& base = test_view.base(); - STATIC_ASSERT(noexcept(test_view.base())); - assert(addressof(base) != nullptr); + same_as> auto first = test_view.begin(); + STATIC_ASSERT(noexcept(test_view.begin()) == noexcept(declval().begin())); + assert(first.peek() == input); - same_as auto& cbase = as_const(test_view).base(); - STATIC_ASSERT(noexcept(as_const(test_view).base())); - assert(addressof(cbase) == addressof(base)); + const same_as> auto last = test_view.end(); + STATIC_ASSERT(noexcept(test_view.end()) == noexcept(declval().end())); + assert(last.peek() == end(input)); + } - same_as auto&& rbase = move(test_view).base(); - STATIC_ASSERT(noexcept(move(test_view).base())); - assert(addressof(rbase) == addressof(base)); + if constexpr (input_range) { + const owning_view ctest_view{R{input}}; + same_as> auto first = ctest_view.begin(); + STATIC_ASSERT(noexcept(ctest_view.begin()) == noexcept(declval().begin())); + assert(first.peek() == input); - same_as auto&& crbase = move(as_const(test_view)).base(); - STATIC_ASSERT(noexcept(move(as_const(test_view)).base())); - assert(addressof(crbase) == addressof(base)); + const same_as> auto last = ctest_view.end(); + STATIC_ASSERT(noexcept(ctest_view.end()) == noexcept(declval().end())); + assert(last.peek() == end(input)); } + } - { // iterators - { - owning_view test_view{R{input}}; - same_as> auto first = test_view.begin(); - STATIC_ASSERT(noexcept(test_view.begin()) == noexcept(declval().begin())); - assert(first.peek() == input); +#if _HAS_CXX23 + { // const iterators + { + owning_view test_view{R{input}}; + same_as> auto first = test_view.cbegin(); + assert(first.base().peek() == input); - const same_as> auto last = test_view.end(); - STATIC_ASSERT(noexcept(test_view.end()) == noexcept(declval().end())); + same_as> auto last = test_view.cend(); + if constexpr (_Is_specialization_v) { + assert(last.base().peek() == end(input)); + } else { assert(last.peek() == end(input)); } + } - if constexpr (input_range) { - const owning_view ctest_view{R{input}}; - same_as> auto first = ctest_view.begin(); - STATIC_ASSERT(noexcept(ctest_view.begin()) == noexcept(declval().begin())); - assert(first.peek() == input); + if constexpr (input_range) { + const owning_view ctest_view{R{input}}; + same_as> auto first = ctest_view.cbegin(); + assert(first.base().peek() == input); - const same_as> auto last = ctest_view.end(); - STATIC_ASSERT(noexcept(ctest_view.end()) == noexcept(declval().end())); + same_as> auto last = ctest_view.cend(); + if constexpr (_Is_specialization_v) { + assert(last.base().peek() == end(input)); + } else { assert(last.peek() == end(input)); } } + } +#endif // _HAS_CXX23 - { // empty - STATIC_ASSERT(CanMemberEmpty> == CanEmpty); - if constexpr (CanEmpty) { - owning_view test_view{R{input}}; + { // empty + STATIC_ASSERT(CanMemberEmpty> == CanEmpty); + if constexpr (CanEmpty) { + owning_view test_view{R{input}}; - const same_as auto is_empty = test_view.empty(); - STATIC_ASSERT(noexcept(test_view.empty()) == noexcept(ranges::empty(declval()))); - assert(!is_empty); + const same_as auto is_empty = test_view.empty(); + STATIC_ASSERT(noexcept(test_view.empty()) == noexcept(ranges::empty(declval()))); + assert(!is_empty); - owning_view empty_view{R{span{}}}; - assert(empty_view.empty()); + owning_view empty_view{R{span{}}}; + assert(empty_view.empty()); - // view_interface::operator bool - assert(test_view); - assert(!empty_view); - } + // view_interface::operator bool + assert(test_view); + assert(!empty_view); + } - STATIC_ASSERT(CanMemberEmpty> == CanEmpty); - if constexpr (CanEmpty) { - const owning_view test_view{R{input}}; + STATIC_ASSERT(CanMemberEmpty> == CanEmpty); + if constexpr (CanEmpty) { + const owning_view test_view{R{input}}; - const same_as auto is_empty = test_view.empty(); - STATIC_ASSERT(noexcept(test_view.empty()) == noexcept(ranges::empty(declval()))); - assert(!is_empty); + const same_as auto is_empty = test_view.empty(); + STATIC_ASSERT(noexcept(test_view.empty()) == noexcept(ranges::empty(declval()))); + assert(!is_empty); - owning_view empty_view{R{span{}}}; - assert(empty_view.empty()); + owning_view empty_view{R{span{}}}; + assert(empty_view.empty()); - // view_interface::operator bool - assert(test_view); - assert(!empty_view); - } + // view_interface::operator bool + assert(test_view); + assert(!empty_view); } + } - { // size - STATIC_ASSERT(CanMemberSize> == ranges::sized_range); - if constexpr (ranges::sized_range) { - owning_view test_view{R{input}}; + { // size + STATIC_ASSERT(CanMemberSize> == ranges::sized_range); + if constexpr (ranges::sized_range) { + owning_view test_view{R{input}}; - const same_as> auto ref_size = test_view.size(); - assert(ref_size == ranges::size(input)); + const same_as> auto ref_size = test_view.size(); + assert(_To_unsigned_like(ref_size) == ranges::size(input)); - STATIC_ASSERT(noexcept(test_view.size()) == noexcept(ranges::size(declval()))); - } + STATIC_ASSERT(noexcept(test_view.size()) == noexcept(ranges::size(declval()))); + } - STATIC_ASSERT(CanMemberSize> == ranges::sized_range); - if constexpr (ranges::sized_range) { - const owning_view test_view{R{input}}; + STATIC_ASSERT(CanMemberSize> == ranges::sized_range); + if constexpr (ranges::sized_range) { + const owning_view test_view{R{input}}; - const same_as> auto ref_size = test_view.size(); - assert(ref_size == ranges::size(input)); + const same_as> auto ref_size = test_view.size(); + assert(_To_unsigned_like(ref_size) == ranges::size(input)); - STATIC_ASSERT(noexcept(test_view.size()) == noexcept(ranges::size(declval()))); - } + STATIC_ASSERT(noexcept(test_view.size()) == noexcept(ranges::size(declval()))); } + } - { // data - STATIC_ASSERT(CanMemberData> == contiguous_range); - if constexpr (contiguous_range) { - owning_view test_view{R{input}}; + { // data + STATIC_ASSERT(CanMemberData> == contiguous_range); + if constexpr (contiguous_range) { + owning_view test_view{R{input}}; - const same_as auto ptr = test_view.data(); - assert(ptr == input); + const same_as auto ptr = test_view.data(); + assert(ptr == input); - STATIC_ASSERT(noexcept(test_view.data()) == noexcept(ranges::data(declval()))); - } + STATIC_ASSERT(noexcept(test_view.data()) == noexcept(ranges::data(declval()))); + } - STATIC_ASSERT(CanMemberData> == contiguous_range); - if constexpr (contiguous_range) { - const owning_view test_view{R{input}}; + STATIC_ASSERT(CanMemberData> == contiguous_range); + if constexpr (contiguous_range) { + const owning_view test_view{R{input}}; - const same_as auto ptr = test_view.data(); - assert(ptr == input); + const same_as auto ptr = test_view.data(); + assert(ptr == input); - STATIC_ASSERT(noexcept(test_view.data()) == noexcept(ranges::data(declval()))); - } + STATIC_ASSERT(noexcept(test_view.data()) == noexcept(ranges::data(declval()))); } + } - // CTAD - STATIC_ASSERT(same_as>); + // CTAD + STATIC_ASSERT(same_as>); - { // view_interface::back, ::front - STATIC_ASSERT(CanMemberFront> == forward_range); - if constexpr (forward_range) { - owning_view test_view{R{input}}; - assert(test_view.front() == input[0]); + { // view_interface::back, ::front + STATIC_ASSERT(CanMemberFront> == forward_range); + if constexpr (forward_range) { + owning_view test_view{R{input}}; + assert(test_view.front() == input[0]); - STATIC_ASSERT(CanMemberBack> == (bidirectional_range && common_range) ); - if constexpr (bidirectional_range && common_range) { - assert(test_view.back() == input[2]); - } + STATIC_ASSERT(CanMemberBack> == (bidirectional_range && common_range) ); + if constexpr (bidirectional_range && common_range) { + assert(test_view.back() == input[2]); } + } - STATIC_ASSERT(CanMemberFront> == forward_range); - if constexpr (forward_range) { - const owning_view test_view{R{input}}; - assert(test_view.front() == input[0]); + STATIC_ASSERT(CanMemberFront> == forward_range); + if constexpr (forward_range) { + const owning_view test_view{R{input}}; + assert(test_view.front() == input[0]); - STATIC_ASSERT(CanMemberBack> - == (bidirectional_range && common_range) ); - if constexpr (bidirectional_range && common_range) { - assert(test_view.back() == input[2]); - } + STATIC_ASSERT( + CanMemberBack> == (bidirectional_range && common_range) ); + if constexpr (bidirectional_range && common_range) { + assert(test_view.back() == input[2]); } } + } - { // view_interface::operator[] - STATIC_ASSERT(CanIndex> == random_access_range); - if constexpr (random_access_range) { - owning_view test_view{R{input}}; - assert(test_view[0] == input[0]); - assert(test_view[1] == input[1]); - assert(test_view[2] == input[2]); - } + { // view_interface::operator[] + STATIC_ASSERT(CanIndex> == random_access_range); + if constexpr (random_access_range) { + owning_view test_view{R{input}}; + assert(test_view[0] == input[0]); + assert(test_view[1] == input[1]); + assert(test_view[2] == input[2]); + } - STATIC_ASSERT(CanIndex> == random_access_range); - if constexpr (random_access_range) { - const owning_view test_view{R{input}}; - assert(test_view[0] == input[0]); - assert(test_view[1] == input[1]); - assert(test_view[2] == input[2]); - } + STATIC_ASSERT(CanIndex> == random_access_range); + if constexpr (random_access_range) { + const owning_view test_view{R{input}}; + assert(test_view[0] == input[0]); + assert(test_view[1] == input[1]); + assert(test_view[2] == input[2]); } } }