]>
Commit | Line | Data |
---|---|---|
52066eae | 1 | // { dg-do run { target c++11 } } |
3a63c9cd | 2 | |
83ffe9cd | 3 | // Copyright (C) 2008-2023 Free Software Foundation, Inc. |
3a63c9cd ESR |
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 | |
748086b7 | 8 | // Free Software Foundation; either version 3, or (at your option) |
3a63c9cd ESR |
9 | // any later version. |
10 | ||
11 | // This library is distributed in the hope that it will be useful, | |
2328b1de | 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
3a63c9cd ESR |
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 | |
748086b7 JJ |
17 | // with this library; see the file COPYING3. If not see |
18 | // <http://www.gnu.org/licenses/>. | |
3a63c9cd | 19 | |
749ee734 | 20 | // C++11 23.3.4.6 Operations [forwardlist.ops] |
3a63c9cd ESR |
21 | |
22 | #include <forward_list> | |
23 | #include <testsuite_hooks.h> | |
24 | ||
3a63c9cd | 25 | // This test verifies the following: |
749ee734 | 26 | // splice_after for entire list |
3a63c9cd ESR |
27 | void |
28 | test01() | |
29 | { | |
30 | std::forward_list<double> a = {0.0, 1.0, 2.0, 3.0, 4.0}; | |
31 | std::forward_list<double>::const_iterator posa = a.cbefore_begin(); | |
32 | ||
33 | std::forward_list<double> x = {666.0, 777.0, 888.0}; | |
34 | ||
4c650853 | 35 | a.splice_after(posa, std::move(x)); |
3a63c9cd ESR |
36 | |
37 | ++posa; | |
38 | VERIFY(*posa == 666.0); | |
39 | ||
40 | VERIFY(x.empty() == true); | |
41 | } | |
42 | ||
43 | // This test verifies the following: | |
749ee734 | 44 | // splice_after for iterator range |
3a63c9cd ESR |
45 | void |
46 | test02() | |
47 | { | |
48 | std::forward_list<double> a = {0.0, 1.0, 2.0, 3.0, 4.0}; | |
49 | std::forward_list<double>::const_iterator posa = a.cbefore_begin(); | |
50 | ++posa; | |
51 | VERIFY(*posa == 0.0); | |
52 | ||
53 | std::forward_list<double> y = {10.0, 11.0, 12.0, 13.0, 14.0, 15.0}; | |
54 | std::forward_list<double>::const_iterator befy = y.cbefore_begin(); | |
55 | ++befy; | |
56 | VERIFY(*befy == 10.0); | |
57 | std::forward_list<double>::const_iterator endy = befy; | |
58 | ++endy; | |
59 | ++endy; | |
60 | ++endy; | |
61 | ++endy; | |
62 | VERIFY(*endy == 14.0); | |
63 | ||
4c650853 | 64 | a.splice_after(posa, std::move(y), befy, endy); |
3a63c9cd ESR |
65 | VERIFY(*posa == 0.0); |
66 | ||
67 | VERIFY(*befy == 10.0); | |
68 | ++befy; | |
78263296 | 69 | VERIFY(*befy == 14.0); |
3a63c9cd ESR |
70 | } |
71 | ||
72 | // This test verifies the following: | |
749ee734 | 73 | // splice_after for single element |
3a63c9cd ESR |
74 | void |
75 | test03() | |
76 | { | |
77 | std::forward_list<double> a = {0.0, 1.0, 2.0, 3.0, 4.0}; | |
78 | std::forward_list<double>::const_iterator posa = a.cbefore_begin(); | |
79 | ++posa; | |
80 | ++posa; | |
81 | VERIFY(*posa == 1.0); | |
82 | ||
83 | std::forward_list<double> z = {42.0, 43.0, 44.0}; | |
84 | std::forward_list<double>::const_iterator posz = z.begin(); | |
85 | VERIFY(*posz == 42.0); | |
86 | ||
4c650853 | 87 | a.splice_after(posa, std::move(z), posz); |
3a63c9cd ESR |
88 | VERIFY(*posa == 1.0); |
89 | ++posa; | |
90 | VERIFY(*posa == 43.0); | |
91 | ||
92 | VERIFY(*posz == 42.0); | |
93 | ++posz; | |
94 | VERIFY(*posz == 44.0); | |
95 | } | |
96 | ||
97 | int | |
98 | main() | |
99 | { | |
100 | test01(); | |
101 | test02(); | |
102 | test03(); | |
103 | return 0; | |
104 | } |