| 1 |
// { dg-do run { target c++11 } } |
| 2 |
|
| 3 |
// Copyright (C) 2009-2025 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.2.10 rotate |
| 21 |
|
| 22 |
// Tests rotate when an moveable class is used |
| 23 |
|
| 24 |
#undef _GLIBCXX_CONCEPT_CHECKS |
| 25 |
|
| 26 |
#include <algorithm> |
| 27 |
#include <testsuite_hooks.h> |
| 28 |
#include <testsuite_iterators.h> |
| 29 |
#include <testsuite_rvalref.h> |
| 30 |
|
| 31 |
using __gnu_test::test_container; |
| 32 |
using __gnu_test::forward_iterator_wrapper; |
| 33 |
using __gnu_test::bidirectional_iterator_wrapper; |
| 34 |
using __gnu_test::random_access_iterator_wrapper; |
| 35 |
using __gnu_test::rvalstruct; |
| 36 |
|
| 37 |
typedef test_container<rvalstruct, forward_iterator_wrapper> Fcontainer; |
| 38 |
typedef test_container<rvalstruct, bidirectional_iterator_wrapper> Bcontainer; |
| 39 |
typedef test_container<rvalstruct, random_access_iterator_wrapper> Rcontainer; |
| 40 |
|
| 41 |
template<typename Con> |
| 42 |
void |
| 43 |
test_con(int length, int rotate_pos) |
| 44 |
{ |
| 45 |
/* Make sure the VLA upper bound is positive. */ |
| 46 |
rvalstruct array[length + 1]; |
| 47 |
for(int i = 0; i < length; ++i) |
| 48 |
array[i] = i; |
| 49 |
Con con(array, array + length); |
| 50 |
std::rotate(con.begin(), con.it(rotate_pos), con.end()); |
| 51 |
|
| 52 |
if(length != 0) |
| 53 |
{ |
| 54 |
for(int i = 0; i < length; ++i) |
| 55 |
VERIFY( array[i].valid && array[i].val == (i + rotate_pos) % length ); |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
void |
| 60 |
test01() |
| 61 |
{ |
| 62 |
for(int i = 0; i < 20; ++i) |
| 63 |
{ |
| 64 |
for(int j = 0; j <= i; ++j) |
| 65 |
{ |
| 66 |
test_con<Fcontainer>(i, j); |
| 67 |
test_con<Bcontainer>(i, j); |
| 68 |
test_con<Rcontainer>(i, j); |
| 69 |
} |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
int |
| 74 |
main() |
| 75 |
{ |
| 76 |
test01(); |
| 77 |
return 0; |
| 78 |
} |