1 // { dg-options "-std=gnu++0x" }
3 // Copyright (C) 2009 Free Software Foundation, Inc.
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)
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.3.9 [lib.alg.permutation.generators]
23 #include <testsuite_hooks.h>
24 #include <testsuite_iterators.h>
25 #include <testsuite_rvalref.h>
27 using __gnu_test::test_container;
28 using __gnu_test::bidirectional_iterator_wrapper;
29 using __gnu_test::rvalstruct;
30 using std::prev_permutation;
32 typedef test_container<rvalstruct, bidirectional_iterator_wrapper> Container;
37 bool test __attribute__((unused)) = true;
39 // Note: The standard is unclear on what should happen in this case.
40 // This seems the only really sensible behaviour, and what is done.
41 rvalstruct array[] = {0};
42 Container con(array, array);
43 VERIFY( !prev_permutation(con.begin(), con.end()) );
49 bool test __attribute__((unused)) = true;
51 rvalstruct array[] = {0};
52 Container con(array, array + 1);
53 VERIFY( !prev_permutation(con.begin(), con.end()) );
59 bool test __attribute__((unused)) = true;
61 rvalstruct array[] = {3, 0};
62 Container con(array, array + 2);
63 VERIFY( prev_permutation(con.begin(), con.end()) );
64 VERIFY( array[0] == 0 && array[1] == 3 );
65 VERIFY( !prev_permutation(con.begin(), con.end()) );
66 VERIFY( array[0] == 3 && array[1] == 0 );
72 bool test __attribute__((unused)) = true;
74 int array[6] = {5, 4, 3, 2, 1, 0};
75 for(int i = 0 ; i < 719; ++i)
77 rvalstruct temp_array[6];
78 std::copy(array, array + 6, temp_array);
79 Container con(temp_array, temp_array + 6);
80 VERIFY( prev_permutation(array, array + 6) );
81 VERIFY( !std::lexicographical_compare(temp_array, temp_array + 6,
84 VERIFY( !prev_permutation(array,array + 6)) ;
85 for(int i = 0; i < 6; ++i)
86 VERIFY( array[i] == (5 - i) );
90 are_ordered(const rvalstruct& lhs, const rvalstruct& rhs)
96 bool test __attribute__((unused)) = true;
98 int array[6] = {5, 4, 3, 2, 1, 0};
99 for(int i = 0 ; i < 719; ++i)
101 rvalstruct temp_array[6];
102 std::copy(array, array + 6, temp_array);
103 Container con(temp_array, temp_array + 6);
104 VERIFY( prev_permutation(array, array + 6, are_ordered) );
105 VERIFY( !std::lexicographical_compare(temp_array, temp_array + 6,
106 array, array + 6, are_ordered) );
108 VERIFY( !prev_permutation(array,array + 6, are_ordered) );
109 for(int i = 0; i < 6; ++i)
110 VERIFY( array[i] == (5 - i) );