OSDN Git Service

2008-11-11 Bob Walters <bob.s.walters@gmail.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / testsuite / 23_containers / forward_list / ext_pointer / modifiers / 2.cc
1 // { dg-options "-std=gnu++0x" }
2
3 // Copyright (C) 2008 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 2, 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 COPYING.  If not, write to the Free
18 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 // USA.
20
21 // 23.2.3.n forward_list xxx [lib.forward_list.xxx]
22
23 #include <forward_list>
24 #include <ext/extptr_allocator.h>
25 #include <testsuite_hooks.h>
26
27 #include <string>
28
29 bool test __attribute__((unused)) = true;
30
31 using __gnu_cxx::_ExtPtr_allocator;
32
33 // This test verifies the following:
34 //   insert_after single item
35 //   before_begin iterator
36 void
37 test01()
38 {
39   std::forward_list<int, _ExtPtr_allocator<int> > fl(
40     {0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
41
42   fl.insert_after(fl.before_begin(), 42);
43   VERIFY(fl.front() == 42);
44 }
45
46 // This test verifies the following:
47 void
48 test02()
49 {
50   std::forward_list<int, _ExtPtr_allocator<int> > fl(
51     {0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
52
53   std::forward_list<int, _ExtPtr_allocator<int> >::const_iterator 
54     pos = fl.cbegin();
55
56   ++pos;
57   VERIFY(*pos == 1);
58
59   // Note: Calling l.insert_after(pos, 5, 42); without the long five
60   // gets resolved to the iterator range version and fails to compile!
61   fl.insert_after(pos, 5, 42);
62   VERIFY(*pos == 1);
63
64   ++pos;
65   VERIFY(*pos == 42);
66   ++pos;
67   ++pos;
68   ++pos;
69   ++pos;
70   VERIFY(*pos == 42);
71 }
72
73 // This test verifies the following:
74 void
75 test03()
76 {
77   std::forward_list<int, _ExtPtr_allocator<int> > fl(
78     {0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
79
80   std::forward_list<int, _ExtPtr_allocator<int> >::const_iterator 
81     pos = fl.cbegin();
82
83   ++pos;
84   VERIFY(*pos == 1);
85
86   int i[3] = {666, 777, 888};
87   fl.insert_after(pos, i, i+3);
88   VERIFY(*pos == 1);
89
90   ++pos;
91   ++pos;
92   ++pos;
93   VERIFY(*pos == 888);
94   ++pos;
95   VERIFY(*pos == 2);
96 }
97
98 // This test verifies the following:
99 void
100 test04()
101 {
102   std::forward_list<int, _ExtPtr_allocator<int> > fl(
103     {0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
104
105   std::forward_list<int, _ExtPtr_allocator<int> >::const_iterator 
106     pos = fl.cbegin();
107
108   ++pos;
109   VERIFY(*pos == 1);
110
111   fl.insert_after(pos, {-1, -2, -3, -4, -5});
112   VERIFY(*pos == 1);
113
114   ++pos;
115   ++pos;
116   ++pos;
117   VERIFY(*pos == -3);
118 }
119
120 // This test verifies the following:
121 void
122 test05()
123 {
124   std::forward_list<std::string, _ExtPtr_allocator<std::string> > fl(
125     {"AAA", "BBB", "CCC"});
126
127   std::forward_list<std::string, _ExtPtr_allocator<std::string> >::const_iterator 
128     pos = fl.cbegin();
129
130   ++pos;
131   VERIFY(*pos == "BBB");
132
133   std::string x( "XXX" );
134   fl.insert_after(pos, std::move(x));
135   VERIFY(*pos == "BBB");
136   ++pos;
137   VERIFY(*pos == "XXX");
138   ++pos;
139   VERIFY(*pos == "CCC");
140 }
141
142 int
143 main()
144 {
145   test01();
146   test02();
147   test03();
148   test04();
149   test05();
150   return 0;
151 }