This commit was manufactured by cvs2svn to create branch
[official-gcc.git] / libstdc++-v3 / testsuite / 23_containers / list / modifiers / 3.cc
blobdda9d9afee242f92b8449ca8592ec3e09ab69a3f
1 // Copyright (C) 2001, 2003, 2004 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 2, or (at your option)
7 // any later version.
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,
17 // USA.
19 // 23.2.2.3 list modifiers [lib.list.modifiers]
21 #include <list>
22 #include <testsuite_hooks.h>
24 typedef __gnu_test::copy_tracker T;
26 bool test __attribute__((unused)) = true;
29 // This test verifies the following.
31 // 23.2.2.3 void push_front(const T& x)
32 // 23.2.2.3 void push_back(const T& x)
33 // 23.2.2.3 (1) iterator and reference non-invalidation
34 // 23.2.2.3 (1) exception effects
35 // 23.2.2.3 (2) complexity requirements
37 // 23.2.2.3 void pop_front()
38 // 23.2.2.3 void pop_back()
39 // 23.2.2.3 (3) iterator and reference non-invalidation
40 // 23.2.2.3 (5) complexity requirements
42 // 23.2.2 const_iterator begin() const
43 // 23.2.2 iterator end()
44 // 23.2.2 const_reverse_iterator rbegin() const
45 // 23.2.2 _reference front()
46 // 23.2.2 const_reference front() const
47 // 23.2.2 reference back()
48 // 23.2.2 const_reference back() const
50 void
51 test01()
53 std::list<T> list0101;
54 std::list<T>::const_iterator i;
55 std::list<T>::const_reverse_iterator j;
56 std::list<T>::iterator k;
57 T::reset();
59 list0101.push_back(T(1)); // list should be [1]
60 VERIFY(list0101.size() == 1);
61 VERIFY(T::copyCount() == 1);
63 k = list0101.end();
64 --k;
65 VERIFY(k->id() == 1);
66 VERIFY(k->id() == list0101.front().id());
67 VERIFY(k->id() == list0101.back().id());
69 list0101.push_front(T(2)); // list should be [2 1]
70 VERIFY(list0101.size() == 2);
71 VERIFY(T::copyCount() == 2);
72 VERIFY(k->id() == 1);
74 list0101.push_back(T(3)); // list should be [2 1 3]
75 VERIFY(list0101.size() == 3);
76 VERIFY(T::copyCount() == 3);
77 VERIFY(k->id() == 1);
79 try
81 list0101.push_back(T(4, true));
82 VERIFY(false);
84 catch (...)
86 VERIFY(list0101.size() == 3);
87 VERIFY(T::copyCount() == 4);
90 i = list0101.begin();
91 VERIFY(i->id() == 2);
92 VERIFY(i->id() == list0101.front().id());
94 j = list0101.rbegin();
95 VERIFY(j->id() == 3);
96 VERIFY(j->id() == list0101.back().id());
98 ++i;
99 VERIFY(i->id() == 1);
101 ++j;
102 VERIFY(j->id() == 1);
104 T::reset();
106 list0101.pop_back(); // list should be [2 1]
107 VERIFY(list0101.size() == 2);
108 VERIFY(T::dtorCount() == 1);
109 VERIFY(i->id() == 1);
110 VERIFY(k->id() == 1);
112 list0101.pop_front(); // list should be [1]
113 VERIFY(list0101.size() == 1);
114 VERIFY(T::dtorCount() == 2);
115 VERIFY(i->id() == 1);
116 VERIFY(k->id() == 1);
119 #if !__GXX_WEAK__ && _MT_ALLOCATOR_H
120 // Explicitly instantiate for systems with no COMDAT or weak support.
121 template class __gnu_cxx::__mt_alloc<__gnu_test::copy_tracker>;
122 template class __gnu_cxx::__mt_alloc<std::_List_node<__gnu_test::copy_tracker> >;
123 #endif
125 int main()
127 test01();
128 return 0;