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