1 // Copyright (C) 2001, 2003, 2004, 2005, 2009 Free Software Foundation, Inc.
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 3, or (at your option)
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 COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // 23.2.2.3 list modifiers [lib.list.modifiers]
21 #include <testsuite_hooks.h>
23 typedef __gnu_test::copy_tracker T;
25 bool test __attribute__((unused)) = true;
27 // range and fill insert/erase + clear
28 // missing: o fill insert disguised as a range insert in all its variants
29 // o exception effects
33 std::list<T> list0301;
36 // fill insert at beginning of list / empty list
37 list0301.insert(list0301.begin(), 3, T(11)); // should be [11 11 11]
38 VERIFY(list0301.size() == 3);
39 VERIFY(T::copyCount() == 3);
41 // save iterators to verify post-insert validity
42 std::list<T>::iterator b = list0301.begin();
43 std::list<T>::iterator m = list0301.end(); --m;
44 std::list<T>::iterator e = list0301.end();
46 // fill insert at end of list
48 list0301.insert(list0301.end(), 3, T(13)); // should be [11 11 11 13 13 13]
49 VERIFY(list0301.size() == 6);
50 VERIFY(T::copyCount() == 3);
51 VERIFY(b == list0301.begin() && b->id() == 11);
52 VERIFY(e == list0301.end());
53 VERIFY(m->id() == 11);
55 // fill insert in the middle of list
58 list0301.insert(m, 3, T(12)); // should be [11 11 11 12 12 12 13 13 13]
59 VERIFY(list0301.size() == 9);
60 VERIFY(T::copyCount() == 3);
61 VERIFY(b == list0301.begin() && b->id() == 11);
62 VERIFY(e == list0301.end());
63 VERIFY(m->id() == 13);
67 m = list0301.erase(m); // should be [11 11 11 12 12 12 13 13]
68 VERIFY(list0301.size() == 8);
69 VERIFY(T::dtorCount() == 1);
70 VERIFY(b == list0301.begin() && b->id() == 11);
71 VERIFY(e == list0301.end());
72 VERIFY(m->id() == 13);
76 m = list0301.erase(list0301.begin(), m); // should be [13 13]
77 VERIFY(list0301.size() == 2);
78 VERIFY(T::dtorCount() == 6);
79 VERIFY(m->id() == 13);
81 // range fill at beginning
82 const int A[] = {321, 322, 333};
83 const int N = sizeof(A) / sizeof(int);
86 list0301.insert(b, A, A + N); // should be [321 322 333 13 13]
87 VERIFY(list0301.size() == 5);
88 VERIFY(T::copyCount() == 3);
89 VERIFY(m->id() == 13);
93 list0301.insert(e, A, A + N); // should be [321 322 333 13 13 321 322 333]
94 VERIFY(list0301.size() == 8);
95 VERIFY(T::copyCount() == 3);
96 VERIFY(e == list0301.end());
97 VERIFY(m->id() == 13);
99 // range fill in middle
101 list0301.insert(m, A, A + N);
102 VERIFY(list0301.size() == 11);
103 VERIFY(T::copyCount() == 3);
104 VERIFY(e == list0301.end());
105 VERIFY(m->id() == 13);
109 VERIFY(list0301.size() == 0);
110 VERIFY(T::dtorCount() == 11);
111 VERIFY(e == list0301.end());