]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | |
2 | // Copyright 2006-2009 Daniel James. | |
3 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | |
4 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
5 | ||
6 | // This test creates the containers with members that meet their minimum | |
7 | // requirements. Makes sure everything compiles and is defined correctly. | |
8 | ||
b32b8144 | 9 | // clang-format off |
7c673cae FG |
10 | #include "../helpers/prefix.hpp" |
11 | #include <boost/unordered_set.hpp> | |
12 | #include "../helpers/postfix.hpp" | |
b32b8144 | 13 | // clang-format on |
7c673cae | 14 | |
7c673cae FG |
15 | #include "../helpers/test.hpp" |
16 | #include "../objects/minimal.hpp" | |
17 | #include "./compile_tests.hpp" | |
18 | ||
19 | // Explicit instantiation to catch compile-time errors | |
20 | ||
b32b8144 FG |
21 | #define INSTANTIATE(type) \ |
22 | template class boost::unordered::detail::instantiate_##type | |
23 | ||
24 | INSTANTIATE(set)<int, boost::hash<int>, std::equal_to<int>, | |
25 | test::minimal::allocator<int> >; | |
26 | INSTANTIATE(multiset)<int const, boost::hash<int>, std::equal_to<int>, | |
27 | test::minimal::allocator<int> >; | |
28 | ||
29 | INSTANTIATE(set)<test::minimal::assignable const, | |
30 | test::minimal::hash<test::minimal::assignable>, | |
31 | test::minimal::equal_to<test::minimal::assignable>, | |
32 | test::minimal::allocator<int> >; | |
33 | INSTANTIATE(multiset)<test::minimal::assignable, | |
34 | test::minimal::hash<test::minimal::assignable>, | |
35 | test::minimal::equal_to<test::minimal::assignable>, | |
36 | test::minimal::allocator<int> >; | |
37 | ||
38 | UNORDERED_AUTO_TEST (test0) { | |
39 | test::minimal::constructor_param x; | |
40 | ||
41 | test::minimal::assignable assignable(x); | |
42 | ||
43 | BOOST_LIGHTWEIGHT_TEST_OSTREAM << "Test unordered_set.\n"; | |
44 | ||
45 | boost::unordered_set<int> int_set; | |
46 | ||
47 | boost::unordered_set<int, boost::hash<int>, std::equal_to<int>, | |
48 | test::minimal::cxx11_allocator<int> > | |
49 | int_set2; | |
50 | ||
51 | boost::unordered_set<test::minimal::assignable, | |
7c673cae FG |
52 | test::minimal::hash<test::minimal::assignable>, |
53 | test::minimal::equal_to<test::minimal::assignable>, | |
b32b8144 FG |
54 | test::minimal::allocator<test::minimal::assignable> > |
55 | set; | |
56 | ||
57 | container_test(int_set, 0); | |
58 | container_test(int_set2, 0); | |
59 | container_test(set, assignable); | |
60 | ||
61 | BOOST_LIGHTWEIGHT_TEST_OSTREAM << "Test unordered_multiset.\n"; | |
62 | ||
63 | boost::unordered_multiset<int> int_multiset; | |
64 | ||
65 | boost::unordered_multiset<int, boost::hash<int>, std::equal_to<int>, | |
66 | test::minimal::cxx11_allocator<int> > | |
67 | int_multiset2; | |
68 | ||
69 | boost::unordered_multiset<test::minimal::assignable, | |
7c673cae FG |
70 | test::minimal::hash<test::minimal::assignable>, |
71 | test::minimal::equal_to<test::minimal::assignable>, | |
b32b8144 FG |
72 | test::minimal::allocator<test::minimal::assignable> > |
73 | multiset; | |
7c673cae | 74 | |
b32b8144 FG |
75 | container_test(int_multiset, 0); |
76 | container_test(int_multiset2, 0); | |
77 | container_test(multiset, assignable); | |
78 | } | |
7c673cae | 79 | |
b32b8144 FG |
80 | UNORDERED_AUTO_TEST (equality_tests) { |
81 | typedef test::minimal::copy_constructible_equality_comparable value_type; | |
7c673cae | 82 | |
b32b8144 | 83 | boost::unordered_set<int> int_set; |
7c673cae | 84 | |
b32b8144 FG |
85 | boost::unordered_set<int, boost::hash<int>, std::equal_to<int>, |
86 | test::minimal::cxx11_allocator<int> > | |
87 | int_set2; | |
7c673cae | 88 | |
b32b8144 FG |
89 | boost::unordered_set<test::minimal::copy_constructible_equality_comparable, |
90 | test::minimal::hash<test::minimal::copy_constructible_equality_comparable>, | |
91 | test::minimal::equal_to< | |
92 | test::minimal::copy_constructible_equality_comparable>, | |
93 | test::minimal::allocator<value_type> > | |
94 | set; | |
7c673cae | 95 | |
b32b8144 FG |
96 | equality_test(int_set); |
97 | equality_test(int_set2); | |
98 | equality_test(set); | |
7c673cae | 99 | |
b32b8144 | 100 | boost::unordered_multiset<int> int_multiset; |
7c673cae | 101 | |
b32b8144 FG |
102 | boost::unordered_multiset<int, boost::hash<int>, std::equal_to<int>, |
103 | test::minimal::cxx11_allocator<int> > | |
104 | int_multiset2; | |
7c673cae | 105 | |
b32b8144 FG |
106 | boost::unordered_multiset< |
107 | test::minimal::copy_constructible_equality_comparable, | |
108 | test::minimal::hash<test::minimal::copy_constructible_equality_comparable>, | |
109 | test::minimal::equal_to< | |
110 | test::minimal::copy_constructible_equality_comparable>, | |
111 | test::minimal::allocator<value_type> > | |
112 | multiset; | |
7c673cae | 113 | |
b32b8144 FG |
114 | equality_test(int_multiset); |
115 | equality_test(int_multiset2); | |
116 | equality_test(multiset); | |
117 | } | |
7c673cae | 118 | |
b32b8144 FG |
119 | UNORDERED_AUTO_TEST (test1) { |
120 | boost::hash<int> hash; | |
121 | std::equal_to<int> equal_to; | |
122 | int value = 0; | |
7c673cae | 123 | |
b32b8144 | 124 | BOOST_LIGHTWEIGHT_TEST_OSTREAM << "Test unordered_set." << std::endl; |
7c673cae | 125 | |
b32b8144 | 126 | boost::unordered_set<int> set; |
7c673cae | 127 | |
b32b8144 FG |
128 | boost::unordered_set<int, boost::hash<int>, std::equal_to<int>, |
129 | test::minimal::cxx11_allocator<int> > | |
130 | set2; | |
7c673cae | 131 | |
b32b8144 FG |
132 | unordered_unique_test(set, value); |
133 | unordered_set_test(set, value); | |
134 | unordered_copyable_test(set, value, value, hash, equal_to); | |
7c673cae | 135 | |
b32b8144 FG |
136 | unordered_unique_test(set2, value); |
137 | unordered_set_test(set2, value); | |
138 | unordered_copyable_test(set2, value, value, hash, equal_to); | |
7c673cae | 139 | |
b32b8144 | 140 | BOOST_LIGHTWEIGHT_TEST_OSTREAM << "Test unordered_multiset." << std::endl; |
7c673cae | 141 | |
b32b8144 | 142 | boost::unordered_multiset<int> multiset; |
7c673cae | 143 | |
b32b8144 FG |
144 | boost::unordered_multiset<int, boost::hash<int>, std::equal_to<int>, |
145 | test::minimal::cxx11_allocator<int> > | |
146 | multiset2; | |
7c673cae | 147 | |
b32b8144 FG |
148 | unordered_equivalent_test(multiset, value); |
149 | unordered_set_test(multiset, value); | |
150 | unordered_copyable_test(multiset, value, value, hash, equal_to); | |
7c673cae | 151 | |
b32b8144 FG |
152 | unordered_equivalent_test(multiset2, value); |
153 | unordered_set_test(multiset2, value); | |
154 | unordered_copyable_test(multiset2, value, value, hash, equal_to); | |
7c673cae FG |
155 | } |
156 | ||
b32b8144 FG |
157 | UNORDERED_AUTO_TEST (test2) { |
158 | test::minimal::constructor_param x; | |
7c673cae | 159 | |
b32b8144 FG |
160 | test::minimal::assignable assignable(x); |
161 | test::minimal::copy_constructible copy_constructible(x); | |
162 | test::minimal::hash<test::minimal::assignable> hash(x); | |
163 | test::minimal::equal_to<test::minimal::assignable> equal_to(x); | |
164 | ||
165 | BOOST_LIGHTWEIGHT_TEST_OSTREAM << "Test unordered_set.\n"; | |
166 | ||
167 | boost::unordered_set<test::minimal::assignable, | |
168 | test::minimal::hash<test::minimal::assignable>, | |
169 | test::minimal::equal_to<test::minimal::assignable>, | |
170 | test::minimal::allocator<test::minimal::assignable> > | |
171 | set; | |
172 | ||
173 | unordered_unique_test(set, assignable); | |
174 | unordered_set_test(set, assignable); | |
175 | unordered_copyable_test(set, assignable, assignable, hash, equal_to); | |
176 | unordered_set_member_test(set, assignable); | |
177 | ||
178 | BOOST_LIGHTWEIGHT_TEST_OSTREAM << "Test unordered_multiset.\n"; | |
179 | ||
180 | boost::unordered_multiset<test::minimal::assignable, | |
181 | test::minimal::hash<test::minimal::assignable>, | |
182 | test::minimal::equal_to<test::minimal::assignable>, | |
183 | test::minimal::allocator<test::minimal::assignable> > | |
184 | multiset; | |
185 | ||
186 | unordered_equivalent_test(multiset, assignable); | |
187 | unordered_set_test(multiset, assignable); | |
188 | unordered_copyable_test(multiset, assignable, assignable, hash, equal_to); | |
189 | unordered_set_member_test(multiset, assignable); | |
7c673cae FG |
190 | } |
191 | ||
b32b8144 FG |
192 | UNORDERED_AUTO_TEST (movable1_tests) { |
193 | test::minimal::constructor_param x; | |
7c673cae | 194 | |
b32b8144 FG |
195 | test::minimal::movable1 movable1(x); |
196 | test::minimal::hash<test::minimal::movable1> hash(x); | |
197 | test::minimal::equal_to<test::minimal::movable1> equal_to(x); | |
7c673cae | 198 | |
b32b8144 | 199 | BOOST_LIGHTWEIGHT_TEST_OSTREAM << "Test unordered_set.\n"; |
7c673cae | 200 | |
b32b8144 FG |
201 | boost::unordered_set<test::minimal::movable1, |
202 | test::minimal::hash<test::minimal::movable1>, | |
203 | test::minimal::equal_to<test::minimal::movable1>, | |
204 | test::minimal::allocator<test::minimal::movable1> > | |
205 | set; | |
7c673cae | 206 | |
b32b8144 FG |
207 | // unordered_unique_test(set, movable1); |
208 | unordered_set_test(set, movable1); | |
209 | unordered_movable_test(set, movable1, movable1, hash, equal_to); | |
7c673cae | 210 | |
b32b8144 | 211 | BOOST_LIGHTWEIGHT_TEST_OSTREAM << "Test unordered_multiset.\n"; |
7c673cae | 212 | |
b32b8144 FG |
213 | boost::unordered_multiset<test::minimal::movable1, |
214 | test::minimal::hash<test::minimal::movable1>, | |
215 | test::minimal::equal_to<test::minimal::movable1>, | |
216 | test::minimal::allocator<test::minimal::movable1> > | |
217 | multiset; | |
7c673cae | 218 | |
b32b8144 FG |
219 | // unordered_equivalent_test(multiset, movable1); |
220 | unordered_set_test(multiset, movable1); | |
221 | unordered_movable_test(multiset, movable1, movable1, hash, equal_to); | |
7c673cae FG |
222 | } |
223 | ||
b32b8144 FG |
224 | UNORDERED_AUTO_TEST (movable2_tests) { |
225 | test::minimal::constructor_param x; | |
7c673cae | 226 | |
b32b8144 FG |
227 | test::minimal::movable2 movable2(x); |
228 | test::minimal::hash<test::minimal::movable2> hash(x); | |
229 | test::minimal::equal_to<test::minimal::movable2> equal_to(x); | |
7c673cae | 230 | |
b32b8144 | 231 | BOOST_LIGHTWEIGHT_TEST_OSTREAM << "Test unordered_set.\n"; |
7c673cae | 232 | |
b32b8144 FG |
233 | boost::unordered_set<test::minimal::movable2, |
234 | test::minimal::hash<test::minimal::movable2>, | |
235 | test::minimal::equal_to<test::minimal::movable2>, | |
236 | test::minimal::allocator<test::minimal::movable2> > | |
237 | set; | |
7c673cae | 238 | |
b32b8144 FG |
239 | // unordered_unique_test(set, movable2); |
240 | unordered_set_test(set, movable2); | |
241 | unordered_movable_test(set, movable2, movable2, hash, equal_to); | |
7c673cae | 242 | |
b32b8144 | 243 | BOOST_LIGHTWEIGHT_TEST_OSTREAM << "Test unordered_multiset.\n"; |
7c673cae | 244 | |
b32b8144 FG |
245 | boost::unordered_multiset<test::minimal::movable2, |
246 | test::minimal::hash<test::minimal::movable2>, | |
247 | test::minimal::equal_to<test::minimal::movable2>, | |
248 | test::minimal::allocator<test::minimal::movable2> > | |
249 | multiset; | |
7c673cae | 250 | |
b32b8144 FG |
251 | // unordered_equivalent_test(multiset, movable2); |
252 | unordered_set_test(multiset, movable2); | |
253 | unordered_movable_test(multiset, movable2, movable2, hash, equal_to); | |
7c673cae FG |
254 | } |
255 | ||
b32b8144 FG |
256 | UNORDERED_AUTO_TEST (destructible_tests) { |
257 | test::minimal::constructor_param x; | |
7c673cae | 258 | |
b32b8144 FG |
259 | test::minimal::destructible destructible(x); |
260 | test::minimal::hash<test::minimal::destructible> hash(x); | |
261 | test::minimal::equal_to<test::minimal::destructible> equal_to(x); | |
7c673cae | 262 | |
b32b8144 | 263 | BOOST_LIGHTWEIGHT_TEST_OSTREAM << "Test unordered_set.\n"; |
7c673cae | 264 | |
b32b8144 FG |
265 | boost::unordered_set<test::minimal::destructible, |
266 | test::minimal::hash<test::minimal::destructible>, | |
267 | test::minimal::equal_to<test::minimal::destructible> > | |
268 | set; | |
7c673cae | 269 | |
b32b8144 FG |
270 | unordered_destructible_test(set); |
271 | ||
272 | BOOST_LIGHTWEIGHT_TEST_OSTREAM << "Test unordered_multiset.\n"; | |
273 | ||
274 | boost::unordered_multiset<test::minimal::destructible, | |
275 | test::minimal::hash<test::minimal::destructible>, | |
276 | test::minimal::equal_to<test::minimal::destructible> > | |
277 | multiset; | |
278 | ||
279 | unordered_destructible_test(multiset); | |
280 | } | |
281 | ||
282 | // Test for ambiguity when using key convertible from iterator | |
283 | // See LWG2059 | |
284 | ||
285 | struct lwg2059_key | |
286 | { | |
287 | int value; | |
288 | ||
289 | template <typename T> lwg2059_key(T v) : value(v) {} | |
290 | }; | |
291 | ||
292 | std::size_t hash_value(lwg2059_key x) | |
293 | { | |
294 | return static_cast<std::size_t>(x.value); | |
295 | } | |
7c673cae | 296 | |
b32b8144 | 297 | bool operator==(lwg2059_key x, lwg2059_key y) { return x.value == y.value; } |
7c673cae | 298 | |
b32b8144 FG |
299 | UNORDERED_AUTO_TEST (lwg2059) { |
300 | { | |
301 | boost::unordered_set<lwg2059_key> x; | |
302 | x.emplace(lwg2059_key(10)); | |
303 | x.erase(x.begin()); | |
304 | } | |
7c673cae | 305 | |
b32b8144 FG |
306 | { |
307 | boost::unordered_multiset<lwg2059_key> x; | |
308 | x.emplace(lwg2059_key(10)); | |
309 | x.erase(x.begin()); | |
310 | } | |
7c673cae FG |
311 | } |
312 | ||
313 | RUN_TESTS() |