]>
Commit | Line | Data |
---|---|---|
cd9b223a | 1 | // { dg-options "-std=gnu++14" } |
f7fbb003 | 2 | |
5624e564 | 3 | // Copyright (C) 2013-2015 Free Software Foundation, Inc. |
f7fbb003 JW |
4 | // |
5 | // This file is part of the GNU ISO C++ Library. This library is free | |
6 | // software; you can redistribute it and/or modify it under the | |
7 | // terms of the GNU General Public License as published by the | |
8 | // Free Software Foundation; either version 3, or (at your option) | |
9 | // any later version. | |
10 | ||
11 | // This library is distributed in the hope that it will be useful, | |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | // GNU General Public License for more details. | |
15 | ||
16 | // You should have received a copy of the GNU General Public License along | |
17 | // with this library; see the file COPYING3. If not see | |
18 | // <http://www.gnu.org/licenses/>. | |
19 | ||
20 | // 25.2.12 [alg.is_permutation] Is permutation | |
21 | ||
22 | #include <algorithm> | |
23 | #include <functional> | |
24 | #include <testsuite_hooks.h> | |
25 | ||
26 | struct my_equal_to | |
27 | { | |
28 | bool | |
29 | operator()(int __x, int __y) const | |
30 | { return __x % 10 == __y % 10; } | |
31 | }; | |
32 | ||
33 | const int arr0[] = { 11, 22, 33, 44, 55 }; | |
34 | ||
35 | void | |
36 | do_test(int arr1[5], bool np = true, unsigned N = 5) | |
37 | { | |
38 | bool test __attribute__((unused)) = true; | |
39 | ||
40 | do | |
41 | VERIFY( std::is_permutation(arr1, arr1 + 5, arr0, arr0 + N) == np ); | |
42 | while (std::next_permutation(arr1, arr1 + 5)); | |
43 | } | |
44 | ||
45 | template<typename Predicate> | |
46 | void | |
47 | do_test(int arr1[5], Predicate pred, bool np = true, unsigned N = 5) | |
48 | { | |
49 | bool test __attribute__((unused)) = true; | |
50 | ||
51 | do | |
52 | VERIFY( std::is_permutation(arr1, arr1 + 5, arr0, arr0 + N, pred) == np ); | |
53 | while (std::next_permutation(arr1, arr1 + 5)); | |
54 | } | |
55 | ||
56 | void test01() | |
57 | { | |
58 | int arr1[] = { 11, 22, 33, 44, 55 }; | |
59 | do_test(arr1); | |
60 | do_test(arr1, false, 4); | |
61 | ||
62 | int arr2[] = { 11, 33, 33, 44, 55 }; | |
63 | do_test(arr2, false); | |
64 | ||
65 | int arr3[] = { 33, 33, 33, 44, 44 }; | |
66 | do_test(arr3, false); | |
67 | ||
68 | int arr4[] = { 11, 22, 33, 44, 55 }; | |
69 | do_test(arr4, std::equal_to<int>()); | |
70 | do_test(arr4, std::equal_to<int>(), false, 4); | |
71 | ||
72 | int arr5[] = { 11, 33, 33, 44, 55 }; | |
73 | do_test(arr5, std::equal_to<int>(), false); | |
74 | ||
75 | int arr6[] = { 33, 33, 33, 44, 44 }; | |
76 | do_test(arr6, std::equal_to<int>(), false); | |
77 | ||
78 | int arr7[] = { 1, 2, 3, 4, 5 }; | |
79 | do_test(arr7, my_equal_to()); | |
80 | do_test(arr7, my_equal_to(), false, 4); | |
81 | ||
82 | int arr8[] = { 1, 3, 3, 4, 5 }; | |
83 | do_test(arr8, my_equal_to(), false); | |
84 | ||
85 | int arr9[] = { 3, 3, 3, 4, 4 }; | |
86 | do_test(arr9, my_equal_to(), false); | |
87 | ||
88 | int arr10[] = { 111, 222, 333, 444, 555 }; | |
89 | do_test(arr10, my_equal_to()); | |
90 | do_test(arr10, my_equal_to(), false, 4); | |
91 | ||
92 | int arr11[] = { 1, 222, 33, 4, 55 }; | |
93 | do_test(arr11, my_equal_to()); | |
94 | ||
95 | int arr12[] = { 111, 333, 333, 444, 555 }; | |
96 | do_test(arr12, my_equal_to(), false); | |
97 | ||
98 | int arr13[] = { 333, 333, 333, 444, 444 }; | |
99 | do_test(arr13, my_equal_to(), false); | |
100 | } | |
101 | ||
102 | bool thrower(int, int) { throw 1; } | |
103 | ||
104 | void test02() | |
105 | { | |
106 | int arr[] = { 11, 22, 33 }; | |
107 | using namespace std; | |
108 | is_permutation(begin(arr0), end(arr0), begin(arr), end(arr), thrower); | |
109 | } | |
110 | ||
111 | int main() | |
112 | { | |
113 | test01(); | |
114 | test02(); | |
115 | } |