OSDN Git Service

2010-03-15 Paolo Carlini <paolo.carlini@oracle.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / testsuite / 23_containers / forward_list / modifiers / 2.cc
1 // { dg-options "-std=gnu++0x" }
2
3 // Copyright (C) 2008, 2009, 2010 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   std::forward_list<int>::iterator ret = fl.insert_after(fl.before_begin(),
38                                                          42);
39   VERIFY( ret == fl.begin() );
40   VERIFY( fl.front() == 42 );
41 }
42
43 // This test verifies the following:
44 void
45 test02()
46 {
47   std::forward_list<int> fl({0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
48
49   std::forward_list<int>::const_iterator pos = fl.cbegin();
50   ++pos;
51   VERIFY( *pos == 1 );
52
53   std::forward_list<int>::iterator ret = fl.insert_after(pos, 0, 42);
54   VERIFY( ret == pos );
55
56   ret = fl.insert_after(pos, 5, 42);
57   VERIFY( *pos == 1 );
58
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 );
69 }
70
71 // This test verifies the following:
72 void
73 test03()
74 {
75   std::forward_list<int> fl({0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
76
77   std::forward_list<int>::const_iterator pos = fl.cbegin();
78   ++pos;
79   VERIFY( *pos == 1 );
80
81   int i[3] = {666, 777, 888};
82   std::forward_list<int>::iterator ret = fl.insert_after(pos, i, i);
83   VERIFY( ret == pos );
84
85   ret = fl.insert_after(pos, i, i + 3);
86   VERIFY( *pos == 1 );
87
88   ++pos;
89   ++pos;
90   ++pos;
91   VERIFY( *pos == 888 );
92   VERIFY( ret == pos );
93   ++pos;
94   VERIFY( *pos == 2 );
95 }
96
97 // This test verifies the following:
98 void
99 test04()
100 {
101   std::forward_list<int> fl({0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
102
103   std::forward_list<int>::const_iterator pos = fl.cbegin();
104   ++pos;
105   VERIFY( *pos == 1 );
106
107   std::forward_list<int>::iterator ret = fl.insert_after(pos, { });
108   VERIFY( ret == pos);
109
110   ret = fl.insert_after(pos, {-1, -2, -3, -4, -5});
111   VERIFY( *pos == 1);
112
113   ++pos;
114   ++pos;
115   ++pos;
116   VERIFY( *pos == -3 );
117   ++pos;
118   ++pos;
119   VERIFY( ret == pos );
120   ++pos;
121   VERIFY( *pos == 2 );
122 }
123
124 // This test verifies the following:
125 void
126 test05()
127 {
128   std::forward_list<std::string> fl({"AAA", "BBB", "CCC"});
129
130   std::forward_list<std::string>::const_iterator pos = fl.cbegin();
131   ++pos;
132   VERIFY( *pos == "BBB" );
133
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" );
143 }
144
145 int
146 main()
147 {
148   test01();
149   test02();
150   test03();
151   test04();
152   test05();
153   return 0;
154 }