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