]>
Commit | Line | Data |
---|---|---|
7adcbafe | 1 | // Copyright (C) 2001-2022 Free Software Foundation, Inc. |
a9a51750 BK |
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, | |
2328b1de | 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
a9a51750 BK |
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 | |
23 | template<typename _Tp> | |
24 | void | |
25 | modifiers2() | |
26 | { | |
a9a51750 BK |
27 | typedef _Tp list_type; |
28 | typedef typename list_type::value_type value_type; | |
29 | typedef typename list_type::iterator iterator; | |
30 | typedef typename list_type::const_iterator const_iterator; | |
31 | ||
bf4967a1 BK |
32 | using __gnu_test::copy_constructor; |
33 | using __gnu_test::destructor; | |
34 | ||
a9a51750 BK |
35 | list_type list0201; |
36 | value_type::reset(); | |
37 | ||
38 | list0201.insert(list0201.begin(), value_type(1)); // list should be [1] | |
39 | VERIFY(list0201.size() == 1); | |
bf4967a1 | 40 | VERIFY(copy_constructor::count() == 1); |
a9a51750 BK |
41 | |
42 | list0201.insert(list0201.end(), value_type(2)); // list should be [1 2] | |
43 | VERIFY(list0201.size() == 2); | |
bf4967a1 | 44 | VERIFY(copy_constructor::count() == 2); |
a9a51750 BK |
45 | |
46 | iterator i = list0201.begin(); | |
47 | const_iterator j = i; | |
48 | VERIFY(i->id() == 1); ++i; | |
49 | VERIFY(i->id() == 2); | |
50 | ||
51 | list0201.insert(i, value_type(3)); // list should be [1 3 2] | |
52 | VERIFY(list0201.size() == 3); | |
bf4967a1 | 53 | VERIFY(copy_constructor::count() == 3); |
a9a51750 BK |
54 | |
55 | const_iterator k = i; | |
56 | VERIFY(i->id() == 2); --i; | |
57 | VERIFY(i->id() == 3); --i; | |
58 | VERIFY(i->id() == 1); | |
59 | VERIFY(j->id() == 1); | |
60 | ||
61 | ++i; // will point to '3' | |
62 | value_type::reset(); | |
63 | list0201.erase(i); // should be [1 2] | |
64 | VERIFY(list0201.size() == 2); | |
bf4967a1 | 65 | VERIFY(destructor::count() == 1); |
a9a51750 BK |
66 | VERIFY(k->id() == 2); |
67 | VERIFY(j->id() == 1); | |
68 | ||
69 | list_type list0202; | |
70 | value_type::reset(); | |
71 | VERIFY(list0202.size() == 0); | |
bf4967a1 BK |
72 | VERIFY(copy_constructor::count() == 0); |
73 | VERIFY(destructor::count() == 0); | |
a9a51750 BK |
74 | |
75 | // member swap | |
76 | list0202.swap(list0201); | |
77 | VERIFY(list0201.size() == 0); | |
78 | VERIFY(list0202.size() == 2); | |
bf4967a1 BK |
79 | VERIFY(copy_constructor::count() == 0); |
80 | VERIFY(destructor::count() == 0); | |
a9a51750 BK |
81 | |
82 | // specialized swap | |
83 | swap(list0201, list0202); | |
84 | VERIFY(list0201.size() == 2); | |
85 | VERIFY(list0202.size() == 0); | |
bf4967a1 BK |
86 | VERIFY(copy_constructor::count() == 0); |
87 | VERIFY(destructor::count() == 0); | |
a9a51750 | 88 | } |