Merged revision 156805 into branch.
[official-gcc.git] / libstdc++-v3 / testsuite / 25_algorithms / prev_permutation / moveable.cc
blob5570239b01f552e409708173a45a4add88c9bc14
1 // { dg-options "-std=gnu++0x" }
3 // Copyright (C) 2009, 2010 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.3.9 [lib.alg.permutation.generators]
22 // XXX FIXME: parallel-mode should deal correctly with moveable-only types
23 // per C++0x, at minimum smoothly fall back to serial.
24 #undef _GLIBCXX_PARALLEL
26 #include <algorithm>
27 #include <testsuite_hooks.h>
28 #include <testsuite_iterators.h>
29 #include <testsuite_rvalref.h>
31 using __gnu_test::test_container;
32 using __gnu_test::bidirectional_iterator_wrapper;
33 using __gnu_test::rvalstruct;
34 using std::prev_permutation;
36 typedef test_container<rvalstruct, bidirectional_iterator_wrapper> Container;
38 void
39 test1()
41 bool test __attribute__((unused)) = true;
43 // Note: The standard is unclear on what should happen in this case.
44 // This seems the only really sensible behaviour, and what is done.
45 rvalstruct array[] = {0};
46 Container con(array, array);
47 VERIFY( !prev_permutation(con.begin(), con.end()) );
50 void
51 test2()
53 bool test __attribute__((unused)) = true;
55 rvalstruct array[] = {0};
56 Container con(array, array + 1);
57 VERIFY( !prev_permutation(con.begin(), con.end()) );
60 void
61 test3()
63 bool test __attribute__((unused)) = true;
65 rvalstruct array[] = {3, 0};
66 Container con(array, array + 2);
67 VERIFY( prev_permutation(con.begin(), con.end()) );
68 VERIFY( array[0] == 0 && array[1] == 3 );
69 VERIFY( !prev_permutation(con.begin(), con.end()) );
70 VERIFY( array[0] == 3 && array[1] == 0 );
73 void
74 test4()
76 bool test __attribute__((unused)) = true;
78 int array[6] = {5, 4, 3, 2, 1, 0};
79 for(int i = 0 ; i < 719; ++i)
81 rvalstruct temp_array[6];
82 std::copy(array, array + 6, temp_array);
83 Container con(temp_array, temp_array + 6);
84 VERIFY( prev_permutation(array, array + 6) );
85 VERIFY( !std::lexicographical_compare(temp_array, temp_array + 6,
86 array, array + 6) );
88 VERIFY( !prev_permutation(array,array + 6)) ;
89 for(int i = 0; i < 6; ++i)
90 VERIFY( array[i] == (5 - i) );
93 bool
94 are_ordered(const rvalstruct& lhs, const rvalstruct& rhs)
95 { return lhs < rhs; }
97 void
98 test5()
100 bool test __attribute__((unused)) = true;
102 int array[6] = {5, 4, 3, 2, 1, 0};
103 for(int i = 0 ; i < 719; ++i)
105 rvalstruct temp_array[6];
106 std::copy(array, array + 6, temp_array);
107 Container con(temp_array, temp_array + 6);
108 VERIFY( prev_permutation(array, array + 6, are_ordered) );
109 VERIFY( !std::lexicographical_compare(temp_array, temp_array + 6,
110 array, array + 6, are_ordered) );
112 VERIFY( !prev_permutation(array,array + 6, are_ordered) );
113 for(int i = 0; i < 6; ++i)
114 VERIFY( array[i] == (5 - i) );
117 int main()
119 test1();
120 test2();
121 test3();
122 test4();
123 test5();
124 return 0;