1 // { dg-do run { target c++11 } }
3 // Copyright (C) 2009-2025 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::next_permutation
;
32 typedef test_container
<rvalstruct
, bidirectional_iterator_wrapper
> Container
;
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( !next_permutation(con
.begin(), con
.end()) );
47 rvalstruct array
[] = {0};
48 Container
con(array
, array
+ 1);
49 VERIFY( !next_permutation(con
.begin(), con
.end()) );
55 rvalstruct array
[] = {0, 3};
56 Container
con(array
, array
+ 2);
57 VERIFY( next_permutation(con
.begin(), con
.end()) );
58 VERIFY( array
[0] == 3 && array
[1] == 0 );
59 VERIFY( !next_permutation(con
.begin(), con
.end()) );
60 VERIFY( array
[0] == 0 && array
[1] == 3 );
66 int array
[6] = {0, 1, 2, 3, 4, 5};
67 for(int i
= 0 ; i
< 719; ++i
)
69 rvalstruct temp_array
[6];
70 std::copy(array
, array
+ 6, temp_array
);
71 Container
con(temp_array
, temp_array
+ 6);
72 VERIFY( next_permutation(array
, array
+ 6) );
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
77 VERIFY( std::lexicographical_compare(temp_array
, temp_array
+ 6,
81 VERIFY( !next_permutation(array
,array
+ 6) );
82 for(int i
= 0; i
< 6; ++i
)
83 VERIFY( array
[i
] == i
);
87 are_ordered(const rvalstruct
& lhs
, const rvalstruct
& rhs
)
93 int array
[6] = {0, 1, 2, 3, 4, 5};
94 for(int i
= 0 ; i
< 719; ++i
)
96 rvalstruct temp_array
[6];
97 std::copy(array
, array
+ 6, temp_array
);
98 Container
con(temp_array
, temp_array
+ 6);
99 VERIFY( next_permutation(array
, array
+ 6, are_ordered
) );
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
104 VERIFY( std::lexicographical_compare(temp_array
, temp_array
+ 6,
105 array
, array
+ 6, are_ordered
) );
108 VERIFY( !next_permutation(array
,array
+ 6, are_ordered
) );
109 for(int i
= 0; i
< 6; ++i
)
110 VERIFY( array
[i
] == i
);