* include/bits/stl_algo.h (is_permutation): Add overloads from N3671.
[official-gcc.git] / libstdc++-v3 / testsuite / 25_algorithms / is_permutation / 2.cc
blobd573fa2c932f32ae4c0d3abb2f511b2b5482a701
1 // { dg-options "-std=gnu++1y" }
3 // Copyright (C) 2013 Free Software Foundation, Inc.
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.
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.
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/>.
20 // 25.2.12 [alg.is_permutation] Is permutation
22 #include <algorithm>
23 #include <functional>
24 #include <testsuite_hooks.h>
26 struct my_equal_to
28 bool
29 operator()(int __x, int __y) const
30 { return __x % 10 == __y % 10; }
33 const int arr0[] = { 11, 22, 33, 44, 55 };
35 void
36 do_test(int arr1[5], bool np = true, unsigned N = 5)
38 bool test __attribute__((unused)) = true;
41 VERIFY( std::is_permutation(arr1, arr1 + 5, arr0, arr0 + N) == np );
42 while (std::next_permutation(arr1, arr1 + 5));
45 template<typename Predicate>
46 void
47 do_test(int arr1[5], Predicate pred, bool np = true, unsigned N = 5)
49 bool test __attribute__((unused)) = true;
52 VERIFY( std::is_permutation(arr1, arr1 + 5, arr0, arr0 + N, pred) == np );
53 while (std::next_permutation(arr1, arr1 + 5));
56 void test01()
58 int arr1[] = { 11, 22, 33, 44, 55 };
59 do_test(arr1);
60 do_test(arr1, false, 4);
62 int arr2[] = { 11, 33, 33, 44, 55 };
63 do_test(arr2, false);
65 int arr3[] = { 33, 33, 33, 44, 44 };
66 do_test(arr3, false);
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);
72 int arr5[] = { 11, 33, 33, 44, 55 };
73 do_test(arr5, std::equal_to<int>(), false);
75 int arr6[] = { 33, 33, 33, 44, 44 };
76 do_test(arr6, std::equal_to<int>(), false);
78 int arr7[] = { 1, 2, 3, 4, 5 };
79 do_test(arr7, my_equal_to());
80 do_test(arr7, my_equal_to(), false, 4);
82 int arr8[] = { 1, 3, 3, 4, 5 };
83 do_test(arr8, my_equal_to(), false);
85 int arr9[] = { 3, 3, 3, 4, 4 };
86 do_test(arr9, my_equal_to(), false);
88 int arr10[] = { 111, 222, 333, 444, 555 };
89 do_test(arr10, my_equal_to());
90 do_test(arr10, my_equal_to(), false, 4);
92 int arr11[] = { 1, 222, 33, 4, 55 };
93 do_test(arr11, my_equal_to());
95 int arr12[] = { 111, 333, 333, 444, 555 };
96 do_test(arr12, my_equal_to(), false);
98 int arr13[] = { 333, 333, 333, 444, 444 };
99 do_test(arr13, my_equal_to(), false);
102 bool thrower(int, int) { throw 1; }
104 void test02()
106 int arr[] = { 11, 22, 33 };
107 using namespace std;
108 is_permutation(begin(arr0), end(arr0), begin(arr), end(arr), thrower);
111 int main()
113 test01();
114 test02();