]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/23_containers/list/modifiers/1.h
Update Copyright years for files modified in 2011 and/or 2012.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / list / modifiers / 1.h
CommitLineData
71e45bc2 1// Copyright (C) 2001, 2003, 2004, 2005, 2009, 2012
2// Free Software Foundation, Inc.
2b3fc9df 3//
4// This file is part of the GNU ISO C++ Library. This library is free
5// software; you can redistribute it and/or modify it under the
6// terms of the GNU General Public License as published by the
7// Free Software Foundation; either version 3, or (at your option)
8// any later version.
9
10// This library is distributed in the hope that it will be useful,
c68c6d54 11// but WITHOUT ANY WARRANTY; without even the implied warranty of
2b3fc9df 12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14
15// You should have received a copy of the GNU General Public License along
16// with this library; see the file COPYING3. If not see
17// <http://www.gnu.org/licenses/>.
18
19// 23.2.2.3 list modifiers [lib.list.modifiers]
20
21#include <testsuite_hooks.h>
22
23// range and fill insert/erase + clear
24// missing: o fill insert disguised as a range insert in all its variants
25// o exception effects
26template<typename _Tp>
27void
28modifiers1()
29{
30 bool test __attribute__((unused)) = true;
31 typedef _Tp list_type;
32 typedef typename list_type::iterator iterator;
33 typedef typename list_type::value_type value_type;
b44d17e8 34
35 using __gnu_test::copy_constructor;
36 using __gnu_test::destructor;
2b3fc9df 37
38 list_type list0301;
39 value_type::reset();
40
41 // fill insert at beginning of list / empty list
42 list0301.insert(list0301.begin(), 3, value_type(11)); // should be [11 11 11]
43 VERIFY(list0301.size() == 3);
b44d17e8 44 VERIFY(copy_constructor::count() == 3);
2b3fc9df 45
46 // save iterators to verify post-insert validity
47 iterator b = list0301.begin();
48 iterator m = list0301.end(); --m;
49 iterator e = list0301.end();
50
51 // fill insert at end of list
52 value_type::reset();
53 list0301.insert(list0301.end(), 3, value_type(13)); // should be [11 11 11 13 13 13]
54 VERIFY(list0301.size() == 6);
b44d17e8 55 VERIFY(copy_constructor::count() == 3);
2b3fc9df 56 VERIFY(b == list0301.begin() && b->id() == 11);
57 VERIFY(e == list0301.end());
58 VERIFY(m->id() == 11);
59
60 // fill insert in the middle of list
61 ++m;
62 value_type::reset();
63 list0301.insert(m, 3, value_type(12)); // should be [11 11 11 12 12 12 13 13 13]
64 VERIFY(list0301.size() == 9);
b44d17e8 65 VERIFY(copy_constructor::count() == 3);
2b3fc9df 66 VERIFY(b == list0301.begin() && b->id() == 11);
67 VERIFY(e == list0301.end());
68 VERIFY(m->id() == 13);
69
70 // single erase
71 value_type::reset();
72 m = list0301.erase(m); // should be [11 11 11 12 12 12 13 13]
73 VERIFY(list0301.size() == 8);
b44d17e8 74 VERIFY(destructor::count() == 1);
2b3fc9df 75 VERIFY(b == list0301.begin() && b->id() == 11);
76 VERIFY(e == list0301.end());
77 VERIFY(m->id() == 13);
78
79 // range erase
80 value_type::reset();
81 m = list0301.erase(list0301.begin(), m); // should be [13 13]
82 VERIFY(list0301.size() == 2);
b44d17e8 83 VERIFY(destructor::count() == 6);
2b3fc9df 84 VERIFY(m->id() == 13);
85
86 // range fill at beginning
87 const int A[] = {321, 322, 333};
88 const int N = sizeof(A) / sizeof(int);
89 value_type::reset();
90 b = list0301.begin();
91 list0301.insert(b, A, A + N); // should be [321 322 333 13 13]
92 VERIFY(list0301.size() == 5);
b44d17e8 93 VERIFY(copy_constructor::count() == 3);
2b3fc9df 94 VERIFY(m->id() == 13);
95
96 // range fill at end
97 value_type::reset();
98 list0301.insert(e, A, A + N); // should be [321 322 333 13 13 321 322 333]
99 VERIFY(list0301.size() == 8);
b44d17e8 100 VERIFY(copy_constructor::count() == 3);
2b3fc9df 101 VERIFY(e == list0301.end());
102 VERIFY(m->id() == 13);
103
104 // range fill in middle
105 value_type::reset();
106 list0301.insert(m, A, A + N);
107 VERIFY(list0301.size() == 11);
b44d17e8 108 VERIFY(copy_constructor::count() == 3);
2b3fc9df 109 VERIFY(e == list0301.end());
110 VERIFY(m->id() == 13);
111
112 value_type::reset();
113 list0301.clear();
114 VERIFY(list0301.size() == 0);
b44d17e8 115 VERIFY(destructor::count() == 11);
2b3fc9df 116 VERIFY(e == list0301.end());
117}