]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/25_algorithms/prev_permutation/moveable.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 25_algorithms / prev_permutation / moveable.cc
CommitLineData
52066eae 1// { dg-do run { target c++11 } }
01bbe151 2
85ec4feb 3// Copyright (C) 2009-2018 Free Software Foundation, Inc.
01bbe151
CJ
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
27using __gnu_test::test_container;
28using __gnu_test::bidirectional_iterator_wrapper;
29using __gnu_test::rvalstruct;
30using std::prev_permutation;
31
32typedef test_container<rvalstruct, bidirectional_iterator_wrapper> Container;
33
34void
35test1()
36{
01bbe151
CJ
37 // Note: The standard is unclear on what should happen in this case.
38 // This seems the only really sensible behaviour, and what is done.
39 rvalstruct array[] = {0};
40 Container con(array, array);
41 VERIFY( !prev_permutation(con.begin(), con.end()) );
42}
43
44void
45test2()
46{
01bbe151
CJ
47 rvalstruct array[] = {0};
48 Container con(array, array + 1);
49 VERIFY( !prev_permutation(con.begin(), con.end()) );
50}
51
52void
53test3()
54{
01bbe151
CJ
55 rvalstruct array[] = {3, 0};
56 Container con(array, array + 2);
57 VERIFY( prev_permutation(con.begin(), con.end()) );
58 VERIFY( array[0] == 0 && array[1] == 3 );
59 VERIFY( !prev_permutation(con.begin(), con.end()) );
60 VERIFY( array[0] == 3 && array[1] == 0 );
61}
62
63void
64test4()
65{
01bbe151
CJ
66 int array[6] = {5, 4, 3, 2, 1, 0};
67 for(int i = 0 ; i < 719; ++i)
68 {
69 rvalstruct temp_array[6];
70 std::copy(array, array + 6, temp_array);
71 Container con(temp_array, temp_array + 6);
72 VERIFY( prev_permutation(array, array + 6) );
061217e9
PC
73
74// XXX FIXME: parallel-mode should deal correctly with moveable-only types
75// per C++0x, at minimum smoothly fall back to serial.
76#ifndef _GLIBCXX_PARALLEL
01bbe151
CJ
77 VERIFY( !std::lexicographical_compare(temp_array, temp_array + 6,
78 array, array + 6) );
061217e9 79#endif
01bbe151
CJ
80 }
81 VERIFY( !prev_permutation(array,array + 6)) ;
82 for(int i = 0; i < 6; ++i)
83 VERIFY( array[i] == (5 - i) );
84}
85
86bool
87are_ordered(const rvalstruct& lhs, const rvalstruct& rhs)
88{ return lhs < rhs; }
89
90void
91test5()
92{
01bbe151
CJ
93 int array[6] = {5, 4, 3, 2, 1, 0};
94 for(int i = 0 ; i < 719; ++i)
95 {
96 rvalstruct temp_array[6];
97 std::copy(array, array + 6, temp_array);
98 Container con(temp_array, temp_array + 6);
99 VERIFY( prev_permutation(array, array + 6, are_ordered) );
061217e9
PC
100
101// XXX FIXME: parallel-mode should deal correctly with moveable-only types
102// per C++0x, at minimum smoothly fall back to serial.
103#ifndef _GLIBCXX_PARALLEL
01bbe151
CJ
104 VERIFY( !std::lexicographical_compare(temp_array, temp_array + 6,
105 array, array + 6, are_ordered) );
061217e9 106#endif
01bbe151
CJ
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
113int main()
114{
115 test1();
116 test2();
117 test3();
118 test4();
119 test5();
120 return 0;
121}