]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/list/modifiers/3.h
c3ba5484bbdffff23755b1f3ab007e7b9a909c49
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / list / modifiers / 3.h
1 // Copyright (C) 2001-2014 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 3, or (at your option)
7 // any later version.
8
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
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 // This test verifies the following.
23 //
24 // 23.2.2.3 void push_front(const T& x)
25 // 23.2.2.3 void push_back(const T& x)
26 // 23.2.2.3 (1) iterator and reference non-invalidation
27 // 23.2.2.3 (1) exception effects
28 // 23.2.2.3 (2) complexity requirements
29 //
30 // 23.2.2.3 void pop_front()
31 // 23.2.2.3 void pop_back()
32 // 23.2.2.3 (3) iterator and reference non-invalidation
33 // 23.2.2.3 (5) complexity requirements
34 //
35 // 23.2.2 const_iterator begin() const
36 // 23.2.2 iterator end()
37 // 23.2.2 const_reverse_iterator rbegin() const
38 // 23.2.2 _reference front()
39 // 23.2.2 const_reference front() const
40 // 23.2.2 reference back()
41 // 23.2.2 const_reference back() const
42 //
43 template<typename _Tp>
44 void
45 modifiers3()
46 {
47 bool test __attribute__((unused)) = true;
48 typedef _Tp list_type;
49 typedef typename list_type::iterator iterator;
50 typedef typename list_type::value_type value_type;
51 typedef typename list_type::const_iterator const_iterator;
52 typedef typename list_type::const_reverse_iterator const_reverse_iterator;
53
54 using __gnu_test::copy_constructor;
55 using __gnu_test::destructor;
56
57 list_type list0101;
58 const_iterator i;
59 const_reverse_iterator j;
60 iterator k;
61 value_type::reset();
62
63 list0101.push_back(value_type(1)); // list should be [1]
64 VERIFY(list0101.size() == 1);
65 VERIFY(copy_constructor::count() == 1);
66
67 k = list0101.end();
68 --k;
69 VERIFY(k->id() == 1);
70 VERIFY(k->id() == list0101.front().id());
71 VERIFY(k->id() == list0101.back().id());
72
73 list0101.push_front(value_type(2)); // list should be [2 1]
74 VERIFY(list0101.size() == 2);
75 VERIFY(copy_constructor::count() == 2);
76 VERIFY(k->id() == 1);
77
78 list0101.push_back(value_type(3)); // list should be [2 1 3]
79 VERIFY(list0101.size() == 3);
80 VERIFY(copy_constructor::count() == 3);
81 VERIFY(k->id() == 1);
82
83 try
84 {
85 list0101.push_back(value_type(4, true));
86 VERIFY(false);
87 }
88 catch (...)
89 {
90 VERIFY(list0101.size() == 3);
91 VERIFY(copy_constructor::count() == 4);
92 }
93
94 i = list0101.begin();
95 VERIFY(i->id() == 2);
96 VERIFY(i->id() == list0101.front().id());
97
98 j = list0101.rbegin();
99 VERIFY(j->id() == 3);
100 VERIFY(j->id() == list0101.back().id());
101
102 ++i;
103 VERIFY(i->id() == 1);
104
105 ++j;
106 VERIFY(j->id() == 1);
107
108 value_type::reset();
109
110 list0101.pop_back(); // list should be [2 1]
111 VERIFY(list0101.size() == 2);
112 VERIFY(destructor::count() == 1);
113 VERIFY(i->id() == 1);
114 VERIFY(k->id() == 1);
115
116 list0101.pop_front(); // list should be [1]
117 VERIFY(list0101.size() == 1);
118 VERIFY(destructor::count() == 2);
119 VERIFY(i->id() == 1);
120 VERIFY(k->id() == 1);
121 }