[03/46] Remove unnecessary update of NUM_SLP_USES
[official-gcc.git] / libstdc++-v3 / testsuite / 25_algorithms / is_permutation / 1.cc
blob52fc8afa85c52c6ba1e7ab69e1425de5c3546fdc
1 // { dg-do run { target c++11 } }
3 // 2011-01-13 Paolo Carlini <paolo.carlini@oracle.com>
4 //
5 // Copyright (C) 2011-2018 Free Software Foundation, Inc.
6 //
7 // This file is part of the GNU ISO C++ Library. This library is free
8 // software; you can redistribute it and/or modify it under the
9 // terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 3, or (at your option)
11 // any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License along
19 // with this library; see the file COPYING3. If not see
20 // <http://www.gnu.org/licenses/>.
22 // 25.2.12 [alg.is_permutation] Is permutation
24 #include <algorithm>
25 #include <functional>
26 #include <testsuite_hooks.h>
28 struct my_equal_to
30 bool
31 operator()(int __x, int __y) const
32 { return __x % 10 == __y % 10; }
35 const int arr0[] = { 11, 22, 33, 44, 55 };
37 void
38 do_test(int arr1[5], bool np = true)
41 VERIFY( std::is_permutation(arr1, arr1 + 5, arr0) == 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)
50 VERIFY( std::is_permutation(arr1, arr1 + 5, arr0, pred) == np );
51 while (std::next_permutation(arr1, arr1 + 5));
54 void test01()
56 int arr1[] = { 11, 22, 33, 44, 55 };
57 do_test(arr1);
59 int arr2[] = { 11, 33, 33, 44, 55 };
60 do_test(arr2, false);
62 int arr3[] = { 33, 33, 33, 44, 44 };
63 do_test(arr3, false);
65 int arr4[] = { 11, 22, 33, 44, 55 };
66 do_test(arr4, std::equal_to<int>());
68 int arr5[] = { 11, 33, 33, 44, 55 };
69 do_test(arr5, std::equal_to<int>(), false);
71 int arr6[] = { 33, 33, 33, 44, 44 };
72 do_test(arr6, std::equal_to<int>(), false);
74 int arr7[] = { 1, 2, 3, 4, 5 };
75 do_test(arr7, my_equal_to());
77 int arr8[] = { 1, 3, 3, 4, 5 };
78 do_test(arr8, my_equal_to(), false);
80 int arr9[] = { 3, 3, 3, 4, 4 };
81 do_test(arr9, my_equal_to(), false);
83 int arr10[] = { 111, 222, 333, 444, 555 };
84 do_test(arr10, my_equal_to());
86 int arr11[] = { 1, 222, 33, 4, 55 };
87 do_test(arr11, my_equal_to());
89 int arr12[] = { 111, 333, 333, 444, 555 };
90 do_test(arr12, my_equal_to(), false);
92 int arr13[] = { 333, 333, 333, 444, 444 };
93 do_test(arr13, my_equal_to(), false);
96 int main()
98 test01();
99 return 0;