1 | //////////////////////////////////////// |
2 | // |
3 | // (C) Copyright Ion Gaztanaga 2006. Distributed under the Boost |
4 | // Software License, Version 1.0. (See accompanying file |
5 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
6 | // |
7 | // See http://www.boost.org/libs/container for documentation. |
8 | // |
9 | //////////////////////////////////////// |
10 | |
11 | #ifndef BOOST_CONTAINER_TEST_MAP_TEST_HEADER |
12 | #define |
13 | |
14 | #include <boost/container/detail/config_begin.hpp> |
15 | #include "check_equal_containers.hpp" |
16 | #include "print_container.hpp" |
17 | #include "movable_int.hpp" |
18 | #include <boost/container/detail/pair.hpp> |
19 | #include <boost/move/iterator.hpp> |
20 | #include <boost/move/utility_core.hpp> |
21 | #include <boost/move/make_unique.hpp> |
22 | |
23 | #include <boost/intrusive/detail/minimal_pair_header.hpp> //pair |
24 | #include <string> |
25 | #include <iostream> |
26 | |
27 | #include <boost/intrusive/detail/mpl.hpp> |
28 | |
29 | namespace boost { namespace container { namespace test { |
30 | |
31 | BOOST_INTRUSIVE_HAS_MEMBER_FUNC_CALLED(has_member_rebalance, rebalance) |
32 | |
33 | }}} |
34 | |
35 | const int MaxElem = 50; |
36 | |
37 | template<class T1, class T2, class T3, class T4> |
38 | bool operator ==(std::pair<T1, T2> &p1, std::pair<T1, T2> &p2) |
39 | { |
40 | return p1.first == p2.first && p1.second == p2.second; |
41 | } |
42 | |
43 | namespace boost{ |
44 | namespace container { |
45 | namespace test{ |
46 | |
47 | template<class C> |
48 | void map_test_rebalanceable(C &, boost::container::dtl::false_type) |
49 | {} |
50 | |
51 | template<class C> |
52 | void map_test_rebalanceable(C &c, boost::container::dtl::true_type) |
53 | { |
54 | c.rebalance(); |
55 | } |
56 | |
57 | template<class MyBoostMap |
58 | ,class MyStdMap |
59 | ,class MyBoostMultiMap |
60 | ,class MyStdMultiMap> |
61 | int map_test_copyable(boost::container::dtl::false_type) |
62 | { return 0; } |
63 | |
64 | template<class MyBoostMap |
65 | ,class MyStdMap |
66 | ,class MyBoostMultiMap |
67 | ,class MyStdMultiMap> |
68 | int map_test_copyable(boost::container::dtl::true_type) |
69 | { |
70 | typedef typename MyBoostMap::key_type IntType; |
71 | typedef dtl::pair<IntType, IntType> IntPairType; |
72 | typedef typename MyStdMap::value_type StdPairType; |
73 | |
74 | ::boost::movelib::unique_ptr<MyBoostMap> const pboostmap = ::boost::movelib::make_unique<MyBoostMap>(); |
75 | ::boost::movelib::unique_ptr<MyStdMap> const pstdmap = ::boost::movelib::make_unique<MyStdMap>(); |
76 | ::boost::movelib::unique_ptr<MyBoostMultiMap> const pboostmultimap = ::boost::movelib::make_unique<MyBoostMultiMap>(); |
77 | ::boost::movelib::unique_ptr<MyStdMultiMap> const pstdmultimap = ::boost::movelib::make_unique<MyStdMultiMap>(); |
78 | MyBoostMap &boostmap = *pboostmap; |
79 | MyStdMap &stdmap = *pstdmap; |
80 | MyBoostMultiMap &boostmultimap = *pboostmultimap; |
81 | MyStdMultiMap &stdmultimap = *pstdmultimap; |
82 | |
83 | //Just to test move aware catch conversions |
84 | boostmap.insert(boostmap.cbegin(), boostmap.cend()); |
85 | boostmultimap.insert(boostmultimap.cbegin(), boostmultimap.cend()); |
86 | boostmap.insert(boostmap.begin(), boostmap.end()); |
87 | boostmultimap.insert(boostmultimap.begin(), boostmultimap.end()); |
88 | |
89 | int i; |
90 | for(i = 0; i < MaxElem; ++i){ |
91 | { |
92 | IntType i1(i), i2(i); |
93 | IntPairType intpair1(boost::move(i1), boost::move(i2)); |
94 | boostmap.insert(boost::move(intpair1)); |
95 | stdmap.insert(StdPairType(i, i)); |
96 | } |
97 | { |
98 | IntType i1(i), i2(i); |
99 | IntPairType intpair2(boost::move(i1), boost::move(i2)); |
100 | boostmultimap.insert(boost::move(intpair2)); |
101 | stdmultimap.insert(StdPairType(i, i)); |
102 | } |
103 | } |
104 | if(!CheckEqualContainers(boostmap, stdmap)) return 1; |
105 | if(!CheckEqualContainers(boostmultimap, stdmultimap)) return 1; |
106 | |
107 | boostmap.clear(); |
108 | boostmap.clear(); |
109 | boostmultimap.clear(); |
110 | stdmultimap.clear(); |
111 | |
112 | //Now try from convertible pair |
113 | for(i = 0; i < MaxElem; ++i){ |
114 | { |
115 | boostmap.insert(std::pair<signed short, signed short>((signed short)i, (signed short)i)); |
116 | stdmap.insert(StdPairType(i, i)); |
117 | } |
118 | { |
119 | boostmultimap.insert(std::pair<signed short, signed short>((signed short)i, (signed short)i)); |
120 | stdmultimap.insert(StdPairType(i, i)); |
121 | } |
122 | } |
123 | |
124 | if(!CheckEqualContainers(boostmap, stdmap)) return 1; |
125 | if(!CheckEqualContainers(boostmultimap, stdmultimap)) return 1; |
126 | |
127 | #if !defined BOOST_NO_CXX11_HDR_INITIALIZER_LIST |
128 | boostmap.clear(); |
129 | boostmap.clear(); |
130 | boostmultimap.clear(); |
131 | stdmultimap.clear(); |
132 | //Now try from convertible pair |
133 | for(i = 0; i < MaxElem; ++i){ |
134 | { |
135 | boostmap.insert({IntType(i), IntType(i)}); |
136 | stdmap.insert(StdPairType(i, i)); |
137 | } |
138 | { |
139 | boostmultimap.insert({IntType(i), IntType(i)}); |
140 | stdmultimap.insert(StdPairType(i, i)); |
141 | } |
142 | } |
143 | if(!CheckEqualContainers(boostmap, stdmap)) return 1; |
144 | if(!CheckEqualContainers(boostmultimap, stdmultimap)) return 1; |
145 | #endif //BOOST_NO_CXX11_HDR_INITIALIZER_LIST |
146 | { |
147 | //Now, test copy constructor |
148 | MyBoostMap boostmapcopy(boostmap); |
149 | MyStdMap stdmapcopy(stdmap); |
150 | MyBoostMultiMap boostmmapcopy(boostmultimap); |
151 | MyStdMultiMap stdmmapcopy(stdmultimap); |
152 | |
153 | if(!CheckEqualContainers(boostmapcopy, stdmapcopy)) |
154 | return 1; |
155 | if(!CheckEqualContainers(boostmmapcopy, stdmmapcopy)) |
156 | return 1; |
157 | |
158 | //And now assignment |
159 | boostmapcopy = boostmap; |
160 | stdmapcopy = stdmap; |
161 | boostmmapcopy = boostmultimap; |
162 | stdmmapcopy = stdmultimap; |
163 | |
164 | if(!CheckEqualContainers(boostmapcopy, stdmapcopy)) |
165 | return 1; |
166 | if(!CheckEqualContainers(boostmmapcopy, stdmmapcopy)) |
167 | return 1; |
168 | } |
169 | |
170 | return 0; |
171 | } |
172 | |
173 | template<class MyBoostMap |
174 | ,class MyStdMap |
175 | ,class MyBoostMultiMap |
176 | ,class MyStdMultiMap> |
177 | int map_test_range() |
178 | { |
179 | typedef typename MyBoostMap::key_type IntType; |
180 | typedef dtl::pair<IntType, IntType> IntPairType; |
181 | typedef typename MyStdMap::value_type StdValueType; |
182 | typedef typename MyStdMap::key_type StdKeyType; |
183 | typedef typename MyStdMap::mapped_type StdMappedType; |
184 | |
185 | //Test construction from a range |
186 | { |
187 | IntPairType aux_vect[(std::size_t)MaxElem]; |
188 | for(int i = 0; i < MaxElem; ++i){ |
189 | IntType i1(i/2); |
190 | IntType i2(i/2); |
191 | new(&aux_vect[i])IntPairType(boost::move(i1), boost::move(i2)); |
192 | } |
193 | |
194 | StdValueType aux_vect2[(std::size_t)MaxElem]; |
195 | for(int i = 0; i < MaxElem; ++i){ |
196 | new(&aux_vect2[i])StdValueType(StdKeyType(i/2), StdMappedType(i/2)); |
197 | } |
198 | |
199 | IntPairType aux_vect3[(std::size_t)MaxElem]; |
200 | for(int i = 0; i < MaxElem; ++i){ |
201 | IntType i1(i/2); |
202 | IntType i2(i/2); |
203 | new(&aux_vect3[i])IntPairType(boost::move(i1), boost::move(i2)); |
204 | } |
205 | |
206 | ::boost::movelib::unique_ptr<MyBoostMap> const pboostmap = ::boost::movelib::make_unique<MyBoostMap> |
207 | ( boost::make_move_iterator(&aux_vect[0]) |
208 | , boost::make_move_iterator(&aux_vect[0] + MaxElem), typename MyBoostMap::key_compare()); |
209 | ::boost::movelib::unique_ptr<MyStdMap> const pstdmap = ::boost::movelib::make_unique<MyStdMap> |
210 | (&aux_vect2[0], &aux_vect2[0] + MaxElem, typename MyStdMap::key_compare()); |
211 | if(!CheckEqualContainers(*pboostmap, *pstdmap)) return 1; |
212 | |
213 | ::boost::movelib::unique_ptr<MyBoostMultiMap> const pboostmultimap = ::boost::movelib::make_unique<MyBoostMultiMap> |
214 | ( boost::make_move_iterator(&aux_vect3[0]) |
215 | , boost::make_move_iterator(&aux_vect3[0] + MaxElem), typename MyBoostMap::key_compare()); |
216 | ::boost::movelib::unique_ptr<MyStdMultiMap> const pstdmultimap = ::boost::movelib::make_unique<MyStdMultiMap> |
217 | (&aux_vect2[0], &aux_vect2[0] + MaxElem, typename MyStdMap::key_compare()); |
218 | if(!CheckEqualContainers(*pboostmultimap, *pstdmultimap)) return 1; |
219 | } |
220 | { |
221 | IntPairType aux_vect[(std::size_t)MaxElem]; |
222 | for(int i = 0; i < MaxElem; ++i){ |
223 | IntType i1(i/2); |
224 | IntType i2(i/2); |
225 | new(&aux_vect[i])IntPairType(boost::move(i1), boost::move(i2)); |
226 | } |
227 | |
228 | StdValueType aux_vect2[(std::size_t)MaxElem]; |
229 | for(int i = 0; i < MaxElem; ++i){ |
230 | new(&aux_vect2[i])StdValueType(StdKeyType(i/2), StdMappedType(i/2)); |
231 | } |
232 | |
233 | IntPairType aux_vect3[(std::size_t)MaxElem]; |
234 | for(int i = 0; i < MaxElem; ++i){ |
235 | IntType i1(i/2); |
236 | IntType i2(i/2); |
237 | new(&aux_vect3[i])IntPairType(boost::move(i1), boost::move(i2)); |
238 | } |
239 | |
240 | ::boost::movelib::unique_ptr<MyBoostMap> const pboostmap = ::boost::movelib::make_unique<MyBoostMap> |
241 | ( boost::make_move_iterator(&aux_vect[0]) |
242 | , boost::make_move_iterator(&aux_vect[0] + MaxElem), typename MyBoostMap::allocator_type()); |
243 | ::boost::movelib::unique_ptr<MyStdMap> const pstdmap = ::boost::movelib::make_unique<MyStdMap> |
244 | (&aux_vect2[0], &aux_vect2[0] + MaxElem, typename MyStdMap::key_compare()); |
245 | if(!CheckEqualContainers(*pboostmap, *pstdmap)) return 1; |
246 | |
247 | ::boost::movelib::unique_ptr<MyBoostMultiMap> const pboostmultimap = ::boost::movelib::make_unique<MyBoostMultiMap> |
248 | ( boost::make_move_iterator(&aux_vect3[0]) |
249 | , boost::make_move_iterator(&aux_vect3[0] + MaxElem), typename MyBoostMap::allocator_type()); |
250 | ::boost::movelib::unique_ptr<MyStdMultiMap> const pstdmultimap = ::boost::movelib::make_unique<MyStdMultiMap> |
251 | (&aux_vect2[0], &aux_vect2[0] + MaxElem, typename MyStdMap::key_compare()); |
252 | if(!CheckEqualContainers(*pboostmultimap, *pstdmultimap)) return 1; |
253 | } |
254 | return 0; |
255 | } |
256 | |
257 | |
258 | template<class MyBoostMap |
259 | ,class MyStdMap |
260 | ,class MyBoostMultiMap |
261 | ,class MyStdMultiMap> |
262 | int map_test_step(MyBoostMap &, MyStdMap &, MyBoostMultiMap &, MyStdMultiMap &) |
263 | { |
264 | typedef typename MyBoostMap::key_type IntType; |
265 | typedef dtl::pair<IntType, IntType> IntPairType; |
266 | |
267 | { |
268 | //This is really nasty, but we have no other simple choice |
269 | IntPairType aux_vect[(std::size_t)MaxElem]; |
270 | for(int i = 0; i < MaxElem; ++i){ |
271 | IntType i1(i/2); |
272 | IntType i2(i/2); |
273 | new(&aux_vect[i])IntPairType(boost::move(i1), boost::move(i2)); |
274 | } |
275 | |
276 | typedef typename MyStdMap::value_type StdValueType; |
277 | typedef typename MyStdMap::key_type StdKeyType; |
278 | typedef typename MyStdMap::mapped_type StdMappedType; |
279 | StdValueType aux_vect2[(std::size_t)MaxElem]; |
280 | for(int i = 0; i < MaxElem; ++i){ |
281 | new(&aux_vect2[i])StdValueType(StdKeyType(i/2), StdMappedType(i/2)); |
282 | } |
283 | |
284 | IntPairType aux_vect3[(std::size_t)MaxElem]; |
285 | for(int i = 0; i < MaxElem; ++i){ |
286 | IntType i1(i/2); |
287 | IntType i2(i/2); |
288 | new(&aux_vect3[i])IntPairType(boost::move(i1), boost::move(i2)); |
289 | } |
290 | |
291 | ::boost::movelib::unique_ptr<MyBoostMap> const pboostmap2 = ::boost::movelib::make_unique<MyBoostMap> |
292 | ( boost::make_move_iterator(&aux_vect[0]) |
293 | , boost::make_move_iterator(&aux_vect[0] + MaxElem)); |
294 | ::boost::movelib::unique_ptr<MyStdMap> const pstdmap2 = ::boost::movelib::make_unique<MyStdMap> |
295 | (&aux_vect2[0], &aux_vect2[0] + MaxElem); |
296 | ::boost::movelib::unique_ptr<MyBoostMultiMap> const pboostmultimap2 = ::boost::movelib::make_unique<MyBoostMultiMap> |
297 | ( boost::make_move_iterator(&aux_vect3[0]) |
298 | , boost::make_move_iterator(&aux_vect3[0] + MaxElem)); |
299 | ::boost::movelib::unique_ptr<MyStdMultiMap> const pstdmultimap2 = ::boost::movelib::make_unique<MyStdMultiMap> |
300 | (&aux_vect2[0], &aux_vect2[0] + MaxElem); |
301 | MyBoostMap &boostmap2 = *pboostmap2; |
302 | MyStdMap &stdmap2 = *pstdmap2; |
303 | MyBoostMultiMap &boostmultimap2 = *pboostmultimap2; |
304 | MyStdMultiMap &stdmultimap2 = *pstdmultimap2; |
305 | |
306 | if(!CheckEqualContainers(boostmap2, stdmap2)) return 1; |
307 | if(!CheckEqualContainers(boostmultimap2, stdmultimap2)) return 1; |
308 | |
309 | |
310 | |
311 | //ordered range insertion |
312 | //This is really nasty, but we have no other simple choice |
313 | for(int i = 0; i < MaxElem; ++i){ |
314 | IntType i1(i); |
315 | IntType i2(i); |
316 | new(&aux_vect[i])IntPairType(boost::move(i1), boost::move(i2)); |
317 | } |
318 | |
319 | for(int i = 0; i < MaxElem; ++i){ |
320 | new(&aux_vect2[i])StdValueType(StdKeyType(i), StdMappedType(i)); |
321 | } |
322 | |
323 | for(int i = 0; i < MaxElem; ++i){ |
324 | IntType i1(i); |
325 | IntType i2(i); |
326 | new(&aux_vect3[i])IntPairType(boost::move(i1), boost::move(i2)); |
327 | } |
328 | if(!CheckEqualContainers(boostmap2, stdmap2)) return 1; |
329 | if(!CheckEqualContainers(boostmultimap2, stdmultimap2)) return 1; |
330 | |
331 | //some comparison operators |
332 | if(!(boostmap2 == boostmap2)) |
333 | return 1; |
334 | if(boostmap2 != boostmap2) |
335 | return 1; |
336 | if(boostmap2 < boostmap2) |
337 | return 1; |
338 | if(boostmap2 > boostmap2) |
339 | return 1; |
340 | if(!(boostmap2 <= boostmap2)) |
341 | return 1; |
342 | if(!(boostmap2 >= boostmap2)) |
343 | return 1; |
344 | |
345 | ::boost::movelib::unique_ptr<MyBoostMap> const pboostmap3 = ::boost::movelib::make_unique<MyBoostMap> |
346 | ( boost::make_move_iterator(&aux_vect[0]) |
347 | , boost::make_move_iterator(&aux_vect[0] + MaxElem)); |
348 | ::boost::movelib::unique_ptr<MyStdMap> const pstdmap3 = ::boost::movelib::make_unique<MyStdMap> |
349 | (&aux_vect2[0], &aux_vect2[0] + MaxElem); |
350 | ::boost::movelib::unique_ptr<MyBoostMultiMap> const pboostmultimap3 = ::boost::movelib::make_unique<MyBoostMultiMap> |
351 | ( boost::make_move_iterator(&aux_vect3[0]) |
352 | , boost::make_move_iterator(&aux_vect3[0] + MaxElem)); |
353 | ::boost::movelib::unique_ptr<MyStdMultiMap> const pstdmultimap3 = ::boost::movelib::make_unique<MyStdMultiMap> |
354 | (&aux_vect2[0], &aux_vect2[0] + MaxElem); |
355 | MyBoostMap &boostmap3 = *pboostmap3; |
356 | MyStdMap &stdmap3 = *pstdmap3; |
357 | MyBoostMultiMap &boostmultimap3 = *pboostmultimap3; |
358 | MyStdMultiMap &stdmultimap3 = *pstdmultimap3; |
359 | |
360 | if(!CheckEqualContainers(boostmap3, stdmap3)){ |
361 | std::cout << "Error in construct<MyBoostMap>(MyBoostMap3)" << std::endl; |
362 | return 1; |
363 | } |
364 | if(!CheckEqualContainers(boostmultimap3, stdmultimap3)){ |
365 | std::cout << "Error in construct<MyBoostMultiMap>(MyBoostMultiMap3)" << std::endl; |
366 | return 1; |
367 | } |
368 | |
369 | { |
370 | IntType i0(0); |
371 | boostmap2.erase(i0); |
372 | boostmultimap2.erase(i0); |
373 | stdmap2.erase(0); |
374 | stdmultimap2.erase(0); |
375 | } |
376 | { |
377 | IntType i0(0); |
378 | IntType i1(1); |
379 | boostmap2[::boost::move(i0)] = ::boost::move(i1); |
380 | } |
381 | { |
382 | IntType i1(1); |
383 | boostmap2[IntType(0)] = ::boost::move(i1); |
384 | } |
385 | stdmap2[0] = 1; |
386 | if(!CheckEqualContainers(boostmap2, stdmap2)) return 1; |
387 | } |
388 | return 0; |
389 | } |
390 | |
391 | template<class MyBoostMap |
392 | , class MyStdMap |
393 | , class MyBoostMultiMap |
394 | , class MyStdMultiMap> |
395 | int map_test_insert(MyBoostMap &boostmap, MyStdMap &stdmap, MyBoostMultiMap &boostmultimap, MyStdMultiMap &stdmultimap) |
396 | { |
397 | typedef typename MyBoostMap::key_type IntType; |
398 | typedef dtl::pair<IntType, IntType> IntPairType; |
399 | typedef typename MyStdMap::value_type StdPairType; |
400 | |
401 | { |
402 | //This is really nasty, but we have no other simple choice |
403 | IntPairType aux_vect[(std::size_t)MaxElem]; |
404 | for(int i = 0; i < MaxElem; ++i){ |
405 | IntType i1(i); |
406 | IntType i2(i); |
407 | new(&aux_vect[i])IntPairType(boost::move(i1), boost::move(i2)); |
408 | } |
409 | IntPairType aux_vect3[(std::size_t)MaxElem]; |
410 | for(int i = 0; i < MaxElem; ++i){ |
411 | IntType i1(i); |
412 | IntType i2(i); |
413 | new(&aux_vect3[i])IntPairType(boost::move(i1), boost::move(i2)); |
414 | } |
415 | |
416 | for(int i = 0; i < MaxElem; ++i){ |
417 | boostmap.insert(boost::move(aux_vect[i])); |
418 | stdmap.insert(StdPairType(i, i)); |
419 | boostmultimap.insert(boost::move(aux_vect3[i])); |
420 | stdmultimap.insert(StdPairType(i, i)); |
421 | } |
422 | |
423 | if(!CheckEqualPairContainers(boostmap, stdmap)) return 1; |
424 | if(!CheckEqualPairContainers(boostmultimap, stdmultimap)) return 1; |
425 | |
426 | typename MyBoostMap::iterator it = boostmap.begin(); |
427 | typename MyBoostMap::const_iterator cit = it; |
428 | (void)cit; |
429 | |
430 | boostmap.erase(boostmap.begin()); |
431 | stdmap.erase(stdmap.begin()); |
432 | boostmultimap.erase(boostmultimap.begin()); |
433 | stdmultimap.erase(stdmultimap.begin()); |
434 | if(!CheckEqualPairContainers(boostmap, stdmap)) return 1; |
435 | if(!CheckEqualPairContainers(boostmultimap, stdmultimap)) return 1; |
436 | |
437 | boostmap.erase(boostmap.begin()); |
438 | stdmap.erase(stdmap.begin()); |
439 | boostmultimap.erase(boostmultimap.begin()); |
440 | stdmultimap.erase(stdmultimap.begin()); |
441 | if(!CheckEqualPairContainers(boostmap, stdmap)) return 1; |
442 | if(!CheckEqualPairContainers(boostmultimap, stdmultimap)) return 1; |
443 | |
444 | { |
445 | //Swapping test |
446 | MyBoostMap tmpboostemap2; |
447 | MyStdMap tmpstdmap2; |
448 | MyBoostMultiMap tmpboostemultimap2; |
449 | MyStdMultiMap tmpstdmultimap2; |
450 | boostmap.swap(tmpboostemap2); |
451 | stdmap.swap(tmpstdmap2); |
452 | boostmultimap.swap(tmpboostemultimap2); |
453 | stdmultimap.swap(tmpstdmultimap2); |
454 | boostmap.swap(tmpboostemap2); |
455 | stdmap.swap(tmpstdmap2); |
456 | boostmultimap.swap(tmpboostemultimap2); |
457 | stdmultimap.swap(tmpstdmultimap2); |
458 | if(!CheckEqualPairContainers(boostmap, stdmap)) return 1; |
459 | if(!CheckEqualPairContainers(boostmultimap, stdmultimap)) return 1; |
460 | } |
461 | |
462 | //move constructor/assignment |
463 | { |
464 | MyBoostMap tmpboostemap2(boost::move(boostmap)); |
465 | if(!CheckEqualContainers(tmpboostemap2, stdmap)){ |
466 | std::cout << "Error in boostmap move constructor" << std::endl; |
467 | return 1; |
468 | } |
469 | MyBoostMultiMap tmpboostemultimap2(boost::move(boostmultimap)); |
470 | if(!CheckEqualContainers(tmpboostemultimap2, stdmultimap)){ |
471 | std::cout << "Error in boostmultimap move constructor" << std::endl; |
472 | return 1; |
473 | } |
474 | |
475 | boostmap = boost::move(tmpboostemap2); |
476 | if(!CheckEqualContainers(boostmap, stdmap)){ |
477 | std::cout << "Error in boostmap move assignment" << std::endl; |
478 | return 1; |
479 | } |
480 | boostmultimap = boost::move(tmpboostemultimap2); |
481 | if(!CheckEqualContainers(boostmultimap, stdmultimap)){ |
482 | std::cout << "Error in boostmultimap move assignment" << std::endl; |
483 | return 1; |
484 | } |
485 | } |
486 | } |
487 | return 0; |
488 | } |
489 | |
490 | template<class MyBoostMap |
491 | , class MyStdMap |
492 | , class MyBoostMultiMap |
493 | , class MyStdMultiMap> |
494 | int map_test_erase(MyBoostMap &boostmap, MyStdMap &stdmap, MyBoostMultiMap &boostmultimap, MyStdMultiMap &stdmultimap) |
495 | { |
496 | typedef typename MyBoostMap::key_type IntType; |
497 | typedef dtl::pair<IntType, IntType> IntPairType; |
498 | typedef typename MyStdMap::value_type StdPairType; |
499 | |
500 | //Insertion from other container |
501 | //Initialize values |
502 | { |
503 | //This is really nasty, but we have no other simple choice |
504 | IntPairType aux_vect[(std::size_t)MaxElem]; |
505 | for(int i = 0; i < MaxElem; ++i){ |
506 | IntType i1(-1); |
507 | IntType i2(-1); |
508 | new(&aux_vect[i])IntPairType(boost::move(i1), boost::move(i2)); |
509 | } |
510 | IntPairType aux_vect3[(std::size_t)MaxElem]; |
511 | for(int i = 0; i < MaxElem; ++i){ |
512 | IntType i1(-1); |
513 | IntType i2(-1); |
514 | new(&aux_vect3[i])IntPairType(boost::move(i1), boost::move(i2)); |
515 | } |
516 | |
517 | boostmap.insert(boost::make_move_iterator(&aux_vect[0]), boost::make_move_iterator(&aux_vect[0] + MaxElem)); |
518 | boostmultimap.insert(boost::make_move_iterator(&aux_vect3[0]), boost::make_move_iterator(&aux_vect3[0] + MaxElem)); |
519 | for(int i = 0; i != MaxElem; ++i){ |
520 | StdPairType stdpairtype(-1, -1); |
521 | stdmap.insert(stdpairtype); |
522 | stdmultimap.insert(stdpairtype); |
523 | } |
524 | if(!CheckEqualPairContainers(boostmap, stdmap)) return 1; |
525 | if(!CheckEqualPairContainers(boostmultimap, stdmultimap)) return 1; |
526 | |
527 | for(int i = 0, j = static_cast<int>(boostmap.size()); i < j; ++i){ |
528 | IntType k(i); |
529 | boostmap.erase(k); |
530 | stdmap.erase(i); |
531 | boostmultimap.erase(k); |
532 | stdmultimap.erase(i); |
533 | } |
534 | if(!CheckEqualPairContainers(boostmap, stdmap)) return 1; |
535 | if(!CheckEqualPairContainers(boostmultimap, stdmultimap)) return 1; |
536 | } |
537 | { |
538 | IntPairType aux_vect[(std::size_t)MaxElem]; |
539 | for(int i = 0; i < MaxElem; ++i){ |
540 | IntType i1(-1); |
541 | IntType i2(-1); |
542 | new(&aux_vect[i])IntPairType(boost::move(i1), boost::move(i2)); |
543 | } |
544 | |
545 | IntPairType aux_vect3[(std::size_t)MaxElem]; |
546 | for(int i = 0; i < MaxElem; ++i){ |
547 | IntType i1(-1); |
548 | IntType i2(-1); |
549 | new(&aux_vect3[i])IntPairType(boost::move(i1), boost::move(i2)); |
550 | } |
551 | |
552 | IntPairType aux_vect4[(std::size_t)MaxElem]; |
553 | for(int i = 0; i < MaxElem; ++i){ |
554 | IntType i1(-1); |
555 | IntType i2(-1); |
556 | new(&aux_vect4[i])IntPairType(boost::move(i1), boost::move(i2)); |
557 | } |
558 | |
559 | IntPairType aux_vect5[(std::size_t)MaxElem]; |
560 | for(int i = 0; i < MaxElem; ++i){ |
561 | IntType i1(-1); |
562 | IntType i2(-1); |
563 | new(&aux_vect5[i])IntPairType(boost::move(i1), boost::move(i2)); |
564 | } |
565 | |
566 | boostmap.insert(boost::make_move_iterator(&aux_vect[0]), boost::make_move_iterator(&aux_vect[0] + MaxElem)); |
567 | boostmap.insert(boost::make_move_iterator(&aux_vect3[0]), boost::make_move_iterator(&aux_vect3[0] + MaxElem)); |
568 | boostmultimap.insert(boost::make_move_iterator(&aux_vect4[0]), boost::make_move_iterator(aux_vect4 + MaxElem)); |
569 | boostmultimap.insert(boost::make_move_iterator(&aux_vect5[0]), boost::make_move_iterator(aux_vect5 + MaxElem)); |
570 | |
571 | for(int i = 0; i != MaxElem; ++i){ |
572 | StdPairType stdpairtype(-1, -1); |
573 | stdmap.insert(stdpairtype); |
574 | stdmultimap.insert(stdpairtype); |
575 | stdmap.insert(stdpairtype); |
576 | stdmultimap.insert(stdpairtype); |
577 | } |
578 | if(!CheckEqualPairContainers(boostmap, stdmap)) return 1; |
579 | if(!CheckEqualPairContainers(boostmultimap, stdmultimap)) return 1; |
580 | |
581 | boostmap.erase(boostmap.begin()->first); |
582 | stdmap.erase(stdmap.begin()->first); |
583 | boostmultimap.erase(boostmultimap.begin()->first); |
584 | stdmultimap.erase(stdmultimap.begin()->first); |
585 | if(!CheckEqualPairContainers(boostmap, stdmap)) return 1; |
586 | if(!CheckEqualPairContainers(boostmultimap, stdmultimap)) return 1; |
587 | } |
588 | return 0; |
589 | } |
590 | |
591 | template<class MyBoostMap |
592 | , class MyStdMap |
593 | , class MyBoostMultiMap |
594 | , class MyStdMultiMap> |
595 | int map_test_insert2(MyBoostMap &boostmap, MyStdMap &stdmap, MyBoostMultiMap &boostmultimap, MyStdMultiMap &stdmultimap) |
596 | { |
597 | typedef typename MyBoostMap::key_type IntType; |
598 | typedef dtl::pair<IntType, IntType> IntPairType; |
599 | typedef typename MyStdMap::value_type StdPairType; |
600 | |
601 | //This is really nasty, but we have no other simple choice |
602 | IntPairType aux_vect[(std::size_t)MaxElem]; |
603 | for(int i = 0; i < MaxElem; ++i){ |
604 | IntType i1(i); |
605 | IntType i2(i); |
606 | new(&aux_vect[i])IntPairType(boost::move(i1), boost::move(i2)); |
607 | } |
608 | IntPairType aux_vect3[(std::size_t)MaxElem]; |
609 | for(int i = 0; i < MaxElem; ++i){ |
610 | IntType i1(i); |
611 | IntType i2(i); |
612 | new(&aux_vect3[i])IntPairType(boost::move(i1), boost::move(i2)); |
613 | } |
614 | |
615 | for(int i = 0; i < MaxElem; ++i){ |
616 | boostmap.insert(boost::move(aux_vect[i])); |
617 | stdmap.insert(StdPairType(i, i)); |
618 | boostmultimap.insert(boost::move(aux_vect3[i])); |
619 | stdmultimap.insert(StdPairType(i, i)); |
620 | } |
621 | |
622 | if(!CheckEqualPairContainers(boostmap, stdmap)) return 1; |
623 | if(!CheckEqualPairContainers(boostmultimap, stdmultimap)) return 1; |
624 | |
625 | for(int i = 0; i < MaxElem; ++i){ |
626 | IntPairType intpair; |
627 | { |
628 | IntType i1(i); |
629 | IntType i2(i); |
630 | new(&intpair)IntPairType(boost::move(i1), boost::move(i2)); |
631 | } |
632 | boostmap.insert(boostmap.begin(), boost::move(intpair)); |
633 | stdmap.insert(stdmap.begin(), StdPairType(i, i)); |
634 | //PrintContainers(boostmap, stdmap); |
635 | { |
636 | IntType i1(i); |
637 | IntType i2(i); |
638 | new(&intpair)IntPairType(boost::move(i1), boost::move(i2)); |
639 | } |
640 | boostmultimap.insert(boostmultimap.begin(), boost::move(intpair)); |
641 | stdmultimap.insert(stdmultimap.begin(), StdPairType(i, i)); |
642 | //PrintContainers(boostmultimap, stdmultimap); |
643 | if(!CheckEqualPairContainers(boostmap, stdmap)) |
644 | return 1; |
645 | if(!CheckEqualPairContainers(boostmultimap, stdmultimap)) |
646 | return 1; |
647 | { |
648 | IntType i1(i); |
649 | IntType i2(i); |
650 | new(&intpair)IntPairType(boost::move(i1), boost::move(i2)); |
651 | } |
652 | boostmap.insert(boostmap.end(), boost::move(intpair)); |
653 | stdmap.insert(stdmap.end(), StdPairType(i, i)); |
654 | { |
655 | IntType i1(i); |
656 | IntType i2(i); |
657 | new(&intpair)IntPairType(boost::move(i1), boost::move(i2)); |
658 | } |
659 | boostmultimap.insert(boostmultimap.end(), boost::move(intpair)); |
660 | stdmultimap.insert(stdmultimap.end(), StdPairType(i, i)); |
661 | if(!CheckEqualPairContainers(boostmap, stdmap)) |
662 | return 1; |
663 | if(!CheckEqualPairContainers(boostmultimap, stdmultimap)) |
664 | return 1; |
665 | { |
666 | IntType i1(i); |
667 | IntType i2(i); |
668 | new(&intpair)IntPairType(boost::move(i1), boost::move(i2)); |
669 | } |
670 | IntType k(i); |
671 | boostmap.insert(boostmap.lower_bound(k), boost::move(intpair)); |
672 | stdmap.insert(stdmap.lower_bound(i), StdPairType(i, i)); |
673 | //PrintContainers(boostmap, stdmap); |
674 | { |
675 | IntType i1(i); |
676 | IntType i2(i); |
677 | new(&intpair)IntPairType(boost::move(i1), boost::move(i2)); |
678 | } |
679 | { |
680 | IntType i1(i); |
681 | boostmultimap.insert(boostmultimap.lower_bound(boost::move(i1)), boost::move(intpair)); |
682 | stdmultimap.insert(stdmultimap.lower_bound(i), StdPairType(i, i)); |
683 | } |
684 | |
685 | //PrintContainers(boostmultimap, stdmultimap); |
686 | if(!CheckEqualPairContainers(boostmap, stdmap)) |
687 | return 1; |
688 | if(!CheckEqualPairContainers(boostmultimap, stdmultimap)) |
689 | return 1; |
690 | { //Check equal_range |
691 | std::pair<typename MyBoostMultiMap::iterator, typename MyBoostMultiMap::iterator> bret = |
692 | boostmultimap.equal_range(boostmultimap.begin()->first); |
693 | |
694 | std::pair<typename MyStdMultiMap::iterator, typename MyStdMultiMap::iterator> sret = |
695 | stdmultimap.equal_range(stdmultimap.begin()->first); |
696 | |
697 | if( boost::container::iterator_udistance(bret.first, bret.second) != |
698 | boost::container::iterator_udistance(sret.first, sret.second) ){ |
699 | return 1; |
700 | } |
701 | } |
702 | { |
703 | IntType i1(i); |
704 | boostmap.insert(boostmap.upper_bound(boost::move(i1)), boost::move(intpair)); |
705 | stdmap.insert(stdmap.upper_bound(i), StdPairType(i, i)); |
706 | } |
707 | //PrintContainers(boostmap, stdmap); |
708 | { |
709 | IntType i1(i); |
710 | IntType i2(i); |
711 | new(&intpair)IntPairType(boost::move(i1), boost::move(i2)); |
712 | } |
713 | { |
714 | IntType i1(i); |
715 | boostmultimap.insert(boostmultimap.upper_bound(boost::move(i1)), boost::move(intpair)); |
716 | stdmultimap.insert(stdmultimap.upper_bound(i), StdPairType(i, i)); |
717 | } |
718 | //PrintContainers(boostmultimap, stdmultimap); |
719 | if(!CheckEqualPairContainers(boostmap, stdmap)) |
720 | return 1; |
721 | if(!CheckEqualPairContainers(boostmultimap, stdmultimap)) |
722 | return 1; |
723 | |
724 | map_test_rebalanceable(boostmap |
725 | , dtl::bool_<has_member_rebalance<MyBoostMap>::value>()); |
726 | if(!CheckEqualContainers(boostmap, stdmap)){ |
727 | std::cout << "Error in boostmap.rebalance()" << std::endl; |
728 | return 1; |
729 | } |
730 | map_test_rebalanceable(boostmultimap |
731 | , dtl::bool_<has_member_rebalance<MyBoostMap>::value>()); |
732 | if(!CheckEqualContainers(boostmultimap, stdmultimap)){ |
733 | std::cout << "Error in boostmultimap.rebalance()" << std::endl; |
734 | return 1; |
735 | } |
736 | } |
737 | return 0; |
738 | } |
739 | |
740 | |
741 | template<class MyBoostMap |
742 | , class MyStdMap |
743 | , class MyBoostMultiMap |
744 | , class MyStdMultiMap> |
745 | int map_test_search(MyBoostMap &boostmap, MyStdMap &stdmap, MyBoostMultiMap &boostmultimap, MyStdMultiMap &stdmultimap) |
746 | { |
747 | typedef typename MyBoostMap::key_type IntType; |
748 | typedef dtl::pair<IntType, IntType> IntPairType; |
749 | |
750 | //Compare count/contains with std containers |
751 | for(int i = 0; i < MaxElem; ++i){ |
752 | IntType k(i); |
753 | if(boostmap.count(k) != stdmap.count(i)){ |
754 | return -1; |
755 | } |
756 | |
757 | if(boostmap.contains(k) != (stdmap.find(i) != stdmap.end())){ |
758 | return -1; |
759 | } |
760 | |
761 | if(boostmultimap.count(k) != stdmultimap.count(i)){ |
762 | return -1; |
763 | } |
764 | |
765 | if(boostmultimap.contains(k) != (stdmultimap.find(i) != stdmultimap.end())){ |
766 | return -1; |
767 | } |
768 | } |
769 | |
770 | { |
771 | //Now do count exercise |
772 | boostmap.erase(boostmap.begin(), boostmap.end()); |
773 | boostmultimap.erase(boostmultimap.begin(), boostmultimap.end()); |
774 | boostmap.clear(); |
775 | boostmultimap.clear(); |
776 | |
777 | for(int j = 0; j < 3; ++j) |
778 | for(int i = 0; i < 100; ++i){ |
779 | IntPairType intpair; |
780 | { |
781 | IntType i1(i), i2(i); |
782 | new(&intpair)IntPairType(boost::move(i1), boost::move(i2)); |
783 | } |
784 | boostmap.insert(boost::move(intpair)); |
785 | { |
786 | IntType i1(i), i2(i); |
787 | new(&intpair)IntPairType(boost::move(i1), boost::move(i2)); |
788 | } |
789 | boostmultimap.insert(boost::move(intpair)); |
790 | IntType k(i); |
791 | if(boostmap.count(k) != typename MyBoostMultiMap::size_type(1)) |
792 | return 1; |
793 | if(boostmultimap.count(k) != typename MyBoostMultiMap::size_type(j+1)) |
794 | return 1; |
795 | } |
796 | } |
797 | |
798 | return 0; |
799 | } |
800 | |
801 | template<class MyBoostMap |
802 | , class MyStdMap |
803 | , class MyBoostMultiMap |
804 | , class MyStdMultiMap> |
805 | int map_test_indexing(MyBoostMap &boostmap, MyStdMap &stdmap, MyBoostMultiMap &boostmultimap, MyStdMultiMap &stdmultimap) |
806 | { |
807 | typedef typename MyBoostMap::key_type IntType; |
808 | typedef dtl::pair<IntType, IntType> IntPairType; |
809 | |
810 | { //operator[] test |
811 | boostmap.clear(); |
812 | boostmultimap.clear(); |
813 | stdmap.clear(); |
814 | stdmultimap.clear(); |
815 | |
816 | IntPairType aux_vect[(std::size_t)MaxElem]; |
817 | for(int i = 0; i < MaxElem; ++i){ |
818 | IntType i1(i); |
819 | IntType i2(i); |
820 | new(&aux_vect[i])IntPairType(boost::move(i1), boost::move(i2)); |
821 | } |
822 | |
823 | for(int i = 0; i < MaxElem; ++i){ |
824 | boostmap[boost::move(aux_vect[i].first)] = boost::move(aux_vect[i].second); |
825 | stdmap[i] = i; |
826 | } |
827 | |
828 | if(!CheckEqualPairContainers(boostmap, stdmap)) return 1; |
829 | if(!CheckEqualPairContainers(boostmultimap, stdmultimap)) return 1; |
830 | } |
831 | return 0; |
832 | } |
833 | |
834 | template< class MyBoostMap, class StdMap, class MaybeMove> |
835 | int map_test_insert_or_assign_impl() |
836 | { |
837 | typedef typename MyBoostMap::key_type IntType; |
838 | typedef dtl::pair<IntType, IntType> IntPairType; |
839 | typedef typename MyBoostMap::iterator Biterator; |
840 | typedef std::pair<Biterator, bool> Bpair; |
841 | |
842 | MaybeMove maybe_move; |
843 | |
844 | { //insert_or_assign test |
845 | MyBoostMap boostmap; |
846 | StdMap stdmap; |
847 | IntPairType aux_vect[(std::size_t)MaxElem]; |
848 | for(int i = 0; i < MaxElem; ++i){ |
849 | IntType i1(i); |
850 | IntType i2(MaxElem-i); |
851 | new(&aux_vect[i])IntPairType(maybe_move(i1), maybe_move(i2)); |
852 | } |
853 | |
854 | IntPairType aux_vect2[(std::size_t)MaxElem]; |
855 | for(int i = 0; i < MaxElem; ++i){ |
856 | IntType i1(i); |
857 | IntType i2(i); |
858 | new(&aux_vect2[i])IntPairType(maybe_move(i1), maybe_move(i2)); |
859 | } |
860 | |
861 | for(int i = 0; i < MaxElem; ++i){ |
862 | Bpair r = boostmap.insert_or_assign(maybe_move(aux_vect[i].first), maybe_move(aux_vect[i].second)); |
863 | stdmap[i] = MaxElem-i; |
864 | if(!r.second) |
865 | return 1; |
866 | const IntType key(i); |
867 | if(r.first->first != key) |
868 | return 1; |
869 | const IntType mapped(MaxElem-i); |
870 | if(r.first->second != mapped) |
871 | return 1; |
872 | } |
873 | |
874 | if(!CheckEqualPairContainers(boostmap, stdmap)) return 1; |
875 | |
876 | for(int i = 0; i < MaxElem; ++i){ |
877 | Bpair r = boostmap.insert_or_assign(maybe_move(aux_vect2[i].first), maybe_move(aux_vect2[i].second)); |
878 | stdmap[i] = i; |
879 | if(r.second) |
880 | return 1; |
881 | const IntType key(i); |
882 | if(r.first->first != key) |
883 | return 1; |
884 | const IntType mapped(i); |
885 | if(r.first->second != mapped) |
886 | return 1; |
887 | } |
888 | |
889 | if(!CheckEqualPairContainers(boostmap, stdmap)) return 1; |
890 | } |
891 | { //insert_or_assign test with hint |
892 | MyBoostMap boostmap; |
893 | StdMap stdmap; |
894 | IntPairType aux_vect[(std::size_t)MaxElem]; |
895 | for(int i = 0; i < MaxElem; ++i){ |
896 | IntType i1(i); |
897 | IntType i2(MaxElem-i); |
898 | new(&aux_vect[i])IntPairType(maybe_move(i1), maybe_move(i2)); |
899 | } |
900 | |
901 | IntPairType aux_vect2[(std::size_t)MaxElem]; |
902 | for(int i = 0; i < MaxElem; ++i){ |
903 | IntType i1(i); |
904 | IntType i2(i); |
905 | new(&aux_vect2[i])IntPairType(maybe_move(i1), maybe_move(i2)); |
906 | } |
907 | |
908 | for(int i = 0; i < MaxElem; ++i){ |
909 | Biterator r = boostmap.insert_or_assign(boostmap.end(), maybe_move(aux_vect[i].first), maybe_move(aux_vect[i].second)); |
910 | stdmap[i] = MaxElem-i; |
911 | const IntType key(i); |
912 | if(r->first != key) |
913 | return 1; |
914 | const IntType mapped(MaxElem-i); |
915 | if(r->second != mapped) |
916 | return 1; |
917 | } |
918 | |
919 | if(!CheckEqualPairContainers(boostmap, stdmap)) return 1; |
920 | |
921 | for(int i = 0; i < MaxElem; ++i){ |
922 | Biterator r = boostmap.insert_or_assign(boostmap.end(), maybe_move(aux_vect2[i].first), maybe_move(aux_vect2[i].second)); |
923 | stdmap[i] = i; |
924 | const IntType key(i); |
925 | if(r->first != key) |
926 | return 1; |
927 | const IntType mapped(i); |
928 | if(r->second != mapped) |
929 | return 1; |
930 | } |
931 | |
932 | if(!CheckEqualPairContainers(boostmap, stdmap)) return 1; |
933 | } |
934 | return 0; |
935 | } |
936 | |
937 | template< class MyBoostMap, class StdMap> |
938 | int map_test_insert_or_assign(dtl::bool_<false> )//noncopyable |
939 | { |
940 | return map_test_insert_or_assign_impl<MyBoostMap, StdMap, move_op>(); |
941 | } |
942 | |
943 | template< class MyBoostMap, class StdMap> |
944 | int map_test_insert_or_assign(dtl::bool_<true> )//copyable |
945 | { |
946 | int r = map_test_insert_or_assign_impl<MyBoostMap, StdMap, const_ref_op>(); |
947 | if (r) |
948 | r = map_test_insert_or_assign_impl<MyBoostMap, StdMap, move_op>(); |
949 | return r; |
950 | } |
951 | |
952 | template< class MyBoostMap |
953 | , class MyStdMap |
954 | , class MyBoostMultiMap |
955 | , class MyStdMultiMap> |
956 | int map_test_try_emplace(MyBoostMap &boostmap, MyStdMap &stdmap, MyBoostMultiMap &boostmultimap, MyStdMultiMap &stdmultimap) |
957 | { |
958 | typedef typename MyBoostMap::key_type IntType; |
959 | typedef dtl::pair<IntType, IntType> IntPairType; |
960 | |
961 | { //try_emplace |
962 | boostmap.clear(); |
963 | boostmultimap.clear(); |
964 | stdmap.clear(); |
965 | stdmultimap.clear(); |
966 | |
967 | IntPairType aux_vect[(std::size_t)MaxElem]; |
968 | for(int i = 0; i < MaxElem; ++i){ |
969 | IntType i1(i); |
970 | IntType i2(i); |
971 | new(&aux_vect[i])IntPairType(boost::move(i1), boost::move(i2)); |
972 | } |
973 | |
974 | IntPairType aux_vect2[(std::size_t)MaxElem]; |
975 | for(int i = 0; i < MaxElem; ++i){ |
976 | IntType i1(i); |
977 | IntType i2(MaxElem-i); |
978 | new(&aux_vect2[i])IntPairType(boost::move(i1), boost::move(i2)); |
979 | } |
980 | |
981 | typedef typename MyBoostMap::iterator iterator; |
982 | for(int i = 0; i < MaxElem; ++i){ |
983 | iterator it; |
984 | if(i&1){ |
985 | std::pair<typename MyBoostMap::iterator, bool> ret = |
986 | boostmap.try_emplace(boost::move(aux_vect[i].first), boost::move(aux_vect[i].second)); |
987 | if(!ret.second) |
988 | return 1; |
989 | it = ret.first; |
990 | } |
991 | else{ |
992 | it = boostmap.try_emplace |
993 | (boostmap.upper_bound(aux_vect[i].first), boost::move(aux_vect[i].first), boost::move(aux_vect[i].second)); |
994 | } |
995 | if(boostmap.end() == it || it->first != aux_vect2[i].first || it->second != aux_vect2[i].first){ |
996 | return 1; |
997 | } |
998 | stdmap[i] = i; |
999 | } |
1000 | |
1001 | if(!CheckEqualPairContainers(boostmap, stdmap)) return 1; |
1002 | if(!CheckEqualPairContainers(boostmultimap, stdmultimap)) return 1; |
1003 | |
1004 | for(int i = 0; i < MaxElem; ++i){ |
1005 | iterator it; |
1006 | iterator itex = boostmap.find(aux_vect2[i].first); |
1007 | if(itex == boostmap.end()) |
1008 | return 1; |
1009 | if(i&1){ |
1010 | std::pair<typename MyBoostMap::iterator, bool> ret = |
1011 | boostmap.try_emplace(boost::move(aux_vect2[i].first), boost::move(aux_vect2[i].second)); |
1012 | if(ret.second) |
1013 | return 1; |
1014 | it = ret.first; |
1015 | } |
1016 | else{ |
1017 | it = boostmap.try_emplace |
1018 | (boostmap.upper_bound(aux_vect2[i].first), boost::move(aux_vect2[i].first), boost::move(aux_vect2[i].second)); |
1019 | } |
1020 | const IntType test_int(i); |
1021 | if(boostmap.end() == it || it != itex || it->second != test_int){ |
1022 | return 1; |
1023 | } |
1024 | } |
1025 | |
1026 | if(!CheckEqualPairContainers(boostmap, stdmap)) return 1; |
1027 | if(!CheckEqualPairContainers(boostmultimap, stdmultimap)) return 1; |
1028 | } |
1029 | return 0; |
1030 | } |
1031 | |
1032 | |
1033 | template< class MyBoostMap |
1034 | , class MyStdMap |
1035 | , class MyBoostMultiMap |
1036 | , class MyStdMultiMap> |
1037 | int map_test_merge(MyBoostMap &boostmap, MyStdMap &stdmap, MyBoostMultiMap &boostmultimap, MyStdMultiMap &stdmultimap) |
1038 | { |
1039 | typedef typename MyBoostMap::key_type IntType; |
1040 | typedef dtl::pair<IntType, IntType> IntPairType; |
1041 | typedef typename MyStdMap::value_type StdPairType; |
1042 | |
1043 | { //merge |
1044 | ::boost::movelib::unique_ptr<MyBoostMap> const pboostmap2 = ::boost::movelib::make_unique<MyBoostMap>(); |
1045 | ::boost::movelib::unique_ptr<MyBoostMultiMap> const pboostmultimap2 = ::boost::movelib::make_unique<MyBoostMultiMap>(); |
1046 | |
1047 | MyBoostMap &boostmap2 = *pboostmap2; |
1048 | MyBoostMultiMap &boostmultimap2 = *pboostmultimap2; |
1049 | |
1050 | boostmap.clear(); |
1051 | boostmap2.clear(); |
1052 | boostmultimap.clear(); |
1053 | boostmultimap2.clear(); |
1054 | stdmap.clear(); |
1055 | stdmultimap.clear(); |
1056 | |
1057 | { |
1058 | IntPairType aux_vect[(std::size_t)MaxElem]; |
1059 | for(int i = 0; i < MaxElem; ++i){ |
1060 | IntType i1(i); |
1061 | IntType i2(i); |
1062 | new(&aux_vect[i])IntPairType(boost::move(i1), boost::move(i2)); |
1063 | } |
1064 | |
1065 | IntPairType aux_vect2[(std::size_t)MaxElem]; |
1066 | for(int i = 0; i < MaxElem; ++i){ |
1067 | IntType i1(MaxElem/2+i); |
1068 | IntType i2(MaxElem-i); |
1069 | new(&aux_vect2[i])IntPairType(boost::move(i1), boost::move(i2)); |
1070 | } |
1071 | IntPairType aux_vect3[(std::size_t)MaxElem]; |
1072 | for(int i = 0; i < MaxElem; ++i){ |
1073 | IntType i1(MaxElem*2/2+i); |
1074 | IntType i2(MaxElem*2+i); |
1075 | new(&aux_vect3[i])IntPairType(boost::move(i1), boost::move(i2)); |
1076 | } |
1077 | boostmap.insert(boost::make_move_iterator(&aux_vect[0]), boost::make_move_iterator(&aux_vect[0] + MaxElem)); |
1078 | boostmap2.insert(boost::make_move_iterator(&aux_vect2[0]), boost::make_move_iterator(&aux_vect2[0] + MaxElem)); |
1079 | boostmultimap2.insert(boost::make_move_iterator(&aux_vect3[0]), boost::make_move_iterator(&aux_vect3[0] + MaxElem)); |
1080 | } |
1081 | for(int i = 0; i < MaxElem; ++i){ |
1082 | stdmap.insert(StdPairType(i, i)); |
1083 | } |
1084 | for(int i = 0; i < MaxElem; ++i){ |
1085 | stdmap.insert(StdPairType(MaxElem/2+i, MaxElem-i)); |
1086 | } |
1087 | |
1088 | boostmap.merge(boost::move(boostmap2)); |
1089 | if(!CheckEqualPairContainers(boostmap, stdmap)) return 1; |
1090 | |
1091 | for(int i = 0; i < MaxElem; ++i){ |
1092 | stdmap.insert(StdPairType(MaxElem*2/2+i, MaxElem*2+i)); |
1093 | } |
1094 | |
1095 | boostmap.merge(boost::move(boostmultimap2)); |
1096 | if(!CheckEqualPairContainers(boostmap, stdmap)) return 1; |
1097 | |
1098 | boostmap.clear(); |
1099 | boostmap2.clear(); |
1100 | boostmultimap.clear(); |
1101 | boostmultimap2.clear(); |
1102 | stdmap.clear(); |
1103 | stdmultimap.clear(); |
1104 | { |
1105 | IntPairType aux_vect[(std::size_t)MaxElem]; |
1106 | for(int i = 0; i < MaxElem; ++i){ |
1107 | IntType i1(i); |
1108 | IntType i2(i); |
1109 | new(&aux_vect[i])IntPairType(boost::move(i1), boost::move(i2)); |
1110 | } |
1111 | |
1112 | IntPairType aux_vect2[(std::size_t)MaxElem]; |
1113 | for(int i = 0; i < MaxElem; ++i){ |
1114 | IntType i1(MaxElem/2+i); |
1115 | IntType i2(MaxElem-i); |
1116 | new(&aux_vect2[i])IntPairType(boost::move(i1), boost::move(i2)); |
1117 | } |
1118 | IntPairType aux_vect3[(std::size_t)MaxElem]; |
1119 | for(int i = 0; i < MaxElem; ++i){ |
1120 | IntType i1(MaxElem*2/2+i); |
1121 | IntType i2(MaxElem*2+i); |
1122 | new(&aux_vect3[i])IntPairType(boost::move(i1), boost::move(i2)); |
1123 | } |
1124 | boostmultimap.insert(boost::make_move_iterator(&aux_vect[0]), boost::make_move_iterator(&aux_vect[0] + MaxElem)); |
1125 | boostmultimap2.insert(boost::make_move_iterator(&aux_vect2[0]), boost::make_move_iterator(&aux_vect2[0] + MaxElem)); |
1126 | boostmap2.insert(boost::make_move_iterator(&aux_vect3[0]), boost::make_move_iterator(&aux_vect3[0] + MaxElem)); |
1127 | } |
1128 | for(int i = 0; i < MaxElem; ++i){ |
1129 | stdmultimap.insert(StdPairType(i, i)); |
1130 | } |
1131 | for(int i = 0; i < MaxElem; ++i){ |
1132 | stdmultimap.insert(StdPairType(MaxElem/2+i, MaxElem-i)); |
1133 | } |
1134 | boostmultimap.merge(boostmultimap2); |
1135 | if(!CheckEqualPairContainers(boostmultimap, stdmultimap)) return 1; |
1136 | |
1137 | for(int i = 0; i < MaxElem; ++i){ |
1138 | stdmultimap.insert(StdPairType(MaxElem*2/2+i, MaxElem*2+i)); |
1139 | } |
1140 | |
1141 | boostmultimap.merge(boostmap2); |
1142 | if(!CheckEqualPairContainers(boostmultimap, stdmultimap)) return 1; |
1143 | } |
1144 | return 0; |
1145 | } |
1146 | |
1147 | |
1148 | template<class MyBoostMap |
1149 | ,class MyStdMap |
1150 | ,class MyBoostMultiMap |
1151 | ,class MyStdMultiMap> |
1152 | int map_test() |
1153 | { |
1154 | typedef typename MyBoostMap::key_type IntType; |
1155 | |
1156 | if(map_test_range<MyBoostMap, MyStdMap, MyBoostMultiMap, MyStdMultiMap>()) |
1157 | return 1; |
1158 | |
1159 | ::boost::movelib::unique_ptr<MyBoostMap> const pboostmap = ::boost::movelib::make_unique<MyBoostMap>(); |
1160 | ::boost::movelib::unique_ptr<MyStdMap> const pstdmap = ::boost::movelib::make_unique<MyStdMap>(); |
1161 | ::boost::movelib::unique_ptr<MyBoostMultiMap> const pboostmultimap = ::boost::movelib::make_unique<MyBoostMultiMap>(); |
1162 | ::boost::movelib::unique_ptr<MyStdMultiMap> const pstdmultimap = ::boost::movelib::make_unique<MyStdMultiMap>(); |
1163 | MyBoostMap &boostmap = *pboostmap; |
1164 | MyStdMap &stdmap = *pstdmap; |
1165 | MyBoostMultiMap &boostmultimap = *pboostmultimap; |
1166 | MyStdMultiMap &stdmultimap = *pstdmultimap; |
1167 | typedef dtl::bool_<boost::container::test::is_copyable<IntType>::value> copyable_t; |
1168 | |
1169 | if (map_test_step(boostmap, stdmap, boostmultimap, stdmultimap)) |
1170 | return 1; |
1171 | |
1172 | if (map_test_insert(boostmap, stdmap, boostmultimap, stdmultimap)) |
1173 | return 1; |
1174 | |
1175 | if (map_test_erase(boostmap, stdmap, boostmultimap, stdmultimap)) |
1176 | return 1; |
1177 | |
1178 | if (map_test_insert2(boostmap, stdmap, boostmultimap, stdmultimap)) |
1179 | return 1; |
1180 | |
1181 | if (map_test_search(boostmap, stdmap, boostmultimap, stdmultimap)) |
1182 | return 1; |
1183 | |
1184 | if (map_test_indexing(boostmap, stdmap, boostmultimap, stdmultimap)) |
1185 | return 1; |
1186 | |
1187 | if (map_test_try_emplace(boostmap, stdmap, boostmultimap, stdmultimap)) |
1188 | return 1; |
1189 | |
1190 | if (map_test_merge(boostmap, stdmap, boostmultimap, stdmultimap)) |
1191 | return 1; |
1192 | |
1193 | if (map_test_insert_or_assign<MyBoostMap, MyStdMap>(copyable_t())) |
1194 | return 1; |
1195 | |
1196 | if(map_test_copyable<MyBoostMap, MyStdMap, MyBoostMultiMap, MyStdMultiMap>(copyable_t())) |
1197 | return 1; |
1198 | return 0; |
1199 | } |
1200 | |
1201 | template<typename MapType> |
1202 | bool test_map_support_for_initialization_list_for() |
1203 | { |
1204 | #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) |
1205 | const std::initializer_list<std::pair<typename MapType::value_type::first_type, typename MapType::mapped_type>> il |
1206 | = { std::make_pair(x: 1, y: 2), std::make_pair(x: 3, y: 4) }; |
1207 | |
1208 | const MapType expected_map(il.begin(), il.end()); |
1209 | { |
1210 | const MapType sil = il; |
1211 | if (sil != expected_map) |
1212 | return false; |
1213 | |
1214 | MapType sila(il, typename MapType::allocator_type()); |
1215 | if (sila != expected_map) |
1216 | return false; |
1217 | |
1218 | MapType silca(il, typename MapType::key_compare(), typename MapType::allocator_type()); |
1219 | if (silca != expected_map) |
1220 | return false; |
1221 | |
1222 | const MapType sil_ordered(ordered_unique_range, il); |
1223 | if (sil_ordered != expected_map) |
1224 | return false; |
1225 | |
1226 | MapType sil_assign = { std::make_pair(x: 99, y: 100) }; |
1227 | sil_assign = il; |
1228 | if (sil_assign != expected_map) |
1229 | return false; |
1230 | } |
1231 | { |
1232 | MapType sil; |
1233 | sil.insert(il); |
1234 | if (sil != expected_map) |
1235 | return false; |
1236 | } |
1237 | return true; |
1238 | #endif |
1239 | return true; |
1240 | } |
1241 | |
1242 | template<typename MapType, typename MultimapType> |
1243 | bool instantiate_constructors() |
1244 | { |
1245 | { |
1246 | typedef typename MapType::value_type value_type; |
1247 | typename MapType::key_compare comp; |
1248 | typename MapType::allocator_type a; |
1249 | value_type value; |
1250 | { |
1251 | MapType s0; |
1252 | MapType s1(comp); |
1253 | MapType s2(a); |
1254 | MapType s3(comp, a); |
1255 | } |
1256 | { |
1257 | MapType s0(&value, &value); |
1258 | MapType s1(&value, &value ,comp); |
1259 | MapType s2(&value, &value ,a); |
1260 | MapType s3(&value, &value ,comp, a); |
1261 | } |
1262 | #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) |
1263 | { |
1264 | std::initializer_list<value_type> il; |
1265 | MapType s0(il); |
1266 | MapType s1(il, comp); |
1267 | MapType s2(il, a); |
1268 | MapType s3(il, comp, a); |
1269 | } |
1270 | { |
1271 | std::initializer_list<value_type> il; |
1272 | MapType s0(ordered_unique_range, il); |
1273 | MapType s1(ordered_unique_range, il, comp); |
1274 | MapType s3(ordered_unique_range, il, comp, a); |
1275 | } |
1276 | #endif |
1277 | { |
1278 | MapType s0(ordered_unique_range, &value, &value); |
1279 | MapType s1(ordered_unique_range, &value, &value ,comp); |
1280 | MapType s2(ordered_unique_range, &value, &value ,comp, a); |
1281 | } |
1282 | } |
1283 | |
1284 | { |
1285 | typedef typename MultimapType::value_type value_type; |
1286 | typename MultimapType::key_compare comp; |
1287 | typename MultimapType::allocator_type a; |
1288 | value_type value; |
1289 | { |
1290 | MultimapType s0; |
1291 | MultimapType s1(comp); |
1292 | MultimapType s2(a); |
1293 | MultimapType s3(comp, a); |
1294 | } |
1295 | { |
1296 | MultimapType s0(&value, &value); |
1297 | MultimapType s1(&value, &value ,comp); |
1298 | MultimapType s2(&value, &value ,a); |
1299 | MultimapType s3(&value, &value ,comp, a); |
1300 | } |
1301 | #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) |
1302 | { |
1303 | std::initializer_list<value_type> il; |
1304 | MultimapType s0(il); |
1305 | MultimapType s1(il, comp); |
1306 | MultimapType s2(il, a); |
1307 | MultimapType s3(il, comp, a); |
1308 | } |
1309 | { |
1310 | std::initializer_list<value_type> il; |
1311 | MultimapType s0(ordered_range, il); |
1312 | MultimapType s1(ordered_range, il, comp); |
1313 | MultimapType s3(ordered_range, il, comp, a); |
1314 | } |
1315 | #endif |
1316 | { |
1317 | MultimapType s0(ordered_range, &value, &value); |
1318 | MultimapType s1(ordered_range, &value, &value ,comp); |
1319 | MultimapType s2(ordered_range, &value, &value ,comp, a); |
1320 | } |
1321 | } |
1322 | return true; |
1323 | } |
1324 | |
1325 | } //namespace test{ |
1326 | } //namespace container { |
1327 | } //namespace boost{ |
1328 | |
1329 | #include <boost/container/detail/config_end.hpp> |
1330 | |
1331 | #endif //#ifndef BOOST_CONTAINER_TEST_MAP_TEST_HEADER |
1332 | |