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