|
17 | 17 | #include <cassert>
|
18 | 18 | #include "test_macros.h"
|
19 | 19 | #include "test_iterators.h"
|
20 |
| -#include "types.h" |
21 | 20 |
|
22 | 21 | template<size_t I, class S>
|
23 |
| -concept GetInvocable = requires { |
| 22 | +concept HasGet = requires { |
24 | 23 | std::get<I>(std::declval<S>());
|
25 | 24 | };
|
26 | 25 |
|
27 |
| -static_assert( GetInvocable<0, std::ranges::subrange<int*>>); |
28 |
| -static_assert( GetInvocable<1, std::ranges::subrange<int*>>); |
29 |
| -static_assert(!GetInvocable<2, std::ranges::subrange<int*>>); |
30 |
| -static_assert(!GetInvocable<3, std::ranges::subrange<int*>>); |
| 26 | +static_assert( HasGet<0, std::ranges::subrange<int*>>); |
| 27 | +static_assert( HasGet<1, std::ranges::subrange<int*>>); |
| 28 | +static_assert(!HasGet<2, std::ranges::subrange<int*>>); |
| 29 | +static_assert(!HasGet<3, std::ranges::subrange<int*>>); |
31 | 30 |
|
32 | 31 | constexpr bool test() {
|
33 |
| - std::ranges::subrange<int*> a(globalBuff, globalBuff + 8, 8); |
34 |
| - assert(std::get<0>(a) == a.begin()); |
35 |
| - assert(std::get<1>(a) == a.end()); |
36 |
| - |
37 |
| - assert(a.begin() == std::get<0>(std::move(a))); |
38 |
| - std::ranges::subrange<int*> b(globalBuff, globalBuff + 8, 8); |
39 |
| - assert(b.end() == std::get<1>(std::move(b))); |
| 32 | + { |
| 33 | + using It = int*; |
| 34 | + using Sent = sentinel_wrapper<int*>; |
| 35 | + int a[] = {1, 2, 3}; |
| 36 | + using R = std::ranges::subrange<It, Sent, std::ranges::subrange_kind::unsized>; |
| 37 | + R r = R(It(a), Sent(It(a + 3))); |
| 38 | + ASSERT_SAME_TYPE(decltype(std::get<0>(r)), It); |
| 39 | + ASSERT_SAME_TYPE(decltype(std::get<1>(r)), Sent); |
| 40 | + ASSERT_SAME_TYPE(decltype(std::get<0>(static_cast<R&&>(r))), It); |
| 41 | + ASSERT_SAME_TYPE(decltype(std::get<1>(static_cast<R&&>(r))), Sent); |
| 42 | + ASSERT_SAME_TYPE(decltype(std::get<0>(static_cast<const R&>(r))), It); |
| 43 | + ASSERT_SAME_TYPE(decltype(std::get<1>(static_cast<const R&>(r))), Sent); |
| 44 | + ASSERT_SAME_TYPE(decltype(std::get<0>(static_cast<const R&&>(r))), It); |
| 45 | + ASSERT_SAME_TYPE(decltype(std::get<1>(static_cast<const R&&>(r))), Sent); |
| 46 | + assert(base(std::get<0>(r)) == a); // copy from It |
| 47 | + assert(base(base(std::get<1>(r))) == a + 3); // copy from Sent |
| 48 | + assert(base(std::get<0>(std::move(r))) == a); // copy from It |
| 49 | + assert(base(base(std::get<1>(std::move(r)))) == a + 3); // copy from Sent |
| 50 | + } |
| 51 | + { |
| 52 | + using It = int*; |
| 53 | + using Sent = sentinel_wrapper<int*>; |
| 54 | + int a[] = {1, 2, 3}; |
| 55 | + using R = std::ranges::subrange<It, Sent, std::ranges::subrange_kind::sized>; |
| 56 | + R r = R(It(a), Sent(It(a + 3)), 3); |
| 57 | + ASSERT_SAME_TYPE(decltype(std::get<0>(r)), It); |
| 58 | + ASSERT_SAME_TYPE(decltype(std::get<1>(r)), Sent); |
| 59 | + ASSERT_SAME_TYPE(decltype(std::get<0>(static_cast<R&&>(r))), It); |
| 60 | + ASSERT_SAME_TYPE(decltype(std::get<1>(static_cast<R&&>(r))), Sent); |
| 61 | + ASSERT_SAME_TYPE(decltype(std::get<0>(static_cast<const R&>(r))), It); |
| 62 | + ASSERT_SAME_TYPE(decltype(std::get<1>(static_cast<const R&>(r))), Sent); |
| 63 | + ASSERT_SAME_TYPE(decltype(std::get<0>(static_cast<const R&&>(r))), It); |
| 64 | + ASSERT_SAME_TYPE(decltype(std::get<1>(static_cast<const R&&>(r))), Sent); |
| 65 | + assert(base(std::get<0>(r)) == a); // copy from It |
| 66 | + assert(base(base(std::get<1>(r))) == a + 3); // copy from Sent |
| 67 | + assert(base(std::get<0>(std::move(r))) == a); // copy from It |
| 68 | + assert(base(base(std::get<1>(std::move(r)))) == a + 3); // copy from Sent |
| 69 | + } |
| 70 | + { |
| 71 | + // Test the fix for LWG 3589. |
| 72 | + using It = cpp20_input_iterator<int*>; |
| 73 | + using Sent = sentinel_wrapper<It>; |
| 74 | + int a[] = {1, 2, 3}; |
| 75 | + using R = std::ranges::subrange<It, Sent>; |
| 76 | + R r = R(It(a), Sent(It(a + 3))); |
| 77 | + static_assert(!HasGet<0, R&>); |
| 78 | + ASSERT_SAME_TYPE(decltype(std::get<1>(r)), Sent); |
| 79 | + ASSERT_SAME_TYPE(decltype(std::get<0>(static_cast<R&&>(r))), It); |
| 80 | + ASSERT_SAME_TYPE(decltype(std::get<1>(static_cast<R&&>(r))), Sent); |
| 81 | + static_assert(!HasGet<0, const R&>); |
| 82 | + ASSERT_SAME_TYPE(decltype(std::get<1>(static_cast<const R&>(r))), Sent); |
| 83 | + static_assert(!HasGet<0, const R&&>); |
| 84 | + ASSERT_SAME_TYPE(decltype(std::get<1>(static_cast<const R&&>(r))), Sent); |
| 85 | + assert(base(base(std::get<1>(r))) == a + 3); // copy from Sent |
| 86 | + assert(base(std::get<0>(std::move(r))) == a); // move from It |
| 87 | + assert(base(base(std::get<1>(std::move(r)))) == a + 3); // copy from Sent |
| 88 | + } |
40 | 89 |
|
41 | 90 | return true;
|
42 | 91 | }
|
|
0 commit comments