set_test.hpp 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942
  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. #ifndef BOOST_CONTAINER_TEST_SET_TEST_HEADER
  11. #define BOOST_CONTAINER_TEST_SET_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/move/utility_core.hpp>
  17. #include <boost/move/iterator.hpp>
  18. #include <boost/move/make_unique.hpp>
  19. #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME rebalance
  20. #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEG namespace boost { namespace container { namespace test {
  21. #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END }}}
  22. #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MIN 0
  23. #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MAX 0
  24. #include <boost/intrusive/detail/has_member_function_callable_with.hpp>
  25. namespace boost{
  26. namespace container {
  27. namespace test{
  28. template<class C>
  29. void set_test_rebalanceable(C &, boost::container::dtl::false_type)
  30. {}
  31. template<class C>
  32. void set_test_rebalanceable(C &c, boost::container::dtl::true_type)
  33. {
  34. c.rebalance();
  35. }
  36. template<class MyBoostSet
  37. ,class MyStdSet
  38. ,class MyBoostMultiSet
  39. ,class MyStdMultiSet>
  40. int set_test_copyable(boost::container::dtl::false_type)
  41. { return 0; }
  42. const int MaxElem = 50;
  43. template<class MyBoostSet
  44. ,class MyStdSet
  45. ,class MyBoostMultiSet
  46. ,class MyStdMultiSet>
  47. int set_test_copyable(boost::container::dtl::true_type)
  48. {
  49. typedef typename MyBoostSet::value_type IntType;
  50. ::boost::movelib::unique_ptr<MyBoostSet> const pboostset = ::boost::movelib::make_unique<MyBoostSet>();
  51. ::boost::movelib::unique_ptr<MyStdSet> const pstdset = ::boost::movelib::make_unique<MyStdSet>();
  52. ::boost::movelib::unique_ptr<MyBoostMultiSet> const pboostmultiset = ::boost::movelib::make_unique<MyBoostMultiSet>();
  53. ::boost::movelib::unique_ptr<MyStdMultiSet> const pstdmultiset = ::boost::movelib::make_unique<MyStdMultiSet>();
  54. MyBoostSet &boostset = *pboostset;
  55. MyStdSet &stdset = *pstdset;
  56. MyBoostMultiSet &boostmultiset = *pboostmultiset;
  57. MyStdMultiSet &stdmultiset = *pstdmultiset;
  58. //Just to test move aware catch conversions
  59. boostset.insert(boostset.cbegin(), boostset.cend());
  60. boostmultiset.insert(boostmultiset.cbegin(), boostmultiset.cend());
  61. boostset.insert(boostset.begin(), boostset.end());
  62. boostmultiset.insert(boostmultiset.begin(), boostmultiset.end());
  63. for(int i = 0; i < MaxElem; ++i){
  64. IntType move_me(i);
  65. boostset.insert(boost::move(move_me));
  66. stdset.insert(i);
  67. IntType move_me2(i);
  68. boostmultiset.insert(boost::move(move_me2));
  69. stdmultiset.insert(i);
  70. }
  71. if(!CheckEqualContainers(boostset, stdset)) return 1;
  72. if(!CheckEqualContainers(boostmultiset, stdmultiset)) return 1;
  73. {
  74. //Now, test copy constructor
  75. MyBoostSet boostsetcopy(boostset);
  76. MyStdSet stdsetcopy(stdset);
  77. if(!CheckEqualContainers(boostsetcopy, stdsetcopy))
  78. return 1;
  79. MyBoostMultiSet boostmsetcopy(boostmultiset);
  80. MyStdMultiSet stdmsetcopy(stdmultiset);
  81. if(!CheckEqualContainers(boostmsetcopy, stdmsetcopy))
  82. return 1;
  83. //And now assignment
  84. boostsetcopy =boostset;
  85. stdsetcopy = stdset;
  86. if(!CheckEqualContainers(boostsetcopy, stdsetcopy))
  87. return 1;
  88. boostmsetcopy = boostmultiset;
  89. stdmsetcopy = stdmultiset;
  90. if(!CheckEqualContainers(boostmsetcopy, stdmsetcopy))
  91. return 1;
  92. }
  93. {
  94. //Now, test copy constructor
  95. MyBoostSet boostsetcopy(boostset, typename MyBoostSet::allocator_type());
  96. MyStdSet stdsetcopy(stdset);
  97. if(!CheckEqualContainers(boostsetcopy, stdsetcopy))
  98. return 1;
  99. MyBoostMultiSet boostmsetcopy(boostmultiset, typename MyBoostSet::allocator_type());
  100. MyStdMultiSet stdmsetcopy(stdmultiset);
  101. if(!CheckEqualContainers(boostmsetcopy, stdmsetcopy))
  102. return 1;
  103. }
  104. return 0;
  105. }
  106. template<class MyBoostSet
  107. ,class MyStdSet
  108. ,class MyBoostMultiSet
  109. ,class MyStdMultiSet>
  110. int set_test ()
  111. {
  112. typedef typename MyBoostSet::value_type IntType;
  113. ::boost::movelib::unique_ptr<MyBoostSet> const pboostset = ::boost::movelib::make_unique<MyBoostSet>();
  114. ::boost::movelib::unique_ptr<MyStdSet> const pstdset = ::boost::movelib::make_unique<MyStdSet>();
  115. ::boost::movelib::unique_ptr<MyBoostMultiSet> const pboostmultiset = ::boost::movelib::make_unique<MyBoostMultiSet>();
  116. ::boost::movelib::unique_ptr<MyStdMultiSet> const pstdmultiset = ::boost::movelib::make_unique<MyStdMultiSet>();
  117. MyBoostSet &boostset = *pboostset;
  118. MyStdSet &stdset = *pstdset;
  119. MyBoostMultiSet &boostmultiset = *pboostmultiset;
  120. MyStdMultiSet &stdmultiset = *pstdmultiset;
  121. //Test construction from a range
  122. { //Set(beg, end, compare)
  123. IntType aux_vect[50];
  124. for(int i = 0; i < 50; ++i){
  125. IntType move_me(i/2);
  126. aux_vect[i] = boost::move(move_me);
  127. }
  128. int aux_vect2[50];
  129. for(int i = 0; i < 50; ++i){
  130. aux_vect2[i] = i/2;
  131. }
  132. IntType aux_vect3[50];
  133. for(int i = 0; i < 50; ++i){
  134. IntType move_me(i/2);
  135. aux_vect3[i] = boost::move(move_me);
  136. }
  137. ::boost::movelib::unique_ptr<MyBoostSet> const pboostset2 = ::boost::movelib::make_unique<MyBoostSet>
  138. (boost::make_move_iterator(&aux_vect[0]), boost::make_move_iterator(&aux_vect[0]+50), typename MyBoostSet::key_compare());
  139. ::boost::movelib::unique_ptr<MyStdSet> const pstdset2 = ::boost::movelib::make_unique<MyStdSet>(&aux_vect2[0], &aux_vect2[0]+50);
  140. if(!test::CheckEqualContainers(*pboostset2, *pstdset2)) return 1;
  141. ::boost::movelib::unique_ptr<MyBoostMultiSet> const pboostmultiset2 = ::boost::movelib::make_unique<MyBoostMultiSet>
  142. (boost::make_move_iterator(&aux_vect3[0]), boost::make_move_iterator(&aux_vect3[0]+50), typename MyBoostMultiSet::key_compare());
  143. ::boost::movelib::unique_ptr<MyStdMultiSet> const pstdmultiset2 = ::boost::movelib::make_unique<MyStdMultiSet>(&aux_vect2[0], &aux_vect2[0]+50);
  144. if(!test::CheckEqualContainers(*pboostmultiset2, *pstdmultiset2)) return 1;
  145. }
  146. { //Set(beg, end, alloc)
  147. IntType aux_vect[50];
  148. for(int i = 0; i < 50; ++i){
  149. IntType move_me(i/2);
  150. aux_vect[i] = boost::move(move_me);
  151. }
  152. int aux_vect2[50];
  153. for(int i = 0; i < 50; ++i){
  154. aux_vect2[i] = i/2;
  155. }
  156. IntType aux_vect3[50];
  157. for(int i = 0; i < 50; ++i){
  158. IntType move_me(i/2);
  159. aux_vect3[i] = boost::move(move_me);
  160. }
  161. ::boost::movelib::unique_ptr<MyBoostSet> const pboostset2 = ::boost::movelib::make_unique<MyBoostSet>
  162. (boost::make_move_iterator(&aux_vect[0]), boost::make_move_iterator(&aux_vect[0]+50), typename MyBoostSet::allocator_type());
  163. ::boost::movelib::unique_ptr<MyStdSet> const pstdset2 = ::boost::movelib::make_unique<MyStdSet>(&aux_vect2[0], &aux_vect2[0]+50);
  164. if(!test::CheckEqualContainers(*pboostset2, *pstdset2)) return 1;
  165. ::boost::movelib::unique_ptr<MyBoostMultiSet> const pboostmultiset2 = ::boost::movelib::make_unique<MyBoostMultiSet>
  166. (boost::make_move_iterator(&aux_vect3[0]), boost::make_move_iterator(&aux_vect3[0]+50), typename MyBoostMultiSet::allocator_type());
  167. ::boost::movelib::unique_ptr<MyStdMultiSet> const pstdmultiset2 = ::boost::movelib::make_unique<MyStdMultiSet>(&aux_vect2[0], &aux_vect2[0]+50);
  168. if(!test::CheckEqualContainers(*pboostmultiset2, *pstdmultiset2)) return 1;
  169. }
  170. {
  171. IntType aux_vect[50];
  172. for(int i = 0; i < 50; ++i){
  173. IntType move_me(i/2);
  174. aux_vect[i] = boost::move(move_me);
  175. }
  176. int aux_vect2[50];
  177. for(int i = 0; i < 50; ++i){
  178. aux_vect2[i] = i/2;
  179. }
  180. IntType aux_vect3[50];
  181. for(int i = 0; i < 50; ++i){
  182. IntType move_me(i/2);
  183. aux_vect3[i] = boost::move(move_me);
  184. }
  185. ::boost::movelib::unique_ptr<MyBoostSet> const pboostset2 = ::boost::movelib::make_unique<MyBoostSet>
  186. ( boost::make_move_iterator(&aux_vect[0])
  187. , boost::make_move_iterator(aux_vect + 50));
  188. ::boost::movelib::unique_ptr<MyStdSet> const pstdset2 = ::boost::movelib::make_unique<MyStdSet>
  189. (&aux_vect2[0], &aux_vect2[0] + 50);
  190. ::boost::movelib::unique_ptr<MyBoostMultiSet> const pboostmultiset2 = ::boost::movelib::make_unique<MyBoostMultiSet>
  191. ( boost::make_move_iterator(&aux_vect3[0])
  192. , boost::make_move_iterator(aux_vect3 + 50));
  193. ::boost::movelib::unique_ptr<MyStdMultiSet> const pstdmultiset2 = ::boost::movelib::make_unique<MyStdMultiSet>
  194. (&aux_vect2[0], &aux_vect2[0] + 50);
  195. MyBoostSet &boostset2 = *pboostset2;
  196. MyStdSet &stdset2 = *pstdset2;
  197. MyBoostMultiSet &boostmultiset2 = *pboostmultiset2;
  198. MyStdMultiSet &stdmultiset2 = *pstdmultiset2;
  199. if(!CheckEqualContainers(boostset2, stdset2)){
  200. std::cout << "Error in construct<MyBoostSet>(MyBoostSet2)" << std::endl;
  201. return 1;
  202. }
  203. if(!CheckEqualContainers(boostmultiset2, stdmultiset2)){
  204. std::cout << "Error in construct<MyBoostMultiSet>(MyBoostMultiSet2)" << std::endl;
  205. return 1;
  206. }
  207. //ordered range insertion
  208. for(int i = 0; i < 50; ++i){
  209. IntType move_me(i);
  210. aux_vect[i] = boost::move(move_me);
  211. }
  212. for(int i = 0; i < 50; ++i){
  213. aux_vect2[i] = i;
  214. }
  215. for(int i = 0; i < 50; ++i){
  216. IntType move_me(i);
  217. aux_vect3[i] = boost::move(move_me);
  218. }
  219. //some comparison operators
  220. if(!(boostset2 == boostset2))
  221. return 1;
  222. if(boostset2 != boostset2)
  223. return 1;
  224. if(boostset2 < boostset2)
  225. return 1;
  226. if(boostset2 > boostset2)
  227. return 1;
  228. if(!(boostset2 <= boostset2))
  229. return 1;
  230. if(!(boostset2 >= boostset2))
  231. return 1;
  232. ::boost::movelib::unique_ptr<MyBoostSet> const pboostset3 = ::boost::movelib::make_unique<MyBoostSet>
  233. ( ordered_unique_range
  234. , boost::make_move_iterator(&aux_vect[0])
  235. , boost::make_move_iterator(&aux_vect[0] + 50));
  236. ::boost::movelib::unique_ptr<MyStdSet> const pstdset3 = ::boost::movelib::make_unique<MyStdSet>
  237. (&aux_vect2[0], &aux_vect2[0] + 50);
  238. ::boost::movelib::unique_ptr<MyBoostMultiSet> const pboostmultiset3 = ::boost::movelib::make_unique<MyBoostMultiSet>
  239. ( ordered_range
  240. , boost::make_move_iterator(&aux_vect3[0])
  241. , boost::make_move_iterator(aux_vect3 + 50));
  242. ::boost::movelib::unique_ptr<MyStdMultiSet> const pstdmultiset3 = ::boost::movelib::make_unique<MyStdMultiSet>
  243. (&aux_vect2[0], &aux_vect2[0] + 50);
  244. MyBoostSet &boostset3 = *pboostset3;
  245. MyStdSet &stdset3 = *pstdset3;
  246. MyBoostMultiSet &boostmultiset3 = *pboostmultiset3;
  247. MyStdMultiSet &stdmultiset3 = *pstdmultiset3;
  248. if(!CheckEqualContainers(boostset3, stdset3)){
  249. std::cout << "Error in construct<MyBoostSet>(MyBoostSet3)" << std::endl;
  250. return 1;
  251. }
  252. if(!CheckEqualContainers(boostmultiset3, stdmultiset3)){
  253. std::cout << "Error in construct<MyBoostMultiSet>(MyBoostMultiSet3)" << std::endl;
  254. return 1;
  255. }
  256. }
  257. for(int i = 0; i < MaxElem; ++i){
  258. IntType move_me(i);
  259. boostset.insert(boost::move(move_me));
  260. stdset.insert(i);
  261. boostset.insert(IntType(i));
  262. stdset.insert(i);
  263. IntType move_me2(i);
  264. boostmultiset.insert(boost::move(move_me2));
  265. stdmultiset.insert(i);
  266. boostmultiset.insert(IntType(i));
  267. stdmultiset.insert(i);
  268. }
  269. if(!CheckEqualContainers(boostset, stdset)){
  270. std::cout << "Error in boostset.insert(boost::move(move_me)" << std::endl;
  271. return 1;
  272. }
  273. if(!CheckEqualContainers(boostmultiset, stdmultiset)){
  274. std::cout << "Error in boostmultiset.insert(boost::move(move_me)" << std::endl;
  275. return 1;
  276. }
  277. typename MyBoostSet::iterator it = boostset.begin();
  278. typename MyBoostSet::const_iterator cit = it;
  279. (void)cit;
  280. boostset.erase(boostset.begin());
  281. stdset.erase(stdset.begin());
  282. boostmultiset.erase(boostmultiset.begin());
  283. stdmultiset.erase(stdmultiset.begin());
  284. if(!CheckEqualContainers(boostset, stdset)){
  285. std::cout << "Error in boostset.erase(boostset.begin())" << std::endl;
  286. return 1;
  287. }
  288. if(!CheckEqualContainers(boostmultiset, stdmultiset)){
  289. std::cout << "Error in boostmultiset.erase(boostmultiset.begin())" << std::endl;
  290. return 1;
  291. }
  292. boostset.erase(boostset.begin());
  293. stdset.erase(stdset.begin());
  294. boostmultiset.erase(boostmultiset.begin());
  295. stdmultiset.erase(stdmultiset.begin());
  296. if(!CheckEqualContainers(boostset, stdset)){
  297. std::cout << "Error in boostset.erase(boostset.begin())" << std::endl;
  298. return 1;
  299. }
  300. if(!CheckEqualContainers(boostmultiset, stdmultiset)){
  301. std::cout << "Error in boostmultiset.erase(boostmultiset.begin())" << std::endl;
  302. return 1;
  303. }
  304. //Swapping test
  305. MyBoostSet tmpboosteset2;
  306. MyStdSet tmpstdset2;
  307. MyBoostMultiSet tmpboostemultiset2;
  308. MyStdMultiSet tmpstdmultiset2;
  309. boostset.swap(tmpboosteset2);
  310. stdset.swap(tmpstdset2);
  311. boostmultiset.swap(tmpboostemultiset2);
  312. stdmultiset.swap(tmpstdmultiset2);
  313. boostset.swap(tmpboosteset2);
  314. stdset.swap(tmpstdset2);
  315. boostmultiset.swap(tmpboostemultiset2);
  316. stdmultiset.swap(tmpstdmultiset2);
  317. if(!CheckEqualContainers(boostset, stdset)){
  318. std::cout << "Error in boostset.swap(tmpboosteset2)" << std::endl;
  319. return 1;
  320. }
  321. if(!CheckEqualContainers(boostmultiset, stdmultiset)){
  322. std::cout << "Error in boostmultiset.swap(tmpboostemultiset2)" << std::endl;
  323. return 1;
  324. }
  325. //Insertion from other container
  326. //Initialize values
  327. {
  328. IntType aux_vect[50];
  329. for(int i = 0; i < 50; ++i){
  330. IntType move_me(-1);
  331. aux_vect[i] = boost::move(move_me);
  332. }
  333. int aux_vect2[50];
  334. for(int i = 0; i < 50; ++i){
  335. aux_vect2[i] = -1;
  336. }
  337. IntType aux_vect3[50];
  338. for(int i = 0; i < 50; ++i){
  339. IntType move_me(-1);
  340. aux_vect3[i] = boost::move(move_me);
  341. }
  342. boostset.insert(boost::make_move_iterator(&aux_vect[0]), boost::make_move_iterator(&aux_vect[0] + 50));
  343. stdset.insert(&aux_vect2[0], &aux_vect2[0] + 50);
  344. if(!CheckEqualContainers(boostset, stdset)){
  345. std::cout << "Error in boostset.insert(boost::make_move_iterator(&aux_vect3[0])..." << std::endl;
  346. return 1;
  347. }
  348. boostmultiset.insert(boost::make_move_iterator(&aux_vect3[0]), boost::make_move_iterator(aux_vect3 + 50));
  349. stdmultiset.insert(&aux_vect2[0], &aux_vect2[0] + 50);
  350. if(!CheckEqualContainers(boostmultiset, stdmultiset)){
  351. std::cout << "Error in boostmultiset.insert(boost::make_move_iterator(&aux_vect3[0]), ..." << std::endl;
  352. return 1;
  353. }
  354. for(int i = 0, j = static_cast<int>(boostset.size()); i < j; ++i){
  355. IntType erase_me(i);
  356. boostset.erase(erase_me);
  357. stdset.erase(i);
  358. boostmultiset.erase(erase_me);
  359. stdmultiset.erase(i);
  360. if(!CheckEqualContainers(boostset, stdset)){
  361. std::cout << "Error in boostset.erase(erase_me)" << boostset.size() << " " << stdset.size() << std::endl;
  362. return 1;
  363. }
  364. if(!CheckEqualContainers(boostmultiset, stdmultiset)){
  365. std::cout << "Error in boostmultiset.erase(erase_me)" << std::endl;
  366. return 1;
  367. }
  368. }
  369. }
  370. {
  371. IntType aux_vect[50];
  372. for(int i = 0; i < 50; ++i){
  373. IntType move_me(-1);
  374. aux_vect[i] = boost::move(move_me);
  375. }
  376. int aux_vect2[50];
  377. for(int i = 0; i < 50; ++i){
  378. aux_vect2[i] = -1;
  379. }
  380. IntType aux_vect3[50];
  381. for(int i = 0; i < 50; ++i){
  382. IntType move_me(-1);
  383. aux_vect3[i] = boost::move(move_me);
  384. }
  385. IntType aux_vect4[50];
  386. for(int i = 0; i < 50; ++i){
  387. IntType move_me(-1);
  388. aux_vect4[i] = boost::move(move_me);
  389. }
  390. IntType aux_vect5[50];
  391. for(int i = 0; i < 50; ++i){
  392. IntType move_me(-1);
  393. aux_vect5[i] = boost::move(move_me);
  394. }
  395. boostset.insert(boost::make_move_iterator(&aux_vect[0]), boost::make_move_iterator(&aux_vect[0] + 50));
  396. boostset.insert(boost::make_move_iterator(&aux_vect3[0]), boost::make_move_iterator(&aux_vect3[0] + 50));
  397. stdset.insert(&aux_vect2[0], &aux_vect2[0] + 50);
  398. stdset.insert(&aux_vect2[0], &aux_vect2[0] + 50);
  399. if(!CheckEqualContainers(boostset, stdset)){
  400. std::cout << "Error in boostset.insert(boost::make_move_iterator(&aux_vect3[0])..." << std::endl;
  401. return 1;
  402. }
  403. boostmultiset.insert(boost::make_move_iterator(&aux_vect4[0]), boost::make_move_iterator(&aux_vect4[0] + 50));
  404. boostmultiset.insert(boost::make_move_iterator(&aux_vect5[0]), boost::make_move_iterator(&aux_vect5[0] + 50));
  405. stdmultiset.insert(&aux_vect2[0], &aux_vect2[0] + 50);
  406. stdmultiset.insert(&aux_vect2[0], &aux_vect2[0] + 50);
  407. if(!CheckEqualContainers(boostmultiset, stdmultiset)){
  408. std::cout << "Error in boostmultiset.insert(boost::make_move_iterator(&aux_vect5[0])..." << std::endl;
  409. return 1;
  410. }
  411. boostset.erase(*boostset.begin());
  412. stdset.erase(*stdset.begin());
  413. if(!CheckEqualContainers(boostset, stdset)){
  414. std::cout << "Error in boostset.erase(*boostset.begin())" << std::endl;
  415. return 1;
  416. }
  417. boostmultiset.erase(*boostmultiset.begin());
  418. stdmultiset.erase(*stdmultiset.begin());
  419. if(!CheckEqualContainers(boostmultiset, stdmultiset)){
  420. std::cout << "Error in boostmultiset.erase(*boostmultiset.begin())" << std::endl;
  421. return 1;
  422. }
  423. }
  424. for(int i = 0; i < MaxElem; ++i){
  425. IntType move_me(i);
  426. boostset.insert(boost::move(move_me));
  427. stdset.insert(i);
  428. IntType move_me2(i);
  429. boostmultiset.insert(boost::move(move_me2));
  430. stdmultiset.insert(i);
  431. }
  432. if(!CheckEqualContainers(boostset, stdset)){
  433. std::cout << "Error in boostset.insert(boost::move(move_me)) try 2" << std::endl;
  434. return 1;
  435. }
  436. if(!CheckEqualContainers(boostmultiset, stdmultiset)){
  437. std::cout << "Error in boostmultiset.insert(boost::move(move_me2)) try 2" << std::endl;
  438. return 1;
  439. }
  440. for(int i = 0; i < MaxElem; ++i){
  441. {
  442. IntType move_me(i);
  443. boostset.insert(boostset.begin(), boost::move(move_me));
  444. stdset.insert(stdset.begin(), i);
  445. //PrintContainers(boostset, stdset);
  446. IntType move_me2(i);
  447. boostmultiset.insert(boostmultiset.begin(), boost::move(move_me2));
  448. stdmultiset.insert(stdmultiset.begin(), i);
  449. //PrintContainers(boostmultiset, stdmultiset);
  450. if(!CheckEqualContainers(boostset, stdset)){
  451. std::cout << "Error in boostset.insert(boostset.begin(), boost::move(move_me))" << std::endl;
  452. return 1;
  453. }
  454. if(!CheckEqualContainers(boostmultiset, stdmultiset)){
  455. std::cout << "Error in boostmultiset.insert(boostmultiset.begin(), boost::move(move_me2))" << std::endl;
  456. return 1;
  457. }
  458. IntType move_me3(i);
  459. boostset.insert(boostset.end(), boost::move(move_me3));
  460. stdset.insert(stdset.end(), i);
  461. IntType move_me4(i);
  462. boostmultiset.insert(boostmultiset.end(), boost::move(move_me4));
  463. stdmultiset.insert(stdmultiset.end(), i);
  464. if(!CheckEqualContainers(boostset, stdset)){
  465. std::cout << "Error in boostset.insert(boostset.end(), boost::move(move_me3))" << std::endl;
  466. return 1;
  467. }
  468. if(!CheckEqualContainers(boostmultiset, stdmultiset)){
  469. std::cout << "Error in boostmultiset.insert(boostmultiset.end(), boost::move(move_me4))" << std::endl;
  470. return 1;
  471. }
  472. }
  473. {
  474. IntType move_me(i);
  475. boostset.insert(boostset.upper_bound(move_me), boost::move(move_me));
  476. stdset.insert(stdset.upper_bound(i), i);
  477. //PrintContainers(boostset, stdset);
  478. IntType move_me2(i);
  479. boostmultiset.insert(boostmultiset.upper_bound(move_me2), boost::move(move_me2));
  480. stdmultiset.insert(stdmultiset.upper_bound(i), i);
  481. //PrintContainers(boostmultiset, stdmultiset);
  482. if(!CheckEqualContainers(boostset, stdset)){
  483. std::cout << "Error in boostset.insert(boostset.upper_bound(move_me), boost::move(move_me))" << std::endl;
  484. return 1;
  485. }
  486. if(!CheckEqualContainers(boostmultiset, stdmultiset)){
  487. std::cout << "Error in boostmultiset.insert(boostmultiset.upper_bound(move_me2), boost::move(move_me2))" << std::endl;
  488. return 1;
  489. }
  490. }
  491. {
  492. IntType move_me(i);
  493. IntType move_me2(i);
  494. boostset.insert(boostset.lower_bound(move_me), boost::move(move_me2));
  495. stdset.insert(stdset.lower_bound(i), i);
  496. //PrintContainers(boostset, stdset);
  497. move_me2 = i;
  498. boostmultiset.insert(boostmultiset.lower_bound(move_me2), boost::move(move_me2));
  499. stdmultiset.insert(stdmultiset.lower_bound(i), i);
  500. //PrintContainers(boostmultiset, stdmultiset);
  501. if(!CheckEqualContainers(boostset, stdset)){
  502. std::cout << "Error in boostset.insert(boostset.lower_bound(move_me), boost::move(move_me2))" << std::endl;
  503. return 1;
  504. }
  505. if(!CheckEqualContainers(boostmultiset, stdmultiset)){
  506. std::cout << "Error in boostmultiset.insert(boostmultiset.lower_bound(move_me2), boost::move(move_me2))" << std::endl;
  507. return 1;
  508. }
  509. set_test_rebalanceable(boostset
  510. , dtl::bool_<has_member_function_callable_with_rebalance<MyBoostSet>::value>());
  511. if(!CheckEqualContainers(boostset, stdset)){
  512. std::cout << "Error in boostset.rebalance()" << std::endl;
  513. return 1;
  514. }
  515. set_test_rebalanceable(boostmultiset
  516. , dtl::bool_<has_member_function_callable_with_rebalance<MyBoostMultiSet>::value>());
  517. if(!CheckEqualContainers(boostmultiset, stdmultiset)){
  518. std::cout << "Error in boostmultiset.rebalance()" << std::endl;
  519. return 1;
  520. }
  521. }
  522. }
  523. //Compare count with std containers
  524. for(int i = 0; i < MaxElem; ++i){
  525. IntType k(i);
  526. if(boostset.count(k) != stdset.count(i)){
  527. return -1;
  528. }
  529. if(boostset.contains(k) != (stdset.find(i) != stdset.end())){
  530. return -1;
  531. }
  532. if(boostmultiset.count(k) != stdmultiset.count(i)){
  533. return -1;
  534. }
  535. if(boostmultiset.contains(k) != (stdmultiset.find(i) != stdmultiset.end())){
  536. return -1;
  537. }
  538. }
  539. //Compare find/lower_bound/upper_bound in set
  540. {
  541. typename MyBoostSet::iterator bs_b = boostset.begin();
  542. typename MyBoostSet::iterator bs_e = boostset.end();
  543. typename MyStdSet::iterator ss_b = stdset.begin();
  544. std::size_t i = 0;
  545. while(bs_b != bs_e){
  546. ++i;
  547. typename MyBoostSet::iterator bs_i;
  548. typename MyStdSet::iterator ss_i;
  549. //find
  550. bs_i = boostset.find(*bs_b);
  551. ss_i = stdset.find(*ss_b);
  552. if(!CheckEqualIt(bs_i, ss_i, boostset, stdset)){
  553. return -1;
  554. }
  555. //lower bound
  556. bs_i = boostset.lower_bound(*bs_b);
  557. ss_i = stdset.lower_bound(*ss_b);
  558. if(!CheckEqualIt(bs_i, ss_i, boostset, stdset)){
  559. return -1;
  560. }
  561. //upper bound
  562. bs_i = boostset.upper_bound(*bs_b);
  563. ss_i = stdset.upper_bound(*ss_b);
  564. if(!CheckEqualIt(bs_i, ss_i, boostset, stdset)){
  565. return -1;
  566. }
  567. //equal range
  568. std::pair<typename MyBoostSet::iterator
  569. ,typename MyBoostSet::iterator> bs_ip;
  570. std::pair<typename MyStdSet::iterator
  571. ,typename MyStdSet::iterator> ss_ip;
  572. bs_ip = boostset.equal_range(*bs_b);
  573. ss_ip = stdset.equal_range(*ss_b);
  574. if(!CheckEqualIt(bs_ip.first, ss_ip.first, boostset, stdset)){
  575. return -1;
  576. }
  577. if(!CheckEqualIt(bs_ip.second, ss_ip.second, boostset, stdset)){
  578. return -1;
  579. }
  580. ++bs_b;
  581. ++ss_b;
  582. }
  583. }
  584. //Compare find/lower_bound/upper_bound in multiset
  585. {
  586. typename MyBoostMultiSet::iterator bm_b = boostmultiset.begin();
  587. typename MyBoostMultiSet::iterator bm_e = boostmultiset.end();
  588. typename MyStdMultiSet::iterator sm_b = stdmultiset.begin();
  589. while(bm_b != bm_e){
  590. typename MyBoostMultiSet::iterator bm_i;
  591. typename MyStdMultiSet::iterator sm_i;
  592. //find
  593. bm_i = boostmultiset.find(*bm_b);
  594. sm_i = stdmultiset.find(*sm_b);
  595. if(!CheckEqualIt(bm_i, sm_i, boostmultiset, stdmultiset)){
  596. return -1;
  597. }
  598. //lower bound
  599. bm_i = boostmultiset.lower_bound(*bm_b);
  600. sm_i = stdmultiset.lower_bound(*sm_b);
  601. if(!CheckEqualIt(bm_i, sm_i, boostmultiset, stdmultiset)){
  602. return -1;
  603. }
  604. //upper bound
  605. bm_i = boostmultiset.upper_bound(*bm_b);
  606. sm_i = stdmultiset.upper_bound(*sm_b);
  607. if(!CheckEqualIt(bm_i, sm_i, boostmultiset, stdmultiset)){
  608. return -1;
  609. }
  610. //equal range
  611. std::pair<typename MyBoostMultiSet::iterator
  612. ,typename MyBoostMultiSet::iterator> bm_ip;
  613. std::pair<typename MyStdMultiSet::iterator
  614. ,typename MyStdMultiSet::iterator> sm_ip;
  615. bm_ip = boostmultiset.equal_range(*bm_b);
  616. sm_ip = stdmultiset.equal_range(*sm_b);
  617. if(!CheckEqualIt(bm_ip.first, sm_ip.first, boostmultiset, stdmultiset)){
  618. return -1;
  619. }
  620. if(!CheckEqualIt(bm_ip.second, sm_ip.second, boostmultiset, stdmultiset)){
  621. return -1;
  622. }
  623. ++bm_b;
  624. ++sm_b;
  625. }
  626. }
  627. //Now do count exercise
  628. boostset.erase(boostset.begin(), boostset.end());
  629. boostmultiset.erase(boostmultiset.begin(), boostmultiset.end());
  630. boostset.clear();
  631. boostmultiset.clear();
  632. for(int j = 0; j < 3; ++j)
  633. for(int i = 0; i < 100; ++i){
  634. IntType move_me(i);
  635. boostset.insert(boost::move(move_me));
  636. IntType move_me2(i);
  637. boostmultiset.insert(boost::move(move_me2));
  638. IntType count_me(i);
  639. if(boostset.count(count_me) != typename MyBoostMultiSet::size_type(1)){
  640. std::cout << "Error in boostset.count(count_me)" << std::endl;
  641. return 1;
  642. }
  643. if(boostmultiset.count(count_me) != typename MyBoostMultiSet::size_type(j+1)){
  644. std::cout << "Error in boostmultiset.count(count_me)" << std::endl;
  645. return 1;
  646. }
  647. }
  648. { //merge
  649. ::boost::movelib::unique_ptr<MyBoostSet> const pboostset2 = ::boost::movelib::make_unique<MyBoostSet>();
  650. ::boost::movelib::unique_ptr<MyBoostMultiSet> const pboostmultiset2 = ::boost::movelib::make_unique<MyBoostMultiSet>();
  651. MyBoostSet &boostset2 = *pboostset2;
  652. MyBoostMultiSet &boostmultiset2 = *pboostmultiset2;
  653. boostset.clear();
  654. boostset2.clear();
  655. boostmultiset.clear();
  656. boostmultiset2.clear();
  657. stdset.clear();
  658. stdmultiset.clear();
  659. {
  660. IntType aux_vect[MaxElem];
  661. for(int i = 0; i < MaxElem; ++i){
  662. aux_vect[i] = i;
  663. }
  664. IntType aux_vect2[MaxElem];
  665. for(int i = 0; i < MaxElem; ++i){
  666. aux_vect2[i] = MaxElem/2+i;
  667. }
  668. IntType aux_vect3[MaxElem];
  669. for(int i = 0; i < MaxElem; ++i){
  670. aux_vect3[i] = MaxElem*2/2+i;
  671. }
  672. boostset.insert(boost::make_move_iterator(&aux_vect[0]), boost::make_move_iterator(&aux_vect[0] + MaxElem));
  673. boostset2.insert(boost::make_move_iterator(&aux_vect2[0]), boost::make_move_iterator(&aux_vect2[0] + MaxElem));
  674. boostmultiset2.insert(boost::make_move_iterator(&aux_vect3[0]), boost::make_move_iterator(&aux_vect3[0] + MaxElem));
  675. }
  676. for(int i = 0; i < MaxElem; ++i){
  677. stdset.insert(i);
  678. }
  679. for(int i = 0; i < MaxElem; ++i){
  680. stdset.insert(MaxElem/2+i);
  681. }
  682. boostset.merge(boost::move(boostset2));
  683. if(!CheckEqualContainers(boostset, stdset)) return 1;
  684. for(int i = 0; i < MaxElem; ++i){
  685. stdset.insert(MaxElem*2/2+i);
  686. }
  687. boostset.merge(boost::move(boostmultiset2));
  688. if(!CheckEqualContainers(boostset, stdset)) return 1;
  689. boostset.clear();
  690. boostset2.clear();
  691. boostmultiset.clear();
  692. boostmultiset2.clear();
  693. stdset.clear();
  694. stdmultiset.clear();
  695. {
  696. IntType aux_vect[MaxElem];
  697. for(int i = 0; i < MaxElem; ++i){
  698. aux_vect[i] = i;
  699. }
  700. IntType aux_vect2[MaxElem];
  701. for(int i = 0; i < MaxElem; ++i){
  702. aux_vect2[i] = MaxElem/2+i;
  703. }
  704. IntType aux_vect3[MaxElem];
  705. for(int i = 0; i < MaxElem; ++i){
  706. aux_vect3[i] = MaxElem*2/2+i;
  707. }
  708. boostmultiset.insert(boost::make_move_iterator(&aux_vect[0]), boost::make_move_iterator(&aux_vect[0] + MaxElem));
  709. boostmultiset2.insert(boost::make_move_iterator(&aux_vect2[0]), boost::make_move_iterator(&aux_vect2[0] + MaxElem));
  710. boostset2.insert(boost::make_move_iterator(&aux_vect3[0]), boost::make_move_iterator(&aux_vect3[0] + MaxElem));
  711. }
  712. for(int i = 0; i < MaxElem; ++i){
  713. stdmultiset.insert(i);
  714. }
  715. for(int i = 0; i < MaxElem; ++i){
  716. stdmultiset.insert(MaxElem/2+i);
  717. }
  718. boostmultiset.merge(boost::move(boostmultiset2));
  719. if(!CheckEqualContainers(boostmultiset, stdmultiset)) return 1;
  720. for(int i = 0; i < MaxElem; ++i){
  721. stdmultiset.insert(MaxElem*2/2+i);
  722. }
  723. boostmultiset.merge(boost::move(boostset2));
  724. if(!CheckEqualContainers(boostmultiset, stdmultiset)) return 1;
  725. }
  726. if(set_test_copyable<MyBoostSet, MyStdSet, MyBoostMultiSet, MyStdMultiSet>
  727. (dtl::bool_<boost::container::test::is_copyable<IntType>::value>())){
  728. return 1;
  729. }
  730. return 0;
  731. }
  732. template<typename SetType>
  733. bool test_set_methods_with_initializer_list_as_argument_for()
  734. {
  735. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  736. std::initializer_list<int> il = { 1, 2, 3, 4, 5, 5 };
  737. std::initializer_list<int> ilu = { 1, 2, 3, 4, 5 };
  738. SetType expected(il.begin(), il.end());
  739. SetType expectedu(ilu.begin(), ilu.end());
  740. {
  741. SetType sil((il));
  742. if (sil != expected)
  743. return false;
  744. SetType sila(il, typename SetType::allocator_type());
  745. if (sila != expected)
  746. return false;
  747. SetType silca(il, typename SetType::key_compare(), typename SetType::allocator_type());
  748. if (silca != expected)
  749. return false;
  750. SetType sil_ordered(ordered_unique_range, ilu);
  751. if (sil_ordered != expectedu)
  752. return false;
  753. SetType sil_assign = { 99, 100, 101, 102, 103, 104, 105 };
  754. sil_assign = il;
  755. if (sil_assign != expected)
  756. return false;
  757. }
  758. {
  759. SetType sil;
  760. sil.insert(il);
  761. if (sil != expected)
  762. return false;
  763. }
  764. return true;
  765. #endif
  766. return true;
  767. }
  768. template<typename SetType, typename MultisetType>
  769. bool instantiate_constructors()
  770. {
  771. {
  772. typedef typename SetType::value_type value_type;
  773. typename SetType::key_compare comp;
  774. typename SetType::allocator_type a;
  775. value_type value;
  776. {
  777. SetType s0;
  778. SetType s1(comp);
  779. SetType s2(a);
  780. SetType s3(comp, a);
  781. }
  782. {
  783. SetType s0(&value, &value);
  784. SetType s1(&value, &value ,comp);
  785. SetType s2(&value, &value ,a);
  786. SetType s3(&value, &value ,comp, a);
  787. }
  788. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  789. {
  790. SetType s0({ 0 });
  791. SetType s1({ 0 },comp);
  792. SetType s2({ 0 },a);
  793. SetType s3({ 0 },comp, a);
  794. }
  795. {
  796. std::initializer_list<value_type> il{0};
  797. SetType s0(ordered_unique_range, il);
  798. SetType s1(ordered_unique_range, il,comp);
  799. SetType s3(ordered_unique_range, il,comp, a);
  800. }
  801. #endif
  802. {
  803. SetType s0(ordered_unique_range, &value, &value);
  804. SetType s1(ordered_unique_range, &value, &value ,comp);
  805. SetType s2(ordered_unique_range, &value, &value ,comp, a);
  806. }
  807. }
  808. {
  809. typedef typename MultisetType::value_type value_type;
  810. typename MultisetType::key_compare comp;
  811. typename MultisetType::allocator_type a;
  812. value_type value;
  813. {
  814. MultisetType s0;
  815. MultisetType s1(comp);
  816. MultisetType s2(a);
  817. MultisetType s3(comp, a);
  818. }
  819. {
  820. MultisetType s0(&value, &value);
  821. MultisetType s1(&value, &value ,comp);
  822. MultisetType s2(&value, &value ,a);
  823. MultisetType s3(&value, &value ,comp, a);
  824. }
  825. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  826. {
  827. MultisetType s0({ 0 });
  828. MultisetType s1({ 0 },comp);
  829. MultisetType s2({ 0 },a);
  830. MultisetType s3({ 0 },comp, a);
  831. }
  832. {
  833. std::initializer_list<value_type>il{0};
  834. MultisetType s0(ordered_range, il);
  835. MultisetType s1(ordered_range, il,comp);
  836. MultisetType s3(ordered_range, il,comp, a);
  837. }
  838. #endif
  839. {
  840. MultisetType s0(ordered_range, &value, &value);
  841. MultisetType s1(ordered_range, &value, &value ,comp);
  842. MultisetType s2(ordered_range, &value, &value ,comp, a);
  843. }
  844. }
  845. return true;
  846. }
  847. } //namespace test{
  848. } //namespace container {
  849. } //namespace boost{
  850. #include <boost/container/detail/config_end.hpp>
  851. #endif