]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/23_containers/list/modifiers/2.h
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / list / modifiers / 2.h
CommitLineData
f1717362 1// Copyright (C) 2001-2016 Free Software Foundation, Inc.
2b3fc9df 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,
c68c6d54 10// but WITHOUT ANY WARRANTY; without even the implied warranty of
2b3fc9df 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// general single insert/erase + swap
23template<typename _Tp>
24void
25modifiers2()
26{
27 bool test __attribute__((unused)) = true;
28 typedef _Tp list_type;
29 typedef typename list_type::value_type value_type;
30 typedef typename list_type::iterator iterator;
31 typedef typename list_type::const_iterator const_iterator;
32
b44d17e8 33 using __gnu_test::copy_constructor;
34 using __gnu_test::destructor;
35
2b3fc9df 36 list_type list0201;
37 value_type::reset();
38
39 list0201.insert(list0201.begin(), value_type(1)); // list should be [1]
40 VERIFY(list0201.size() == 1);
b44d17e8 41 VERIFY(copy_constructor::count() == 1);
2b3fc9df 42
43 list0201.insert(list0201.end(), value_type(2)); // list should be [1 2]
44 VERIFY(list0201.size() == 2);
b44d17e8 45 VERIFY(copy_constructor::count() == 2);
2b3fc9df 46
47 iterator i = list0201.begin();
48 const_iterator j = i;
49 VERIFY(i->id() == 1); ++i;
50 VERIFY(i->id() == 2);
51
52 list0201.insert(i, value_type(3)); // list should be [1 3 2]
53 VERIFY(list0201.size() == 3);
b44d17e8 54 VERIFY(copy_constructor::count() == 3);
2b3fc9df 55
56 const_iterator k = i;
57 VERIFY(i->id() == 2); --i;
58 VERIFY(i->id() == 3); --i;
59 VERIFY(i->id() == 1);
60 VERIFY(j->id() == 1);
61
62 ++i; // will point to '3'
63 value_type::reset();
64 list0201.erase(i); // should be [1 2]
65 VERIFY(list0201.size() == 2);
b44d17e8 66 VERIFY(destructor::count() == 1);
2b3fc9df 67 VERIFY(k->id() == 2);
68 VERIFY(j->id() == 1);
69
70 list_type list0202;
71 value_type::reset();
72 VERIFY(list0202.size() == 0);
b44d17e8 73 VERIFY(copy_constructor::count() == 0);
74 VERIFY(destructor::count() == 0);
2b3fc9df 75
76 // member swap
77 list0202.swap(list0201);
78 VERIFY(list0201.size() == 0);
79 VERIFY(list0202.size() == 2);
b44d17e8 80 VERIFY(copy_constructor::count() == 0);
81 VERIFY(destructor::count() == 0);
2b3fc9df 82
83 // specialized swap
84 swap(list0201, list0202);
85 VERIFY(list0201.size() == 2);
86 VERIFY(list0202.size() == 0);
b44d17e8 87 VERIFY(copy_constructor::count() == 0);
88 VERIFY(destructor::count() == 0);
2b3fc9df 89}