| 1 |
// { dg-do run { target c++11 } } |
| 2 |
|
| 3 |
// Copyright (C) 2008-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 |
// 23.2.3.n forward_list xxx [lib.forward_list.xxx] |
| 21 |
|
| 22 |
#include <forward_list> |
| 23 |
#include <testsuite_hooks.h> |
| 24 |
|
| 25 |
// This test verifies the following: |
| 26 |
// cbegin |
| 27 |
// erase_after one iterator |
| 28 |
// pos is useable and points to current element |
| 29 |
void |
| 30 |
test01() |
| 31 |
{ |
| 32 |
std::forward_list<int> fl({0, 1, 2, 3, 4, 5, 6, 7, 8, 9}); |
| 33 |
|
| 34 |
std::forward_list<int>::const_iterator pos = fl.cbegin(); |
| 35 |
++pos; |
| 36 |
VERIFY( *pos == 1 ); |
| 37 |
|
| 38 |
std::forward_list<int>::iterator pos2 = fl.erase_after(pos); |
| 39 |
|
| 40 |
VERIFY( *pos == 1 ); |
| 41 |
++pos; |
| 42 |
VERIFY( *pos == 3 ); |
| 43 |
VERIFY( pos == pos2 ); |
| 44 |
} |
| 45 |
|
| 46 |
// This test verifies the following: |
| 47 |
// cbegin |
| 48 |
// erase_after iterator range |
| 49 |
// pos is useable and points to current element |
| 50 |
void |
| 51 |
test02() |
| 52 |
{ |
| 53 |
std::forward_list<int> fl({0, 1, 2, 3, 4, 5, 6, 7, 8, 9}); |
| 54 |
|
| 55 |
std::forward_list<int>::const_iterator pos = fl.cbegin(); |
| 56 |
++pos; |
| 57 |
VERIFY( *pos == 1 ); |
| 58 |
|
| 59 |
std::forward_list<int>::iterator stop = fl.begin(); |
| 60 |
++stop; |
| 61 |
++stop; |
| 62 |
++stop; |
| 63 |
++stop; |
| 64 |
VERIFY( *stop == 4 ); |
| 65 |
|
| 66 |
std::forward_list<int>::iterator pos2 = fl.erase_after(pos, stop); |
| 67 |
|
| 68 |
VERIFY( pos2 == stop ); |
| 69 |
VERIFY( *pos == 1 ); |
| 70 |
++pos; |
| 71 |
VERIFY( *pos == 4 ); |
| 72 |
VERIFY( std::distance(fl.begin(), fl.end()) == 8 ); |
| 73 |
|
| 74 |
std::forward_list<int>::iterator pos3 |
| 75 |
= fl.erase_after(pos, fl.end()); |
| 76 |
VERIFY( pos3 == fl.end() ); |
| 77 |
VERIFY( ++pos == fl.end() ); |
| 78 |
VERIFY( std::distance(fl.begin(), fl.end()) == 3 ); |
| 79 |
|
| 80 |
std::forward_list<int>::iterator pos4 |
| 81 |
= fl.erase_after(fl.before_begin(), pos); |
| 82 |
VERIFY( pos4 == pos ); |
| 83 |
VERIFY( std::distance(fl.begin(), fl.end()) == 0 ); |
| 84 |
VERIFY( fl.empty() ); |
| 85 |
} |
| 86 |
|
| 87 |
int |
| 88 |
main() |
| 89 |
{ |
| 90 |
test01(); |
| 91 |
test02(); |
| 92 |
return 0; |
| 93 |
} |