]>
Commit | Line | Data |
---|---|---|
7adcbafe | 1 | // Copyright (C) 2020-2022 Free Software Foundation, Inc. |
bc464641 PP |
2 | // |
3 | // This file is part of the GNU ISO C++ Library. This library is free | |
4 | // software; you can redistribute it and/or modify it under the | |
5 | // terms of the GNU General Public License as published by the | |
6 | // Free Software Foundation; either version 3, or (at your option) | |
7 | // any later version. | |
8 | ||
9 | // This library is distributed in the hope that it will be useful, | |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | // GNU General Public License for more details. | |
13 | ||
14 | // You should have received a copy of the GNU General Public License along | |
15 | // with this library; see the file COPYING3. If not see | |
16 | // <http://www.gnu.org/licenses/>. | |
17 | ||
18 | // { dg-options "-std=gnu++2a" } | |
19 | // { dg-do run { target c++2a } } | |
20 | ||
21 | #include <algorithm> | |
22 | #include <testsuite_hooks.h> | |
23 | #include <testsuite_iterators.h> | |
24 | ||
25 | using __gnu_test::test_container; | |
26 | using __gnu_test::test_range; | |
27 | using __gnu_test::input_iterator_wrapper; | |
28 | using __gnu_test::forward_iterator_wrapper; | |
29 | using __gnu_test::bidirectional_iterator_wrapper; | |
30 | ||
31 | namespace ranges = std::ranges; | |
32 | ||
33 | struct X { int i; }; | |
34 | ||
35 | void | |
36 | test01() | |
37 | { | |
38 | int x[] = { {2}, {2}, {6}, {8}, {10}, {11} }; | |
39 | int y[] = { {2}, {6}, {8}, {10}, {11}, {2} }; | |
40 | int z[] = { {2}, {6}, {8}, {10}, {2}, {2} }; | |
41 | ||
42 | VERIFY( ranges::is_permutation(x, x+6, y, y+6) ); | |
43 | VERIFY( !ranges::is_permutation(x, x+6, y, y+5) ); | |
44 | ||
45 | test_container<int, forward_iterator_wrapper> cx(x), cy(y), cz(z); | |
46 | test_range<int, forward_iterator_wrapper> rx(x), ry(y), rz(z); | |
47 | VERIFY( ranges::is_permutation(cx, ry) ); | |
48 | VERIFY( !ranges::is_permutation(rx, cz) ); | |
49 | VERIFY( ranges::is_permutation(rx, cy) ); | |
50 | VERIFY( !ranges::is_permutation(cx, rz) ); | |
51 | } | |
52 | ||
53 | void | |
54 | test02() | |
55 | { | |
56 | static constexpr X x[] = { {2}, {2}, {6}, {8}, {10}, {11} }; | |
57 | static constexpr X y[] = { {2}, {6}, {8}, {10}, {11}, {2} }; | |
58 | static constexpr int z[] = { {2}, {6}, {8}, {10}, {2}, {2} }; | |
59 | static_assert(ranges::is_permutation(x, y, {}, &X::i, &X::i)); | |
60 | static_assert(!ranges::is_permutation(x, z, {}, &X::i)); | |
61 | static_assert(!ranges::is_permutation(z, y, {}, {}, &X::i)); | |
62 | } | |
63 | ||
64 | void | |
65 | test03() | |
66 | { | |
67 | int x[] = { 1, 2, 3, 4 }; | |
68 | int y[] = { 1, 2, 3, 3 }; | |
69 | test_container<int, bidirectional_iterator_wrapper> cx(x); | |
70 | do | |
71 | do | |
72 | { | |
73 | VERIFY( ranges::is_permutation(cx, x) ); | |
74 | VERIFY( !ranges::is_permutation(y, cx) ); | |
75 | } while (std::next_permutation(y, y+4)); | |
76 | while (std::next_permutation(std::begin(cx), std::end(cx))); | |
77 | } | |
78 | ||
79 | int | |
80 | main() | |
81 | { | |
82 | test01(); | |
83 | test02(); | |
84 | test03(); | |
85 | } |