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