1 | //===----------------------------------------------------------------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 |
10 | |
11 | // constexpr auto end() requires(!(simple-view<Views> && ...)) |
12 | // constexpr auto end() const requires(range<const Views>&&...) |
13 | |
14 | #include <ranges> |
15 | #include <tuple> |
16 | |
17 | #include "types.h" |
18 | |
19 | // ID | simple | common | bidi | random | sized | #views | v.end() | as_const(v) |
20 | // | | | | access | | | | .end() |
21 | // ---|--------|--------|------|--------|-------|--------|----------------|--------------- |
22 | // 1 | Y | Y | Y | Y | Y | 1 | iterator<true> | iterator<true> |
23 | // 2 | Y | Y | Y | Y | Y | >1 | iterator<true> | iterator<true> |
24 | // 3 | Y | N | Y | Y | N | 1 | sentinel<true> | sentinel<true> |
25 | // 4 | Y | N | Y | Y | N | >1 | sentinel<true> | sentinel<true> |
26 | // 5 | Y | Y | Y | N | Y | 1 | iterator<true> | iterator<true> |
27 | // 6 | Y | Y | Y | N | Y | >1 | sentinel<true> | sentinel<true> |
28 | // 7 | Y | Y | Y | N | N | 1 | iterator<true> | iterator<true> |
29 | // 8 | Y | Y | Y | N | N | >1 | sentinel<true> | sentinel<true> |
30 | // 9 | Y | Y | N | N | Y | 1 | iterator<true> | iterator<true> |
31 | // 10 | Y | Y | N | N | Y | >1 | iterator<true> | iterator<true> |
32 | // 11 | Y | Y | N | N | N | 1 | iterator<true> | iterator<true> |
33 | // 12 | Y | Y | N | N | N | >1 | iterator<true> | iterator<true> |
34 | // 13 | Y | N | Y | Y | Y | 1 | iterator<true> | iterator<true> |
35 | // 14 | Y | N | Y | Y | Y | >1 | iterator<true> | iterator<true> |
36 | // 15 | Y | N | Y | N | Y | 1 | sentinel<true> | sentinel<true> |
37 | // 16 | Y | N | Y | N | Y | >1 | sentinel<true> | sentinel<true> |
38 | // 17 | Y | N | Y | N | N | 1 | sentinel<true> | sentinel<true> |
39 | // 18 | Y | N | Y | N | N | >1 | sentinel<true> | sentinel<true> |
40 | // 19 | Y | N | N | N | Y | 1 | sentinel<true> | sentinel<true> |
41 | // 20 | Y | N | N | N | Y | >1 | sentinel<true> | sentinel<true> |
42 | // 21 | Y | N | N | N | N | 1 | sentinel<true> | sentinel<true> |
43 | // 22 | Y | N | N | N | N | >1 | sentinel<true> | sentinel<true> |
44 | // 23 | N | Y | Y | Y | Y | 1 | iterator<false>| iterator<true> |
45 | // 24 | N | Y | Y | Y | Y | >1 | iterator<false>| iterator<true> |
46 | // 25 | N | N | Y | Y | N | 1 | sentinel<false>| sentinel<true> |
47 | // 26 | N | N | Y | Y | N | >1 | sentinel<false>| sentinel<true> |
48 | // 27 | N | Y | Y | N | Y | 1 | iterator<false>| iterator<true> |
49 | // 28 | N | Y | Y | N | Y | >1 | sentinel<false>| sentinel<true> |
50 | // 29 | N | Y | Y | N | N | 1 | iterator<false>| iterator<true> |
51 | // 30 | N | Y | Y | N | N | >1 | sentinel<false>| sentinel<true> |
52 | // 31 | N | Y | N | N | Y | 1 | iterator<false>| iterator<true> |
53 | // 32 | N | Y | N | N | Y | >1 | iterator<false>| iterator<true> |
54 | // 33 | N | Y | N | N | N | 1 | iterator<false>| iterator<true> |
55 | // 34 | N | Y | N | N | N | >1 | iterator<false>| iterator<true> |
56 | // 35 | N | N | Y | Y | Y | 1 | iterator<false>| iterator<true> |
57 | // 36 | N | N | Y | Y | Y | >1 | iterator<false>| iterator<true> |
58 | // 37 | N | N | Y | N | Y | 1 | sentinel<false>| sentinel<true> |
59 | // 38 | N | N | Y | N | Y | >1 | sentinel<false>| sentinel<true> |
60 | // 39 | N | N | Y | N | N | 1 | sentinel<false>| sentinel<true> |
61 | // 40 | N | N | Y | N | N | >1 | sentinel<false>| sentinel<true> |
62 | // 41 | N | N | N | N | Y | 1 | sentinel<false>| sentinel<true> |
63 | // 42 | N | N | N | N | Y | >1 | sentinel<false>| sentinel<true> |
64 | // 43 | N | N | N | N | N | 1 | sentinel<false>| sentinel<true> |
65 | // 44 | N | N | N | N | N | >1 | sentinel<false>| sentinel<true> |
66 | |
67 | constexpr bool test() { |
68 | int buffer1[5] = {1, 2, 3, 4, 5}; |
69 | int buffer2[1] = {1}; |
70 | int buffer3[3] = {1, 2, 3}; |
71 | { |
72 | // test ID 1 |
73 | std::ranges::zip_view v{SimpleCommonRandomAccessSized(buffer1)}; |
74 | static_assert(std::ranges::common_range<decltype(v)>); |
75 | assert(v.begin() + 5 == v.end()); |
76 | static_assert(std::is_same_v<decltype(v.end()), decltype(std::as_const(v).end())>); |
77 | } |
78 | { |
79 | // test ID 2 |
80 | std::ranges::zip_view v{SimpleCommonRandomAccessSized(buffer1), SimpleCommonRandomAccessSized(buffer2)}; |
81 | static_assert(std::ranges::common_range<decltype(v)>); |
82 | assert(v.begin() + 1 == v.end()); |
83 | static_assert(std::is_same_v<decltype(v.end()), decltype(std::as_const(v).end())>); |
84 | } |
85 | { |
86 | // test ID 3 |
87 | std::ranges::zip_view v{NonSizedRandomAccessView(buffer1)}; |
88 | static_assert(!std::ranges::common_range<decltype(v)>); |
89 | assert(v.begin() + 5 == v.end()); |
90 | static_assert(std::is_same_v<decltype(v.end()), decltype(std::as_const(v).end())>); |
91 | } |
92 | { |
93 | // test ID 4 |
94 | std::ranges::zip_view v{NonSizedRandomAccessView(buffer1), NonSizedRandomAccessView(buffer3)}; |
95 | static_assert(!std::ranges::common_range<decltype(v)>); |
96 | assert(v.begin() + 3 == v.end()); |
97 | static_assert(std::is_same_v<decltype(v.end()), decltype(std::as_const(v).end())>); |
98 | } |
99 | { |
100 | // test ID 5 |
101 | std::ranges::zip_view v{SizedBidiCommon(buffer1)}; |
102 | static_assert(std::ranges::common_range<decltype(v)>); |
103 | assert(std::next(v.begin(), 5) == v.end()); |
104 | static_assert(std::is_same_v<decltype(v.end()), decltype(std::as_const(v).end())>); |
105 | } |
106 | { |
107 | // test ID 6 |
108 | std::ranges::zip_view v{SizedBidiCommon(buffer1), SizedBidiCommon(buffer2)}; |
109 | static_assert(!std::ranges::common_range<decltype(v)>); |
110 | assert(++v.begin() == v.end()); |
111 | static_assert(std::is_same_v<decltype(v.end()), decltype(std::as_const(v).end())>); |
112 | } |
113 | { |
114 | // test ID 7 |
115 | std::ranges::zip_view v{BidiCommonView(buffer1)}; |
116 | static_assert(std::ranges::common_range<decltype(v)>); |
117 | assert(std::next(v.begin(), 5) == v.end()); |
118 | static_assert(std::is_same_v<decltype(v.end()), decltype(std::as_const(v).end())>); |
119 | } |
120 | { |
121 | // test ID 8 |
122 | std::ranges::zip_view v{BidiCommonView(buffer1), BidiCommonView(buffer2)}; |
123 | static_assert(!std::ranges::common_range<decltype(v)>); |
124 | assert(++v.begin() == v.end()); |
125 | static_assert(std::is_same_v<decltype(v.end()), decltype(std::as_const(v).end())>); |
126 | } |
127 | { |
128 | // test ID 9 |
129 | std::ranges::zip_view v{ForwardSizedView(buffer1)}; |
130 | static_assert(std::ranges::common_range<decltype(v)>); |
131 | assert(std::next(v.begin(), 5) == v.end()); |
132 | static_assert(std::is_same_v<decltype(v.end()), decltype(std::as_const(v).end())>); |
133 | } |
134 | { |
135 | // test ID 10 |
136 | std::ranges::zip_view v{ForwardSizedView(buffer1), ForwardSizedView(buffer2)}; |
137 | static_assert(std::ranges::common_range<decltype(v)>); |
138 | assert(++v.begin() == v.end()); |
139 | static_assert(std::is_same_v<decltype(v.end()), decltype(std::as_const(v).end())>); |
140 | } |
141 | { |
142 | // test ID 11 |
143 | std::ranges::zip_view v{InputCommonView(buffer1)}; |
144 | static_assert(std::ranges::common_range<decltype(v)>); |
145 | assert(std::ranges::next(v.begin(), 5) == v.end()); |
146 | static_assert(std::is_same_v<decltype(v.end()), decltype(std::as_const(v).end())>); |
147 | } |
148 | { |
149 | // test ID 12 |
150 | std::ranges::zip_view v{InputCommonView(buffer1), InputCommonView(buffer2)}; |
151 | static_assert(std::ranges::common_range<decltype(v)>); |
152 | assert(++v.begin() == v.end()); |
153 | static_assert(std::is_same_v<decltype(v.end()), decltype(std::as_const(v).end())>); |
154 | } |
155 | { |
156 | // test ID 13 |
157 | std::ranges::zip_view v{SimpleNonCommonRandomAccessSized(buffer1)}; |
158 | static_assert(std::ranges::common_range<decltype(v)>); |
159 | assert(v.begin() + 5 == v.end()); |
160 | static_assert(std::is_same_v<decltype(v.end()), decltype(std::as_const(v).end())>); |
161 | } |
162 | { |
163 | // test ID 14 |
164 | std::ranges::zip_view v{SimpleNonCommonRandomAccessSized(buffer1), SimpleNonCommonRandomAccessSized(buffer2)}; |
165 | static_assert(std::ranges::common_range<decltype(v)>); |
166 | assert(v.begin() + 1 == v.end()); |
167 | static_assert(std::is_same_v<decltype(v.end()), decltype(std::as_const(v).end())>); |
168 | } |
169 | { |
170 | // test ID 15 |
171 | std::ranges::zip_view v{SizedBidiNonCommonView(buffer1)}; |
172 | static_assert(!std::ranges::common_range<decltype(v)>); |
173 | assert(std::next(v.begin(), 5) == v.end()); |
174 | static_assert(std::is_same_v<decltype(v.end()), decltype(std::as_const(v).end())>); |
175 | } |
176 | { |
177 | // test ID 16 |
178 | std::ranges::zip_view v{SizedBidiNonCommonView(buffer1), SizedBidiNonCommonView(buffer2)}; |
179 | static_assert(!std::ranges::common_range<decltype(v)>); |
180 | assert(++v.begin() == v.end()); |
181 | static_assert(std::is_same_v<decltype(v.end()), decltype(std::as_const(v).end())>); |
182 | } |
183 | { |
184 | // test ID 17 |
185 | std::ranges::zip_view v{BidiNonCommonView(buffer1)}; |
186 | static_assert(!std::ranges::common_range<decltype(v)>); |
187 | assert(std::next(v.begin(), 5) == v.end()); |
188 | static_assert(std::is_same_v<decltype(v.end()), decltype(std::as_const(v).end())>); |
189 | } |
190 | { |
191 | // test ID 18 |
192 | std::ranges::zip_view v{BidiNonCommonView(buffer1), BidiNonCommonView(buffer2)}; |
193 | static_assert(!std::ranges::common_range<decltype(v)>); |
194 | assert(++v.begin() == v.end()); |
195 | static_assert(std::is_same_v<decltype(v.end()), decltype(std::as_const(v).end())>); |
196 | } |
197 | { |
198 | // test ID 19 |
199 | std::ranges::zip_view v{ForwardSizedNonCommon(buffer1)}; |
200 | static_assert(!std::ranges::common_range<decltype(v)>); |
201 | assert(std::next(v.begin(), 5) == v.end()); |
202 | static_assert(std::is_same_v<decltype(v.end()), decltype(std::as_const(v).end())>); |
203 | } |
204 | { |
205 | // test ID 20 |
206 | std::ranges::zip_view v{ForwardSizedNonCommon(buffer1), ForwardSizedNonCommon(buffer2)}; |
207 | static_assert(!std::ranges::common_range<decltype(v)>); |
208 | assert(++v.begin() == v.end()); |
209 | static_assert(std::is_same_v<decltype(v.end()), decltype(std::as_const(v).end())>); |
210 | } |
211 | { |
212 | // test ID 21 |
213 | std::ranges::zip_view v{InputNonCommonView(buffer1)}; |
214 | static_assert(!std::ranges::common_range<decltype(v)>); |
215 | assert(std::ranges::next(v.begin(), 5) == v.end()); |
216 | static_assert(std::is_same_v<decltype(v.end()), decltype(std::as_const(v).end())>); |
217 | } |
218 | { |
219 | // test ID 22 |
220 | std::ranges::zip_view v{InputNonCommonView(buffer1), InputNonCommonView(buffer2)}; |
221 | static_assert(!std::ranges::common_range<decltype(v)>); |
222 | assert(++v.begin() == v.end()); |
223 | static_assert(std::is_same_v<decltype(v.end()), decltype(std::as_const(v).end())>); |
224 | } |
225 | { |
226 | // test ID 23 |
227 | std::ranges::zip_view v{NonSimpleCommonRandomAccessSized(buffer1)}; |
228 | static_assert(std::ranges::common_range<decltype(v)>); |
229 | assert(v.begin() + 5 == v.end()); |
230 | static_assert(!std::is_same_v<decltype(v.end()), decltype(std::as_const(v).end())>); |
231 | } |
232 | { |
233 | // test ID 24 |
234 | std::ranges::zip_view v{NonSimpleCommonRandomAccessSized(buffer1), NonSimpleCommonRandomAccessSized(buffer2)}; |
235 | static_assert(std::ranges::common_range<decltype(v)>); |
236 | assert(v.begin() + 1 == v.end()); |
237 | static_assert(!std::is_same_v<decltype(v.end()), decltype(std::as_const(v).end())>); |
238 | } |
239 | { |
240 | // test ID 25 |
241 | std::ranges::zip_view v{NonSimpleNonSizedRandomAccessView(buffer1)}; |
242 | static_assert(!std::ranges::common_range<decltype(v)>); |
243 | assert(v.begin() + 5 == v.end()); |
244 | static_assert(!std::is_same_v<decltype(v.end()), decltype(std::as_const(v).end())>); |
245 | } |
246 | { |
247 | // test ID 26 |
248 | std::ranges::zip_view v{NonSimpleNonSizedRandomAccessView(buffer1), NonSimpleNonSizedRandomAccessView(buffer3)}; |
249 | static_assert(!std::ranges::common_range<decltype(v)>); |
250 | assert(v.begin() + 3 == v.end()); |
251 | static_assert(!std::is_same_v<decltype(v.end()), decltype(std::as_const(v).end())>); |
252 | } |
253 | { |
254 | // test ID 27 |
255 | std::ranges::zip_view v{NonSimpleSizedBidiCommon(buffer1)}; |
256 | static_assert(std::ranges::common_range<decltype(v)>); |
257 | assert(std::next(v.begin(), 5) == v.end()); |
258 | static_assert(!std::is_same_v<decltype(v.end()), decltype(std::as_const(v).end())>); |
259 | } |
260 | { |
261 | // test ID 28 |
262 | std::ranges::zip_view v{NonSimpleSizedBidiCommon(buffer1), NonSimpleSizedBidiCommon(buffer2)}; |
263 | static_assert(!std::ranges::common_range<decltype(v)>); |
264 | assert(++v.begin() == v.end()); |
265 | static_assert(!std::is_same_v<decltype(v.end()), decltype(std::as_const(v).end())>); |
266 | } |
267 | { |
268 | // test ID 29 |
269 | std::ranges::zip_view v{NonSimpleBidiCommonView(buffer1)}; |
270 | static_assert(std::ranges::common_range<decltype(v)>); |
271 | assert(std::next(v.begin(), 5) == v.end()); |
272 | static_assert(!std::is_same_v<decltype(v.end()), decltype(std::as_const(v).end())>); |
273 | } |
274 | { |
275 | // test ID 30 |
276 | std::ranges::zip_view v{NonSimpleBidiCommonView(buffer1), NonSimpleBidiCommonView(buffer2)}; |
277 | static_assert(!std::ranges::common_range<decltype(v)>); |
278 | assert(++v.begin() == v.end()); |
279 | static_assert(!std::is_same_v<decltype(v.end()), decltype(std::as_const(v).end())>); |
280 | } |
281 | { |
282 | // test ID 31 |
283 | std::ranges::zip_view v{NonSimpleForwardSizedView(buffer1)}; |
284 | static_assert(std::ranges::common_range<decltype(v)>); |
285 | assert(std::next(v.begin(), 5) == v.end()); |
286 | static_assert(!std::is_same_v<decltype(v.end()), decltype(std::as_const(v).end())>); |
287 | } |
288 | { |
289 | // test ID 32 |
290 | std::ranges::zip_view v{NonSimpleForwardSizedView(buffer1), NonSimpleForwardSizedView(buffer2)}; |
291 | static_assert(std::ranges::common_range<decltype(v)>); |
292 | assert(++v.begin() == v.end()); |
293 | static_assert(!std::is_same_v<decltype(v.end()), decltype(std::as_const(v).end())>); |
294 | } |
295 | { |
296 | // test ID 33 |
297 | std::ranges::zip_view v{NonSimpleInputCommonView(buffer1)}; |
298 | static_assert(std::ranges::common_range<decltype(v)>); |
299 | assert(std::ranges::next(v.begin(), 5) == v.end()); |
300 | static_assert(!std::is_same_v<decltype(v.end()), decltype(std::as_const(v).end())>); |
301 | } |
302 | { |
303 | // test ID 34 |
304 | std::ranges::zip_view v{NonSimpleInputCommonView(buffer1), NonSimpleInputCommonView(buffer2)}; |
305 | static_assert(std::ranges::common_range<decltype(v)>); |
306 | assert(++v.begin() == v.end()); |
307 | static_assert(!std::is_same_v<decltype(v.end()), decltype(std::as_const(v).end())>); |
308 | } |
309 | { |
310 | // test ID 35 |
311 | std::ranges::zip_view v{NonSimpleNonCommonRandomAccessSized(buffer1)}; |
312 | static_assert(std::ranges::common_range<decltype(v)>); |
313 | assert(v.begin() + 5 == v.end()); |
314 | static_assert(!std::is_same_v<decltype(v.end()), decltype(std::as_const(v).end())>); |
315 | } |
316 | { |
317 | // test ID 36 |
318 | std::ranges::zip_view v{NonSimpleNonCommonRandomAccessSized(buffer1), NonSimpleNonCommonRandomAccessSized(buffer2)}; |
319 | static_assert(std::ranges::common_range<decltype(v)>); |
320 | assert(v.begin() + 1 == v.end()); |
321 | static_assert(!std::is_same_v<decltype(v.end()), decltype(std::as_const(v).end())>); |
322 | } |
323 | { |
324 | // test ID 37 |
325 | std::ranges::zip_view v{NonSimpleSizedBidiNonCommonView(buffer1)}; |
326 | static_assert(!std::ranges::common_range<decltype(v)>); |
327 | assert(std::next(v.begin(), 5) == v.end()); |
328 | static_assert(!std::is_same_v<decltype(v.end()), decltype(std::as_const(v).end())>); |
329 | } |
330 | { |
331 | // test ID 38 |
332 | std::ranges::zip_view v{NonSimpleSizedBidiNonCommonView(buffer1), NonSimpleSizedBidiNonCommonView(buffer2)}; |
333 | static_assert(!std::ranges::common_range<decltype(v)>); |
334 | assert(++v.begin() == v.end()); |
335 | static_assert(!std::is_same_v<decltype(v.end()), decltype(std::as_const(v).end())>); |
336 | } |
337 | { |
338 | // test ID 39 |
339 | std::ranges::zip_view v{NonSimpleBidiNonCommonView(buffer1)}; |
340 | static_assert(!std::ranges::common_range<decltype(v)>); |
341 | assert(std::next(v.begin(), 5) == v.end()); |
342 | static_assert(!std::is_same_v<decltype(v.end()), decltype(std::as_const(v).end())>); |
343 | } |
344 | { |
345 | // test ID 40 |
346 | std::ranges::zip_view v{NonSimpleBidiNonCommonView(buffer1), NonSimpleBidiNonCommonView(buffer2)}; |
347 | static_assert(!std::ranges::common_range<decltype(v)>); |
348 | assert(++v.begin() == v.end()); |
349 | static_assert(!std::is_same_v<decltype(v.end()), decltype(std::as_const(v).end())>); |
350 | } |
351 | { |
352 | // test ID 41 |
353 | std::ranges::zip_view v{NonSimpleForwardSizedNonCommon(buffer1)}; |
354 | static_assert(!std::ranges::common_range<decltype(v)>); |
355 | assert(std::next(v.begin(), 5) == v.end()); |
356 | static_assert(!std::is_same_v<decltype(v.end()), decltype(std::as_const(v).end())>); |
357 | } |
358 | { |
359 | // test ID 42 |
360 | std::ranges::zip_view v{NonSimpleForwardSizedNonCommon(buffer1), NonSimpleForwardSizedNonCommon(buffer2)}; |
361 | static_assert(!std::ranges::common_range<decltype(v)>); |
362 | assert(++v.begin() == v.end()); |
363 | static_assert(!std::is_same_v<decltype(v.end()), decltype(std::as_const(v).end())>); |
364 | } |
365 | { |
366 | // test ID 43 |
367 | std::ranges::zip_view v{NonSimpleInputNonCommonView(buffer1)}; |
368 | static_assert(!std::ranges::common_range<decltype(v)>); |
369 | assert(std::ranges::next(v.begin(), 5) == v.end()); |
370 | static_assert(!std::is_same_v<decltype(v.end()), decltype(std::as_const(v).end())>); |
371 | } |
372 | { |
373 | // test ID 44 |
374 | std::ranges::zip_view v{NonSimpleInputNonCommonView(buffer1), NonSimpleInputNonCommonView(buffer2)}; |
375 | static_assert(!std::ranges::common_range<decltype(v)>); |
376 | assert(++v.begin() == v.end()); |
377 | static_assert(!std::is_same_v<decltype(v.end()), decltype(std::as_const(v).end())>); |
378 | } |
379 | { |
380 | // end should go to the minimum length when zip is common and random_access sized |
381 | std::ranges::zip_view v(std::views::iota(0, 4), std::views::iota(0, 8)); |
382 | auto it = --(v.end()); |
383 | auto [x, y] = *it; |
384 | assert(x == 3); |
385 | assert(y == 3); // y should not go to the end "7" |
386 | } |
387 | return true; |
388 | } |
389 | |
390 | int main(int, char**) { |
391 | test(); |
392 | static_assert(test()); |
393 | |
394 | return 0; |
395 | } |
396 | |