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 | // test if zip_view models input_range, forward_range, bidirectional_range, |
12 | // random_access_range, contiguous_range, common_range |
13 | // sized_range |
14 | |
15 | #include <cassert> |
16 | #include <concepts> |
17 | #include <ranges> |
18 | #include <tuple> |
19 | #include <utility> |
20 | |
21 | #include "types.h" |
22 | |
23 | void testConceptPair() { |
24 | int buffer1[2] = {1, 2}; |
25 | int buffer2[3] = {1, 2, 3}; |
26 | { |
27 | std::ranges::zip_view v{ContiguousCommonView{buffer1}, ContiguousCommonView{buffer2}}; |
28 | using View = decltype(v); |
29 | static_assert(std::ranges::random_access_range<View>); |
30 | static_assert(!std::ranges::contiguous_range<View>); |
31 | static_assert(std::ranges::common_range<View>); |
32 | static_assert(std::ranges::sized_range<View>); |
33 | } |
34 | |
35 | { |
36 | std::ranges::zip_view v{ContiguousNonCommonView{buffer1}, ContiguousNonCommonView{buffer2}}; |
37 | using View = decltype(v); |
38 | static_assert(std::ranges::random_access_range<View>); |
39 | static_assert(!std::ranges::contiguous_range<View>); |
40 | static_assert(!std::ranges::common_range<View>); |
41 | static_assert(!std::ranges::sized_range<View>); |
42 | } |
43 | |
44 | { |
45 | std::ranges::zip_view v{ContiguousNonCommonSized{buffer1}, ContiguousNonCommonSized{buffer2}}; |
46 | using View = decltype(v); |
47 | static_assert(std::ranges::random_access_range<View>); |
48 | static_assert(!std::ranges::contiguous_range<View>); |
49 | static_assert(std::ranges::common_range<View>); |
50 | static_assert(std::ranges::sized_range<View>); |
51 | } |
52 | |
53 | { |
54 | std::ranges::zip_view v{SizedRandomAccessView{buffer1}, ContiguousCommonView{buffer2}}; |
55 | using View = decltype(v); |
56 | static_assert(std::ranges::random_access_range<View>); |
57 | static_assert(!std::ranges::contiguous_range<View>); |
58 | static_assert(std::ranges::common_range<View>); |
59 | static_assert(std::ranges::sized_range<View>); |
60 | } |
61 | |
62 | { |
63 | std::ranges::zip_view v{SizedRandomAccessView{buffer1}, SizedRandomAccessView{buffer2}}; |
64 | using View = decltype(v); |
65 | static_assert(std::ranges::random_access_range<View>); |
66 | static_assert(!std::ranges::contiguous_range<View>); |
67 | static_assert(std::ranges::common_range<View>); |
68 | static_assert(std::ranges::sized_range<View>); |
69 | } |
70 | |
71 | { |
72 | std::ranges::zip_view v{NonSizedRandomAccessView{buffer1}, NonSizedRandomAccessView{buffer2}}; |
73 | using View = decltype(v); |
74 | static_assert(std::ranges::random_access_range<View>); |
75 | static_assert(!std::ranges::contiguous_range<View>); |
76 | static_assert(!std::ranges::common_range<View>); |
77 | static_assert(!std::ranges::sized_range<View>); |
78 | } |
79 | |
80 | { |
81 | std::ranges::zip_view v{BidiCommonView{buffer1}, SizedRandomAccessView{buffer2}}; |
82 | using View = decltype(v); |
83 | static_assert(std::ranges::bidirectional_range<View>); |
84 | static_assert(!std::ranges::random_access_range<View>); |
85 | static_assert(!std::ranges::common_range<View>); |
86 | static_assert(!std::ranges::sized_range<View>); |
87 | } |
88 | |
89 | { |
90 | std::ranges::zip_view v{BidiCommonView{buffer1}, BidiCommonView{buffer2}}; |
91 | using View = decltype(v); |
92 | static_assert(std::ranges::bidirectional_range<View>); |
93 | static_assert(!std::ranges::random_access_range<View>); |
94 | static_assert(!std::ranges::common_range<View>); |
95 | static_assert(!std::ranges::sized_range<View>); |
96 | } |
97 | |
98 | { |
99 | std::ranges::zip_view v{BidiCommonView{buffer1}, ForwardSizedView{buffer2}}; |
100 | using View = decltype(v); |
101 | static_assert(std::ranges::forward_range<View>); |
102 | static_assert(!std::ranges::bidirectional_range<View>); |
103 | static_assert(std::ranges::common_range<View>); |
104 | static_assert(!std::ranges::sized_range<View>); |
105 | } |
106 | |
107 | { |
108 | std::ranges::zip_view v{BidiNonCommonView{buffer1}, ForwardSizedView{buffer2}}; |
109 | using View = decltype(v); |
110 | static_assert(std::ranges::forward_range<View>); |
111 | static_assert(!std::ranges::bidirectional_range<View>); |
112 | static_assert(!std::ranges::common_range<View>); |
113 | static_assert(!std::ranges::sized_range<View>); |
114 | } |
115 | |
116 | { |
117 | std::ranges::zip_view v{ForwardSizedView{buffer1}, ForwardSizedView{buffer2}}; |
118 | using View = decltype(v); |
119 | static_assert(std::ranges::forward_range<View>); |
120 | static_assert(!std::ranges::bidirectional_range<View>); |
121 | static_assert(std::ranges::common_range<View>); |
122 | static_assert(std::ranges::sized_range<View>); |
123 | } |
124 | |
125 | { |
126 | std::ranges::zip_view v{ForwardSizedNonCommon{buffer1}, ForwardSizedView{buffer2}}; |
127 | using View = decltype(v); |
128 | static_assert(std::ranges::forward_range<View>); |
129 | static_assert(!std::ranges::bidirectional_range<View>); |
130 | static_assert(!std::ranges::common_range<View>); |
131 | static_assert(std::ranges::sized_range<View>); |
132 | } |
133 | |
134 | { |
135 | std::ranges::zip_view v{InputCommonView{buffer1}, ForwardSizedView{buffer2}}; |
136 | using View = decltype(v); |
137 | static_assert(std::ranges::input_range<View>); |
138 | static_assert(!std::ranges::forward_range<View>); |
139 | static_assert(std::ranges::common_range<View>); |
140 | static_assert(!std::ranges::sized_range<View>); |
141 | } |
142 | |
143 | { |
144 | std::ranges::zip_view v{InputCommonView{buffer1}, InputCommonView{buffer2}}; |
145 | using View = decltype(v); |
146 | static_assert(std::ranges::input_range<View>); |
147 | static_assert(!std::ranges::forward_range<View>); |
148 | static_assert(std::ranges::common_range<View>); |
149 | static_assert(!std::ranges::sized_range<View>); |
150 | } |
151 | |
152 | { |
153 | std::ranges::zip_view v{InputNonCommonView{buffer1}, InputCommonView{buffer2}}; |
154 | using View = decltype(v); |
155 | static_assert(std::ranges::input_range<View>); |
156 | static_assert(!std::ranges::forward_range<View>); |
157 | static_assert(!std::ranges::common_range<View>); |
158 | static_assert(!std::ranges::sized_range<View>); |
159 | } |
160 | } |
161 | |
162 | void testConceptTuple() { |
163 | int buffer1[2] = {1, 2}; |
164 | int buffer2[3] = {1, 2, 3}; |
165 | int buffer3[4] = {1, 2, 3, 4}; |
166 | |
167 | { |
168 | std::ranges::zip_view v{ContiguousCommonView{buffer1}, ContiguousCommonView{buffer2}, |
169 | ContiguousCommonView{buffer3}}; |
170 | using View = decltype(v); |
171 | static_assert(std::ranges::random_access_range<View>); |
172 | static_assert(!std::ranges::contiguous_range<View>); |
173 | static_assert(std::ranges::common_range<View>); |
174 | static_assert(std::ranges::sized_range<View>); |
175 | } |
176 | |
177 | { |
178 | std::ranges::zip_view v{ContiguousNonCommonView{buffer1}, ContiguousNonCommonView{buffer2}, |
179 | ContiguousNonCommonView{buffer3}}; |
180 | using View = decltype(v); |
181 | static_assert(std::ranges::random_access_range<View>); |
182 | static_assert(!std::ranges::contiguous_range<View>); |
183 | static_assert(!std::ranges::common_range<View>); |
184 | static_assert(!std::ranges::sized_range<View>); |
185 | } |
186 | |
187 | { |
188 | std::ranges::zip_view v{ContiguousNonCommonSized{buffer1}, ContiguousNonCommonSized{buffer2}, |
189 | ContiguousNonCommonSized{buffer3}}; |
190 | using View = decltype(v); |
191 | static_assert(std::ranges::random_access_range<View>); |
192 | static_assert(!std::ranges::contiguous_range<View>); |
193 | static_assert(std::ranges::common_range<View>); |
194 | static_assert(std::ranges::sized_range<View>); |
195 | } |
196 | |
197 | { |
198 | std::ranges::zip_view v{SizedRandomAccessView{buffer1}, ContiguousCommonView{buffer2}, |
199 | ContiguousCommonView{buffer3}}; |
200 | using View = decltype(v); |
201 | static_assert(std::ranges::random_access_range<View>); |
202 | static_assert(!std::ranges::contiguous_range<View>); |
203 | static_assert(std::ranges::common_range<View>); |
204 | static_assert(std::ranges::sized_range<View>); |
205 | } |
206 | |
207 | { |
208 | std::ranges::zip_view v{SizedRandomAccessView{buffer1}, SizedRandomAccessView{buffer2}, |
209 | SizedRandomAccessView{buffer3}}; |
210 | using View = decltype(v); |
211 | static_assert(std::ranges::random_access_range<View>); |
212 | static_assert(!std::ranges::contiguous_range<View>); |
213 | static_assert(std::ranges::common_range<View>); |
214 | static_assert(std::ranges::sized_range<View>); |
215 | } |
216 | |
217 | { |
218 | std::ranges::zip_view v{NonSizedRandomAccessView{buffer1}, NonSizedRandomAccessView{buffer2}, |
219 | NonSizedRandomAccessView{buffer3}}; |
220 | using View = decltype(v); |
221 | static_assert(std::ranges::random_access_range<View>); |
222 | static_assert(!std::ranges::contiguous_range<View>); |
223 | static_assert(!std::ranges::common_range<View>); |
224 | static_assert(!std::ranges::sized_range<View>); |
225 | } |
226 | |
227 | { |
228 | std::ranges::zip_view v{BidiCommonView{buffer1}, SizedRandomAccessView{buffer2}, SizedRandomAccessView{buffer3}}; |
229 | using View = decltype(v); |
230 | static_assert(std::ranges::bidirectional_range<View>); |
231 | static_assert(!std::ranges::random_access_range<View>); |
232 | static_assert(!std::ranges::common_range<View>); |
233 | static_assert(!std::ranges::sized_range<View>); |
234 | } |
235 | |
236 | { |
237 | std::ranges::zip_view v{BidiCommonView{buffer1}, BidiCommonView{buffer2}, BidiCommonView{buffer3}}; |
238 | using View = decltype(v); |
239 | static_assert(std::ranges::bidirectional_range<View>); |
240 | static_assert(!std::ranges::random_access_range<View>); |
241 | static_assert(!std::ranges::common_range<View>); |
242 | static_assert(!std::ranges::sized_range<View>); |
243 | } |
244 | |
245 | { |
246 | std::ranges::zip_view v{BidiCommonView{buffer1}, ForwardSizedView{buffer2}, ForwardSizedView{buffer3}}; |
247 | using View = decltype(v); |
248 | static_assert(std::ranges::forward_range<View>); |
249 | static_assert(!std::ranges::bidirectional_range<View>); |
250 | static_assert(std::ranges::common_range<View>); |
251 | static_assert(!std::ranges::sized_range<View>); |
252 | } |
253 | |
254 | { |
255 | std::ranges::zip_view v{BidiNonCommonView{buffer1}, ForwardSizedView{buffer2}, ForwardSizedView{buffer3}}; |
256 | using View = decltype(v); |
257 | static_assert(std::ranges::forward_range<View>); |
258 | static_assert(!std::ranges::bidirectional_range<View>); |
259 | static_assert(!std::ranges::common_range<View>); |
260 | static_assert(!std::ranges::sized_range<View>); |
261 | } |
262 | |
263 | { |
264 | std::ranges::zip_view v{ForwardSizedView{buffer1}, ForwardSizedView{buffer2}, ForwardSizedView{buffer3}}; |
265 | using View = decltype(v); |
266 | static_assert(std::ranges::forward_range<View>); |
267 | static_assert(!std::ranges::bidirectional_range<View>); |
268 | static_assert(std::ranges::common_range<View>); |
269 | static_assert(std::ranges::sized_range<View>); |
270 | } |
271 | |
272 | { |
273 | std::ranges::zip_view v{ForwardSizedNonCommon{buffer1}, ForwardSizedView{buffer2}, ForwardSizedView{buffer3}}; |
274 | using View = decltype(v); |
275 | static_assert(std::ranges::forward_range<View>); |
276 | static_assert(!std::ranges::bidirectional_range<View>); |
277 | static_assert(!std::ranges::common_range<View>); |
278 | static_assert(std::ranges::sized_range<View>); |
279 | } |
280 | |
281 | { |
282 | std::ranges::zip_view v{InputCommonView{buffer1}, ForwardSizedView{buffer2}, ForwardSizedView{buffer3}}; |
283 | using View = decltype(v); |
284 | static_assert(std::ranges::input_range<View>); |
285 | static_assert(!std::ranges::forward_range<View>); |
286 | static_assert(std::ranges::common_range<View>); |
287 | static_assert(!std::ranges::sized_range<View>); |
288 | } |
289 | |
290 | { |
291 | std::ranges::zip_view v{InputCommonView{buffer1}, InputCommonView{buffer2}, InputCommonView{buffer3}}; |
292 | using View = decltype(v); |
293 | static_assert(std::ranges::input_range<View>); |
294 | static_assert(!std::ranges::forward_range<View>); |
295 | static_assert(std::ranges::common_range<View>); |
296 | static_assert(!std::ranges::sized_range<View>); |
297 | } |
298 | |
299 | { |
300 | std::ranges::zip_view v{InputNonCommonView{buffer1}, InputCommonView{buffer2}, InputCommonView{buffer3}}; |
301 | using View = decltype(v); |
302 | static_assert(std::ranges::input_range<View>); |
303 | static_assert(!std::ranges::forward_range<View>); |
304 | static_assert(!std::ranges::common_range<View>); |
305 | static_assert(!std::ranges::sized_range<View>); |
306 | } |
307 | } |
308 | |
309 | using OutputIter = cpp17_output_iterator<int*>; |
310 | static_assert(std::output_iterator<OutputIter, int>); |
311 | |
312 | struct OutputView : std::ranges::view_base { |
313 | OutputIter begin() const; |
314 | sentinel_wrapper<OutputIter> end() const; |
315 | }; |
316 | static_assert(std::ranges::output_range<OutputView, int>); |
317 | static_assert(!std::ranges::input_range<OutputView>); |
318 | |
319 | template <class... Ts> |
320 | concept zippable = requires { |
321 | typename std::ranges::zip_view<Ts...>; |
322 | }; |
323 | |
324 | // output_range is not supported |
325 | static_assert(!zippable<OutputView>); |
326 | static_assert(!zippable<SimpleCommon, OutputView>); |
327 | static_assert(zippable<SimpleCommon>); |
328 | |