]>
Commit | Line | Data |
---|---|---|
8d9254fc | 1 | // Copyright (C) 2011-2020 Free Software Foundation, Inc. |
77e0bf4e FD |
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 | ||
19 | #include <testsuite_hooks.h> | |
20 | ||
21 | namespace __gnu_test | |
22 | { | |
23 | template<typename _Tp> | |
24 | struct CopyableValueType | |
25 | { | |
26 | typedef _Tp value_type; | |
27 | }; | |
28 | ||
29 | template<typename _Tp1, typename _Tp2> | |
30 | struct CopyableValueType<std::pair<const _Tp1, _Tp2> > | |
31 | { | |
32 | typedef std::pair<_Tp1, _Tp2> value_type; | |
33 | }; | |
34 | ||
35 | template<typename _Tp> | |
36 | struct generate_unique | |
37 | { | |
38 | typedef _Tp value_type; | |
39 | ||
40 | value_type build() | |
41 | { | |
42 | static value_type _S_; | |
43 | ++_S_; | |
44 | return _S_; | |
45 | } | |
46 | }; | |
47 | ||
48 | template<typename _Tp1, typename _Tp2> | |
49 | struct generate_unique<std::pair<_Tp1, _Tp2> > | |
50 | { | |
51 | typedef _Tp1 first_type; | |
52 | typedef _Tp2 second_type; | |
53 | typedef std::pair<_Tp1, _Tp2> pair_type; | |
f92ab29f | 54 | |
77e0bf4e FD |
55 | pair_type build() |
56 | { | |
57 | static first_type _S_1; | |
58 | static second_type _S_2; | |
59 | ++_S_1; | |
60 | ++_S_2; | |
61 | return pair_type(_S_1, _S_2); | |
62 | } | |
63 | }; | |
64 | ||
65 | template<typename _Tp> | |
66 | struct KeyExtractor | |
67 | { | |
68 | static _Tp get_key(const _Tp& val) | |
69 | { return val; } | |
70 | }; | |
71 | ||
72 | template<typename _Tp1, typename _Tp2> | |
73 | struct KeyExtractor<std::pair<const _Tp1, _Tp2>> | |
74 | { | |
75 | static _Tp1 get_key(const std::pair<const _Tp1, _Tp2>& val) | |
76 | { return val.first; } | |
77 | }; | |
78 | ||
79 | template<typename _Tp> | |
80 | void use_erased_local_iterator() | |
81 | { | |
77e0bf4e FD |
82 | typedef _Tp cont_type; |
83 | typedef typename cont_type::value_type cont_val_type; | |
84 | typedef typename CopyableValueType<cont_val_type>::value_type val_type; | |
85 | generate_unique<val_type> gu; | |
86 | ||
87 | cont_type c; | |
88 | for (size_t i = 0; i != 5; ++i) | |
89 | c.insert(gu.build()); | |
90 | ||
91 | typename cont_type::local_iterator it, end; | |
92 | for (size_t i = 0; i != c.bucket_count(); ++i) | |
93 | { | |
94 | it = c.begin(i); | |
95 | end = c.end(i); | |
96 | if (it != end) | |
97 | break; | |
98 | } | |
99 | typename cont_type::key_type key = KeyExtractor<cont_val_type>::get_key(*it); | |
100 | c.erase(key); | |
101 | VERIFY( it != end ); | |
102 | } | |
103 | ||
104 | template<typename _Tp> | |
105 | void use_invalid_local_iterator() | |
106 | { | |
77e0bf4e FD |
107 | typedef _Tp cont_type; |
108 | typedef typename cont_type::value_type cont_val_type; | |
109 | typedef typename CopyableValueType<cont_val_type>::value_type val_type; | |
110 | generate_unique<val_type> gu; | |
111 | ||
112 | cont_type c; | |
113 | for (size_t i = 0; i != 5; ++i) | |
114 | c.insert(gu.build()); | |
115 | ||
116 | typename cont_type::local_iterator it; | |
117 | for (size_t i = 0; i != c.bucket_count(); ++i) | |
118 | { | |
119 | it = c.begin(i); | |
120 | if (it != c.end(i)) | |
121 | break; | |
122 | } | |
123 | cont_val_type val = *it; | |
124 | c.clear(); | |
125 | VERIFY( *it == val ); | |
126 | } | |
127 | ||
128 | template<typename _Tp> | |
129 | void invalid_local_iterator_compare() | |
130 | { | |
77e0bf4e FD |
131 | typedef _Tp cont_type; |
132 | typedef typename cont_type::value_type cont_val_type; | |
133 | typedef typename CopyableValueType<cont_val_type>::value_type val_type; | |
134 | generate_unique<val_type> gu; | |
135 | ||
136 | cont_type c; | |
137 | for (size_t i = 0; i != 5; ++i) | |
138 | c.insert(gu.build()); | |
139 | ||
140 | typename cont_type::local_iterator it1, it2; | |
141 | size_t i; | |
142 | for (i = 0; i != c.bucket_count(); ++i) | |
143 | { | |
144 | it1 = c.begin(i); | |
145 | if (it1 != c.end(i)) | |
146 | break; | |
147 | } | |
148 | VERIFY( i != c.bucket_count() ); | |
149 | for (++i; i != c.bucket_count(); ++i) | |
150 | { | |
151 | it2 = c.begin(i); | |
152 | if (it2 != c.end(i)) | |
153 | break; | |
154 | } | |
155 | ||
156 | VERIFY( it1 != it2 ); | |
157 | } | |
158 | ||
159 | template<typename _Tp> | |
160 | void invalid_local_iterator_range() | |
161 | { | |
77e0bf4e FD |
162 | typedef _Tp cont_type; |
163 | typedef typename cont_type::value_type cont_val_type; | |
164 | typedef typename CopyableValueType<cont_val_type>::value_type val_type; | |
165 | generate_unique<val_type> gu; | |
166 | ||
167 | cont_type c; | |
168 | for (size_t i = 0; i != 5; ++i) | |
169 | c.insert(gu.build()); | |
170 | ||
171 | typename cont_type::local_iterator it, end; | |
172 | for (size_t i = 0; i != c.bucket_count(); ++i) | |
173 | { | |
174 | it = c.begin(i); | |
175 | end = c.end(i); | |
176 | if (it != end) | |
177 | break; | |
178 | } | |
179 | c.insert(end, it); | |
180 | } | |
181 | } | |
182 |