2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libstdc++-v3 / testsuite / 23_containers / list / modifiers / 1.cc
blob2e75dcabb31e68cd80335fd01a1d94f563f2b25a
1 // Copyright (C) 2001, 2003 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 2, or (at your option)
7 // any later version.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without Pred the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING. If not, write to the Free
16 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
17 // USA.
19 // 23.2.2.3 list modifiers [lib.list.modifiers]
21 #include <list>
22 #include <testsuite_hooks.h>
24 typedef __gnu_test::copy_tracker T;
26 bool test __attribute__((unused)) = true;
28 // range and fill insert/erase + clear
29 // missing: o fill insert disguised as a range insert in all its variants
30 // o exception effects
31 void
32 test03()
34 std::list<T> list0301;
35 T::reset();
37 // fill insert at beginning of list / empty list
38 list0301.insert(list0301.begin(), 3, T(11)); // should be [11 11 11]
39 VERIFY(list0301.size() == 3);
40 VERIFY(T::copyCount() == 3);
42 // save iterators to verify post-insert validity
43 std::list<T>::iterator b = list0301.begin();
44 std::list<T>::iterator m = list0301.end(); --m;
45 std::list<T>::iterator e = list0301.end();
47 // fill insert at end of list
48 T::reset();
49 list0301.insert(list0301.end(), 3, T(13)); // should be [11 11 11 13 13 13]
50 VERIFY(list0301.size() == 6);
51 VERIFY(T::copyCount() == 3);
52 VERIFY(b == list0301.begin() && b->id() == 11);
53 VERIFY(e == list0301.end());
54 VERIFY(m->id() == 11);
56 // fill insert in the middle of list
57 ++m;
58 T::reset();
59 list0301.insert(m, 3, T(12)); // should be [11 11 11 12 12 12 13 13 13]
60 VERIFY(list0301.size() == 9);
61 VERIFY(T::copyCount() == 3);
62 VERIFY(b == list0301.begin() && b->id() == 11);
63 VERIFY(e == list0301.end());
64 VERIFY(m->id() == 13);
66 // single erase
67 T::reset();
68 m = list0301.erase(m); // should be [11 11 11 12 12 12 13 13]
69 VERIFY(list0301.size() == 8);
70 VERIFY(T::dtorCount() == 1);
71 VERIFY(b == list0301.begin() && b->id() == 11);
72 VERIFY(e == list0301.end());
73 VERIFY(m->id() == 13);
75 // range erase
76 T::reset();
77 m = list0301.erase(list0301.begin(), m); // should be [13 13]
78 VERIFY(list0301.size() == 2);
79 VERIFY(T::dtorCount() == 6);
80 VERIFY(m->id() == 13);
82 // range fill at beginning
83 const int A[] = {321, 322, 333};
84 const int N = sizeof(A) / sizeof(int);
85 T::reset();
86 b = list0301.begin();
87 list0301.insert(b, A, A + N); // should be [321 322 333 13 13]
88 VERIFY(list0301.size() == 5);
89 VERIFY(T::copyCount() == 3);
90 VERIFY(m->id() == 13);
92 // range fill at end
93 T::reset();
94 list0301.insert(e, A, A + N); // should be [321 322 333 13 13 321 322 333]
95 VERIFY(list0301.size() == 8);
96 VERIFY(T::copyCount() == 3);
97 VERIFY(e == list0301.end());
98 VERIFY(m->id() == 13);
100 // range fill in middle
101 T::reset();
102 list0301.insert(m, A, A + N);
103 VERIFY(list0301.size() == 11);
104 VERIFY(T::copyCount() == 3);
105 VERIFY(e == list0301.end());
106 VERIFY(m->id() == 13);
108 T::reset();
109 list0301.clear();
110 VERIFY(list0301.size() == 0);
111 VERIFY(T::dtorCount() == 11);
112 VERIFY(e == list0301.end());
115 int main()
117 test03();
118 return 0;
120 // vi:set sw=2 ts=2: