]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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> | |
11fdf7f2 | 58 | bool vector_vector_hash_function_capacity_only(V1&, V2&, boost::container::dtl::false_type) |
7c673cae FG |
59 | { |
60 | return true; | |
61 | } | |
62 | ||
63 | template<class MyBoostVector, class MyStdVector> | |
11fdf7f2 | 64 | bool vector_vector_hash_function_capacity_only(MyBoostVector&boostvector, MyStdVector&stdvector, boost::container::dtl::true_type) |
7c673cae FG |
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> | |
11fdf7f2 | 92 | bool vector_copyable_only(V1&, V2&, boost::container::dtl::false_type) |
7c673cae FG |
93 | { |
94 | return true; | |
95 | } | |
96 | ||
97 | //Function to check if both sets are equal | |
98 | template<class MyBoostVector, class MyStdVector> | |
11fdf7f2 | 99 | bool vector_copyable_only(MyBoostVector &boostvector, MyStdVector &stdvector, boost::container::dtl::true_type) |
7c673cae FG |
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 | return true; | |
207 | } | |
208 | ||
209 | template<class MyBoostVector> | |
210 | int vector_test() | |
211 | { | |
212 | typedef std::vector<int> MyStdVector; | |
213 | typedef typename MyBoostVector::value_type IntType; | |
214 | const int max = 100; | |
215 | ||
216 | if(!test_range_insertion<MyBoostVector>()){ | |
217 | return 1; | |
218 | } | |
219 | { //Vector(n) | |
220 | ::boost::movelib::unique_ptr<MyBoostVector> const boostvectorp = | |
221 | ::boost::movelib::make_unique<MyBoostVector>(100); | |
222 | ::boost::movelib::unique_ptr<MyStdVector> const stdvectorp = | |
223 | ::boost::movelib::make_unique<MyStdVector>(100); | |
224 | if(!test::CheckEqualContainers(*boostvectorp, *stdvectorp)) return 1; | |
225 | } | |
226 | { //Vector(n, alloc) | |
227 | ::boost::movelib::unique_ptr<MyBoostVector> const boostvectorp = | |
228 | ::boost::movelib::make_unique<MyBoostVector>(100, typename MyBoostVector::allocator_type()); | |
229 | ::boost::movelib::unique_ptr<MyStdVector> const stdvectorp = | |
230 | ::boost::movelib::make_unique<MyStdVector>(100); | |
231 | if(!test::CheckEqualContainers(*boostvectorp, *stdvectorp)) return 1; | |
232 | } | |
233 | { //Vector(Vector &&) | |
234 | ::boost::movelib::unique_ptr<MyStdVector> const stdvectorp = | |
235 | ::boost::movelib::make_unique<MyStdVector>(100); | |
236 | ::boost::movelib::unique_ptr<MyBoostVector> const boostvectorp = | |
237 | ::boost::movelib::make_unique<MyBoostVector>(100); | |
238 | ::boost::movelib::unique_ptr<MyBoostVector> const boostvectorp2 = | |
239 | ::boost::movelib::make_unique<MyBoostVector>(::boost::move(*boostvectorp)); | |
240 | if(!test::CheckEqualContainers(*boostvectorp2, *stdvectorp)) return 1; | |
241 | } | |
242 | { //Vector(Vector &&, alloc) | |
243 | ::boost::movelib::unique_ptr<MyStdVector> const stdvectorp = | |
244 | ::boost::movelib::make_unique<MyStdVector>(100); | |
245 | ::boost::movelib::unique_ptr<MyBoostVector> const boostvectorp = | |
246 | ::boost::movelib::make_unique<MyBoostVector>(100); | |
247 | ::boost::movelib::unique_ptr<MyBoostVector> const boostvectorp2 = | |
248 | ::boost::movelib::make_unique<MyBoostVector> | |
249 | (::boost::move(*boostvectorp), typename MyBoostVector::allocator_type()); | |
250 | if(!test::CheckEqualContainers(*boostvectorp2, *stdvectorp)) return 1; | |
251 | } | |
252 | { //Vector operator=(Vector &&) | |
253 | ::boost::movelib::unique_ptr<MyStdVector> const stdvectorp = | |
254 | ::boost::movelib::make_unique<MyStdVector>(100); | |
255 | ::boost::movelib::unique_ptr<MyBoostVector> const boostvectorp = | |
256 | ::boost::movelib::make_unique<MyBoostVector>(100); | |
257 | ::boost::movelib::unique_ptr<MyBoostVector> const boostvectorp2 = | |
258 | ::boost::movelib::make_unique<MyBoostVector>(); | |
259 | *boostvectorp2 = ::boost::move(*boostvectorp); | |
260 | if(!test::CheckEqualContainers(*boostvectorp2, *stdvectorp)) return 1; | |
261 | } | |
262 | { | |
263 | ::boost::movelib::unique_ptr<MyBoostVector> const boostvectorp = ::boost::movelib::make_unique<MyBoostVector>(); | |
264 | ::boost::movelib::unique_ptr<MyStdVector> const stdvectorp = ::boost::movelib::make_unique<MyStdVector>(); | |
265 | ||
266 | MyBoostVector & boostvector = *boostvectorp; | |
267 | MyStdVector & stdvector = *stdvectorp; | |
268 | ||
269 | boostvector.resize(100); | |
270 | stdvector.resize(100); | |
271 | if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; | |
272 | ||
273 | boostvector.resize(200); | |
274 | stdvector.resize(200); | |
275 | if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; | |
276 | ||
277 | boostvector.resize(0); | |
278 | stdvector.resize(0); | |
279 | if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; | |
280 | ||
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 | ||
289 | typename MyBoostVector::iterator boostit(boostvector.begin()); | |
290 | typename MyStdVector::iterator stdit(stdvector.begin()); | |
291 | typename MyBoostVector::const_iterator cboostit = boostit; | |
292 | (void)cboostit; | |
293 | ++boostit; ++stdit; | |
294 | boostvector.erase(boostit); | |
295 | stdvector.erase(stdit); | |
296 | if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; | |
297 | ||
298 | boostvector.erase(boostvector.begin()); | |
299 | stdvector.erase(stdvector.begin()); | |
300 | if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; | |
301 | ||
302 | { | |
303 | //Initialize values | |
304 | IntType aux_vect[50]; | |
305 | for(int i = 0; i < 50; ++i){ | |
306 | IntType new_int(-1); | |
307 | BOOST_STATIC_ASSERT((boost::container::test::is_copyable<boost::container::test::movable_int>::value == false)); | |
308 | aux_vect[i] = boost::move(new_int); | |
309 | } | |
310 | int aux_vect2[50]; | |
311 | for(int i = 0; i < 50; ++i){ | |
312 | aux_vect2[i] = -1; | |
313 | } | |
314 | typename MyBoostVector::iterator insert_it = | |
315 | boostvector.insert(boostvector.end() | |
316 | ,boost::make_move_iterator(&aux_vect[0]) | |
317 | ,boost::make_move_iterator(aux_vect + 50)); | |
318 | if(std::size_t(boost::container::iterator_distance(insert_it, boostvector.end())) != 50) return 1; | |
319 | stdvector.insert(stdvector.end(), aux_vect2, aux_vect2 + 50); | |
320 | if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; | |
321 | ||
322 | for(int i = 0, j = static_cast<int>(boostvector.size()); i < j; ++i){ | |
323 | boostvector.erase(boostvector.begin()); | |
324 | stdvector.erase(stdvector.begin()); | |
325 | } | |
326 | if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; | |
327 | } | |
328 | { | |
329 | boostvector.resize(100); | |
330 | stdvector.resize(100); | |
331 | if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; | |
332 | ||
333 | IntType aux_vect[50]; | |
334 | for(int i = 0; i < 50; ++i){ | |
335 | IntType new_int(-i); | |
336 | aux_vect[i] = boost::move(new_int); | |
337 | } | |
338 | int aux_vect2[50]; | |
339 | for(int i = 0; i < 50; ++i){ | |
340 | aux_vect2[i] = -i; | |
341 | } | |
342 | typename MyBoostVector::size_type old_size = boostvector.size(); | |
343 | typename MyBoostVector::iterator insert_it = | |
344 | boostvector.insert(boostvector.begin() + old_size/2 | |
345 | ,boost::make_move_iterator(&aux_vect[0]) | |
346 | ,boost::make_move_iterator(aux_vect + 50)); | |
347 | if(boostvector.begin() + old_size/2 != insert_it) return 1; | |
348 | stdvector.insert(stdvector.begin() + old_size/2, aux_vect2, aux_vect2 + 50); | |
349 | if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; | |
350 | ||
351 | for(int i = 0; i < 50; ++i){ | |
352 | IntType new_int(-i); | |
353 | aux_vect[i] = boost::move(new_int); | |
354 | } | |
355 | ||
356 | for(int i = 0; i < 50; ++i){ | |
357 | aux_vect2[i] = -i; | |
358 | } | |
359 | old_size = boostvector.size(); | |
360 | //Now try with input iterators instead | |
361 | insert_it = boostvector.insert(boostvector.begin() + old_size/2 | |
362 | ,boost::make_move_iterator(make_input_from_forward_iterator(&aux_vect[0])) | |
363 | ,boost::make_move_iterator(make_input_from_forward_iterator(aux_vect + 50)) | |
364 | ); | |
365 | if(boostvector.begin() + old_size/2 != insert_it) return 1; | |
366 | stdvector.insert(stdvector.begin() + old_size/2, aux_vect2, aux_vect2 + 50); | |
367 | if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; | |
368 | } | |
369 | ||
370 | boostvector.shrink_to_fit(); | |
371 | MyStdVector(stdvector).swap(stdvector); | |
372 | if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; | |
373 | ||
374 | boostvector.shrink_to_fit(); | |
375 | MyStdVector(stdvector).swap(stdvector); | |
376 | if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; | |
377 | ||
378 | { //push_back with not enough capacity | |
379 | IntType push_back_this(1); | |
380 | boostvector.push_back(boost::move(push_back_this)); | |
381 | stdvector.push_back(int(1)); | |
382 | boostvector.push_back(IntType(1)); | |
383 | stdvector.push_back(int(1)); | |
384 | if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; | |
385 | } | |
386 | ||
387 | { //test back() | |
388 | const IntType test_this(1); | |
389 | if(test_this != boostvector.back()) return 1; | |
390 | } | |
391 | { //pop_back with enough capacity | |
392 | boostvector.pop_back(); | |
393 | boostvector.pop_back(); | |
394 | stdvector.pop_back(); | |
395 | stdvector.pop_back(); | |
396 | ||
397 | IntType push_back_this(1); | |
398 | boostvector.push_back(boost::move(push_back_this)); | |
399 | stdvector.push_back(int(1)); | |
400 | boostvector.push_back(IntType(1)); | |
401 | stdvector.push_back(int(1)); | |
402 | if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; | |
403 | } | |
404 | ||
405 | if(!vector_copyable_only(boostvector, stdvector | |
11fdf7f2 | 406 | ,dtl::bool_<boost::container::test::is_copyable<IntType>::value>())){ |
7c673cae FG |
407 | return 1; |
408 | } | |
409 | ||
410 | boostvector.erase(boostvector.begin()); | |
411 | stdvector.erase(stdvector.begin()); | |
412 | if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; | |
413 | ||
414 | for(int i = 0; i < max; ++i){ | |
415 | IntType insert_this(i); | |
416 | boostvector.insert(boostvector.begin(), boost::move(insert_this)); | |
417 | stdvector.insert(stdvector.begin(), i); | |
418 | boostvector.insert(boostvector.begin(), IntType(i)); | |
419 | stdvector.insert(stdvector.begin(), int(i)); | |
420 | } | |
421 | if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; | |
422 | ||
423 | //some comparison operators | |
424 | if(!(boostvector == boostvector)) | |
425 | return 1; | |
426 | if(boostvector != boostvector) | |
427 | return 1; | |
428 | if(boostvector < boostvector) | |
429 | return 1; | |
430 | if(boostvector > boostvector) | |
431 | return 1; | |
432 | if(!(boostvector <= boostvector)) | |
433 | return 1; | |
434 | if(!(boostvector >= boostvector)) | |
435 | return 1; | |
436 | ||
437 | //Test insertion from list | |
438 | { | |
439 | std::list<int> l(50, int(1)); | |
440 | typename MyBoostVector::iterator it_insert = | |
441 | boostvector.insert(boostvector.begin(), l.begin(), l.end()); | |
442 | if(boostvector.begin() != it_insert) return 1; | |
443 | stdvector.insert(stdvector.begin(), l.begin(), l.end()); | |
444 | if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; | |
445 | boostvector.assign(l.begin(), l.end()); | |
446 | stdvector.assign(l.begin(), l.end()); | |
447 | if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; | |
448 | ||
449 | boostvector.clear(); | |
450 | stdvector.clear(); | |
451 | boostvector.assign(make_input_from_forward_iterator(l.begin()), make_input_from_forward_iterator(l.end())); | |
452 | stdvector.assign(l.begin(), l.end()); | |
453 | if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; | |
454 | } | |
455 | ||
11fdf7f2 | 456 | if(!vector_vector_hash_function_capacity_only(boostvector, stdvector, dtl::bool_<vector_hash_function_capacity<MyBoostVector>::value>())) |
7c673cae FG |
457 | return 1; |
458 | ||
459 | boostvector.clear(); | |
460 | stdvector.clear(); | |
461 | boostvector.shrink_to_fit(); | |
462 | MyStdVector(stdvector).swap(stdvector); | |
463 | if(!test::CheckEqualContainers(boostvector, stdvector)) return false; | |
464 | ||
465 | boostvector.resize(100); | |
466 | if(!test_nth_index_of(boostvector)) | |
467 | return 1; | |
468 | ||
469 | } | |
470 | std::cout << std::endl << "Test OK!" << std::endl; | |
471 | return 0; | |
472 | } | |
473 | ||
474 | template<typename VectorContainerType> | |
475 | bool test_vector_methods_with_initializer_list_as_argument_for() | |
476 | { | |
477 | #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) | |
478 | typedef typename VectorContainerType::allocator_type allocator_type; | |
479 | { | |
480 | const VectorContainerType testedVector = {1, 2, 3}; | |
481 | const std::vector<int> expectedVector = {1, 2, 3}; | |
482 | if(!test::CheckEqualContainers(testedVector, expectedVector)) return false; | |
483 | } | |
484 | { | |
485 | const VectorContainerType testedVector( { 1, 2, 3 }, allocator_type() ); | |
486 | const std::vector<int> expectedVector = {1, 2, 3}; | |
487 | if(!test::CheckEqualContainers(testedVector, expectedVector)) return false; | |
488 | } | |
489 | { | |
490 | VectorContainerType testedVector = {1, 2, 3}; | |
491 | testedVector = {11, 12, 13}; | |
492 | ||
493 | const std::vector<int> expectedVector = {11, 12, 13}; | |
494 | if(!test::CheckEqualContainers(testedVector, expectedVector)) return false; | |
495 | } | |
496 | ||
497 | { | |
498 | VectorContainerType testedVector = {1, 2, 3}; | |
499 | testedVector.assign({5, 6, 7}); | |
500 | ||
501 | const std::vector<int> expectedVector = {5, 6, 7}; | |
502 | if(!test::CheckEqualContainers(testedVector, expectedVector)) return false; | |
503 | } | |
504 | ||
505 | { | |
506 | VectorContainerType testedVector = {1, 2, 3}; | |
507 | testedVector.insert(testedVector.cend(), {5, 6, 7}); | |
508 | ||
509 | const std::vector<int> expectedVector = {1, 2, 3, 5, 6, 7}; | |
510 | if(!test::CheckEqualContainers(testedVector, expectedVector)) return false; | |
511 | } | |
512 | return true; | |
513 | #else | |
514 | return true; | |
515 | #endif | |
516 | } | |
517 | ||
518 | } //namespace test{ | |
519 | } //namespace container { | |
520 | } //namespace boost{ | |
521 | ||
522 | #include <boost/container/detail/config_end.hpp> | |
523 | ||
524 | #endif //BOOST_CONTAINER_TEST_VECTOR_TEST_HEADER |