map_test.hpp 44 KB

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