]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/25_algorithms/is_permutation/1.cc
1 // { dg-options "-std=gnu++0x" }
3 // 2011-01-13 Paolo Carlini <paolo.carlini@oracle.com>
5 // Copyright (C) 2011-2014 Free Software Foundation, Inc.
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)
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
26 #include <testsuite_hooks.h>
31 operator()(int __x
, int __y
) const
32 { return __x
% 10 == __y
% 10; }
35 const int arr0
[] = { 11, 22, 33, 44, 55 };
38 do_test(int arr1
[5], bool np
= true)
40 bool test
__attribute__((unused
)) = true;
43 VERIFY( std::is_permutation(arr1
, arr1
+ 5, arr0
) == np
);
44 while (std::next_permutation(arr1
, arr1
+ 5));
47 template<typename Predicate
>
49 do_test(int arr1
[5], Predicate pred
, bool np
= true)
51 bool test
__attribute__((unused
)) = true;
54 VERIFY( std::is_permutation(arr1
, arr1
+ 5, arr0
, pred
) == np
);
55 while (std::next_permutation(arr1
, arr1
+ 5));
60 int arr1
[] = { 11, 22, 33, 44, 55 };
63 int arr2
[] = { 11, 33, 33, 44, 55 };
66 int arr3
[] = { 33, 33, 33, 44, 44 };
69 int arr4
[] = { 11, 22, 33, 44, 55 };
70 do_test(arr4
, std::equal_to
<int>());
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());
81 int arr8
[] = { 1, 3, 3, 4, 5 };
82 do_test(arr8
, my_equal_to(), false);
84 int arr9
[] = { 3, 3, 3, 4, 4 };
85 do_test(arr9
, my_equal_to(), false);
87 int arr10
[] = { 111, 222, 333, 444, 555 };
88 do_test(arr10
, my_equal_to());
90 int arr11
[] = { 1, 222, 33, 4, 55 };
91 do_test(arr11
, my_equal_to());
93 int arr12
[] = { 111, 333, 333, 444, 555 };
94 do_test(arr12
, my_equal_to(), false);
96 int arr13
[] = { 333, 333, 333, 444, 444 };
97 do_test(arr13
, my_equal_to(), false);