vector_test.hpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  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_VECTOR_TEST_HEADER
  11. #define BOOST_CONTAINER_TEST_VECTOR_TEST_HEADER
  12. #include <boost/container/detail/config_begin.hpp>
  13. #include <vector>
  14. #include <iostream>
  15. #include <list>
  16. #include <boost/move/utility_core.hpp>
  17. #include <boost/container/detail/mpl.hpp>
  18. #include <boost/move/utility_core.hpp>
  19. #include <boost/move/iterator.hpp>
  20. #include <boost/move/make_unique.hpp>
  21. #include <boost/core/no_exceptions_support.hpp>
  22. #include <boost/static_assert.hpp>
  23. #include "print_container.hpp"
  24. #include "check_equal_containers.hpp"
  25. #include "movable_int.hpp"
  26. #include "emplace_test.hpp"
  27. #include "input_from_forward_iterator.hpp"
  28. #include "insert_test.hpp"
  29. #include "container_common_tests.hpp"
  30. #include <cstddef>
  31. #include <string>
  32. #include <vector>
  33. namespace boost{
  34. namespace container {
  35. namespace test{
  36. template<class Vector>
  37. struct vector_hash_function_capacity
  38. {
  39. typedef typename Vector::size_type size_type;
  40. template <typename U, size_type (U::*)() const> struct Check;
  41. template <typename U> static char func(Check<U, &U::capacity> *);
  42. template <typename U> static int func(...);
  43. public:
  44. static const bool value = sizeof(func<Vector>(0)) == sizeof(char);
  45. };
  46. template<class V1, class V2>
  47. bool vector_vector_hash_function_capacity_only(V1&, V2&, boost::container::dtl::false_type)
  48. {
  49. return true;
  50. }
  51. template<class MyBoostVector, class MyStdVector>
  52. bool vector_vector_hash_function_capacity_only(MyBoostVector&boostvector, MyStdVector&stdvector, boost::container::dtl::true_type)
  53. {
  54. //deque has no reserve
  55. boostvector.reserve(boostvector.size()*2);
  56. stdvector.reserve(stdvector.size()*2);
  57. if(!test::CheckEqualContainers(boostvector, stdvector)) return false;
  58. std::size_t cap = boostvector.capacity();
  59. boostvector.reserve(cap*2);
  60. stdvector.reserve(cap*2);
  61. if(!test::CheckEqualContainers(boostvector, stdvector)) return false;
  62. boostvector.resize(0);
  63. stdvector.resize(0);
  64. if(!test::CheckEqualContainers(boostvector, stdvector)) return false;
  65. boostvector.resize(cap*2);
  66. stdvector.resize(cap*2);
  67. if(!test::CheckEqualContainers(boostvector, stdvector)) return false;
  68. boostvector.resize(cap*2);
  69. stdvector.resize(cap*2);
  70. if(!test::CheckEqualContainers(boostvector, stdvector)) return false;
  71. return true;
  72. }
  73. template<class V1, class V2>
  74. bool vector_copyable_only(V1&, V2&, boost::container::dtl::false_type)
  75. {
  76. return true;
  77. }
  78. //Function to check if both sets are equal
  79. template<class MyBoostVector, class MyStdVector>
  80. bool vector_copyable_only(MyBoostVector &boostvector, MyStdVector &stdvector, boost::container::dtl::true_type)
  81. {
  82. typedef typename MyBoostVector::value_type IntType;
  83. std::size_t size = boostvector.size();
  84. boostvector.insert(boostvector.end(), 50, IntType(1));
  85. stdvector.insert(stdvector.end(), 50, 1);
  86. if(!test::CheckEqualContainers(boostvector, stdvector)) return false;
  87. {
  88. IntType move_me(1);
  89. boostvector.insert(boostvector.begin()+size/2, 50, boost::move(move_me));
  90. stdvector.insert(stdvector.begin()+size/2, 50, 1);
  91. if(!test::CheckEqualContainers(boostvector, stdvector)) return false;
  92. }
  93. {
  94. IntType move_me(2);
  95. boostvector.assign(boostvector.size()/2, boost::move(move_me));
  96. stdvector.assign(stdvector.size()/2, 2);
  97. if(!test::CheckEqualContainers(boostvector, stdvector)) return false;
  98. }
  99. {
  100. IntType move_me(3);
  101. boostvector.assign(boostvector.size()*3-1, boost::move(move_me));
  102. stdvector.assign(stdvector.size()*3-1, 3);
  103. if(!test::CheckEqualContainers(boostvector, stdvector)) return false;
  104. }
  105. {
  106. IntType copy_me(3);
  107. const IntType ccopy_me(3);
  108. boostvector.push_back(copy_me);
  109. stdvector.push_back(int(3));
  110. boostvector.push_back(ccopy_me);
  111. stdvector.push_back(int(3));
  112. if(!test::CheckEqualContainers(boostvector, stdvector)) return false;
  113. }
  114. { //Vector(const Vector &)
  115. ::boost::movelib::unique_ptr<MyBoostVector> const pv1 =
  116. ::boost::movelib::make_unique<MyBoostVector>(boostvector);
  117. ::boost::movelib::unique_ptr<MyStdVector> const pv2 =
  118. ::boost::movelib::make_unique<MyStdVector>(stdvector);
  119. MyBoostVector &v1 = *pv1;
  120. MyStdVector &v2 = *pv2;
  121. boostvector.clear();
  122. stdvector.clear();
  123. boostvector.assign(v1.begin(), v1.end());
  124. stdvector.assign(v2.begin(), v2.end());
  125. if(!test::CheckEqualContainers(boostvector, stdvector)) return 1;
  126. }
  127. { //Vector(const Vector &, alloc)
  128. ::boost::movelib::unique_ptr<MyBoostVector> const pv1 =
  129. ::boost::movelib::make_unique<MyBoostVector>(boostvector, typename MyBoostVector::allocator_type());
  130. ::boost::movelib::unique_ptr<MyStdVector> const pv2 =
  131. ::boost::movelib::make_unique<MyStdVector>(stdvector);
  132. MyBoostVector &v1 = *pv1;
  133. MyStdVector &v2 = *pv2;
  134. boostvector.clear();
  135. stdvector.clear();
  136. boostvector.assign(v1.begin(), v1.end());
  137. stdvector.assign(v2.begin(), v2.end());
  138. if(!test::CheckEqualContainers(boostvector, stdvector)) return 1;
  139. }
  140. { //Vector(n, T)
  141. ::boost::movelib::unique_ptr<MyStdVector> const stdvectorp =
  142. ::boost::movelib::make_unique<MyStdVector>(100, int(5));
  143. ::boost::movelib::unique_ptr<MyBoostVector> const boostvectorp =
  144. ::boost::movelib::make_unique<MyBoostVector>(100, IntType(5));
  145. if(!test::CheckEqualContainers(*boostvectorp, *stdvectorp)) return 1;
  146. }
  147. { //Vector(n, T, alloc)
  148. ::boost::movelib::unique_ptr<MyStdVector> const stdvectorp =
  149. ::boost::movelib::make_unique<MyStdVector>(100, int(5));
  150. ::boost::movelib::unique_ptr<MyBoostVector> const boostvectorp =
  151. ::boost::movelib::make_unique<MyBoostVector>(100, IntType(5), typename MyBoostVector::allocator_type());
  152. if(!test::CheckEqualContainers(*boostvectorp, *stdvectorp)) return 1;
  153. }
  154. { //Vector(It, It)
  155. ::boost::movelib::unique_ptr<MyStdVector> const stdvectorp =
  156. ::boost::movelib::make_unique<MyStdVector>(100);
  157. ::boost::movelib::unique_ptr<MyBoostVector> const boostvectorp =
  158. ::boost::movelib::make_unique<MyBoostVector>(100);
  159. ::boost::movelib::unique_ptr<MyBoostVector> const boostvectorp2 =
  160. ::boost::movelib::make_unique<MyBoostVector>(boostvectorp->begin(), boostvectorp->end());
  161. if(!test::CheckEqualContainers(*boostvectorp2, *stdvectorp)) return 1;
  162. }
  163. { //Vector(It, It, alloc)
  164. ::boost::movelib::unique_ptr<MyStdVector> const stdvectorp =
  165. ::boost::movelib::make_unique<MyStdVector>(100);
  166. ::boost::movelib::unique_ptr<MyBoostVector> const boostvectorp =
  167. ::boost::movelib::make_unique<MyBoostVector>(100);
  168. ::boost::movelib::unique_ptr<MyBoostVector> const boostvectorp2 =
  169. ::boost::movelib::make_unique<MyBoostVector>(boostvectorp->begin(), boostvectorp->end(), typename MyBoostVector::allocator_type());
  170. if(!test::CheckEqualContainers(*boostvectorp2, *stdvectorp)) return 1;
  171. }
  172. { //resize(n, T)
  173. ::boost::movelib::unique_ptr<MyStdVector> const stdvectorp =
  174. ::boost::movelib::make_unique<MyStdVector>();
  175. ::boost::movelib::unique_ptr<MyBoostVector> const boostvectorp =
  176. ::boost::movelib::make_unique<MyBoostVector>();
  177. stdvectorp->resize(100, int(9));
  178. boostvectorp->resize(100, IntType(9));
  179. if(!test::CheckEqualContainers(*boostvectorp, *stdvectorp)) return 1;
  180. }
  181. //operator=
  182. {
  183. //Copy constructor test
  184. MyBoostVector bcopy((const MyBoostVector&) boostvector);
  185. MyStdVector scopy((const MyStdVector&) stdvector);
  186. MyBoostVector bcopy2(boostvector);
  187. MyStdVector scopy2(stdvector);
  188. if(!test::CheckEqualContainers(bcopy, scopy)) return false;
  189. if(!test::CheckEqualContainers(bcopy2, scopy2)) return false;
  190. //Assignment from a smaller vector
  191. bcopy2.erase(bcopy2.begin() + bcopy2.size()/2, bcopy2.end());
  192. scopy2.erase(scopy2.begin() + scopy2.size()/2, scopy2.end());
  193. bcopy = bcopy2;
  194. scopy = scopy2;
  195. if(!test::CheckEqualContainers(bcopy, scopy)) return false;
  196. //Assignment from a bigger vector with capacity
  197. bcopy2 = boostvector;
  198. scopy2 = stdvector;
  199. if(!test::CheckEqualContainers(bcopy2, scopy2)) return false;
  200. //Assignment from bigger vector with no capacity
  201. bcopy2.erase(bcopy2.begin() + bcopy2.size()/2, bcopy2.end());
  202. scopy2.erase(scopy2.begin() + scopy2.size()/2, scopy2.end());
  203. bcopy2.shrink_to_fit();
  204. MyStdVector(scopy2).swap(scopy2);
  205. bcopy2 = boostvector;
  206. scopy2 = stdvector;
  207. if(!test::CheckEqualContainers(bcopy, scopy)) return false;
  208. //Assignment with equal capacity
  209. bcopy2 = boostvector;
  210. scopy2 = stdvector;
  211. if(!test::CheckEqualContainers(bcopy2, scopy2)) return false;
  212. }
  213. return true;
  214. }
  215. template<class MyBoostVector>
  216. int vector_test()
  217. {
  218. typedef std::vector<int> MyStdVector;
  219. typedef typename MyBoostVector::value_type IntType;
  220. const int max = 100;
  221. if(!test_range_insertion<MyBoostVector>()){
  222. return 1;
  223. }
  224. { //Vector(n)
  225. ::boost::movelib::unique_ptr<MyBoostVector> const boostvectorp =
  226. ::boost::movelib::make_unique<MyBoostVector>(100);
  227. ::boost::movelib::unique_ptr<MyStdVector> const stdvectorp =
  228. ::boost::movelib::make_unique<MyStdVector>(100);
  229. if(!test::CheckEqualContainers(*boostvectorp, *stdvectorp)) return 1;
  230. }
  231. { //Vector(n, alloc)
  232. ::boost::movelib::unique_ptr<MyBoostVector> const boostvectorp =
  233. ::boost::movelib::make_unique<MyBoostVector>(100, typename MyBoostVector::allocator_type());
  234. ::boost::movelib::unique_ptr<MyStdVector> const stdvectorp =
  235. ::boost::movelib::make_unique<MyStdVector>(100);
  236. if(!test::CheckEqualContainers(*boostvectorp, *stdvectorp)) return 1;
  237. }
  238. { //Vector(Vector &&)
  239. ::boost::movelib::unique_ptr<MyStdVector> const stdvectorp =
  240. ::boost::movelib::make_unique<MyStdVector>(100);
  241. ::boost::movelib::unique_ptr<MyBoostVector> const boostvectorp =
  242. ::boost::movelib::make_unique<MyBoostVector>(100);
  243. ::boost::movelib::unique_ptr<MyBoostVector> const boostvectorp2 =
  244. ::boost::movelib::make_unique<MyBoostVector>(::boost::move(*boostvectorp));
  245. if(!test::CheckEqualContainers(*boostvectorp2, *stdvectorp)) return 1;
  246. }
  247. { //Vector(Vector &&, alloc)
  248. ::boost::movelib::unique_ptr<MyStdVector> const stdvectorp =
  249. ::boost::movelib::make_unique<MyStdVector>(100);
  250. ::boost::movelib::unique_ptr<MyBoostVector> const boostvectorp =
  251. ::boost::movelib::make_unique<MyBoostVector>(100);
  252. ::boost::movelib::unique_ptr<MyBoostVector> const boostvectorp2 =
  253. ::boost::movelib::make_unique<MyBoostVector>
  254. (::boost::move(*boostvectorp), typename MyBoostVector::allocator_type());
  255. if(!test::CheckEqualContainers(*boostvectorp2, *stdvectorp)) return 1;
  256. }
  257. { //Vector operator=(Vector &&)
  258. ::boost::movelib::unique_ptr<MyStdVector> const stdvectorp =
  259. ::boost::movelib::make_unique<MyStdVector>(100);
  260. ::boost::movelib::unique_ptr<MyBoostVector> const boostvectorp =
  261. ::boost::movelib::make_unique<MyBoostVector>(100);
  262. ::boost::movelib::unique_ptr<MyBoostVector> const boostvectorp2 =
  263. ::boost::movelib::make_unique<MyBoostVector>();
  264. *boostvectorp2 = ::boost::move(*boostvectorp);
  265. if(!test::CheckEqualContainers(*boostvectorp2, *stdvectorp)) return 1;
  266. }
  267. {
  268. ::boost::movelib::unique_ptr<MyBoostVector> const boostvectorp = ::boost::movelib::make_unique<MyBoostVector>();
  269. ::boost::movelib::unique_ptr<MyStdVector> const stdvectorp = ::boost::movelib::make_unique<MyStdVector>();
  270. MyBoostVector & boostvector = *boostvectorp;
  271. MyStdVector & stdvector = *stdvectorp;
  272. boostvector.resize(100);
  273. stdvector.resize(100);
  274. if(!test::CheckEqualContainers(boostvector, stdvector)) return 1;
  275. boostvector.resize(200);
  276. stdvector.resize(200);
  277. if(!test::CheckEqualContainers(boostvector, stdvector)) return 1;
  278. boostvector.resize(0);
  279. stdvector.resize(0);
  280. if(!test::CheckEqualContainers(boostvector, stdvector)) return 1;
  281. for(int i = 0; i < max; ++i){
  282. IntType new_int(i);
  283. boostvector.insert(boostvector.end(), boost::move(new_int));
  284. stdvector.insert(stdvector.end(), i);
  285. if(!test::CheckEqualContainers(boostvector, stdvector)) return 1;
  286. }
  287. if(!test::CheckEqualContainers(boostvector, stdvector)) return 1;
  288. typename MyBoostVector::iterator boostit(boostvector.begin());
  289. typename MyStdVector::iterator stdit(stdvector.begin());
  290. typename MyBoostVector::const_iterator cboostit = boostit;
  291. (void)cboostit;
  292. ++boostit; ++stdit;
  293. boostvector.erase(boostit);
  294. stdvector.erase(stdit);
  295. if(!test::CheckEqualContainers(boostvector, stdvector)) return 1;
  296. boostvector.erase(boostvector.begin());
  297. stdvector.erase(stdvector.begin());
  298. if(!test::CheckEqualContainers(boostvector, stdvector)) return 1;
  299. {
  300. //Initialize values
  301. IntType aux_vect[50];
  302. for(int i = 0; i < 50; ++i){
  303. IntType new_int(-1);
  304. BOOST_STATIC_ASSERT((boost::container::test::is_copyable<boost::container::test::movable_int>::value == false));
  305. aux_vect[i] = boost::move(new_int);
  306. }
  307. int aux_vect2[50];
  308. for(int i = 0; i < 50; ++i){
  309. aux_vect2[i] = -1;
  310. }
  311. typename MyBoostVector::iterator insert_it =
  312. boostvector.insert(boostvector.end()
  313. ,boost::make_move_iterator(&aux_vect[0])
  314. ,boost::make_move_iterator(aux_vect + 50));
  315. if(std::size_t(boost::container::iterator_distance(insert_it, boostvector.end())) != 50) return 1;
  316. stdvector.insert(stdvector.end(), aux_vect2, aux_vect2 + 50);
  317. if(!test::CheckEqualContainers(boostvector, stdvector)) return 1;
  318. for(int i = 0, j = static_cast<int>(boostvector.size()); i < j; ++i){
  319. boostvector.erase(boostvector.begin());
  320. stdvector.erase(stdvector.begin());
  321. }
  322. if(!test::CheckEqualContainers(boostvector, stdvector)) return 1;
  323. }
  324. {
  325. boostvector.resize(100);
  326. stdvector.resize(100);
  327. if(!test::CheckEqualContainers(boostvector, stdvector)) return 1;
  328. IntType aux_vect[50];
  329. for(int i = 0; i < 50; ++i){
  330. IntType new_int(-i);
  331. aux_vect[i] = boost::move(new_int);
  332. }
  333. int aux_vect2[50];
  334. for(int i = 0; i < 50; ++i){
  335. aux_vect2[i] = -i;
  336. }
  337. typename MyBoostVector::size_type old_size = boostvector.size();
  338. typename MyBoostVector::iterator insert_it =
  339. boostvector.insert(boostvector.begin() + old_size/2
  340. ,boost::make_move_iterator(&aux_vect[0])
  341. ,boost::make_move_iterator(aux_vect + 50));
  342. if(boostvector.begin() + old_size/2 != insert_it) return 1;
  343. stdvector.insert(stdvector.begin() + old_size/2, aux_vect2, aux_vect2 + 50);
  344. if(!test::CheckEqualContainers(boostvector, stdvector)) return 1;
  345. for(int i = 0; i < 50; ++i){
  346. IntType new_int(-i);
  347. aux_vect[i] = boost::move(new_int);
  348. }
  349. for(int i = 0; i < 50; ++i){
  350. aux_vect2[i] = -i;
  351. }
  352. old_size = boostvector.size();
  353. //Now try with input iterators instead
  354. insert_it = boostvector.insert(boostvector.begin() + old_size/2
  355. ,boost::make_move_iterator(make_input_from_forward_iterator(&aux_vect[0]))
  356. ,boost::make_move_iterator(make_input_from_forward_iterator(aux_vect + 50))
  357. );
  358. if(boostvector.begin() + old_size/2 != insert_it) return 1;
  359. stdvector.insert(stdvector.begin() + old_size/2, aux_vect2, aux_vect2 + 50);
  360. if(!test::CheckEqualContainers(boostvector, stdvector)) return 1;
  361. }
  362. boostvector.shrink_to_fit();
  363. MyStdVector(stdvector).swap(stdvector);
  364. if(!test::CheckEqualContainers(boostvector, stdvector)) return 1;
  365. boostvector.shrink_to_fit();
  366. MyStdVector(stdvector).swap(stdvector);
  367. if(!test::CheckEqualContainers(boostvector, stdvector)) return 1;
  368. { //push_back with not enough capacity
  369. IntType push_back_this(1);
  370. boostvector.push_back(boost::move(push_back_this));
  371. stdvector.push_back(int(1));
  372. boostvector.push_back(IntType(1));
  373. stdvector.push_back(int(1));
  374. if(!test::CheckEqualContainers(boostvector, stdvector)) return 1;
  375. }
  376. { //test back()
  377. const IntType test_this(1);
  378. if(test_this != boostvector.back()) return 1;
  379. }
  380. { //pop_back with enough capacity
  381. boostvector.pop_back();
  382. boostvector.pop_back();
  383. stdvector.pop_back();
  384. stdvector.pop_back();
  385. IntType push_back_this(1);
  386. boostvector.push_back(boost::move(push_back_this));
  387. stdvector.push_back(int(1));
  388. boostvector.push_back(IntType(1));
  389. stdvector.push_back(int(1));
  390. if(!test::CheckEqualContainers(boostvector, stdvector)) return 1;
  391. }
  392. if(!vector_copyable_only(boostvector, stdvector
  393. ,dtl::bool_<boost::container::test::is_copyable<IntType>::value>())){
  394. return 1;
  395. }
  396. boostvector.erase(boostvector.begin());
  397. stdvector.erase(stdvector.begin());
  398. if(!test::CheckEqualContainers(boostvector, stdvector)) return 1;
  399. for(int i = 0; i < max; ++i){
  400. IntType insert_this(i);
  401. boostvector.insert(boostvector.begin(), boost::move(insert_this));
  402. stdvector.insert(stdvector.begin(), i);
  403. boostvector.insert(boostvector.begin(), IntType(i));
  404. stdvector.insert(stdvector.begin(), int(i));
  405. }
  406. if(!test::CheckEqualContainers(boostvector, stdvector)) return 1;
  407. //some comparison operators
  408. if(!(boostvector == boostvector))
  409. return 1;
  410. if(boostvector != boostvector)
  411. return 1;
  412. if(boostvector < boostvector)
  413. return 1;
  414. if(boostvector > boostvector)
  415. return 1;
  416. if(!(boostvector <= boostvector))
  417. return 1;
  418. if(!(boostvector >= boostvector))
  419. return 1;
  420. //Test insertion from list
  421. {
  422. std::list<int> l(50, int(1));
  423. typename MyBoostVector::iterator it_insert =
  424. boostvector.insert(boostvector.begin(), l.begin(), l.end());
  425. if(boostvector.begin() != it_insert) return 1;
  426. stdvector.insert(stdvector.begin(), l.begin(), l.end());
  427. if(!test::CheckEqualContainers(boostvector, stdvector)) return 1;
  428. boostvector.assign(l.begin(), l.end());
  429. stdvector.assign(l.begin(), l.end());
  430. if(!test::CheckEqualContainers(boostvector, stdvector)) return 1;
  431. boostvector.clear();
  432. stdvector.clear();
  433. boostvector.assign(make_input_from_forward_iterator(l.begin()), make_input_from_forward_iterator(l.end()));
  434. stdvector.assign(l.begin(), l.end());
  435. if(!test::CheckEqualContainers(boostvector, stdvector)) return 1;
  436. }
  437. if(!vector_vector_hash_function_capacity_only(boostvector, stdvector, dtl::bool_<vector_hash_function_capacity<MyBoostVector>::value>()))
  438. return 1;
  439. boostvector.clear();
  440. stdvector.clear();
  441. boostvector.shrink_to_fit();
  442. MyStdVector(stdvector).swap(stdvector);
  443. if(!test::CheckEqualContainers(boostvector, stdvector)) return false;
  444. boostvector.resize(100);
  445. if(!test_nth_index_of(boostvector))
  446. return 1;
  447. }
  448. std::cout << std::endl << "Test OK!" << std::endl;
  449. return 0;
  450. }
  451. template<typename VectorContainerType>
  452. bool test_vector_methods_with_initializer_list_as_argument_for()
  453. {
  454. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  455. typedef typename VectorContainerType::allocator_type allocator_type;
  456. {
  457. const VectorContainerType testedVector = {1, 2, 3};
  458. const std::vector<int> expectedVector = {1, 2, 3};
  459. if(!test::CheckEqualContainers(testedVector, expectedVector)) return false;
  460. }
  461. {
  462. const VectorContainerType testedVector( { 1, 2, 3 }, allocator_type() );
  463. const std::vector<int> expectedVector = {1, 2, 3};
  464. if(!test::CheckEqualContainers(testedVector, expectedVector)) return false;
  465. }
  466. {
  467. VectorContainerType testedVector = {1, 2, 3};
  468. testedVector = {11, 12, 13};
  469. const std::vector<int> expectedVector = {11, 12, 13};
  470. if(!test::CheckEqualContainers(testedVector, expectedVector)) return false;
  471. }
  472. {
  473. VectorContainerType testedVector = {1, 2, 3};
  474. testedVector.assign({5, 6, 7});
  475. const std::vector<int> expectedVector = {5, 6, 7};
  476. if(!test::CheckEqualContainers(testedVector, expectedVector)) return false;
  477. }
  478. {
  479. VectorContainerType testedVector = {1, 2, 3};
  480. testedVector.insert(testedVector.cend(), {5, 6, 7});
  481. const std::vector<int> expectedVector = {1, 2, 3, 5, 6, 7};
  482. if(!test::CheckEqualContainers(testedVector, expectedVector)) return false;
  483. }
  484. return true;
  485. #else
  486. return true;
  487. #endif
  488. }
  489. } //namespace test{
  490. } //namespace container {
  491. } //namespace boost{
  492. #include <boost/container/detail/config_end.hpp>
  493. #endif //BOOST_CONTAINER_TEST_VECTOR_TEST_HEADER