OSDN Git Service

2009-09-01 Chris Jefferson <chris@bubblescope.net>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / testsuite / 25_algorithms / prev_permutation / moveable.cc
1 // { dg-options "-std=gnu++0x" }
2
3 // Copyright (C) 2009 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.
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.3.9 [lib.alg.permutation.generators]
21
22 #include <algorithm>
23 #include <testsuite_hooks.h>
24 #include <testsuite_iterators.h>
25 #include <testsuite_rvalref.h>
26
27 using __gnu_test::test_container;
28 using __gnu_test::bidirectional_iterator_wrapper;
29 using __gnu_test::rvalstruct;
30 using std::prev_permutation;
31
32 typedef test_container<rvalstruct, bidirectional_iterator_wrapper> Container;
33
34 void
35 test1()
36 {
37   bool test __attribute__((unused)) = true;
38
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()) );
44 }
45
46 void
47 test2()
48 {
49   bool test __attribute__((unused)) = true;
50
51   rvalstruct array[] = {0};
52   Container con(array, array + 1);
53   VERIFY( !prev_permutation(con.begin(), con.end()) );
54 }
55
56 void
57 test3()
58 {
59   bool test __attribute__((unused)) = true;
60
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 );
67 }
68
69 void
70 test4()
71 {
72   bool test __attribute__((unused)) = true;
73
74   int array[6] = {5, 4, 3, 2, 1, 0};
75   for(int i = 0 ; i < 719; ++i)
76     {
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, 
82                                             array, array + 6) );
83     }
84   VERIFY( !prev_permutation(array,array + 6)) ;
85   for(int i = 0; i < 6; ++i)
86     VERIFY( array[i] == (5 - i) );
87 }
88
89 bool
90 are_ordered(const rvalstruct& lhs, const rvalstruct& rhs)
91 { return lhs < rhs; }
92
93 void
94 test5()
95 {
96   bool test __attribute__((unused)) = true;
97
98   int array[6] = {5, 4, 3, 2, 1, 0};
99   for(int i = 0 ; i < 719; ++i)
100     {
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) );
107     }
108   VERIFY( !prev_permutation(array,array + 6, are_ordered) );
109   for(int i = 0; i < 6; ++i)
110     VERIFY( array[i] == (5 - i) );
111 }
112
113 int main()
114 {
115   test1();
116   test2();
117   test3();
118   test4();
119   test5();
120   return 0;
121 }