1 // Copyright (C) 2020-2025 Free Software Foundation, Inc.
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)
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.
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/>.
18 // { dg-do run { target c++20 } }
22 #include <testsuite_hooks.h>
23 #include <testsuite_iterators.h>
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
;
31 namespace ranges
= std::ranges
;
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} };
42 VERIFY( ranges::is_permutation(x
, x
+6, y
, y
+6) );
43 VERIFY( !ranges::is_permutation(x
, x
+6, y
, y
+5) );
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
) );
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
));
67 int x
[] = { 1, 2, 3, 4 };
68 int y
[] = { 1, 2, 3, 3 };
69 test_container
<int, bidirectional_iterator_wrapper
> cx(x
);
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
)));