|
18 | 18 | #include <deque> |
19 | 19 | #include <functional> |
20 | 20 | #include <iterator> |
| 21 | +#include <list> |
21 | 22 | #include <ranges> |
22 | 23 | #include <vector> |
23 | 24 |
|
@@ -46,14 +47,21 @@ struct deque_test { |
46 | 47 | }; |
47 | 48 |
|
48 | 49 | /*TEST_CONSTEXPR_CXX26*/ |
49 | | -void test_segmented_deque_iterator() { // TODO: Mark as TEST_CONSTEXPR_CXX26 once std::deque is constexpr |
50 | | - // check that segmented deque iterators work properly |
51 | | - int sizes[] = {0, 1, 2, 1023, 1024, 1025, 2047, 2048, 2049}; |
52 | | - for (const int size : sizes) { |
53 | | - std::deque<int> d(size); |
54 | | - int index = 0; |
55 | | - |
56 | | - std::for_each_n(d.begin(), d.size(), deque_test(d, index)); |
| 50 | +void test_deque_and_join_view_iterators() { // TODO: Mark as TEST_CONSTEXPR_CXX26 once std::deque is constexpr |
| 51 | + { // Verify that segmented deque iterators work properly |
| 52 | + int sizes[] = {0, 1, 2, 1023, 1024, 1025, 2047, 2048, 2049}; |
| 53 | + for (const int size : sizes) { |
| 54 | + std::deque<int> d(size); |
| 55 | + int index = 0; |
| 56 | + |
| 57 | + std::for_each_n(d.begin(), d.size(), deque_test(d, index)); |
| 58 | + } |
| 59 | + } |
| 60 | + { // Verify that join_view of lists work properly. Note that join_view of (non-random access) lists does |
| 61 | + // not produce segmented iterators. |
| 62 | + std::list<std::list<int>> lst = {{}, {0}, {1, 2}, {}, {3, 4, 5}, {6, 7, 8, 9}, {10}, {11, 12, 13}}; |
| 63 | + auto v = lst | std::views::join; |
| 64 | + std::for_each_n(v.begin(), std::ranges::distance(v), [i = 0](int& a) mutable { assert(a == i++); }); |
57 | 65 | } |
58 | 66 | } |
59 | 67 |
|
@@ -108,11 +116,11 @@ TEST_CONSTEXPR_CXX20 bool test() { |
108 | 116 | } |
109 | 117 |
|
110 | 118 | if (!TEST_IS_CONSTANT_EVALUATED) // TODO: Use TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED when std::deque is made constexpr |
111 | | - test_segmented_deque_iterator(); |
| 119 | + test_deque_and_join_view_iterators(); |
112 | 120 |
|
113 | 121 | #if TEST_STD_VER >= 20 |
114 | | - { |
115 | | - std::vector<std::vector<int>> vec = {{0}, {1, 2}, {3, 4, 5}, {6, 7, 8, 9}, {10}, {11, 12, 13}}; |
| 122 | + { // join_views of (random-access) vectors yield segmented iterators |
| 123 | + std::vector<std::vector<int>> vec = {{}, {0}, {1, 2}, {}, {3, 4, 5}, {6, 7, 8, 9}, {10}, {11, 12, 13}}; |
116 | 124 | auto v = vec | std::views::join; |
117 | 125 | std::for_each_n(v.begin(), std::ranges::distance(v), [i = 0](int& a) mutable { assert(a == i++); }); |
118 | 126 | } |
|
0 commit comments