map_test.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2004-2013. 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. #include <boost/container/detail/config_begin.hpp>
  11. #include <boost/container/map.hpp>
  12. #include <boost/container/adaptive_pool.hpp>
  13. #include <map>
  14. #include "print_container.hpp"
  15. #include "movable_int.hpp"
  16. #include "dummy_test_allocator.hpp"
  17. #include "map_test.hpp"
  18. #include "propagate_allocator_test.hpp"
  19. #include "emplace_test.hpp"
  20. #include "../../intrusive/test/iterator_test.hpp"
  21. using namespace boost::container;
  22. typedef std::pair<const test::movable_and_copyable_int, test::movable_and_copyable_int> pair_t;
  23. class recursive_map
  24. {
  25. public:
  26. recursive_map & operator=(const recursive_map &x)
  27. { id_ = x.id_; map_ = x.map_; return *this; }
  28. int id_;
  29. map<recursive_map, recursive_map> map_;
  30. map<recursive_map, recursive_map>::iterator it_;
  31. map<recursive_map, recursive_map>::const_iterator cit_;
  32. map<recursive_map, recursive_map>::reverse_iterator rit_;
  33. map<recursive_map, recursive_map>::const_reverse_iterator crit_;
  34. friend bool operator< (const recursive_map &a, const recursive_map &b)
  35. { return a.id_ < b.id_; }
  36. };
  37. class recursive_multimap
  38. {
  39. public:
  40. recursive_multimap & operator=(const recursive_multimap &x)
  41. { id_ = x.id_; multimap_ = x.multimap_; return *this; }
  42. int id_;
  43. multimap<recursive_multimap, recursive_multimap> multimap_;
  44. multimap<recursive_multimap, recursive_multimap>::iterator it_;
  45. multimap<recursive_multimap, recursive_multimap>::const_iterator cit_;
  46. multimap<recursive_multimap, recursive_multimap>::reverse_iterator rit_;
  47. multimap<recursive_multimap, recursive_multimap>::const_reverse_iterator crit_;
  48. friend bool operator< (const recursive_multimap &a, const recursive_multimap &b)
  49. { return a.id_ < b.id_; }
  50. };
  51. template<class C>
  52. void test_move()
  53. {
  54. //Now test move semantics
  55. C original;
  56. original.emplace();
  57. C move_ctor(boost::move(original));
  58. C move_assign;
  59. move_assign.emplace();
  60. move_assign = boost::move(move_ctor);
  61. move_assign.swap(original);
  62. }
  63. bool node_type_test()
  64. {
  65. using namespace boost::container;
  66. {
  67. typedef map<test::movable_int, test::movable_int> map_type;
  68. map_type src;
  69. {
  70. test::movable_int mv_1(1), mv_2(2), mv_3(3), mv_11(11), mv_12(12), mv_13(13);
  71. src.try_emplace(boost::move(mv_1), boost::move(mv_11));
  72. src.try_emplace(boost::move(mv_2), boost::move(mv_12));
  73. src.try_emplace(boost::move(mv_3), boost::move(mv_13));
  74. }
  75. if(src.size() != 3)
  76. return false;
  77. map_type dst;
  78. {
  79. test::movable_int mv_3(3), mv_33(33);
  80. dst.try_emplace(boost::move(mv_3), boost::move(mv_33));
  81. }
  82. if(dst.size() != 1)
  83. return false;
  84. const test::movable_int mv_1(1);
  85. const test::movable_int mv_2(2);
  86. const test::movable_int mv_3(3);
  87. const test::movable_int mv_33(33);
  88. const test::movable_int mv_13(13);
  89. map_type::insert_return_type r;
  90. r = dst.insert(src.extract(mv_33)); // Key version, try to insert empty node
  91. if(! (r.position == dst.end() && r.inserted == false && r.node.empty()) )
  92. return false;
  93. r = dst.insert(src.extract(src.find(mv_1))); // Iterator version, successful
  94. if(! (r.position == dst.find(mv_1) && r.inserted == true && r.node.empty()) )
  95. return false;
  96. r = dst.insert(dst.begin(), src.extract(mv_2)); // Key type version, successful
  97. if(! (r.position == dst.find(mv_2) && r.inserted == true && r.node.empty()) )
  98. return false;
  99. r = dst.insert(src.extract(mv_3)); // Key type version, unsuccessful
  100. if(!src.empty())
  101. return false;
  102. if(dst.size() != 3)
  103. return false;
  104. if(! (r.position == dst.find(mv_3) && r.inserted == false && r.node.key() == mv_3 && r.node.mapped() == mv_13) )
  105. return false;
  106. }
  107. {
  108. typedef multimap<test::movable_int, test::movable_int> multimap_type;
  109. multimap_type src;
  110. {
  111. test::movable_int mv_1(1), mv_2(2), mv_3(3), mv_3bis(3), mv_11(11), mv_12(12), mv_13(13), mv_23(23);
  112. src.emplace(boost::move(mv_1), boost::move(mv_11));
  113. src.emplace(boost::move(mv_2), boost::move(mv_12));
  114. src.emplace(boost::move(mv_3), boost::move(mv_13));
  115. src.emplace_hint(src.begin(), boost::move(mv_3bis), boost::move(mv_23));
  116. }
  117. if(src.size() != 4)
  118. return false;
  119. multimap_type dst;
  120. {
  121. test::movable_int mv_3(3), mv_33(33);
  122. dst.emplace(boost::move(mv_3), boost::move(mv_33));
  123. }
  124. if(dst.size() != 1)
  125. return false;
  126. const test::movable_int mv_1(1);
  127. const test::movable_int mv_2(2);
  128. const test::movable_int mv_3(3);
  129. const test::movable_int mv_4(4);
  130. const test::movable_int mv_33(33);
  131. const test::movable_int mv_13(13);
  132. const test::movable_int mv_23(23);
  133. multimap_type::iterator r;
  134. multimap_type::node_type nt(src.extract(mv_3));
  135. r = dst.insert(dst.begin(), boost::move(nt));
  136. if(! (r->first == mv_3 && r->second == mv_23 && dst.find(mv_3) == r && nt.empty()) )
  137. return false;
  138. nt = src.extract(src.find(mv_1));
  139. r = dst.insert(boost::move(nt)); // Iterator version, successful
  140. if(! (r->first == mv_1 && nt.empty()) )
  141. return false;
  142. nt = src.extract(mv_2);
  143. r = dst.insert(boost::move(nt)); // Key type version, successful
  144. if(! (r->first == mv_2 && nt.empty()) )
  145. return false;
  146. r = dst.insert(src.extract(mv_3)); // Key type version, successful
  147. if(! (r->first == mv_3 && r->second == mv_13 && r == --multimap_type::iterator(dst.upper_bound(mv_3)) && nt.empty()) )
  148. return false;
  149. r = dst.insert(src.extract(mv_4)); // Key type version, unsuccessful
  150. if(! (r == dst.end()) )
  151. return false;
  152. if(!src.empty())
  153. return false;
  154. if(dst.size() != 5)
  155. return false;
  156. }
  157. return true;
  158. }
  159. template<class VoidAllocator, boost::container::tree_type_enum tree_type_value>
  160. struct GetAllocatorMap
  161. {
  162. template<class ValueType>
  163. struct apply
  164. {
  165. typedef map< ValueType
  166. , ValueType
  167. , std::less<ValueType>
  168. , typename allocator_traits<VoidAllocator>
  169. ::template portable_rebind_alloc< std::pair<const ValueType, ValueType> >::type
  170. , typename boost::container::tree_assoc_options
  171. < boost::container::tree_type<tree_type_value>
  172. >::type
  173. > map_type;
  174. typedef multimap< ValueType
  175. , ValueType
  176. , std::less<ValueType>
  177. , typename allocator_traits<VoidAllocator>
  178. ::template portable_rebind_alloc< std::pair<const ValueType, ValueType> >::type
  179. , typename boost::container::tree_assoc_options
  180. < boost::container::tree_type<tree_type_value>
  181. >::type
  182. > multimap_type;
  183. };
  184. };
  185. struct boost_container_map;
  186. struct boost_container_multimap;
  187. namespace boost { namespace container { namespace test {
  188. template<>
  189. struct alloc_propagate_base<boost_container_map>
  190. {
  191. template <class T, class Allocator>
  192. struct apply
  193. {
  194. typedef typename boost::container::allocator_traits<Allocator>::
  195. template portable_rebind_alloc<std::pair<const T, T> >::type TypeAllocator;
  196. typedef boost::container::map<T, T, std::less<T>, TypeAllocator> type;
  197. };
  198. };
  199. template<>
  200. struct alloc_propagate_base<boost_container_multimap>
  201. {
  202. template <class T, class Allocator>
  203. struct apply
  204. {
  205. typedef typename boost::container::allocator_traits<Allocator>::
  206. template portable_rebind_alloc<std::pair<const T, T> >::type TypeAllocator;
  207. typedef boost::container::multimap<T, T, std::less<T>, TypeAllocator> type;
  208. };
  209. };
  210. void test_merge_from_different_comparison()
  211. {
  212. map<int, int> map1;
  213. map<int, int, std::greater<int> > map2;
  214. map1.merge(map2);
  215. }
  216. bool test_heterogeneous_lookups()
  217. {
  218. typedef map<int, char, less_transparent> map_t;
  219. typedef multimap<int, char, less_transparent> mmap_t;
  220. typedef map_t::value_type value_type;
  221. map_t map1;
  222. mmap_t mmap1;
  223. const map_t &cmap1 = map1;
  224. const mmap_t &cmmap1 = mmap1;
  225. if(!map1.insert_or_assign(1, 'a').second)
  226. return false;
  227. if( map1.insert_or_assign(1, 'b').second)
  228. return false;
  229. if(!map1.insert_or_assign(2, 'c').second)
  230. return false;
  231. if( map1.insert_or_assign(2, 'd').second)
  232. return false;
  233. if(!map1.insert_or_assign(3, 'e').second)
  234. return false;
  235. if(map1.insert_or_assign(1, 'a').second)
  236. return false;
  237. if(map1.insert_or_assign(1, 'b').second)
  238. return false;
  239. if(map1.insert_or_assign(2, 'c').second)
  240. return false;
  241. if(map1.insert_or_assign(2, 'd').second)
  242. return false;
  243. if(map1.insert_or_assign(3, 'e').second)
  244. return false;
  245. mmap1.insert(value_type(1, 'a'));
  246. mmap1.insert(value_type(1, 'b'));
  247. mmap1.insert(value_type(2, 'c'));
  248. mmap1.insert(value_type(2, 'd'));
  249. mmap1.insert(value_type(3, 'e'));
  250. const test::non_copymovable_int find_me(2);
  251. //find
  252. if(map1.find(find_me)->second != 'd')
  253. return false;
  254. if(cmap1.find(find_me)->second != 'd')
  255. return false;
  256. if(mmap1.find(find_me)->second != 'c')
  257. return false;
  258. if(cmmap1.find(find_me)->second != 'c')
  259. return false;
  260. //count
  261. if(map1.count(find_me) != 1)
  262. return false;
  263. if(cmap1.count(find_me) != 1)
  264. return false;
  265. if(mmap1.count(find_me) != 2)
  266. return false;
  267. if(cmmap1.count(find_me) != 2)
  268. return false;
  269. //contains
  270. if(!map1.contains(find_me))
  271. return false;
  272. if(!cmap1.contains(find_me))
  273. return false;
  274. if(!mmap1.contains(find_me))
  275. return false;
  276. if(!cmmap1.contains(find_me))
  277. return false;
  278. //lower_bound
  279. if(map1.lower_bound(find_me)->second != 'd')
  280. return false;
  281. if(cmap1.lower_bound(find_me)->second != 'd')
  282. return false;
  283. if(mmap1.lower_bound(find_me)->second != 'c')
  284. return false;
  285. if(cmmap1.lower_bound(find_me)->second != 'c')
  286. return false;
  287. //upper_bound
  288. if(map1.upper_bound(find_me)->second != 'e')
  289. return false;
  290. if(cmap1.upper_bound(find_me)->second != 'e')
  291. return false;
  292. if(mmap1.upper_bound(find_me)->second != 'e')
  293. return false;
  294. if(cmmap1.upper_bound(find_me)->second != 'e')
  295. return false;
  296. //equal_range
  297. if(map1.equal_range(find_me).first->second != 'd')
  298. return false;
  299. if(cmap1.equal_range(find_me).second->second != 'e')
  300. return false;
  301. if(mmap1.equal_range(find_me).first->second != 'c')
  302. return false;
  303. if(cmmap1.equal_range(find_me).second->second != 'e')
  304. return false;
  305. return true;
  306. }
  307. bool constructor_template_auto_deduction_test()
  308. {
  309. #ifndef BOOST_CONTAINER_NO_CXX17_CTAD
  310. using namespace boost::container;
  311. const std::size_t NumElements = 100;
  312. {
  313. std::map<int, int> int_map;
  314. for(std::size_t i = 0; i != NumElements; ++i){
  315. int_map.insert(std::map<int, int>::value_type(static_cast<int>(i), static_cast<int>(i)));
  316. }
  317. std::multimap<int, int> int_mmap;
  318. for (std::size_t i = 0; i != NumElements; ++i) {
  319. int_mmap.insert(std::multimap<int, int>::value_type(static_cast<int>(i), static_cast<int>(i)));
  320. }
  321. typedef std::less<int> comp_int_t;
  322. typedef std::allocator<std::pair<const int, int> > alloc_pair_int_t;
  323. //range
  324. {
  325. auto fmap = map(int_map.begin(), int_map.end());
  326. if (!CheckEqualContainers(int_map, fmap))
  327. return false;
  328. auto fmmap = multimap(int_mmap.begin(), int_mmap.end());
  329. if (!CheckEqualContainers(int_mmap, fmmap))
  330. return false;
  331. }
  332. //range+comp
  333. {
  334. auto fmap = map(int_map.begin(), int_map.end(), comp_int_t());
  335. if (!CheckEqualContainers(int_map, fmap))
  336. return false;
  337. auto fmmap = multimap(int_mmap.begin(), int_mmap.end(), comp_int_t());
  338. if (!CheckEqualContainers(int_mmap, fmmap))
  339. return false;
  340. }
  341. //range+comp+alloc
  342. {
  343. auto fmap = map(int_map.begin(), int_map.end(), comp_int_t(), alloc_pair_int_t());
  344. if (!CheckEqualContainers(int_map, fmap))
  345. return false;
  346. auto fmmap = multimap(int_mmap.begin(), int_mmap.end(), comp_int_t(), alloc_pair_int_t());
  347. if (!CheckEqualContainers(int_mmap, fmmap))
  348. return false;
  349. }
  350. //range+alloc
  351. {
  352. auto fmap = map(int_map.begin(), int_map.end(), alloc_pair_int_t());
  353. if (!CheckEqualContainers(int_map, fmap))
  354. return false;
  355. auto fmmap = multimap(int_mmap.begin(), int_mmap.end(), alloc_pair_int_t());
  356. if (!CheckEqualContainers(int_mmap, fmmap))
  357. return false;
  358. }
  359. //ordered_unique_range / ordered_range
  360. //range
  361. {
  362. auto fmap = map(ordered_unique_range, int_map.begin(), int_map.end());
  363. if(!CheckEqualContainers(int_map, fmap))
  364. return false;
  365. auto fmmap = multimap(ordered_range, int_mmap.begin(), int_mmap.end());
  366. if(!CheckEqualContainers(int_mmap, fmmap))
  367. return false;
  368. }
  369. //range+comp
  370. {
  371. auto fmap = map(ordered_unique_range, int_map.begin(), int_map.end(), comp_int_t());
  372. if (!CheckEqualContainers(int_map, fmap))
  373. return false;
  374. auto fmmap = multimap(ordered_range, int_mmap.begin(), int_mmap.end(), comp_int_t());
  375. if (!CheckEqualContainers(int_mmap, fmmap))
  376. return false;
  377. }
  378. //range+comp+alloc
  379. {
  380. auto fmap = map(ordered_unique_range, int_map.begin(), int_map.end(), comp_int_t(), alloc_pair_int_t());
  381. if (!CheckEqualContainers(int_map, fmap))
  382. return false;
  383. auto fmmap = multimap(ordered_range, int_mmap.begin(), int_mmap.end(), comp_int_t(), alloc_pair_int_t());
  384. if (!CheckEqualContainers(int_mmap, fmmap))
  385. return false;
  386. }
  387. //range+alloc
  388. {
  389. auto fmap = map(ordered_unique_range, int_map.begin(), int_map.end(),alloc_pair_int_t());
  390. if (!CheckEqualContainers(int_map, fmap))
  391. return false;
  392. auto fmmap = multimap(ordered_range, int_mmap.begin(), int_mmap.end(),alloc_pair_int_t());
  393. if (!CheckEqualContainers(int_mmap, fmmap))
  394. return false;
  395. }
  396. }
  397. #endif
  398. return true;
  399. }
  400. }}} //namespace boost::container::test
  401. int main ()
  402. {
  403. //Recursive container instantiation
  404. {
  405. map<recursive_map, recursive_map> map_;
  406. multimap<recursive_multimap, recursive_multimap> multimap_;
  407. }
  408. //Allocator argument container
  409. {
  410. map<int, int> map_((map<int, int>::allocator_type()));
  411. multimap<int, int> multimap_((multimap<int, int>::allocator_type()));
  412. }
  413. //Now test move semantics
  414. {
  415. test_move<map<recursive_map, recursive_map> >();
  416. test_move<multimap<recursive_multimap, recursive_multimap> >();
  417. }
  418. //Test std::pair value type as tree has workarounds to make old std::pair
  419. //implementations movable that can break things
  420. {
  421. boost::container::map<pair_t, pair_t> s;
  422. std::pair<const pair_t,pair_t> p;
  423. s.insert(p);
  424. s.emplace(p);
  425. }
  426. ////////////////////////////////////
  427. // Testing allocator implementations
  428. ////////////////////////////////////
  429. {
  430. typedef std::map<int, int> MyStdMap;
  431. typedef std::multimap<int, int> MyStdMultiMap;
  432. if (0 != test::map_test
  433. < GetAllocatorMap<std::allocator<void>, red_black_tree>::apply<int>::map_type
  434. , MyStdMap
  435. , GetAllocatorMap<std::allocator<void>, red_black_tree>::apply<int>::multimap_type
  436. , MyStdMultiMap>()) {
  437. std::cout << "Error in map_test<std::allocator<void>, red_black_tree>" << std::endl;
  438. return 1;
  439. }
  440. if (0 != test::map_test
  441. < GetAllocatorMap<new_allocator<void>, avl_tree>::apply<int>::map_type
  442. , MyStdMap
  443. , GetAllocatorMap<new_allocator<void>, avl_tree>::apply<int>::multimap_type
  444. , MyStdMultiMap>()) {
  445. std::cout << "Error in map_test<new_allocator<void>, avl_tree>" << std::endl;
  446. return 1;
  447. }
  448. if (0 != test::map_test
  449. < GetAllocatorMap<adaptive_pool<void>, scapegoat_tree>::apply<int>::map_type
  450. , MyStdMap
  451. , GetAllocatorMap<adaptive_pool<void>, scapegoat_tree>::apply<int>::multimap_type
  452. , MyStdMultiMap>()) {
  453. std::cout << "Error in map_test<adaptive_pool<void>, scapegoat_tree>" << std::endl;
  454. return 1;
  455. }
  456. ///////////
  457. if (0 != test::map_test
  458. < GetAllocatorMap<new_allocator<void>, splay_tree>::apply<test::movable_int>::map_type
  459. , MyStdMap
  460. , GetAllocatorMap<new_allocator<void>, splay_tree>::apply<test::movable_int>::multimap_type
  461. , MyStdMultiMap>()) {
  462. std::cout << "Error in map_test<new_allocator<void>, splay_tree>" << std::endl;
  463. return 1;
  464. }
  465. if (0 != test::map_test
  466. < GetAllocatorMap<new_allocator<void>, red_black_tree>::apply<test::copyable_int>::map_type
  467. , MyStdMap
  468. , GetAllocatorMap<new_allocator<void>, red_black_tree>::apply<test::copyable_int>::multimap_type
  469. , MyStdMultiMap>()) {
  470. std::cout << "Error in map_test<new_allocator<void>, red_black_tree>" << std::endl;
  471. return 1;
  472. }
  473. if (0 != test::map_test
  474. < GetAllocatorMap<new_allocator<void>, red_black_tree>::apply<test::movable_and_copyable_int>::map_type
  475. , MyStdMap
  476. , GetAllocatorMap<new_allocator<void>, red_black_tree>::apply<test::movable_and_copyable_int>::multimap_type
  477. , MyStdMultiMap>()) {
  478. std::cout << "Error in map_test<new_allocator<void>, red_black_tree>" << std::endl;
  479. return 1;
  480. }
  481. }
  482. ////////////////////////////////////
  483. // Emplace testing
  484. ////////////////////////////////////
  485. const test::EmplaceOptions MapOptions = (test::EmplaceOptions)(test::EMPLACE_HINT_PAIR | test::EMPLACE_ASSOC_PAIR);
  486. if(!boost::container::test::test_emplace<map<test::EmplaceInt, test::EmplaceInt>, MapOptions>())
  487. return 1;
  488. if(!boost::container::test::test_emplace<multimap<test::EmplaceInt, test::EmplaceInt>, MapOptions>())
  489. return 1;
  490. ////////////////////////////////////
  491. // Allocator propagation testing
  492. ////////////////////////////////////
  493. if(!boost::container::test::test_propagate_allocator<boost_container_map>())
  494. return 1;
  495. if(!boost::container::test::test_propagate_allocator<boost_container_multimap>())
  496. return 1;
  497. if (!boost::container::test::test_map_support_for_initialization_list_for<map<int, int> >())
  498. return 1;
  499. if (!boost::container::test::test_map_support_for_initialization_list_for<multimap<int, int> >())
  500. return 1;
  501. ////////////////////////////////////
  502. // Iterator testing
  503. ////////////////////////////////////
  504. {
  505. typedef boost::container::map<int, int> cont_int;
  506. cont_int a; a.insert(cont_int::value_type(0, 9)); a.insert(cont_int::value_type(1, 9)); a.insert(cont_int::value_type(2, 9));
  507. boost::intrusive::test::test_iterator_bidirectional< cont_int >(a);
  508. if(boost::report_errors() != 0) {
  509. return 1;
  510. }
  511. }
  512. {
  513. typedef boost::container::multimap<int, int> cont_int;
  514. cont_int a; a.insert(cont_int::value_type(0, 9)); a.insert(cont_int::value_type(1, 9)); a.insert(cont_int::value_type(2, 9));
  515. boost::intrusive::test::test_iterator_bidirectional< cont_int >(a);
  516. if(boost::report_errors() != 0) {
  517. return 1;
  518. }
  519. }
  520. ////////////////////////////////////
  521. // Node extraction/insertion testing functions
  522. ////////////////////////////////////
  523. if(!node_type_test())
  524. return 1;
  525. ////////////////////////////////////
  526. // Constructor Template Auto Deduction test
  527. ////////////////////////////////////
  528. if (!test::constructor_template_auto_deduction_test()) {
  529. return 1;
  530. }
  531. if (!boost::container::test::instantiate_constructors<map<int, int>, multimap<int, int> >())
  532. return 1;
  533. test::test_merge_from_different_comparison();
  534. if(!test::test_heterogeneous_lookups())
  535. return 1;
  536. ////////////////////////////////////
  537. // Test optimize_size option
  538. ////////////////////////////////////
  539. //
  540. // map
  541. //
  542. typedef map< int*, int*, std::less<int*>, std::allocator< std::pair<int *const, int*> >
  543. , tree_assoc_options< optimize_size<false>, tree_type<red_black_tree> >::type > rbmap_size_optimized_no;
  544. typedef map< int*, int*, std::less<int*>, std::allocator< std::pair<int *const, int*> >
  545. , tree_assoc_options< optimize_size<true>, tree_type<avl_tree> >::type > avlmap_size_optimized_yes;
  546. //
  547. // multimap
  548. //
  549. typedef multimap< int*, int*, std::less<int*>, std::allocator< std::pair<int *const, int*> >
  550. , tree_assoc_options< optimize_size<true>, tree_type<red_black_tree> >::type > rbmmap_size_optimized_yes;
  551. typedef multimap< int*, int*, std::less<int*>, std::allocator< std::pair<int *const, int*> >
  552. , tree_assoc_options< optimize_size<false>, tree_type<avl_tree> >::type > avlmmap_size_optimized_no;
  553. BOOST_STATIC_ASSERT(sizeof(rbmmap_size_optimized_yes) < sizeof(rbmap_size_optimized_no));
  554. BOOST_STATIC_ASSERT(sizeof(avlmap_size_optimized_yes) < sizeof(avlmmap_size_optimized_no));
  555. ////////////////////////////////////
  556. // has_trivial_destructor_after_move testing
  557. ////////////////////////////////////
  558. {
  559. typedef std::pair<const int, int> value_type;
  560. //
  561. // map
  562. //
  563. // default allocator
  564. {
  565. typedef boost::container::map<int, int> cont;
  566. typedef boost::container::dtl::tree<value_type, int, std::less<int>, void, void> tree;
  567. if (boost::has_trivial_destructor_after_move<cont>::value !=
  568. boost::has_trivial_destructor_after_move<tree>::value) {
  569. std::cerr << "has_trivial_destructor_after_move(map, default allocator) test failed" << std::endl;
  570. return 1;
  571. }
  572. }
  573. // std::allocator
  574. {
  575. typedef boost::container::map<int, int, std::less<int>, std::allocator<value_type> > cont;
  576. typedef boost::container::dtl::tree<value_type, int, std::less<int>, std::allocator<value_type>, void> tree;
  577. if (boost::has_trivial_destructor_after_move<cont>::value !=
  578. boost::has_trivial_destructor_after_move<tree>::value) {
  579. std::cerr << "has_trivial_destructor_after_move(map, std::allocator) test failed" << std::endl;
  580. return 1;
  581. }
  582. }
  583. //
  584. // multimap
  585. //
  586. // default allocator
  587. {
  588. // default allocator
  589. typedef boost::container::multimap<int, int> cont;
  590. typedef boost::container::dtl::tree<value_type, int, std::less<int>, void, void> tree;
  591. if (boost::has_trivial_destructor_after_move<cont>::value !=
  592. boost::has_trivial_destructor_after_move<tree>::value) {
  593. std::cerr << "has_trivial_destructor_after_move(multimap, default allocator) test failed" << std::endl;
  594. return 1;
  595. }
  596. }
  597. // std::allocator
  598. {
  599. typedef boost::container::multimap<int, int, std::less<int>, std::allocator<value_type> > cont;
  600. typedef boost::container::dtl::tree<value_type, int, std::less<int>, std::allocator<value_type>, void> tree;
  601. if (boost::has_trivial_destructor_after_move<cont>::value !=
  602. boost::has_trivial_destructor_after_move<tree>::value) {
  603. std::cerr << "has_trivial_destructor_after_move(multimap, std::allocator) test failed" << std::endl;
  604. return 1;
  605. }
  606. }
  607. }
  608. return 0;
  609. }
  610. #include <boost/container/detail/config_end.hpp>