]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/25_algorithms/is_permutation/2.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 25_algorithms / is_permutation / 2.cc
CommitLineData
52066eae 1// { dg-do run { target c++14 } }
f7fbb003 2
85ec4feb 3// Copyright (C) 2013-2018 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
26struct my_equal_to
27{
28 bool
29 operator()(int __x, int __y) const
30 { return __x % 10 == __y % 10; }
31};
32
33const int arr0[] = { 11, 22, 33, 44, 55 };
34
35void
36do_test(int arr1[5], bool np = true, unsigned N = 5)
37{
f7fbb003
JW
38 do
39 VERIFY( std::is_permutation(arr1, arr1 + 5, arr0, arr0 + N) == np );
40 while (std::next_permutation(arr1, arr1 + 5));
41}
42
43template<typename Predicate>
44 void
45 do_test(int arr1[5], Predicate pred, bool np = true, unsigned N = 5)
46 {
f7fbb003
JW
47 do
48 VERIFY( std::is_permutation(arr1, arr1 + 5, arr0, arr0 + N, pred) == np );
49 while (std::next_permutation(arr1, arr1 + 5));
50 }
51
52void test01()
53{
54 int arr1[] = { 11, 22, 33, 44, 55 };
55 do_test(arr1);
56 do_test(arr1, false, 4);
57
58 int arr2[] = { 11, 33, 33, 44, 55 };
59 do_test(arr2, false);
60
61 int arr3[] = { 33, 33, 33, 44, 44 };
62 do_test(arr3, false);
63
64 int arr4[] = { 11, 22, 33, 44, 55 };
65 do_test(arr4, std::equal_to<int>());
66 do_test(arr4, std::equal_to<int>(), false, 4);
67
68 int arr5[] = { 11, 33, 33, 44, 55 };
69 do_test(arr5, std::equal_to<int>(), false);
70
71 int arr6[] = { 33, 33, 33, 44, 44 };
72 do_test(arr6, std::equal_to<int>(), false);
73
74 int arr7[] = { 1, 2, 3, 4, 5 };
75 do_test(arr7, my_equal_to());
76 do_test(arr7, my_equal_to(), false, 4);
77
78 int arr8[] = { 1, 3, 3, 4, 5 };
79 do_test(arr8, my_equal_to(), false);
80
81 int arr9[] = { 3, 3, 3, 4, 4 };
82 do_test(arr9, my_equal_to(), false);
83
84 int arr10[] = { 111, 222, 333, 444, 555 };
85 do_test(arr10, my_equal_to());
86 do_test(arr10, my_equal_to(), false, 4);
87
88 int arr11[] = { 1, 222, 33, 4, 55 };
89 do_test(arr11, my_equal_to());
90
91 int arr12[] = { 111, 333, 333, 444, 555 };
92 do_test(arr12, my_equal_to(), false);
93
94 int arr13[] = { 333, 333, 333, 444, 444 };
95 do_test(arr13, my_equal_to(), false);
96}
97
98bool thrower(int, int) { throw 1; }
99
100void test02()
101{
102 int arr[] = { 11, 22, 33 };
103 using namespace std;
104 is_permutation(begin(arr0), end(arr0), begin(arr), end(arr), thrower);
105}
106
107int main()
108{
109 test01();
110 test02();
111}