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// <algorithm>
10
11// template<class ForwardIterator1, class ForwardIterator2>
12// constexpr bool // constexpr after C++17
13// is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
14// ForwardIterator2 first2);
15
16#include <algorithm>
17#include <cassert>
18
19#include "test_iterators.h"
20
21#include "test_macros.h"
22
23#if TEST_STD_VER > 17
24TEST_CONSTEXPR bool test_constexpr() {
25 int ia[] = {0, 0, 0};
26 int ib[] = {1, 1, 0};
27 int ic[] = {1, 0, 1};
28 int id[] = {1};
29 return !std::is_permutation(std::begin(ia), std::end(ia), std::begin(ib))
30 && !std::is_permutation(std::begin(ia), std::end(ia), std::begin(ib), std::end(ib))
31 && std::is_permutation(std::begin(ib), std::end(ib), std::begin(ic))
32 && std::is_permutation(std::begin(ib), std::end(ib), std::begin(ic), std::end(ic))
33 && !std::is_permutation(std::begin(ic), std::end(ic), std::begin(id), std::end(id))
34 ;
35 }
36#endif
37
38int main(int, char**)
39{
40 {
41 const int ia[] = {0};
42 const int ib[] = {0};
43 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
44 assert(std::is_permutation(forward_iterator<const int*>(ia),
45 forward_iterator<const int*>(ia + 0),
46 forward_iterator<const int*>(ib)) == true);
47#if TEST_STD_VER >= 14
48 assert(std::is_permutation(forward_iterator<const int*>(ia),
49 forward_iterator<const int*>(ia + 0),
50 forward_iterator<const int*>(ib),
51 forward_iterator<const int*>(ib + 0)) == true);
52#endif
53 assert(std::is_permutation(forward_iterator<const int*>(ia),
54 forward_iterator<const int*>(ia + sa),
55 forward_iterator<const int*>(ib)) == true);
56#if TEST_STD_VER >= 14
57 assert(std::is_permutation(forward_iterator<const int*>(ia),
58 forward_iterator<const int*>(ia + sa),
59 forward_iterator<const int*>(ib),
60 forward_iterator<const int*>(ib + sa)) == true);
61 assert(std::is_permutation(forward_iterator<const int*>(ia),
62 forward_iterator<const int*>(ia + sa),
63 forward_iterator<const int*>(ib),
64 forward_iterator<const int*>(ib + sa - 1)) == false);
65#endif
66 }
67 {
68 const int ia[] = {0};
69 const int ib[] = {1};
70 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
71 assert(std::is_permutation(forward_iterator<const int*>(ia),
72 forward_iterator<const int*>(ia + sa),
73 forward_iterator<const int*>(ib)) == false);
74#if TEST_STD_VER >= 14
75 assert(std::is_permutation(forward_iterator<const int*>(ia),
76 forward_iterator<const int*>(ia + sa),
77 forward_iterator<const int*>(ib),
78 forward_iterator<const int*>(ib + sa)) == false);
79#endif
80 }
81
82 {
83 const int ia[] = {0, 0};
84 const int ib[] = {0, 0};
85 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
86 assert(std::is_permutation(forward_iterator<const int*>(ia),
87 forward_iterator<const int*>(ia + sa),
88 forward_iterator<const int*>(ib)) == true);
89#if TEST_STD_VER >= 14
90 assert(std::is_permutation(forward_iterator<const int*>(ia),
91 forward_iterator<const int*>(ia + sa),
92 forward_iterator<const int*>(ib),
93 forward_iterator<const int*>(ib + sa)) == true);
94 assert(std::is_permutation(forward_iterator<const int*>(ia),
95 forward_iterator<const int*>(ia + sa),
96 forward_iterator<const int*>(ib),
97 forward_iterator<const int*>(ib + sa - 1)) == false);
98#endif
99 }
100 {
101 const int ia[] = {0, 0};
102 const int ib[] = {0, 1};
103 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
104 assert(std::is_permutation(forward_iterator<const int*>(ia),
105 forward_iterator<const int*>(ia + sa),
106 forward_iterator<const int*>(ib)) == false);
107#if TEST_STD_VER >= 14
108 assert(std::is_permutation(forward_iterator<const int*>(ia),
109 forward_iterator<const int*>(ia + sa),
110 forward_iterator<const int*>(ib),
111 forward_iterator<const int*>(ib + sa)) == false);
112#endif
113 }
114 {
115 const int ia[] = {0, 0};
116 const int ib[] = {1, 0};
117 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
118 assert(std::is_permutation(forward_iterator<const int*>(ia),
119 forward_iterator<const int*>(ia + sa),
120 forward_iterator<const int*>(ib)) == false);
121#if TEST_STD_VER >= 14
122 assert(std::is_permutation(forward_iterator<const int*>(ia),
123 forward_iterator<const int*>(ia + sa),
124 forward_iterator<const int*>(ib),
125 forward_iterator<const int*>(ib + sa)) == false);
126#endif
127 }
128 {
129 const int ia[] = {0, 0};
130 const int ib[] = {1, 1};
131 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
132 assert(std::is_permutation(forward_iterator<const int*>(ia),
133 forward_iterator<const int*>(ia + sa),
134 forward_iterator<const int*>(ib)) == false);
135#if TEST_STD_VER >= 14
136 assert(std::is_permutation(forward_iterator<const int*>(ia),
137 forward_iterator<const int*>(ia + sa),
138 forward_iterator<const int*>(ib),
139 forward_iterator<const int*>(ib + sa)) == false);
140#endif
141 }
142 {
143 const int ia[] = {0, 1};
144 const int ib[] = {0, 0};
145 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
146 assert(std::is_permutation(forward_iterator<const int*>(ia),
147 forward_iterator<const int*>(ia + sa),
148 forward_iterator<const int*>(ib)) == false);
149#if TEST_STD_VER >= 14
150 assert(std::is_permutation(forward_iterator<const int*>(ia),
151 forward_iterator<const int*>(ia + sa),
152 forward_iterator<const int*>(ib),
153 forward_iterator<const int*>(ib + sa)) == false);
154#endif
155 }
156 {
157 const int ia[] = {0, 1};
158 const int ib[] = {0, 1};
159 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
160 assert(std::is_permutation(forward_iterator<const int*>(ia),
161 forward_iterator<const int*>(ia + sa),
162 forward_iterator<const int*>(ib)) == true);
163#if TEST_STD_VER >= 14
164 assert(std::is_permutation(forward_iterator<const int*>(ia),
165 forward_iterator<const int*>(ia + sa),
166 forward_iterator<const int*>(ib),
167 forward_iterator<const int*>(ib + sa)) == true);
168 assert(std::is_permutation(forward_iterator<const int*>(ia),
169 forward_iterator<const int*>(ia + sa),
170 forward_iterator<const int*>(ib),
171 forward_iterator<const int*>(ib + sa - 1)) == false);
172#endif
173 }
174 {
175 const int ia[] = {0, 1};
176 const int ib[] = {1, 0};
177 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
178 assert(std::is_permutation(forward_iterator<const int*>(ia),
179 forward_iterator<const int*>(ia + sa),
180 forward_iterator<const int*>(ib)) == true);
181#if TEST_STD_VER >= 14
182 assert(std::is_permutation(forward_iterator<const int*>(ia),
183 forward_iterator<const int*>(ia + sa),
184 forward_iterator<const int*>(ib),
185 forward_iterator<const int*>(ib + sa)) == true);
186#endif
187 }
188 {
189 const int ia[] = {0, 1};
190 const int ib[] = {1, 1};
191 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
192 assert(std::is_permutation(forward_iterator<const int*>(ia),
193 forward_iterator<const int*>(ia + sa),
194 forward_iterator<const int*>(ib)) == false);
195#if TEST_STD_VER >= 14
196 assert(std::is_permutation(forward_iterator<const int*>(ia),
197 forward_iterator<const int*>(ia + sa),
198 forward_iterator<const int*>(ib),
199 forward_iterator<const int*>(ib + sa)) == false);
200#endif
201 }
202 {
203 const int ia[] = {1, 0};
204 const int ib[] = {0, 0};
205 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
206 assert(std::is_permutation(forward_iterator<const int*>(ia),
207 forward_iterator<const int*>(ia + sa),
208 forward_iterator<const int*>(ib)) == false);
209#if TEST_STD_VER >= 14
210 assert(std::is_permutation(forward_iterator<const int*>(ia),
211 forward_iterator<const int*>(ia + sa),
212 forward_iterator<const int*>(ib),
213 forward_iterator<const int*>(ib + sa)) == false);
214#endif
215 }
216 {
217 const int ia[] = {1, 0};
218 const int ib[] = {0, 1};
219 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
220 assert(std::is_permutation(forward_iterator<const int*>(ia),
221 forward_iterator<const int*>(ia + sa),
222 forward_iterator<const int*>(ib)) == true);
223#if TEST_STD_VER >= 14
224 assert(std::is_permutation(forward_iterator<const int*>(ia),
225 forward_iterator<const int*>(ia + sa),
226 forward_iterator<const int*>(ib),
227 forward_iterator<const int*>(ib + sa)) == true);
228#endif
229 }
230 {
231 const int ia[] = {1, 0};
232 const int ib[] = {1, 0};
233 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
234 assert(std::is_permutation(forward_iterator<const int*>(ia),
235 forward_iterator<const int*>(ia + sa),
236 forward_iterator<const int*>(ib)) == true);
237#if TEST_STD_VER >= 14
238 assert(std::is_permutation(forward_iterator<const int*>(ia),
239 forward_iterator<const int*>(ia + sa),
240 forward_iterator<const int*>(ib),
241 forward_iterator<const int*>(ib + sa)) == true);
242#endif
243 }
244 {
245 const int ia[] = {1, 0};
246 const int ib[] = {1, 1};
247 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
248 assert(std::is_permutation(forward_iterator<const int*>(ia),
249 forward_iterator<const int*>(ia + sa),
250 forward_iterator<const int*>(ib)) == false);
251#if TEST_STD_VER >= 14
252 assert(std::is_permutation(forward_iterator<const int*>(ia),
253 forward_iterator<const int*>(ia + sa),
254 forward_iterator<const int*>(ib),
255 forward_iterator<const int*>(ib + sa)) == false);
256#endif
257 }
258 {
259 const int ia[] = {1, 1};
260 const int ib[] = {0, 0};
261 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
262 assert(std::is_permutation(forward_iterator<const int*>(ia),
263 forward_iterator<const int*>(ia + sa),
264 forward_iterator<const int*>(ib)) == false);
265#if TEST_STD_VER >= 14
266 assert(std::is_permutation(forward_iterator<const int*>(ia),
267 forward_iterator<const int*>(ia + sa),
268 forward_iterator<const int*>(ib),
269 forward_iterator<const int*>(ib + sa)) == false);
270#endif
271 }
272 {
273 const int ia[] = {1, 1};
274 const int ib[] = {0, 1};
275 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
276 assert(std::is_permutation(forward_iterator<const int*>(ia),
277 forward_iterator<const int*>(ia + sa),
278 forward_iterator<const int*>(ib)) == false);
279#if TEST_STD_VER >= 14
280 assert(std::is_permutation(forward_iterator<const int*>(ia),
281 forward_iterator<const int*>(ia + sa),
282 forward_iterator<const int*>(ib),
283 forward_iterator<const int*>(ib + sa)) == false);
284#endif
285 }
286 {
287 const int ia[] = {1, 1};
288 const int ib[] = {1, 0};
289 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
290 assert(std::is_permutation(forward_iterator<const int*>(ia),
291 forward_iterator<const int*>(ia + sa),
292 forward_iterator<const int*>(ib)) == false);
293#if TEST_STD_VER >= 14
294 assert(std::is_permutation(forward_iterator<const int*>(ia),
295 forward_iterator<const int*>(ia + sa),
296 forward_iterator<const int*>(ib),
297 forward_iterator<const int*>(ib + sa)) == false);
298#endif
299 }
300 {
301 const int ia[] = {1, 1};
302 const int ib[] = {1, 1};
303 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
304 assert(std::is_permutation(forward_iterator<const int*>(ia),
305 forward_iterator<const int*>(ia + sa),
306 forward_iterator<const int*>(ib)) == true);
307#if TEST_STD_VER >= 14
308 assert(std::is_permutation(forward_iterator<const int*>(ia),
309 forward_iterator<const int*>(ia + sa),
310 forward_iterator<const int*>(ib),
311 forward_iterator<const int*>(ib + sa)) == true);
312#endif
313 }
314
315 {
316 const int ia[] = {0, 0, 0};
317 const int ib[] = {1, 0, 0};
318 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
319 assert(std::is_permutation(forward_iterator<const int*>(ia),
320 forward_iterator<const int*>(ia + sa),
321 forward_iterator<const int*>(ib)) == false);
322#if TEST_STD_VER >= 14
323 assert(std::is_permutation(forward_iterator<const int*>(ia),
324 forward_iterator<const int*>(ia + sa),
325 forward_iterator<const int*>(ib),
326 forward_iterator<const int*>(ib + sa)) == false);
327#endif
328 }
329 {
330 const int ia[] = {0, 0, 0};
331 const int ib[] = {1, 0, 1};
332 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
333 assert(std::is_permutation(forward_iterator<const int*>(ia),
334 forward_iterator<const int*>(ia + sa),
335 forward_iterator<const int*>(ib)) == false);
336#if TEST_STD_VER >= 14
337 assert(std::is_permutation(forward_iterator<const int*>(ia),
338 forward_iterator<const int*>(ia + sa),
339 forward_iterator<const int*>(ib),
340 forward_iterator<const int*>(ib + sa)) == false);
341#endif
342 }
343 {
344 const int ia[] = {0, 0, 0};
345 const int ib[] = {1, 0, 2};
346 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
347 assert(std::is_permutation(forward_iterator<const int*>(ia),
348 forward_iterator<const int*>(ia + sa),
349 forward_iterator<const int*>(ib)) == false);
350#if TEST_STD_VER >= 14
351 assert(std::is_permutation(forward_iterator<const int*>(ia),
352 forward_iterator<const int*>(ia + sa),
353 forward_iterator<const int*>(ib),
354 forward_iterator<const int*>(ib + sa)) == false);
355#endif
356 }
357 {
358 const int ia[] = {0, 0, 0};
359 const int ib[] = {1, 1, 0};
360 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
361 assert(std::is_permutation(forward_iterator<const int*>(ia),
362 forward_iterator<const int*>(ia + sa),
363 forward_iterator<const int*>(ib)) == false);
364#if TEST_STD_VER >= 14
365 assert(std::is_permutation(forward_iterator<const int*>(ia),
366 forward_iterator<const int*>(ia + sa),
367 forward_iterator<const int*>(ib),
368 forward_iterator<const int*>(ib + sa)) == false);
369#endif
370 }
371 {
372 const int ia[] = {0, 0, 0};
373 const int ib[] = {1, 1, 1};
374 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
375 assert(std::is_permutation(forward_iterator<const int*>(ia),
376 forward_iterator<const int*>(ia + sa),
377 forward_iterator<const int*>(ib)) == false);
378#if TEST_STD_VER >= 14
379 assert(std::is_permutation(forward_iterator<const int*>(ia),
380 forward_iterator<const int*>(ia + sa),
381 forward_iterator<const int*>(ib),
382 forward_iterator<const int*>(ib + sa)) == false);
383#endif
384 }
385 {
386 const int ia[] = {0, 0, 0};
387 const int ib[] = {1, 1, 2};
388 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
389 assert(std::is_permutation(forward_iterator<const int*>(ia),
390 forward_iterator<const int*>(ia + sa),
391 forward_iterator<const int*>(ib)) == false);
392#if TEST_STD_VER >= 14
393 assert(std::is_permutation(forward_iterator<const int*>(ia),
394 forward_iterator<const int*>(ia + sa),
395 forward_iterator<const int*>(ib),
396 forward_iterator<const int*>(ib + sa)) == false);
397#endif
398 }
399 {
400 const int ia[] = {0, 0, 0};
401 const int ib[] = {1, 2, 0};
402 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
403 assert(std::is_permutation(forward_iterator<const int*>(ia),
404 forward_iterator<const int*>(ia + sa),
405 forward_iterator<const int*>(ib)) == false);
406#if TEST_STD_VER >= 14
407 assert(std::is_permutation(forward_iterator<const int*>(ia),
408 forward_iterator<const int*>(ia + sa),
409 forward_iterator<const int*>(ib),
410 forward_iterator<const int*>(ib + sa)) == false);
411#endif
412 }
413 {
414 const int ia[] = {0, 0, 0};
415 const int ib[] = {1, 2, 1};
416 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
417 assert(std::is_permutation(forward_iterator<const int*>(ia),
418 forward_iterator<const int*>(ia + sa),
419 forward_iterator<const int*>(ib)) == false);
420#if TEST_STD_VER >= 14
421 assert(std::is_permutation(forward_iterator<const int*>(ia),
422 forward_iterator<const int*>(ia + sa),
423 forward_iterator<const int*>(ib),
424 forward_iterator<const int*>(ib + sa)) == false);
425#endif
426 }
427 {
428 const int ia[] = {0, 0, 0};
429 const int ib[] = {1, 2, 2};
430 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
431 assert(std::is_permutation(forward_iterator<const int*>(ia),
432 forward_iterator<const int*>(ia + sa),
433 forward_iterator<const int*>(ib)) == false);
434#if TEST_STD_VER >= 14
435 assert(std::is_permutation(forward_iterator<const int*>(ia),
436 forward_iterator<const int*>(ia + sa),
437 forward_iterator<const int*>(ib),
438 forward_iterator<const int*>(ib + sa)) == false);
439#endif
440 }
441 {
442 const int ia[] = {0, 0, 1};
443 const int ib[] = {1, 0, 0};
444 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
445 assert(std::is_permutation(forward_iterator<const int*>(ia),
446 forward_iterator<const int*>(ia + sa),
447 forward_iterator<const int*>(ib)) == true);
448#if TEST_STD_VER >= 14
449 assert(std::is_permutation(forward_iterator<const int*>(ia),
450 forward_iterator<const int*>(ia + sa),
451 forward_iterator<const int*>(ib),
452 forward_iterator<const int*>(ib + sa)) == true);
453 assert(std::is_permutation(forward_iterator<const int*>(ia),
454 forward_iterator<const int*>(ia + sa),
455 forward_iterator<const int*>(ib),
456 forward_iterator<const int*>(ib + sa - 1)) == false);
457#endif
458 }
459 {
460 const int ia[] = {0, 0, 1};
461 const int ib[] = {1, 0, 1};
462 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
463 assert(std::is_permutation(forward_iterator<const int*>(ia),
464 forward_iterator<const int*>(ia + sa),
465 forward_iterator<const int*>(ib)) == false);
466#if TEST_STD_VER >= 14
467 assert(std::is_permutation(forward_iterator<const int*>(ia),
468 forward_iterator<const int*>(ia + sa),
469 forward_iterator<const int*>(ib),
470 forward_iterator<const int*>(ib + sa)) == false);
471#endif
472 }
473 {
474 const int ia[] = {0, 1, 2};
475 const int ib[] = {1, 0, 2};
476 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
477 assert(std::is_permutation(forward_iterator<const int*>(ia),
478 forward_iterator<const int*>(ia + sa),
479 forward_iterator<const int*>(ib)) == true);
480#if TEST_STD_VER >= 14
481 assert(std::is_permutation(forward_iterator<const int*>(ia),
482 forward_iterator<const int*>(ia + sa),
483 forward_iterator<const int*>(ib),
484 forward_iterator<const int*>(ib + sa)) == true);
485 assert(std::is_permutation(forward_iterator<const int*>(ia),
486 forward_iterator<const int*>(ia + sa),
487 forward_iterator<const int*>(ib),
488 forward_iterator<const int*>(ib + sa - 1)) == false);
489#endif
490 }
491 {
492 const int ia[] = {0, 1, 2};
493 const int ib[] = {1, 2, 0};
494 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
495 assert(std::is_permutation(forward_iterator<const int*>(ia),
496 forward_iterator<const int*>(ia + sa),
497 forward_iterator<const int*>(ib)) == true);
498#if TEST_STD_VER >= 14
499 assert(std::is_permutation(forward_iterator<const int*>(ia),
500 forward_iterator<const int*>(ia + sa),
501 forward_iterator<const int*>(ib),
502 forward_iterator<const int*>(ib + sa)) == true);
503 assert(std::is_permutation(forward_iterator<const int*>(ia),
504 forward_iterator<const int*>(ia + sa),
505 forward_iterator<const int*>(ib),
506 forward_iterator<const int*>(ib + sa - 1)) == false);
507#endif
508 }
509 {
510 const int ia[] = {0, 1, 2};
511 const int ib[] = {2, 1, 0};
512 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
513 assert(std::is_permutation(forward_iterator<const int*>(ia),
514 forward_iterator<const int*>(ia + sa),
515 forward_iterator<const int*>(ib)) == true);
516#if TEST_STD_VER >= 14
517 assert(std::is_permutation(forward_iterator<const int*>(ia),
518 forward_iterator<const int*>(ia + sa),
519 forward_iterator<const int*>(ib),
520 forward_iterator<const int*>(ib + sa)) == true);
521 assert(std::is_permutation(forward_iterator<const int*>(ia),
522 forward_iterator<const int*>(ia + sa),
523 forward_iterator<const int*>(ib),
524 forward_iterator<const int*>(ib + sa - 1)) == false);
525#endif
526 }
527 {
528 const int ia[] = {0, 1, 2};
529 const int ib[] = {2, 0, 1};
530 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
531 assert(std::is_permutation(forward_iterator<const int*>(ia),
532 forward_iterator<const int*>(ia + sa),
533 forward_iterator<const int*>(ib)) == true);
534#if TEST_STD_VER >= 14
535 assert(std::is_permutation(forward_iterator<const int*>(ia),
536 forward_iterator<const int*>(ia + sa),
537 forward_iterator<const int*>(ib),
538 forward_iterator<const int*>(ib + sa)) == true);
539 assert(std::is_permutation(forward_iterator<const int*>(ia),
540 forward_iterator<const int*>(ia + sa),
541 forward_iterator<const int*>(ib),
542 forward_iterator<const int*>(ib + sa - 1)) == false);
543#endif
544 }
545 {
546 const int ia[] = {0, 0, 1};
547 const int ib[] = {1, 0, 1};
548 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
549 assert(std::is_permutation(forward_iterator<const int*>(ia),
550 forward_iterator<const int*>(ia + sa),
551 forward_iterator<const int*>(ib)) == false);
552#if TEST_STD_VER >= 14
553 assert(std::is_permutation(forward_iterator<const int*>(ia),
554 forward_iterator<const int*>(ia + sa),
555 forward_iterator<const int*>(ib),
556 forward_iterator<const int*>(ib + sa)) == false);
557#endif
558 }
559 {
560 const int ia[] = {0, 0, 1};
561 const int ib[] = {1, 0, 0};
562 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
563 assert(std::is_permutation(forward_iterator<const int*>(ia),
564 forward_iterator<const int*>(ia + sa),
565 forward_iterator<const int*>(ib)) == true);
566#if TEST_STD_VER >= 14
567 assert(std::is_permutation(forward_iterator<const int*>(ia),
568 forward_iterator<const int*>(ia + sa),
569 forward_iterator<const int*>(ib),
570 forward_iterator<const int*>(ib + sa)) == true);
571 assert(std::is_permutation(forward_iterator<const int*>(ia),
572 forward_iterator<const int*>(ia + sa),
573 forward_iterator<const int*>(ib + 1),
574 forward_iterator<const int*>(ib + sa)) == false);
575 assert(std::is_permutation(forward_iterator<const int*>(ia),
576 forward_iterator<const int*>(ia + sa),
577 forward_iterator<const int*>(ib),
578 forward_iterator<const int*>(ib + sa - 1)) == false);
579#endif
580 }
581 {
582 const int ia[] = {0, 1, 2, 3, 0, 5, 6, 2, 4, 4};
583 const int ib[] = {4, 2, 3, 0, 1, 4, 0, 5, 6, 2};
584 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
585 assert(std::is_permutation(forward_iterator<const int*>(ia),
586 forward_iterator<const int*>(ia + sa),
587 forward_iterator<const int*>(ib)) == true);
588#if TEST_STD_VER >= 14
589 assert(std::is_permutation(forward_iterator<const int*>(ia),
590 forward_iterator<const int*>(ia + sa),
591 forward_iterator<const int*>(ib),
592 forward_iterator<const int*>(ib + sa)) == true);
593 assert(std::is_permutation(forward_iterator<const int*>(ia),
594 forward_iterator<const int*>(ia + sa),
595 forward_iterator<const int*>(ib + 1 ),
596 forward_iterator<const int*>(ib + sa)) == false);
597 assert(std::is_permutation(forward_iterator<const int*>(ia),
598 forward_iterator<const int*>(ia + sa),
599 forward_iterator<const int*>(ib),
600 forward_iterator<const int*>(ib + sa - 1)) == false);
601#endif
602 }
603 {
604 const int ia[] = {0, 1, 2, 3, 0, 5, 6, 2, 4, 4};
605 const int ib[] = {4, 2, 3, 0, 1, 4, 0, 5, 6, 0};
606 const unsigned sa = sizeof(ia)/sizeof(ia[0]);
607 assert(std::is_permutation(forward_iterator<const int*>(ia),
608 forward_iterator<const int*>(ia + sa),
609 forward_iterator<const int*>(ib)) == false);
610#if TEST_STD_VER >= 14
611 assert(std::is_permutation(forward_iterator<const int*>(ia),
612 forward_iterator<const int*>(ia + sa),
613 forward_iterator<const int*>(ib),
614 forward_iterator<const int*>(ib + sa)) == false);
615#endif
616 }
617
618#if TEST_STD_VER > 17
619 static_assert(test_constexpr());
620#endif
621
622 return 0;
623}
624

source code of libcxx/test/std/algorithms/alg.nonmodifying/alg.is_permutation/is_permutation.pass.cpp