Reverting merge from trunk
[official-gcc.git] / libstdc++-v3 / testsuite / 23_containers / forward_list / modifiers / 2.cc
blob1dfe0880c3504951fcdd9491b3c4abb428123993
1 // { dg-options "-std=gnu++0x" }
3 // Copyright (C) 2008-2013 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.
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 // 23.2.3.n forward_list xxx [lib.forward_list.xxx]
22 #include <forward_list>
23 #include <testsuite_hooks.h>
25 #include <string>
27 bool test __attribute__((unused)) = true;
29 // This test verifies the following:
30 // insert_after single item
31 // before_begin iterator
32 void
33 test01()
35 std::forward_list<int> fl({0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
37 std::forward_list<int>::iterator ret = fl.insert_after(fl.before_begin(),
38 42);
39 VERIFY( ret == fl.begin() );
40 VERIFY( fl.front() == 42 );
43 // This test verifies the following:
44 void
45 test02()
47 std::forward_list<int> fl({0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
49 std::forward_list<int>::const_iterator pos = fl.cbegin();
50 ++pos;
51 VERIFY( *pos == 1 );
53 std::forward_list<int>::iterator ret = fl.insert_after(pos, 0, 42);
54 VERIFY( ret == pos );
56 ret = fl.insert_after(pos, 5, 42);
57 VERIFY( *pos == 1 );
59 ++pos;
60 VERIFY( *pos == 42 );
61 ++pos;
62 ++pos;
63 ++pos;
64 ++pos;
65 VERIFY( *pos == 42 );
66 VERIFY( ret == pos );
67 ++pos;
68 VERIFY( *pos == 2 );
71 // This test verifies the following:
72 void
73 test03()
75 std::forward_list<int> fl({0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
77 std::forward_list<int>::const_iterator pos = fl.cbegin();
78 ++pos;
79 VERIFY( *pos == 1 );
81 int i[3] = {666, 777, 888};
82 std::forward_list<int>::iterator ret = fl.insert_after(pos, i, i);
83 VERIFY( ret == pos );
85 ret = fl.insert_after(pos, i, i + 3);
86 VERIFY( *pos == 1 );
88 ++pos;
89 ++pos;
90 ++pos;
91 VERIFY( *pos == 888 );
92 VERIFY( ret == pos );
93 ++pos;
94 VERIFY( *pos == 2 );
97 // This test verifies the following:
98 void
99 test04()
101 std::forward_list<int> fl({0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
103 std::forward_list<int>::const_iterator pos = fl.cbegin();
104 ++pos;
105 VERIFY( *pos == 1 );
107 std::forward_list<int>::iterator ret = fl.insert_after(pos, { });
108 VERIFY( ret == pos);
110 ret = fl.insert_after(pos, {-1, -2, -3, -4, -5});
111 VERIFY( *pos == 1);
113 ++pos;
114 ++pos;
115 ++pos;
116 VERIFY( *pos == -3 );
117 ++pos;
118 ++pos;
119 VERIFY( ret == pos );
120 ++pos;
121 VERIFY( *pos == 2 );
124 // This test verifies the following:
125 void
126 test05()
128 std::forward_list<std::string> fl({"AAA", "BBB", "CCC"});
130 std::forward_list<std::string>::const_iterator pos = fl.cbegin();
131 ++pos;
132 VERIFY( *pos == "BBB" );
134 std::string x( "XXX" );
135 std::forward_list<std::string>::iterator ret
136 = fl.insert_after(pos, std::move(x));
137 VERIFY( *pos == "BBB" );
138 ++pos;
139 VERIFY( ret == pos );
140 VERIFY( *pos == "XXX" );
141 ++pos;
142 VERIFY( *pos == "CCC" );
146 main()
148 test01();
149 test02();
150 test03();
151 test04();
152 test05();
153 return 0;