]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/forward_list/modifiers/2.cc
Licensing changes to GPLv3 resp. GPLv3 with GCC Runtime Exception.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / forward_list / modifiers / 2.cc
1 // { dg-options "-std=gnu++0x" }
2
3 // Copyright (C) 2008, 2009 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 Pred 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 #include <string>
26
27 bool test __attribute__((unused)) = true;
28
29 // This test verifies the following:
30 // insert_after single item
31 // before_begin iterator
32 void
33 test01()
34 {
35 std::forward_list<int> fl({0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
36
37 fl.insert_after(fl.before_begin(), 42);
38 VERIFY(fl.front() == 42);
39 }
40
41 // This test verifies the following:
42 void
43 test02()
44 {
45 std::forward_list<int> fl({0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
46
47 std::forward_list<int>::const_iterator pos = fl.cbegin();
48 ++pos;
49 VERIFY(*pos == 1);
50
51 // Note: Calling l.insert_after(pos, 5, 42); without the long five
52 // gets resolved to the iterator range version and fails to compile!
53 fl.insert_after(pos, 5, 42);
54 VERIFY(*pos == 1);
55
56 ++pos;
57 VERIFY(*pos == 42);
58 ++pos;
59 ++pos;
60 ++pos;
61 ++pos;
62 VERIFY(*pos == 42);
63 }
64
65 // This test verifies the following:
66 void
67 test03()
68 {
69 std::forward_list<int> fl({0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
70
71 std::forward_list<int>::const_iterator pos = fl.cbegin();
72 ++pos;
73 VERIFY(*pos == 1);
74
75 int i[3] = {666, 777, 888};
76 fl.insert_after(pos, i, i+3);
77 VERIFY(*pos == 1);
78
79 ++pos;
80 ++pos;
81 ++pos;
82 VERIFY(*pos == 888);
83 ++pos;
84 VERIFY(*pos == 2);
85 }
86
87 // This test verifies the following:
88 void
89 test04()
90 {
91 std::forward_list<int> fl({0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
92
93 std::forward_list<int>::const_iterator pos = fl.cbegin();
94 ++pos;
95 VERIFY(*pos == 1);
96
97 fl.insert_after(pos, {-1, -2, -3, -4, -5});
98 VERIFY(*pos == 1);
99
100 ++pos;
101 ++pos;
102 ++pos;
103 VERIFY(*pos == -3);
104 }
105
106 // This test verifies the following:
107 void
108 test05()
109 {
110 std::forward_list<std::string> fl({"AAA", "BBB", "CCC"});
111
112 std::forward_list<std::string>::const_iterator pos = fl.cbegin();
113 ++pos;
114 VERIFY(*pos == "BBB");
115
116 std::string x( "XXX" );
117 fl.insert_after(pos, std::move(x));
118 VERIFY(*pos == "BBB");
119 ++pos;
120 VERIFY(*pos == "XXX");
121 ++pos;
122 VERIFY(*pos == "CCC");
123 }
124
125 int
126 main()
127 {
128 test01();
129 test02();
130 test03();
131 test04();
132 test05();
133 return 0;
134 }