]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/23_containers/list/modifiers/1.h
check_construct_destroy.h: New.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / list / modifiers / 1.h
CommitLineData
a9a51750
BK
1// Copyright (C) 2001, 2003, 2004, 2005, 2009 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 3, or (at your option)
7// any later version.
8
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.
13
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/>.
17
18// 23.2.2.3 list modifiers [lib.list.modifiers]
19
20#include <testsuite_hooks.h>
21
22// range and fill insert/erase + clear
23// missing: o fill insert disguised as a range insert in all its variants
24// o exception effects
25template<typename _Tp>
26void
27modifiers1()
28{
29 bool test __attribute__((unused)) = true;
30 typedef _Tp list_type;
31 typedef typename list_type::iterator iterator;
32 typedef typename list_type::value_type value_type;
33
34 list_type list0301;
35 value_type::reset();
36
37 // fill insert at beginning of list / empty list
38 list0301.insert(list0301.begin(), 3, value_type(11)); // should be [11 11 11]
39 VERIFY(list0301.size() == 3);
40 VERIFY(value_type::copyCount() == 3);
41
42 // save iterators to verify post-insert validity
43 iterator b = list0301.begin();
44 iterator m = list0301.end(); --m;
45 iterator e = list0301.end();
46
47 // fill insert at end of list
48 value_type::reset();
49 list0301.insert(list0301.end(), 3, value_type(13)); // should be [11 11 11 13 13 13]
50 VERIFY(list0301.size() == 6);
51 VERIFY(value_type::copyCount() == 3);
52 VERIFY(b == list0301.begin() && b->id() == 11);
53 VERIFY(e == list0301.end());
54 VERIFY(m->id() == 11);
55
56 // fill insert in the middle of list
57 ++m;
58 value_type::reset();
59 list0301.insert(m, 3, value_type(12)); // should be [11 11 11 12 12 12 13 13 13]
60 VERIFY(list0301.size() == 9);
61 VERIFY(value_type::copyCount() == 3);
62 VERIFY(b == list0301.begin() && b->id() == 11);
63 VERIFY(e == list0301.end());
64 VERIFY(m->id() == 13);
65
66 // single erase
67 value_type::reset();
68 m = list0301.erase(m); // should be [11 11 11 12 12 12 13 13]
69 VERIFY(list0301.size() == 8);
70 VERIFY(value_type::dtorCount() == 1);
71 VERIFY(b == list0301.begin() && b->id() == 11);
72 VERIFY(e == list0301.end());
73 VERIFY(m->id() == 13);
74
75 // range erase
76 value_type::reset();
77 m = list0301.erase(list0301.begin(), m); // should be [13 13]
78 VERIFY(list0301.size() == 2);
79 VERIFY(value_type::dtorCount() == 6);
80 VERIFY(m->id() == 13);
81
82 // range fill at beginning
83 const int A[] = {321, 322, 333};
84 const int N = sizeof(A) / sizeof(int);
85 value_type::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(value_type::copyCount() == 3);
90 VERIFY(m->id() == 13);
91
92 // range fill at end
93 value_type::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(value_type::copyCount() == 3);
97 VERIFY(e == list0301.end());
98 VERIFY(m->id() == 13);
99
100 // range fill in middle
101 value_type::reset();
102 list0301.insert(m, A, A + N);
103 VERIFY(list0301.size() == 11);
104 VERIFY(value_type::copyCount() == 3);
105 VERIFY(e == list0301.end());
106 VERIFY(m->id() == 13);
107
108 value_type::reset();
109 list0301.clear();
110 VERIFY(list0301.size() == 0);
111 VERIFY(value_type::dtorCount() == 11);
112 VERIFY(e == list0301.end());
113}