]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/list/modifiers/2.cc
1 // Copyright (C) 2001, 2003 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 2, 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 COPYING. If not, write to the Free
16 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 // 23.2.2.3 list modifiers [lib.list.modifiers]
22 #include <testsuite_hooks.h>
24 typedef __gnu_test::copy_tracker T
;
26 bool test
__attribute__((unused
)) = true;
28 // general single insert/erase + swap
32 std::list
<T
> list0201
;
35 list0201
.insert(list0201
.begin(), T(1)); // list should be [1]
36 VERIFY(list0201
.size() == 1);
37 VERIFY(T::copyCount() == 1);
39 list0201
.insert(list0201
.end(), T(2)); // list should be [1 2]
40 VERIFY(list0201
.size() == 2);
41 VERIFY(T::copyCount() == 2);
43 std::list
<T
>::iterator i
= list0201
.begin();
44 std::list
<T
>::const_iterator j
= i
;
45 VERIFY(i
->id() == 1); ++i
;
48 list0201
.insert(i
, T(3)); // list should be [1 3 2]
49 VERIFY(list0201
.size() == 3);
50 VERIFY(T::copyCount() == 3);
52 std::list
<T
>::const_iterator k
= i
;
53 VERIFY(i
->id() == 2); --i
;
54 VERIFY(i
->id() == 3); --i
;
58 ++i
; // will point to '3'
60 list0201
.erase(i
); // should be [1 2]
61 VERIFY(list0201
.size() == 2);
62 VERIFY(T::dtorCount() == 1);
66 std::list
<T
> list0202
;
68 VERIFY(list0202
.size() == 0);
69 VERIFY(T::copyCount() == 0);
70 VERIFY(T::dtorCount() == 0);
73 list0202
.swap(list0201
);
74 VERIFY(list0201
.size() == 0);
75 VERIFY(list0202
.size() == 2);
76 VERIFY(T::copyCount() == 0);
77 VERIFY(T::dtorCount() == 0);
80 swap(list0201
, list0202
);
81 VERIFY(list0201
.size() == 2);
82 VERIFY(list0202
.size() == 0);
83 VERIFY(T::copyCount() == 0);
84 VERIFY(T::dtorCount() == 0);