|
6 | 6 | // |
7 | 7 | //===----------------------------------------------------------------------===// |
8 | 8 |
|
9 | | -// REQUIRES: has-unix-headers, std-at-least-c++26 |
| 9 | +// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 |
| 10 | + |
| 11 | +// constexpr auto operator[](difference_type n) const requires |
| 12 | +// all_random_access<Const, Views...> |
10 | 13 |
|
11 | 14 | #include <ranges> |
12 | 15 | #include <cassert> |
13 | | -#include <vector> |
| 16 | + |
| 17 | +#include "../../range_adaptor_types.h" |
14 | 18 |
|
15 | 19 | constexpr bool test() { |
16 | | - std::vector<int> v1 = {1, 2, 3}; |
17 | | - std::vector<int> v2 = {4, 5, 6}; |
18 | | - auto cv = std::views::concat(v1, v2); |
19 | | - static_assert(std::random_access_iterator<decltype(cv.begin())>); |
20 | | - assert(cv[0] == 1); |
21 | | - assert(cv[2] == 3); |
22 | | - assert(cv[3] == 4); |
23 | | - assert(cv[5] == 6); |
| 20 | + int buffer1[8] = {1, 2, 3, 4, 5, 6, 7, 8}; |
| 21 | + int buffer2[8] = {1, 2, 3, 4, 5, 6, 7, 8}; |
| 22 | + |
| 23 | + { |
| 24 | + // random_access_range and common range |
| 25 | + std::ranges::concat_view v(SimpleCommonRandomAccessSized{buffer1}); |
| 26 | + auto it = v.begin(); |
| 27 | + assert(it[0] == *it); |
| 28 | + assert(it[2] == *(it + 2)); |
| 29 | + assert(it[4] == *(it + 4)); |
| 30 | + |
| 31 | + static_assert(std::is_same_v<decltype(it[2]), const int&>); |
| 32 | + } |
| 33 | + |
| 34 | + { |
| 35 | + // random_access_range and common range, with last view is not a common range |
| 36 | + std::ranges::concat_view v(SimpleCommonRandomAccessSized{buffer1}, SimpleNonCommonRandomAccessSized{buffer2}); |
| 37 | + auto it = v.begin(); |
| 38 | + assert(it[0] == *it); |
| 39 | + assert(it[2] == *(it + 2)); |
| 40 | + assert(it[4] == *(it + 4)); |
| 41 | + |
| 42 | + static_assert(std::is_same_v<decltype(it[2]), const int&>); |
| 43 | + } |
| 44 | + |
| 45 | + { |
| 46 | + // random_access_range and non common range |
| 47 | + std::ranges::concat_view v(SimpleNonCommonRandomAccessSized{buffer1}, NonSimpleCommonRandomAccessSized{buffer2}); |
| 48 | + auto it = v.begin(); |
| 49 | + const auto canSubscript = [](auto&& it) { return requires { it[0]; }; }; |
| 50 | + static_assert(!canSubscript(it)); |
| 51 | + |
| 52 | + static_assert(std::is_same_v<decltype(*it), const int&>); |
| 53 | + } |
| 54 | + |
| 55 | + { |
| 56 | + // contiguous_range |
| 57 | + std::ranges::concat_view v(ContiguousCommonView{buffer1}, ContiguousCommonView{buffer2}); |
| 58 | + auto it = v.begin(); |
| 59 | + assert(it[0] == *it); |
| 60 | + assert(it[2] == *(it + 2)); |
| 61 | + assert(it[4] == *(it + 4)); |
| 62 | + |
| 63 | + static_assert(std::is_same_v<decltype(it[2]), int&>); |
| 64 | + } |
| 65 | + |
| 66 | + { |
| 67 | + // non random_access_range |
| 68 | + std::ranges::concat_view v(BidiCommonView{buffer1}); |
| 69 | + auto iter = v.begin(); |
| 70 | + const auto canSubscript = [](auto&& it) { return requires { it[0]; }; }; |
| 71 | + static_assert(!canSubscript(iter)); |
| 72 | + } |
| 73 | + |
24 | 74 | return true; |
25 | 75 | } |
26 | 76 |
|
|
0 commit comments