]>
Commit | Line | Data |
---|---|---|
20effc67 TL |
1 | ////////////////////////////////////////////////////////////////////////////// |
2 | // | |
3 | // \(C\) Copyright Benedek Thaler 2015-2016 | |
4 | // \(C\) Copyright Ion Gaztanaga 2019-2020. Distributed under the Boost | |
5 | // Software License, Version 1.0. (See accompanying file | |
6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
7 | // | |
8 | // See http://www.boost.org/libs/container for documentation. | |
9 | // | |
10 | ////////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #include <boost/core/lightweight_test.hpp> | |
13 | #include <cstring> // memcmp | |
14 | #include <iostream> | |
15 | #include <algorithm> | |
16 | #include <limits> | |
17 | #include <boost/container/list.hpp> | |
18 | #include <boost/container/vector.hpp> | |
19 | #include <boost/core/no_exceptions_support.hpp> | |
20 | #include <boost/type_traits/is_default_constructible.hpp> | |
21 | #include <boost/type_traits/is_nothrow_move_constructible.hpp> | |
22 | #include "dummy_test_allocator.hpp" | |
23 | #include "propagate_allocator_test.hpp" | |
24 | #include "check_equal_containers.hpp" | |
25 | #include "movable_int.hpp" | |
26 | ||
27 | #include <boost/algorithm/cxx14/equal.hpp> | |
28 | ||
29 | #define BOOST_CONTAINER_DEVECTOR_ALLOC_STATS | |
30 | #include <boost/container/devector.hpp> | |
31 | #undef BOOST_CONTAINER_DEVECTOR_ALLOC_STATS | |
32 | ||
33 | #include "test_util.hpp" | |
34 | #include "test_elem.hpp" | |
35 | #include "input_iterator.hpp" | |
36 | ||
37 | using namespace boost::container; | |
38 | ||
39 | struct boost_container_devector; | |
40 | ||
41 | #ifdef _MSC_VER | |
42 | #pragma warning (push) | |
43 | #pragma warning (disable : 4127) // conditional expression is constant | |
44 | #endif | |
45 | ||
46 | namespace boost { | |
47 | namespace container { | |
48 | namespace test { | |
49 | ||
50 | template<> | |
51 | struct alloc_propagate_base<boost_container_devector> | |
52 | { | |
53 | template <class T, class Allocator> | |
54 | struct apply | |
55 | { | |
56 | typedef devector<T, Allocator> type; | |
57 | }; | |
58 | }; | |
59 | ||
60 | }}} //namespace boost::container::test { | |
61 | ||
62 | struct different_growth_policy | |
63 | { | |
64 | template <typename SizeType> | |
65 | static SizeType new_capacity(SizeType capacity) | |
66 | { | |
67 | return (capacity) ? capacity * 4u : 32u; | |
68 | } | |
69 | }; | |
70 | ||
71 | // END HELPERS | |
72 | ||
73 | template <class Devector> void test_constructor_default() | |
74 | { | |
75 | Devector a; | |
76 | ||
77 | BOOST_TEST(a.empty()); | |
78 | BOOST_TEST(a.get_alloc_count() == 0u); | |
79 | BOOST_TEST(a.capacity() == 0u); | |
80 | } | |
81 | ||
82 | template <class Devector> void test_constructor_allocator() | |
83 | { | |
84 | typename Devector::allocator_type alloc_template; | |
85 | ||
86 | Devector a(alloc_template); | |
87 | ||
88 | BOOST_TEST(a.empty()); | |
89 | BOOST_TEST(a.get_alloc_count() == 0u); | |
90 | BOOST_TEST(a.capacity() == 0u); | |
91 | } | |
92 | ||
93 | template <class Devector> void test_constructor_reserve_only() | |
94 | { | |
95 | { | |
96 | Devector a(16, reserve_only_tag_t()); | |
97 | BOOST_TEST(a.size() == 0u); | |
98 | BOOST_TEST(a.capacity() >= 16u); | |
99 | } | |
100 | ||
101 | { | |
102 | Devector b(0, reserve_only_tag_t()); | |
103 | BOOST_TEST(b.get_alloc_count() == 0u); | |
104 | } | |
105 | } | |
106 | ||
107 | template <class Devector> void test_constructor_reserve_only_front_back() | |
108 | { | |
109 | { | |
110 | Devector a(8, 8, reserve_only_tag_t()); | |
111 | BOOST_TEST(a.size() == 0u); | |
112 | BOOST_TEST(a.capacity() >= 16u); | |
113 | ||
114 | for (int i = 8; i; --i) | |
115 | { | |
116 | a.emplace_front(i); | |
117 | } | |
118 | ||
119 | for (int i = 9; i < 17; ++i) | |
120 | { | |
121 | a.emplace_back(i); | |
122 | } | |
123 | ||
124 | const int expected [] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}; | |
125 | test_equal_range(a, expected); | |
126 | BOOST_TEST(a.get_alloc_count() <= 1u); | |
127 | } | |
128 | ||
129 | { | |
130 | Devector b(0, 0, reserve_only_tag_t()); | |
131 | BOOST_TEST(b.get_alloc_count() == 0u); | |
132 | } | |
133 | } | |
134 | ||
135 | template <class Devector> void test_constructor_n() | |
136 | { | |
137 | { | |
138 | Devector a(8); | |
139 | const int expected [] = {0, 0, 0, 0, 0, 0, 0, 0}; | |
140 | test_equal_range(a, expected); | |
141 | } | |
142 | ||
143 | { | |
144 | Devector b(0); | |
145 | ||
146 | test_equal_range(b); | |
147 | BOOST_TEST(b.get_alloc_count() == 0u); | |
148 | } | |
149 | ||
150 | #ifndef BOOST_NO_EXCEPTIONS | |
151 | typedef typename Devector::value_type T; | |
152 | ||
153 | BOOST_IF_CONSTEXPR (! boost::move_detail::is_nothrow_default_constructible<T>::value) | |
154 | { | |
155 | test_elem_throw::on_ctor_after(4); | |
156 | BOOST_TEST_THROWS(Devector(8), test_exception); | |
157 | BOOST_TEST(test_elem_base::no_living_elem()); | |
158 | test_elem_throw::do_not_throw(); | |
159 | } | |
160 | #endif //#ifndef BOOST_NO_EXCEPTIONS | |
161 | } | |
162 | ||
163 | template <class Devector> void test_constructor_n_copy_throwing(dtl::true_) | |
164 | { | |
165 | #ifndef BOOST_NO_EXCEPTIONS | |
166 | typedef typename Devector::value_type T; | |
167 | test_elem_throw::on_copy_after(4); | |
168 | const T x(404); | |
169 | BOOST_TEST_THROWS(Devector(8, x), test_exception); | |
170 | test_elem_throw::do_not_throw(); | |
171 | #endif //#ifndef BOOST_NO_EXCEPTIONS | |
172 | } | |
173 | ||
174 | ||
175 | template <class Devector> void test_constructor_n_copy_throwing(dtl::false_) | |
176 | {} | |
177 | ||
178 | template <class Devector> void test_constructor_n_copy() | |
179 | { | |
180 | typedef typename Devector::value_type T; | |
181 | { | |
182 | const T x(9); | |
183 | Devector a(8, x); | |
184 | const int expected [] = {9, 9, 9, 9, 9, 9, 9, 9}; | |
185 | test_equal_range(a, expected); | |
186 | } | |
187 | ||
188 | { | |
189 | const T x(9); | |
190 | Devector b(0, x); | |
191 | ||
192 | test_equal_range(b); | |
193 | BOOST_TEST(b.get_alloc_count() == 0u); | |
194 | } | |
195 | ||
196 | test_constructor_n_copy_throwing<Devector> | |
197 | (dtl::bool_<! boost::move_detail::is_nothrow_copy_constructible<T>::value>()); | |
198 | ||
199 | BOOST_TEST(test_elem_base::no_living_elem()); | |
200 | } | |
201 | ||
202 | template <class Devector> void test_constructor_input_range() | |
203 | { | |
204 | typedef typename Devector::value_type T; | |
205 | { | |
206 | devector<T> expected; get_range<devector<T> >(16, expected); | |
207 | devector<T> input = expected; | |
208 | ||
209 | input_iterator<Devector> input_begin = make_input_iterator(input, input.begin()); | |
210 | input_iterator<Devector> input_end = make_input_iterator(input, input.end()); | |
211 | ||
212 | Devector a(input_begin, input_end); | |
213 | BOOST_TEST(a == expected); | |
214 | } | |
215 | ||
216 | { // empty range | |
217 | devector<T> input; | |
218 | input_iterator<Devector> input_begin = make_input_iterator(input, input.begin()); | |
219 | ||
220 | Devector b(input_begin, input_begin); | |
221 | ||
222 | test_equal_range(b); | |
223 | BOOST_TEST(b.get_alloc_count() == 0u); | |
224 | } | |
225 | ||
226 | BOOST_TEST(test_elem_base::no_living_elem()); | |
227 | /* //if move_if_noexcept is implemented | |
228 | #ifndef BOOST_NO_EXCEPTIONS | |
229 | if (! boost::move_detail::is_nothrow_copy_constructible<T>::value) | |
230 | { | |
231 | devector<T> input; get_range<devector<T> >(16, input); | |
232 | ||
233 | input_iterator<Devector> input_begin = make_input_iterator(input, input.begin()); | |
234 | input_iterator<Devector> input_end = make_input_iterator(input, input.end()); | |
235 | ||
236 | test_elem_throw::on_copy_after(4); | |
237 | ||
238 | BOOST_TEST_THROWS(Devector c(input_begin, input_end), test_exception); | |
239 | } | |
240 | ||
241 | BOOST_TEST(test_elem_base::no_living_elem()); | |
242 | #endif //#ifndef BOOST_NO_EXCEPTIONS | |
243 | */ | |
244 | } | |
245 | ||
246 | ||
247 | void test_constructor_forward_range_throwing(dtl::true_) | |
248 | {} | |
249 | ||
250 | void test_constructor_forward_range_throwing(dtl::false_) | |
251 | {} | |
252 | ||
253 | template <class Devector> void test_constructor_forward_range() | |
254 | { | |
255 | typedef typename Devector::value_type T; | |
256 | boost::container::list<T> ncx; | |
257 | ncx.emplace_back(1); | |
258 | ncx.emplace_back(2); | |
259 | ncx.emplace_back(3); | |
260 | ncx.emplace_back(4); | |
261 | ncx.emplace_back(5); | |
262 | ncx.emplace_back(6); | |
263 | ncx.emplace_back(7); | |
264 | ncx.emplace_back(8); | |
265 | const boost::container::list<T> &x = ncx; | |
266 | ||
267 | { | |
268 | Devector a(x.begin(), x.end()); | |
269 | const int expected[] = {1, 2, 3, 4, 5, 6, 7, 8}; | |
270 | test_equal_range(a, expected); | |
271 | BOOST_TEST(a.get_alloc_count() <= 1u); | |
272 | a.reset_alloc_stats(); | |
273 | } | |
274 | ||
275 | { | |
276 | Devector b(x.begin(), x.begin()); | |
277 | ||
278 | test_equal_range(b); | |
279 | BOOST_TEST(b.get_alloc_count() == 0u); | |
280 | } | |
281 | ||
282 | #ifndef BOOST_NO_EXCEPTIONS | |
283 | BOOST_IF_CONSTEXPR (! boost::move_detail::is_nothrow_copy_constructible<T>::value) | |
284 | { | |
285 | test_elem_throw::on_copy_after(4); | |
286 | BOOST_TEST_THROWS(Devector c(x.begin(), x.end()), test_exception); | |
287 | test_elem_throw::do_not_throw(); | |
288 | } | |
289 | #endif //#ifndef BOOST_NO_EXCEPTIONS | |
290 | } | |
291 | ||
292 | template <class Devector> void test_constructor_pointer_range() | |
293 | { | |
294 | typedef typename Devector::value_type T; | |
295 | ||
296 | boost::container::vector<T> x; get_range<boost::container::vector<T> >(8, x); | |
297 | const T* xbeg = x.data(); | |
298 | const T* xend = x.data() + x.size(); | |
299 | ||
300 | { | |
301 | Devector a(xbeg, xend); | |
302 | ||
303 | const int expected[] = {1, 2, 3, 4, 5, 6, 7, 8}; | |
304 | test_equal_range(a, expected); | |
305 | BOOST_TEST(a.get_alloc_count() <= 1u); | |
306 | } | |
307 | ||
308 | { | |
309 | Devector b(xbeg, xbeg); | |
310 | ||
311 | test_equal_range(b); | |
312 | BOOST_TEST(b.get_alloc_count() == 0u); | |
313 | } | |
314 | ||
315 | #ifndef BOOST_NO_EXCEPTIONS | |
316 | if (! boost::move_detail::is_nothrow_copy_constructible<T>::value) | |
317 | { | |
318 | test_elem_throw::on_copy_after(4); | |
319 | BOOST_TEST_THROWS(Devector c(xbeg, xend), test_exception); | |
320 | test_elem_throw::do_not_throw(); | |
321 | } | |
322 | #endif //#ifndef BOOST_NO_EXCEPTIONS | |
323 | } | |
324 | ||
325 | template <class Devector> void test_copy_constructor() | |
326 | { | |
327 | { | |
328 | Devector a; | |
329 | Devector b(a); | |
330 | ||
331 | test_equal_range(b); | |
332 | BOOST_TEST(b.get_alloc_count() == 0u); | |
333 | } | |
334 | ||
335 | { | |
336 | Devector a; get_range<Devector>(8, a); | |
337 | Devector b(a); | |
338 | const int expected [] = {1, 2, 3, 4, 5, 6, 7, 8}; | |
339 | test_equal_range(b, expected); | |
340 | BOOST_TEST(b.get_alloc_count() <= 1u); | |
341 | } | |
342 | ||
343 | #ifndef BOOST_NO_EXCEPTIONS | |
344 | typedef typename Devector::value_type T; | |
345 | ||
346 | if (! boost::move_detail::is_nothrow_copy_constructible<T>::value) | |
347 | { | |
348 | Devector a; get_range<Devector>(8, a); | |
349 | ||
350 | test_elem_throw::on_copy_after(4); | |
351 | BOOST_TEST_THROWS(Devector b(a), test_exception); | |
352 | test_elem_throw::do_not_throw(); | |
353 | } | |
354 | #endif //#ifndef BOOST_NO_EXCEPTIONS | |
355 | } | |
356 | ||
357 | template <class Devector> void test_move_constructor() | |
358 | { | |
359 | { // empty | |
360 | Devector a; | |
361 | Devector b(boost::move(a)); | |
362 | ||
363 | BOOST_TEST(a.empty()); | |
364 | BOOST_TEST(b.empty()); | |
365 | } | |
366 | ||
367 | { // maybe small | |
368 | Devector a; get_range<Devector>(1, 5, 5, 9, a); | |
369 | Devector b(boost::move(a)); | |
370 | ||
371 | const int expected [] = {1, 2, 3, 4, 5, 6, 7, 8}; | |
372 | test_equal_range(b, expected); | |
373 | ||
374 | // a is unspecified but valid state | |
375 | a.clear(); | |
376 | BOOST_TEST(a.empty()); | |
377 | } | |
378 | ||
379 | { // big | |
380 | Devector a; get_range<Devector>(32, a); | |
381 | Devector b(boost::move(a)); | |
382 | ||
383 | boost::container::vector<int> expected; get_range<boost::container::vector<int> >(32, expected); | |
384 | test_equal_range(b, expected); | |
385 | ||
386 | // a is unspecified but valid state | |
387 | a.clear(); | |
388 | BOOST_TEST(a.empty()); | |
389 | } | |
390 | } | |
391 | ||
392 | template <class Devector> void test_destructor() | |
393 | { | |
394 | Devector a; | |
395 | ||
396 | Devector b; get_range<Devector>(3, b); | |
397 | } | |
398 | ||
399 | template <class Devector> void test_assignment() | |
400 | { | |
401 | const typename Devector::size_type alloc_count = | |
402 | boost::container::allocator_traits | |
403 | < typename Devector::allocator_type >::propagate_on_container_copy_assignment::value; | |
404 | ||
405 | { // assign to empty (maybe small) | |
406 | Devector a; | |
407 | Devector c; get_range<Devector>(6, c); | |
408 | Devector &b = c; | |
409 | ||
410 | a = b; | |
411 | const int expected[] = {1, 2, 3, 4, 5, 6}; | |
412 | test_equal_range(a, expected); | |
413 | } | |
414 | ||
415 | { // assign from empty | |
416 | Devector a; get_range<Devector>(6, a); | |
417 | const Devector b; | |
418 | ||
419 | a = b; | |
420 | ||
421 | test_equal_range(a); | |
422 | } | |
423 | ||
424 | { // assign to non-empty | |
425 | Devector a; get_range<Devector>(11, 15, 15, 19, a); | |
426 | Devector c; get_range<Devector>(6, c); | |
427 | const Devector &b = c; | |
428 | ||
429 | a = b; | |
430 | const int expected[] = {1, 2, 3, 4, 5, 6}; | |
431 | test_equal_range(a, expected); | |
432 | } | |
433 | ||
434 | { // assign to free front | |
435 | Devector a; get_range<Devector>(11, 15, 15, 19, a); | |
436 | a.reserve_front(8); | |
437 | a.reset_alloc_stats(); | |
438 | ||
439 | Devector c; get_range<Devector>(6, c); | |
440 | const Devector &b = c; | |
441 | ||
442 | a = b; | |
443 | const int expected [] = {1, 2, 3, 4, 5, 6}; | |
444 | test_equal_range(a, expected); | |
445 | BOOST_TEST(a.get_alloc_count() == alloc_count); | |
446 | } | |
447 | ||
448 | { // assignment overlaps contents | |
449 | Devector a; get_range<Devector>(11, 15, 15, 19, a); | |
450 | a.reserve_front(12); | |
451 | a.reset_alloc_stats(); | |
452 | ||
453 | Devector c; get_range<Devector>(6, c); | |
454 | const Devector &b = c; | |
455 | ||
456 | a = b; | |
457 | const int expected [] = {1, 2, 3, 4, 5, 6}; | |
458 | test_equal_range(a, expected); | |
459 | BOOST_TEST(a.get_alloc_count() == alloc_count); | |
460 | } | |
461 | ||
462 | { // assignment exceeds contents | |
463 | Devector a; get_range<Devector>(11, 13, 13, 15, a); | |
464 | a.reserve_front(8); | |
465 | a.reserve_back(8); | |
466 | a.reset_alloc_stats(); | |
467 | ||
468 | Devector c; get_range<Devector>(12, c); | |
469 | const Devector &b = c; | |
470 | ||
471 | a = b; | |
472 | const int expected[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; | |
473 | test_equal_range(a, expected); | |
474 | BOOST_TEST(a.get_alloc_count() == alloc_count); | |
475 | } | |
476 | ||
477 | #ifndef BOOST_NO_EXCEPTIONS | |
478 | typedef typename Devector::value_type T; | |
479 | BOOST_IF_CONSTEXPR (! boost::move_detail::is_nothrow_copy_constructible<T>::value) | |
480 | { | |
481 | // strong guarantee if reallocation is needed (no guarantee otherwise) | |
482 | Devector a; get_range<Devector>(6, a); | |
483 | Devector c; get_range<Devector>(12, c); | |
484 | const Devector &b = c; | |
485 | ||
486 | test_elem_throw::on_copy_after(3); | |
487 | BOOST_TEST_THROWS(a = b, test_exception); | |
488 | test_elem_throw::do_not_throw(); | |
489 | ||
490 | const int expected[] = {1, 2, 3, 4, 5, 6}; | |
491 | test_equal_range(a, expected); | |
492 | } | |
493 | #endif //#ifndef BOOST_NO_EXCEPTIONS | |
494 | } | |
495 | ||
496 | template <class Devector> void test_move_assignment_throwing(dtl::true_) | |
497 | // move should be used on the slow path | |
498 | { | |
499 | Devector a; get_range<Devector>(11, 15, 15, 19, a); | |
500 | Devector b; get_range<Devector>(6, b); | |
501 | ||
502 | test_elem_throw::on_copy_after(3); | |
503 | a = boost::move(b); | |
504 | test_elem_throw::do_not_throw(); | |
505 | ||
506 | const int expected [] = {1, 2, 3, 4, 5, 6}; | |
507 | test_equal_range(a, expected); | |
508 | ||
509 | b.clear(); | |
510 | test_equal_range(b); | |
511 | } | |
512 | ||
513 | template <class Devector> void test_move_assignment_throwing(dtl::false_) | |
514 | {} | |
515 | ||
516 | template <class Devector> void test_move_assignment() | |
517 | { | |
518 | { // assign to empty (maybe small) | |
519 | Devector a; | |
520 | Devector b; get_range<Devector>(6, b); | |
521 | ||
522 | a = boost::move(b); | |
523 | ||
524 | const int expected [] = {1, 2, 3, 4, 5, 6}; | |
525 | test_equal_range(a, expected); | |
526 | ||
527 | // b is in unspecified but valid state | |
528 | b.clear(); | |
529 | test_equal_range(b); | |
530 | } | |
531 | ||
532 | { // assign from empty | |
533 | Devector a; get_range<Devector>(6, a); | |
534 | Devector b; | |
535 | ||
536 | a = boost::move(b); | |
537 | ||
538 | test_equal_range(a); | |
539 | test_equal_range(b); | |
540 | } | |
541 | ||
542 | { // assign to non-empty | |
543 | Devector a; get_range<Devector>(11, 15, 15, 19, a); | |
544 | Devector b; get_range<Devector>(6, b); | |
545 | ||
546 | a = boost::move(b); | |
547 | const int expected [] = {1, 2, 3, 4, 5, 6}; | |
548 | test_equal_range(a, expected); | |
549 | ||
550 | b.clear(); | |
551 | test_equal_range(b); | |
552 | } | |
553 | ||
554 | typedef typename Devector::value_type T; | |
555 | test_move_assignment_throwing<Devector> | |
556 | (boost::move_detail::bool_<! boost::move_detail::is_nothrow_copy_constructible<T>::value>()); | |
557 | } | |
558 | ||
559 | template <class Devector> void test_il_assignment() | |
560 | { | |
561 | #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) | |
562 | ||
563 | { // assign to empty (maybe small) | |
564 | Devector a; | |
565 | a = {1, 2, 3, 4, 5, 6 }; | |
566 | test_equal_range(a, {1, 2, 3, 4, 5, 6}); | |
567 | } | |
568 | ||
569 | { // assign from empty | |
570 | Devector a; get_range<Devector>(6, a); | |
571 | a = {}; | |
572 | ||
573 | test_equal_range(a); | |
574 | } | |
575 | ||
576 | { // assign to non-empty | |
577 | Devector a; get_range<Devector>(11, 15, 15, 19, a); | |
578 | ||
579 | a = {1, 2, 3, 4, 5, 6}; | |
580 | ||
581 | test_equal_range(a, {1, 2, 3, 4, 5, 6}); | |
582 | } | |
583 | ||
584 | { // assign to free front | |
585 | Devector a; get_range<Devector>(11, 15, 15, 19, a); | |
586 | a.reserve_front(8); | |
587 | a.reset_alloc_stats(); | |
588 | ||
589 | a = {1, 2, 3, 4, 5, 6}; | |
590 | ||
591 | test_equal_range(a, {1, 2, 3, 4, 5, 6}); | |
592 | BOOST_TEST(a.get_alloc_count() == 0u); | |
593 | } | |
594 | ||
595 | { // assignment overlaps contents | |
596 | Devector a; get_range<Devector>(11, 15, 15, 19, a); | |
597 | a.reserve_front(12); | |
598 | a.reset_alloc_stats(); | |
599 | ||
600 | a = {1, 2, 3, 4, 5, 6}; | |
601 | ||
602 | test_equal_range(a, {1, 2, 3, 4, 5, 6}); | |
603 | BOOST_TEST(a.get_alloc_count() == 0u); | |
604 | } | |
605 | ||
606 | { // assignment exceeds contents | |
607 | Devector a; get_range<Devector>(11, 13, 13, 15, a); | |
608 | a.reserve_front(8); | |
609 | a.reserve_back(8); | |
610 | a.reset_alloc_stats(); | |
611 | ||
612 | a = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; | |
613 | ||
614 | test_equal_range(a, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}); | |
615 | BOOST_TEST(a.get_alloc_count() == 0u); | |
616 | } | |
617 | ||
618 | #ifndef BOOST_NO_EXCEPTIONS | |
619 | typedef typename Devector::value_type T; | |
620 | if (! boost::move_detail::is_nothrow_copy_constructible<T>::value) | |
621 | { | |
622 | // strong guarantee if reallocation is needed (no guarantee otherwise) | |
623 | Devector a; get_range<Devector>(6, a); | |
624 | ||
625 | test_elem_throw::on_copy_after(3); | |
626 | ||
627 | BOOST_TRY | |
628 | { | |
629 | a = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; | |
630 | BOOST_TEST(false); | |
631 | } | |
632 | BOOST_CATCH(const test_exception&) {} | |
633 | BOOST_CATCH_END | |
634 | test_elem_throw::do_not_throw(); | |
635 | ||
636 | test_equal_range(a, {1, 2, 3, 4, 5, 6}); | |
637 | } | |
638 | #endif //BOOST_NO_EXCEPTIONS | |
639 | #endif //#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) | |
640 | } | |
641 | ||
642 | template <class Devector> void test_assign_input_range() | |
643 | { | |
644 | typedef typename Devector::value_type T; | |
645 | ||
646 | { // assign to empty, keep it small | |
647 | devector<T> expected; get_range<Devector>(1, 13, 13, 25, expected); | |
648 | devector<T> input = expected; | |
649 | ||
650 | input_iterator<Devector> input_begin = make_input_iterator(input, input.begin()); | |
651 | input_iterator<Devector> input_end = make_input_iterator(input, input.end()); | |
652 | ||
653 | Devector a; | |
654 | a.reset_alloc_stats(); | |
655 | a.assign(input_begin, input_end); | |
656 | ||
657 | BOOST_TEST(a == expected); | |
658 | } | |
659 | ||
660 | { // assign to empty (maybe small) | |
661 | devector<T> input; get_range<devector<T> >(6, input); | |
662 | ||
663 | input_iterator<Devector> input_begin = make_input_iterator(input, input.begin()); | |
664 | input_iterator<Devector> input_end = make_input_iterator(input, input.end()); | |
665 | ||
666 | Devector a; | |
667 | ||
668 | a.assign(input_begin, input_end); | |
669 | const int expected [] = {1, 2, 3, 4, 5, 6}; | |
670 | test_equal_range(a, expected); | |
671 | } | |
672 | ||
673 | { // assign from empty | |
674 | devector<T> input; get_range<devector<T> >(6, input); | |
675 | input_iterator<Devector> input_begin = make_input_iterator(input, input.begin()); | |
676 | ||
677 | Devector a; get_range<Devector>(6, a); | |
678 | a.assign(input_begin, input_begin); | |
679 | ||
680 | test_equal_range(a); | |
681 | } | |
682 | ||
683 | { // assign to non-empty | |
684 | devector<T> input; get_range<devector<T> >(6, input); | |
685 | input_iterator<Devector> input_begin = make_input_iterator(input, input.begin()); | |
686 | input_iterator<Devector> input_end = make_input_iterator(input, input.end()); | |
687 | ||
688 | Devector a; get_range<Devector>(11, 15, 15, 19, a); | |
689 | a.assign(input_begin, input_end); | |
690 | const int expected [] = {1, 2, 3, 4, 5, 6}; | |
691 | test_equal_range(a, expected); | |
692 | } | |
693 | ||
694 | { // assign to free front | |
695 | devector<T> input; get_range<devector<T> >(6, input); | |
696 | input_iterator<Devector> input_begin = make_input_iterator(input, input.begin()); | |
697 | input_iterator<Devector> input_end = make_input_iterator(input, input.end()); | |
698 | ||
699 | Devector a; get_range<Devector>(11, 15, 15, 19, a); | |
700 | a.reserve_front(8); | |
701 | a.reset_alloc_stats(); | |
702 | ||
703 | a.assign(input_begin, input_end); | |
704 | const int expected[] = {1, 2, 3, 4, 5, 6}; | |
705 | test_equal_range(a, expected); | |
706 | } | |
707 | ||
708 | { // assignment overlaps contents | |
709 | devector<T> input; get_range<devector<T> >(6, input); | |
710 | input_iterator<Devector> input_begin = make_input_iterator(input, input.begin()); | |
711 | input_iterator<Devector> input_end = make_input_iterator(input, input.end()); | |
712 | ||
713 | Devector a; get_range<Devector>(11, 15, 15, 19, a); | |
714 | a.reserve_front(12); | |
715 | a.reset_alloc_stats(); | |
716 | ||
717 | a.assign(input_begin, input_end); | |
718 | const int expected[] = {1, 2, 3, 4, 5, 6}; | |
719 | test_equal_range(a, expected); | |
720 | } | |
721 | ||
722 | { // assignment exceeds contents | |
723 | devector<T> input; get_range<devector<T> >(12, input); | |
724 | input_iterator<Devector> input_begin = make_input_iterator(input, input.begin()); | |
725 | input_iterator<Devector> input_end = make_input_iterator(input, input.end()); | |
726 | ||
727 | Devector a; get_range<Devector>(11, 13, 13, 15, a); | |
728 | a.reserve_front(8); | |
729 | a.reserve_back(8); | |
730 | a.reset_alloc_stats(); | |
731 | ||
732 | a.assign(input_begin, input_end); | |
733 | const int expected[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; | |
734 | test_equal_range(a, expected); | |
735 | } | |
736 | ||
737 | #ifndef BOOST_NO_EXCEPTIONS | |
738 | if (! boost::move_detail::is_nothrow_copy_constructible<T>::value) | |
739 | { | |
740 | // strong guarantee if reallocation is needed (no guarantee otherwise) | |
741 | ||
742 | devector<T> input; get_range<devector<T> >(12, input); | |
743 | input_iterator<Devector> input_begin = make_input_iterator(input, input.begin()); | |
744 | input_iterator<Devector> input_end = make_input_iterator(input, input.end()); | |
745 | ||
746 | Devector a; get_range<Devector>(6, a); | |
747 | ||
748 | test_elem_throw::on_copy_after(3); | |
749 | BOOST_TEST_THROWS(a.assign(input_begin, input_end), test_exception); | |
750 | test_elem_throw::do_not_throw(); | |
751 | ||
752 | const int expected[] = {1, 2, 3, 4, 5, 6}; | |
753 | test_equal_range(a, expected); | |
754 | } | |
755 | #endif //#ifndef BOOST_NO_EXCEPTIONS | |
756 | } | |
757 | ||
758 | template <class Devector> void test_assign_forward_range_throwing(dtl::false_) | |
759 | {} | |
760 | ||
761 | template <class Devector> void test_assign_forward_range() | |
762 | { | |
763 | typedef typename Devector::value_type T; | |
764 | typedef boost::container::list<T> List; | |
765 | ||
766 | boost::container::list<T> x; | |
767 | typedef typename List::iterator list_iterator; | |
768 | x.emplace_back(1); | |
769 | x.emplace_back(2); | |
770 | x.emplace_back(3); | |
771 | x.emplace_back(4); | |
772 | x.emplace_back(5); | |
773 | x.emplace_back(6); | |
774 | x.emplace_back(7); | |
775 | x.emplace_back(8); | |
776 | x.emplace_back(9); | |
777 | x.emplace_back(10); | |
778 | x.emplace_back(11); | |
779 | x.emplace_back(12); | |
780 | ||
781 | list_iterator one = x.begin(); | |
782 | list_iterator six = one; | |
783 | list_iterator twelve = one; | |
784 | ||
785 | iterator_advance(six, 6); | |
786 | iterator_advance(twelve, 12); | |
787 | ||
788 | { // assign to empty (maybe small) | |
789 | Devector a; | |
790 | ||
791 | a.assign(one, six); | |
792 | ||
793 | const int expected [] = {1, 2, 3, 4, 5, 6}; | |
794 | test_equal_range(a, expected); | |
795 | } | |
796 | ||
797 | { // assign from empty | |
798 | Devector a; get_range<Devector>(6, a); | |
799 | ||
800 | a.assign(one, one); | |
801 | ||
802 | test_equal_range(a); | |
803 | } | |
804 | ||
805 | { // assign to non-empty | |
806 | Devector a; get_range<Devector>(11, 15, 15, 19, a); | |
807 | ||
808 | a.assign(one, six); | |
809 | ||
810 | const int expected [] = {1, 2, 3, 4, 5, 6}; | |
811 | test_equal_range(a, expected); | |
812 | } | |
813 | ||
814 | { // assign to free front | |
815 | Devector a; get_range<Devector>(11, 15, 15, 19, a); | |
816 | a.reserve_front(8); | |
817 | a.reset_alloc_stats(); | |
818 | ||
819 | a.assign(one, six); | |
820 | ||
821 | const int expected [] = {1, 2, 3, 4, 5, 6}; | |
822 | test_equal_range(a, expected); | |
823 | BOOST_TEST(a.get_alloc_count() == 0u); | |
824 | } | |
825 | ||
826 | { // assignment overlaps contents | |
827 | Devector a; get_range<Devector>(11, 15, 15, 19, a); | |
828 | a.reserve_front(12); | |
829 | a.reset_alloc_stats(); | |
830 | ||
831 | a.assign(one, six); | |
832 | ||
833 | const int expected [] = {1, 2, 3, 4, 5, 6}; | |
834 | test_equal_range(a, expected); | |
835 | BOOST_TEST(a.get_alloc_count() == 0u); | |
836 | } | |
837 | ||
838 | { // assignment exceeds contents | |
839 | Devector a; get_range<Devector>(11, 13, 13, 15, a); | |
840 | a.reserve_front(8); | |
841 | a.reserve_back(8); | |
842 | a.reset_alloc_stats(); | |
843 | ||
844 | a.assign(one, twelve); | |
845 | ||
846 | const int expected [] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; | |
847 | test_equal_range(a, expected); | |
848 | BOOST_TEST(a.get_alloc_count() == 0u); | |
849 | } | |
850 | ||
851 | #ifndef BOOST_NO_EXCEPTIONS | |
852 | BOOST_IF_CONSTEXPR(! boost::move_detail::is_nothrow_copy_constructible<T>::value) | |
853 | { | |
854 | // strong guarantee if reallocation is needed (no guarantee otherwise) | |
855 | Devector a; get_range<Devector>(6, a); | |
856 | ||
857 | test_elem_throw::on_copy_after(3); | |
858 | BOOST_TEST_THROWS(a.assign(one, twelve), test_exception); | |
859 | test_elem_throw::do_not_throw(); | |
860 | ||
861 | const int expected [] = {1, 2, 3, 4, 5, 6}; | |
862 | test_equal_range(a, expected); | |
863 | } | |
864 | #endif //#ifndef BOOST_NO_EXCEPTIONS | |
865 | } | |
866 | ||
867 | template <class Devector> void test_assign_pointer_range() | |
868 | { | |
869 | typedef typename Devector::value_type T; | |
870 | ||
871 | boost::container::vector<T> x; get_range<boost::container::vector<T> >(12, x); | |
872 | const T* one = x.data(); | |
873 | const T* six = one + 6; | |
874 | const T* twelve = one + 12; | |
875 | ||
876 | { // assign to empty (maybe small) | |
877 | Devector a; | |
878 | ||
879 | a.assign(one, six); | |
880 | ||
881 | const int expected[] = {1, 2, 3, 4, 5, 6}; | |
882 | test_equal_range(a, expected); | |
883 | } | |
884 | ||
885 | { // assign from empty | |
886 | Devector a; get_range<Devector>(6, a); | |
887 | ||
888 | a.assign(one, one); | |
889 | ||
890 | test_equal_range(a); | |
891 | } | |
892 | ||
893 | { // assign to non-empty | |
894 | Devector a; get_range<Devector>(11, 15, 15, 19, a); | |
895 | ||
896 | a.assign(one, six); | |
897 | ||
898 | const int expected[] = {1, 2, 3, 4, 5, 6}; | |
899 | test_equal_range(a, expected); | |
900 | } | |
901 | ||
902 | { // assign to free front | |
903 | Devector a; get_range<Devector>(11, 15, 15, 19, a); | |
904 | a.reserve_front(8); | |
905 | a.reset_alloc_stats(); | |
906 | ||
907 | a.assign(one, six); | |
908 | ||
909 | const int expected[] = {1, 2, 3, 4, 5, 6}; | |
910 | test_equal_range(a, expected); | |
911 | BOOST_TEST(a.get_alloc_count() == 0u); | |
912 | } | |
913 | ||
914 | { // assignment overlaps contents | |
915 | Devector a; get_range<Devector>(11, 15, 15, 19, a); | |
916 | a.reserve_front(12); | |
917 | a.reset_alloc_stats(); | |
918 | ||
919 | a.assign(one, six); | |
920 | ||
921 | const int expected[] = {1, 2, 3, 4, 5, 6}; | |
922 | test_equal_range(a, expected); | |
923 | BOOST_TEST(a.get_alloc_count() == 0u); | |
924 | } | |
925 | ||
926 | { // assignment exceeds contents | |
927 | Devector a; get_range<Devector>(11, 13, 13, 15, a); | |
928 | a.reserve_front(8); | |
929 | a.reserve_back(8); | |
930 | a.reset_alloc_stats(); | |
931 | ||
932 | a.assign(one, twelve); | |
933 | ||
934 | const int expected[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; | |
935 | test_equal_range(a, expected); | |
936 | BOOST_TEST(a.get_alloc_count() == 0u); | |
937 | } | |
938 | ||
939 | #ifndef BOOST_NO_EXCEPTIONS | |
940 | if (! boost::move_detail::is_nothrow_copy_constructible<T>::value) | |
941 | { | |
942 | // strong guarantee if reallocation is needed (no guarantee otherwise) | |
943 | Devector a; get_range<Devector>(6, a); | |
944 | ||
945 | test_elem_throw::on_copy_after(3); | |
946 | BOOST_TEST_THROWS(a.assign(one, twelve), test_exception); | |
947 | test_elem_throw::do_not_throw(); | |
948 | ||
949 | const int expected[] = {1, 2, 3, 4, 5, 6}; | |
950 | test_equal_range(a, expected); | |
951 | } | |
952 | #endif //#ifndef BOOST_NO_EXCEPTIONS | |
953 | } | |
954 | ||
955 | template <class Devector> void test_assign_n() | |
956 | { | |
957 | typedef typename Devector::value_type T; | |
958 | ||
959 | { // assign to empty (maybe small) | |
960 | Devector a; | |
961 | ||
962 | a.assign(6, T(9)); | |
963 | ||
964 | const int expected[] = {9, 9, 9, 9, 9, 9}; | |
965 | test_equal_range(a, expected); | |
966 | } | |
967 | ||
968 | { // assign from empty | |
969 | Devector a; get_range<Devector>(6, a); | |
970 | ||
971 | a.assign(0, T(404)); | |
972 | ||
973 | test_equal_range(a); | |
974 | } | |
975 | ||
976 | { // assign to non-empty | |
977 | Devector a; get_range<Devector>(11, 15, 15, 19, a); | |
978 | ||
979 | a.assign(6, T(9)); | |
980 | ||
981 | const int expected[] = {9, 9, 9, 9, 9, 9}; | |
982 | test_equal_range(a, expected); | |
983 | } | |
984 | ||
985 | { // assign to free front | |
986 | Devector a; get_range<Devector>(11, 15, 15, 19, a); | |
987 | a.reserve_front(8); | |
988 | a.reset_alloc_stats(); | |
989 | ||
990 | a.assign(6, T(9)); | |
991 | ||
992 | const int expected[] = {9, 9, 9, 9, 9, 9}; | |
993 | test_equal_range(a, expected); | |
994 | BOOST_TEST(a.get_alloc_count() == 0u); | |
995 | } | |
996 | ||
997 | { // assignment overlaps contents | |
998 | Devector a; get_range<Devector>(11, 15, 15, 19, a); | |
999 | a.reserve_front(12); | |
1000 | a.reset_alloc_stats(); | |
1001 | ||
1002 | a.assign(6, T(9)); | |
1003 | ||
1004 | const int expected[] = {9, 9, 9, 9, 9, 9}; | |
1005 | test_equal_range(a, expected); | |
1006 | BOOST_TEST(a.get_alloc_count() == 0u); | |
1007 | } | |
1008 | ||
1009 | { // assignment exceeds contents | |
1010 | Devector a; get_range<Devector>(11, 13, 13, 15, a); | |
1011 | a.reserve_front(8); | |
1012 | a.reserve_back(8); | |
1013 | a.reset_alloc_stats(); | |
1014 | ||
1015 | a.assign(12, T(9)); | |
1016 | ||
1017 | const int expected[] = {9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9}; | |
1018 | test_equal_range(a, expected); | |
1019 | BOOST_TEST(a.get_alloc_count() == 0u); | |
1020 | } | |
1021 | ||
1022 | #ifndef BOOST_NO_EXCEPTIONS | |
1023 | if (! boost::move_detail::is_nothrow_copy_constructible<T>::value) | |
1024 | { | |
1025 | // strong guarantee if reallocation is needed (no guarantee otherwise) | |
1026 | Devector a; get_range<Devector>(6, a); | |
1027 | ||
1028 | test_elem_throw::on_copy_after(3); | |
1029 | BOOST_TEST_THROWS(a.assign(32, T(9)), test_exception); | |
1030 | test_elem_throw::do_not_throw(); | |
1031 | ||
1032 | const int expected[] = {1, 2, 3, 4, 5, 6}; | |
1033 | test_equal_range(a, expected); | |
1034 | } | |
1035 | #endif //#ifndef BOOST_NO_EXCEPTIONS | |
1036 | } | |
1037 | ||
1038 | template <class Devector> void test_assign_il() | |
1039 | { | |
1040 | #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) | |
1041 | ||
1042 | { // assign to empty (maybe small) | |
1043 | Devector a; | |
1044 | ||
1045 | a.assign({1, 2, 3, 4, 5, 6}); | |
1046 | ||
1047 | test_equal_range(a, {1, 2, 3, 4, 5, 6}); | |
1048 | } | |
1049 | ||
1050 | { // assign from empty | |
1051 | Devector a; get_range<Devector>(6, a); | |
1052 | ||
1053 | a.assign({}); | |
1054 | ||
1055 | test_equal_range(a); | |
1056 | } | |
1057 | ||
1058 | { // assign to non-empty | |
1059 | Devector a; get_range<Devector>(11, 15, 15, 19, a); | |
1060 | ||
1061 | a.assign({1, 2, 3, 4, 5, 6}); | |
1062 | ||
1063 | test_equal_range(a, {1, 2, 3, 4, 5, 6}); | |
1064 | } | |
1065 | ||
1066 | { // assign to free front | |
1067 | Devector a; get_range<Devector>(11, 15, 15, 19, a); | |
1068 | a.reserve_front(8); | |
1069 | a.reset_alloc_stats(); | |
1070 | ||
1071 | a.assign({1, 2, 3, 4, 5, 6}); | |
1072 | ||
1073 | test_equal_range(a, {1, 2, 3, 4, 5, 6}); | |
1074 | BOOST_TEST(a.get_alloc_count() == 0u); | |
1075 | } | |
1076 | ||
1077 | { // assignment overlaps contents | |
1078 | Devector a; get_range<Devector>(11, 15, 15, 19, a); | |
1079 | a.reserve_front(12); | |
1080 | a.reset_alloc_stats(); | |
1081 | ||
1082 | a.assign({1, 2, 3, 4, 5, 6}); | |
1083 | ||
1084 | test_equal_range(a, {1, 2, 3, 4, 5, 6}); | |
1085 | BOOST_TEST(a.get_alloc_count() == 0u); | |
1086 | } | |
1087 | ||
1088 | { // assignment exceeds contents | |
1089 | Devector a; get_range<Devector>(11, 13, 13, 15, a); | |
1090 | a.reserve_front(8); | |
1091 | a.reserve_back(8); | |
1092 | a.reset_alloc_stats(); | |
1093 | ||
1094 | a.assign({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}); | |
1095 | ||
1096 | test_equal_range(a, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}); | |
1097 | BOOST_TEST(a.get_alloc_count() == 0u); | |
1098 | } | |
1099 | ||
1100 | #ifndef BOOST_NO_EXCEPTIONS | |
1101 | typedef typename Devector::value_type T; | |
1102 | if (! boost::move_detail::is_nothrow_copy_constructible<T>::value) | |
1103 | { | |
1104 | // strong guarantee if reallocation is needed (no guarantee otherwise) | |
1105 | Devector a; get_range<Devector>(6, a); | |
1106 | ||
1107 | test_elem_throw::on_copy_after(3); | |
1108 | BOOST_TEST_THROWS(a.assign({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18}), test_exception); | |
1109 | test_elem_throw::do_not_throw(); | |
1110 | ||
1111 | test_equal_range(a, {1, 2, 3, 4, 5, 6}); | |
1112 | } | |
1113 | #endif //#ifndef BOOST_NO_EXCEPTIONS | |
1114 | #endif //#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) | |
1115 | } | |
1116 | ||
1117 | template <class Devector> void test_get_allocator() | |
1118 | { | |
1119 | Devector a; | |
1120 | (void) a.get_allocator(); | |
1121 | } | |
1122 | ||
1123 | template <class Devector> void test_begin_end() | |
1124 | { | |
1125 | boost::container::vector<int> expected; get_range<boost::container::vector<int> >(10, expected); | |
1126 | { | |
1127 | Devector actual; get_range<Devector>(10, actual); | |
1128 | ||
1129 | BOOST_TEST(boost::algorithm::equal(expected.begin(), expected.end(), actual.begin(), actual.end())); | |
1130 | BOOST_TEST(boost::algorithm::equal(expected.rbegin(), expected.rend(), actual.rbegin(), actual.rend())); | |
1131 | BOOST_TEST(boost::algorithm::equal(expected.cbegin(), expected.cend(), actual.cbegin(), actual.cend())); | |
1132 | BOOST_TEST(boost::algorithm::equal(expected.crbegin(), expected.crend(), actual.crbegin(), actual.crend())); | |
1133 | } | |
1134 | ||
1135 | { | |
1136 | Devector cactual; get_range<Devector>(10, cactual); | |
1137 | ||
1138 | BOOST_TEST(boost::algorithm::equal(expected.begin(), expected.end(), cactual.begin(), cactual.end())); | |
1139 | BOOST_TEST(boost::algorithm::equal(expected.rbegin(), expected.rend(), cactual.rbegin(), cactual.rend())); | |
1140 | } | |
1141 | } | |
1142 | ||
1143 | template <class Devector> void test_empty() | |
1144 | { | |
1145 | typedef typename Devector::value_type T; | |
1146 | ||
1147 | Devector a; | |
1148 | BOOST_TEST(a.empty()); | |
1149 | ||
1150 | a.push_front(T(1)); | |
1151 | BOOST_TEST(! a.empty()); | |
1152 | ||
1153 | a.pop_back(); | |
1154 | BOOST_TEST(a.empty()); | |
1155 | ||
1156 | Devector b(16, reserve_only_tag_t()); | |
1157 | BOOST_TEST(b.empty()); | |
1158 | ||
1159 | Devector c; get_range<Devector>(3, c); | |
1160 | BOOST_TEST(! c.empty()); | |
1161 | } | |
1162 | ||
1163 | //template <typename ST> | |
1164 | //using gp_devector = devector<unsigned, different_growth_policy>; | |
1165 | ||
1166 | void test_max_size() | |
1167 | {/* | |
1168 | gp_devector<unsigned char> a; | |
1169 | BOOST_TEST(a.max_size() == (std::numeric_limits<unsigned char>::max)()); | |
1170 | ||
1171 | gp_devector<unsigned short> b; | |
1172 | BOOST_TEST(b.max_size() == (std::numeric_limits<unsigned short>::max)()); | |
1173 | ||
1174 | gp_devector<unsigned int> c; | |
1175 | BOOST_TEST(c.max_size() >= b.max_size()); | |
1176 | ||
1177 | gp_devector<std::size_t> d; | |
1178 | BOOST_TEST(d.max_size() >= c.max_size()); | |
1179 | */ | |
1180 | } | |
1181 | ||
1182 | void test_exceeding_max_size() | |
1183 | {/* | |
1184 | #ifndef BOOST_NO_EXCEPTIONS | |
1185 | using Devector = gp_devector<unsigned char>; | |
1186 | ||
1187 | Devector a((std::numeric_limits<typename Devector::size_type>::max)()); | |
1188 | BOOST_TEST_THROWS(a.emplace_back(404), std::length_error); | |
1189 | #endif //#ifndef BOOST_NO_EXCEPTIONS | |
1190 | */ | |
1191 | } | |
1192 | ||
1193 | template <class Devector> void test_size() | |
1194 | { | |
1195 | typedef typename Devector::value_type T; | |
1196 | ||
1197 | Devector a; | |
1198 | BOOST_TEST(a.size() == 0u); | |
1199 | ||
1200 | a.push_front(T(1)); | |
1201 | BOOST_TEST(a.size() == 1u); | |
1202 | ||
1203 | a.pop_back(); | |
1204 | BOOST_TEST(a.size() == 0u); | |
1205 | ||
1206 | Devector b(16, reserve_only_tag_t()); | |
1207 | BOOST_TEST(b.size() == 0u); | |
1208 | ||
1209 | Devector c; get_range<Devector>(3, c); | |
1210 | BOOST_TEST(c.size() == 3u); | |
1211 | } | |
1212 | ||
1213 | template <class Devector> void test_capacity() | |
1214 | { | |
1215 | Devector a; | |
1216 | BOOST_TEST(a.capacity() == 0u); | |
1217 | ||
1218 | Devector b(128, reserve_only_tag_t()); | |
1219 | BOOST_TEST(b.capacity() >= 128u); | |
1220 | ||
1221 | Devector c; get_range<Devector>(10, c); | |
1222 | BOOST_TEST(c.capacity() >= 10u); | |
1223 | } | |
1224 | ||
1225 | template <class Devector> void test_resize_front_throwing(dtl::true_) | |
1226 | { | |
1227 | #ifndef BOOST_NO_EXCEPTIONS | |
1228 | typedef typename Devector::iterator iterator; | |
1229 | ||
1230 | Devector d; get_range<Devector>(5, d); | |
1231 | boost::container::vector<int> d_origi; get_range<boost::container::vector<int> >(5, d_origi); | |
1232 | iterator origi_begin = d.begin(); | |
1233 | ||
1234 | test_elem_throw::on_ctor_after(3); | |
1235 | BOOST_TEST_THROWS(d.resize_front(256), test_exception); | |
1236 | test_elem_throw::do_not_throw(); | |
1237 | ||
1238 | test_equal_range(d, d_origi); | |
1239 | BOOST_TEST(origi_begin == d.begin()); | |
1240 | #endif //#ifndef BOOST_NO_EXCEPTIONS | |
1241 | } | |
1242 | ||
1243 | template <class Devector> void test_resize_front_throwing(dtl::false_) | |
1244 | {} | |
1245 | ||
1246 | ||
1247 | template <class Devector> void test_resize_front() | |
1248 | { | |
1249 | typedef typename Devector::value_type T; | |
1250 | ||
1251 | // size < required, alloc needed | |
1252 | { | |
1253 | Devector a; get_range<Devector>(5, a); | |
1254 | a.resize_front(8); | |
1255 | const int expected [] = {0, 0, 0, 1, 2, 3, 4, 5}; | |
1256 | test_equal_range(a, expected); | |
1257 | } | |
1258 | ||
1259 | // size < required, but capacity provided | |
1260 | { | |
1261 | Devector b; get_range<Devector>(5, b); | |
1262 | b.reserve_front(16); | |
1263 | b.resize_front(8); | |
1264 | const int expected [] = {0, 0, 0, 1, 2, 3, 4, 5}; | |
1265 | test_equal_range(b, expected); | |
1266 | } | |
1267 | /* | |
1268 | // size < required, move would throw | |
1269 | if (! boost::is_nothrow_move_constructible<T>::value && std::is_copy_constructible<T>::value) | |
1270 | { | |
1271 | Devector c; get_range<Devector>(5, c); | |
1272 | ||
1273 | test_elem_throw::on_move_after(3); | |
1274 | c.resize_front(8); // shouldn't use the throwing move | |
1275 | test_elem_throw::do_not_throw(); | |
1276 | ||
1277 | test_equal_range(c, {0, 0, 0, 1, 2, 3, 4, 5}); | |
1278 | } | |
1279 | */ | |
1280 | ||
1281 | test_resize_front_throwing<Devector> | |
1282 | (dtl::bool_<! boost::move_detail::is_nothrow_default_constructible<T>::value>()); | |
1283 | ||
1284 | // size >= required | |
1285 | { | |
1286 | Devector e; get_range<Devector>(6, e); | |
1287 | e.resize_front(4); | |
1288 | const int expected [] = {3, 4, 5, 6}; | |
1289 | test_equal_range(e, expected); | |
1290 | } | |
1291 | ||
1292 | // size < required, does not fit front small buffer | |
1293 | { | |
1294 | boost::container::vector<int> expected(128); | |
1295 | Devector g; | |
1296 | g.resize_front(128); | |
1297 | test_equal_range(g, expected); | |
1298 | } | |
1299 | ||
1300 | // size = required | |
1301 | { | |
1302 | Devector e; get_range<Devector>(6, e); | |
1303 | e.resize_front(6); | |
1304 | const int expected [] = {1, 2, 3, 4, 5, 6}; | |
1305 | test_equal_range(e, expected); | |
1306 | } | |
1307 | } | |
1308 | ||
1309 | template <class Devector> void test_resize_front_copy_throwing(dtl::true_) | |
1310 | { | |
1311 | #ifndef BOOST_NO_EXCEPTIONS | |
1312 | typedef typename Devector::value_type T; | |
1313 | typedef typename Devector::iterator iterator; | |
1314 | ||
1315 | // size < required, copy throws | |
1316 | { | |
1317 | Devector c; get_range<Devector>(5, c); | |
1318 | boost::container::vector<int> c_origi; get_range<boost::container::vector<int> >(5, c_origi); | |
1319 | ||
1320 | test_elem_throw::on_copy_after(3); | |
1321 | BOOST_TEST_THROWS(c.resize_front(256, T(404)), test_exception); | |
1322 | test_elem_throw::do_not_throw(); | |
1323 | ||
1324 | test_equal_range(c, c_origi); | |
1325 | } | |
1326 | ||
1327 | // size < required, copy throws, but later | |
1328 | { | |
1329 | Devector c; get_range<Devector>(5, c); | |
1330 | boost::container::vector<int> c_origi; get_range<boost::container::vector<int> >(5, c_origi); | |
1331 | iterator origi_begin = c.begin(); | |
1332 | ||
1333 | test_elem_throw::on_copy_after(7); | |
1334 | BOOST_TEST_THROWS(c.resize_front(256, T(404)), test_exception); | |
1335 | test_elem_throw::do_not_throw(); | |
1336 | ||
1337 | test_equal_range(c, c_origi); | |
1338 | BOOST_TEST(origi_begin == c.begin()); | |
1339 | } | |
1340 | #endif //#ifndef BOOST_NO_EXCEPTIONS | |
1341 | } | |
1342 | ||
1343 | template <class Devector> void test_resize_front_copy_throwing(dtl::false_) | |
1344 | {} | |
1345 | ||
1346 | template <class Devector> void test_resize_front_copy() | |
1347 | { | |
1348 | typedef typename Devector::value_type T; | |
1349 | ||
1350 | // size < required, alloc needed | |
1351 | { | |
1352 | Devector a; get_range<Devector>(5, a); | |
1353 | a.resize_front(8, T(9)); | |
1354 | const int expected [] = {9, 9, 9, 1, 2, 3, 4, 5}; | |
1355 | test_equal_range(a, expected); | |
1356 | } | |
1357 | ||
1358 | // size < required, but capacity provided | |
1359 | { | |
1360 | Devector b; get_range<Devector>(5, b); | |
1361 | b.reserve_front(16); | |
1362 | b.resize_front(8, T(9)); | |
1363 | const int expected [] = {9, 9, 9, 1, 2, 3, 4, 5}; | |
1364 | test_equal_range(b, expected); | |
1365 | } | |
1366 | ||
1367 | test_resize_front_copy_throwing<Devector> | |
1368 | (dtl::bool_<! boost::move_detail::is_nothrow_copy_constructible<T>::value>()); | |
1369 | ||
1370 | // size >= required | |
1371 | { | |
1372 | Devector e; get_range<Devector>(6, e); | |
1373 | e.resize_front(4, T(404)); | |
1374 | const int expected[] = {3, 4, 5, 6}; | |
1375 | test_equal_range(e, expected); | |
1376 | } | |
1377 | ||
1378 | // size < required, does not fit front small buffer | |
1379 | { | |
1380 | boost::container::vector<int> expected(128, 9); | |
1381 | Devector g; | |
1382 | g.resize_front(128, T(9)); | |
1383 | test_equal_range(g, expected); | |
1384 | } | |
1385 | ||
1386 | // size = required | |
1387 | { | |
1388 | Devector e; get_range<Devector>(6, e); | |
1389 | e.resize_front(6, T(9)); | |
1390 | const int expected[] = {1, 2, 3, 4, 5, 6}; | |
1391 | test_equal_range(e, expected); | |
1392 | } | |
1393 | ||
1394 | // size < required, tmp is already inserted | |
1395 | { | |
1396 | Devector f; get_range<Devector>(8, f); | |
1397 | const T& tmp = *(f.begin() + 1); | |
1398 | f.resize_front(16, tmp); | |
1399 | const int expected[] = {2,2,2,2,2,2,2,2,1,2,3,4,5,6,7,8}; | |
1400 | test_equal_range(f, expected); | |
1401 | } | |
1402 | } | |
1403 | ||
1404 | template <class Devector> void test_resize_back_throwing(dtl::true_) | |
1405 | // size < required, constructor throws | |
1406 | { | |
1407 | #ifndef BOOST_NO_EXCEPTIONS | |
1408 | typedef typename Devector::iterator iterator; | |
1409 | ||
1410 | Devector d; get_range<Devector>(5, d); | |
1411 | boost::container::vector<int> d_origi; get_range<boost::container::vector<int> >(5, d_origi); | |
1412 | iterator origi_begin = d.begin(); | |
1413 | ||
1414 | test_elem_throw::on_ctor_after(3); | |
1415 | BOOST_TEST_THROWS(d.resize_back(256), test_exception); | |
1416 | test_elem_throw::do_not_throw(); | |
1417 | ||
1418 | test_equal_range(d, d_origi); | |
1419 | BOOST_TEST(origi_begin == d.begin()); | |
1420 | #endif //#ifndef BOOST_NO_EXCEPTIONS | |
1421 | } | |
1422 | ||
1423 | template <class Devector> void test_resize_back_throwing(dtl::false_) | |
1424 | {} | |
1425 | ||
1426 | template <class Devector> void test_resize_back() | |
1427 | { | |
1428 | typedef typename Devector::value_type T; | |
1429 | ||
1430 | // size < required, alloc needed | |
1431 | { | |
1432 | Devector a; get_range<Devector>(5, a); | |
1433 | a.resize_back(8); | |
1434 | const int expected [] = {1, 2, 3, 4, 5, 0, 0, 0}; | |
1435 | test_equal_range(a, expected); | |
1436 | } | |
1437 | ||
1438 | // size < required, but capacity provided | |
1439 | { | |
1440 | Devector b; get_range<Devector>(5, b); | |
1441 | b.reserve_back(16); | |
1442 | b.resize_back(8); | |
1443 | const int expected [] = {1, 2, 3, 4, 5, 0, 0, 0}; | |
1444 | test_equal_range(b, expected); | |
1445 | } | |
1446 | /* | |
1447 | // size < required, move would throw | |
1448 | if (! boost::is_nothrow_move_constructible<T>::value && std::is_copy_constructible<T>::value) | |
1449 | { | |
1450 | Devector c; get_range<Devector>(5, c); | |
1451 | ||
1452 | test_elem_throw::on_move_after(3); | |
1453 | c.resize_back(8); // shouldn't use the throwing move | |
1454 | test_elem_throw::do_not_throw(); | |
1455 | ||
1456 | test_equal_range(c, {1, 2, 3, 4, 5, 0, 0, 0}); | |
1457 | } | |
1458 | */ | |
1459 | ||
1460 | test_resize_back_throwing<Devector> | |
1461 | (dtl::bool_<! boost::move_detail::is_nothrow_default_constructible<T>::value>()); | |
1462 | ||
1463 | // size >= required | |
1464 | { | |
1465 | Devector e; get_range<Devector>(6, e); | |
1466 | e.resize_back(4); | |
1467 | const int expected [] = {1, 2, 3, 4}; | |
1468 | test_equal_range(e, expected); | |
1469 | } | |
1470 | ||
1471 | // size < required, does not fit front small buffer | |
1472 | { | |
1473 | boost::container::vector<int> expected(128); | |
1474 | Devector g; | |
1475 | g.resize_back(128); | |
1476 | test_equal_range(g, expected); | |
1477 | } | |
1478 | ||
1479 | // size = required | |
1480 | { | |
1481 | Devector e; get_range<Devector>(6, e); | |
1482 | e.resize_back(6); | |
1483 | const int expected [] = {1, 2, 3, 4, 5, 6}; | |
1484 | test_equal_range(e, expected); | |
1485 | } | |
1486 | } | |
1487 | ||
1488 | template <class Devector> void test_resize_back_copy_throwing(dtl::true_) | |
1489 | { | |
1490 | #ifndef BOOST_NO_EXCEPTIONS | |
1491 | typedef typename Devector::value_type T; | |
1492 | typedef typename Devector::iterator iterator; | |
1493 | ||
1494 | // size < required, copy throws | |
1495 | { | |
1496 | Devector c; get_range<Devector>(5, c); | |
1497 | boost::container::vector<int> c_origi; get_range<boost::container::vector<int> >(5, c_origi); | |
1498 | ||
1499 | test_elem_throw::on_copy_after(3); | |
1500 | BOOST_TEST_THROWS(c.resize_back(256, T(404)), test_exception); | |
1501 | test_elem_throw::do_not_throw(); | |
1502 | ||
1503 | test_equal_range(c, c_origi); | |
1504 | } | |
1505 | ||
1506 | // size < required, copy throws, but later | |
1507 | { | |
1508 | Devector c; get_range<Devector>(5, c); | |
1509 | boost::container::vector<int> c_origi; get_range<boost::container::vector<int> >(5, c_origi); | |
1510 | iterator origi_begin = c.begin(); | |
1511 | ||
1512 | test_elem_throw::on_copy_after(7); | |
1513 | BOOST_TEST_THROWS(c.resize_back(256, T(404)), test_exception); | |
1514 | test_elem_throw::do_not_throw(); | |
1515 | ||
1516 | test_equal_range(c, c_origi); | |
1517 | BOOST_TEST(origi_begin == c.begin()); | |
1518 | } | |
1519 | ||
1520 | // size < required, copy throws | |
1521 | { | |
1522 | Devector c; get_range<Devector>(5, c); | |
1523 | boost::container::vector<int> c_origi; get_range<boost::container::vector<int> >(5, c_origi); | |
1524 | iterator origi_begin = c.begin(); | |
1525 | ||
1526 | test_elem_throw::on_copy_after(3); | |
1527 | BOOST_TEST_THROWS(c.resize_back(256, T(404)), test_exception); | |
1528 | test_elem_throw::do_not_throw(); | |
1529 | ||
1530 | test_equal_range(c, c_origi); | |
1531 | BOOST_TEST(origi_begin == c.begin()); | |
1532 | } | |
1533 | #endif //#ifndef BOOST_NO_EXCEPTIONS | |
1534 | } | |
1535 | ||
1536 | template <class Devector> void test_resize_back_copy_throwing(dtl::false_) | |
1537 | {} | |
1538 | ||
1539 | template <class Devector> void test_resize_back_copy() | |
1540 | { | |
1541 | typedef typename Devector::value_type T; | |
1542 | ||
1543 | // size < required, alloc needed | |
1544 | { | |
1545 | Devector a; get_range<Devector>(5, a); | |
1546 | a.resize_back(8, T(9)); | |
1547 | const int expected [] = {1, 2, 3, 4, 5, 9, 9, 9}; | |
1548 | test_equal_range(a, expected); | |
1549 | } | |
1550 | ||
1551 | // size < required, but capacity provided | |
1552 | { | |
1553 | Devector b; get_range<Devector>(5, b); | |
1554 | b.reserve_back(16); | |
1555 | b.resize_back(8, T(9)); | |
1556 | const int expected [] = {1, 2, 3, 4, 5, 9, 9, 9}; | |
1557 | test_equal_range(b, expected); | |
1558 | } | |
1559 | ||
1560 | test_resize_back_copy_throwing<Devector> | |
1561 | (dtl::bool_<! boost::move_detail::is_nothrow_copy_constructible<T>::value>()); | |
1562 | ||
1563 | // size >= required | |
1564 | { | |
1565 | Devector e; get_range<Devector>(6, e); | |
1566 | e.resize_back(4, T(404)); | |
1567 | const int expected [] = {1, 2, 3, 4}; | |
1568 | test_equal_range(e, expected); | |
1569 | } | |
1570 | ||
1571 | // size < required, does not fit front small buffer | |
1572 | { | |
1573 | boost::container::vector<int> expected(128, 9); | |
1574 | Devector g; | |
1575 | g.resize_back(128, T(9)); | |
1576 | test_equal_range(g, expected); | |
1577 | } | |
1578 | ||
1579 | // size = required | |
1580 | { | |
1581 | Devector e; get_range<Devector>(6, e); | |
1582 | e.resize_back(6, T(9)); | |
1583 | const int expected [] = {1, 2, 3, 4, 5, 6}; | |
1584 | test_equal_range(e, expected); | |
1585 | } | |
1586 | ||
1587 | // size < required, tmp is already inserted | |
1588 | { | |
1589 | Devector f; get_range<Devector>(8, f); | |
1590 | const T& tmp = *(f.begin() + 1); | |
1591 | f.resize_back(16, tmp); | |
1592 | const int expected [] = {1,2,3,4,5,6,7,8,2,2,2,2,2,2,2,2}; | |
1593 | test_equal_range(f, expected); | |
1594 | } | |
1595 | } | |
1596 | ||
1597 | /* | |
1598 | template <class Devector> void test_constructor_unsafe_uninitialized() | |
1599 | { | |
1600 | { | |
1601 | Devector a(8, unsafe_uninitialized_tag_t()); | |
1602 | BOOST_TEST(a.size() == 8u); | |
1603 | ||
1604 | for (int i = 0; i < 8; ++i) | |
1605 | { | |
1606 | new (a.data() + i) T(i+1); | |
1607 | } | |
1608 | ||
1609 | const int expected [] = {1, 2, 3, 4, 5, 6, 7, 8}; | |
1610 | test_equal_range(a, expected); | |
1611 | } | |
1612 | ||
1613 | { | |
1614 | Devector b(0, unsafe_uninitialized_tag_t()); | |
1615 | BOOST_TEST(b.get_alloc_count() == 0u); | |
1616 | } | |
1617 | } | |
1618 | */ | |
1619 | ||
1620 | /* | |
1621 | template <class Devector> void test_unsafe_uninitialized_resize_front() | |
1622 | { | |
1623 | typedef typename Devector::value_type T; | |
1624 | ||
1625 | { // noop | |
1626 | Devector a; get_range<Devector>(8, a); | |
1627 | a.reset_alloc_stats(); | |
1628 | ||
1629 | a.unsafe_uninitialized_resize_front(a.size()); | |
1630 | ||
1631 | const int expected [] = {1, 2, 3, 4, 5, 6, 7, 8}; | |
1632 | test_equal_range(a, expected); | |
1633 | BOOST_TEST(a.get_alloc_count() == 0u); | |
1634 | } | |
1635 | ||
1636 | { // grow (maybe has enough capacity) | |
1637 | Devector b; get_range<Devector>(0, 0, 5, 9, b); | |
1638 | ||
1639 | b.unsafe_uninitialized_resize_front(8); | |
1640 | ||
1641 | for (int i = 0; i < 4; ++i) | |
1642 | { | |
1643 | new (b.data() + i) T(i+1); | |
1644 | } | |
1645 | ||
1646 | const int expected [] = {1, 2, 3, 4, 5, 6, 7, 8}; | |
1647 | test_equal_range(b, expected); | |
1648 | } | |
1649 | ||
1650 | { // shrink uninitialized | |
1651 | Devector c; get_range<Devector>(8, c); | |
1652 | ||
1653 | c.unsafe_uninitialized_resize_front(16); | |
1654 | c.unsafe_uninitialized_resize_front(8); | |
1655 | ||
1656 | const int expected [] = {1, 2, 3, 4, 5, 6, 7, 8}; | |
1657 | test_equal_range(c, expected ); | |
1658 | } | |
1659 | ||
1660 | if (std::is_trivially_destructible<T>::value) | |
1661 | { | |
1662 | // shrink | |
1663 | Devector d; get_range<Devector>(8, d); | |
1664 | ||
1665 | d.unsafe_uninitialized_resize_front(4); | |
1666 | ||
1667 | test_equal_range(d, {5, 6, 7, 8}); | |
1668 | } | |
1669 | } | |
1670 | ||
1671 | template <class Devector> void test_unsafe_uninitialized_resize_back() | |
1672 | { | |
1673 | typedef typename Devector::value_type T; | |
1674 | ||
1675 | { // noop | |
1676 | Devector a; get_range<Devector>(8, a); | |
1677 | a.reset_alloc_stats(); | |
1678 | ||
1679 | a.unsafe_uninitialized_resize_back(a.size()); | |
1680 | ||
1681 | test_equal_range(a, {1, 2, 3, 4, 5, 6, 7, 8}); | |
1682 | BOOST_TEST(a.get_alloc_count() == 0u); | |
1683 | } | |
1684 | ||
1685 | { // grow (maybe has enough capacity) | |
1686 | Devector b; get_range<Devector>(1, 5, 0, 0, b); | |
1687 | ||
1688 | b.unsafe_uninitialized_resize_back(8); | |
1689 | ||
1690 | for (int i = 0; i < 4; ++i) | |
1691 | { | |
1692 | new (b.data() + 4 + i) T(i+5); | |
1693 | } | |
1694 | ||
1695 | test_equal_range(b, {1, 2, 3, 4, 5, 6, 7, 8}); | |
1696 | } | |
1697 | ||
1698 | { // shrink uninitialized | |
1699 | Devector c; get_range<Devector>(8, c); | |
1700 | ||
1701 | c.unsafe_uninitialized_resize_back(16); | |
1702 | c.unsafe_uninitialized_resize_back(8); | |
1703 | ||
1704 | test_equal_range(c, {1, 2, 3, 4, 5, 6, 7, 8}); | |
1705 | } | |
1706 | ||
1707 | if (std::is_trivially_destructible<T>::value) | |
1708 | { | |
1709 | // shrink | |
1710 | Devector d; get_range<Devector>(8, d); | |
1711 | ||
1712 | d.unsafe_uninitialized_resize_back(4); | |
1713 | ||
1714 | test_equal_range(d, {1, 2, 3, 4}); | |
1715 | } | |
1716 | } | |
1717 | */ | |
1718 | ||
1719 | template <class Devector> void test_reserve_front() | |
1720 | { | |
1721 | typedef typename Devector::value_type value_type; | |
1722 | Devector a; | |
1723 | ||
1724 | a.reserve_front(100); | |
1e59de90 | 1725 | for (int i = 0; i < 100; ++i) |
20effc67 TL |
1726 | { |
1727 | a.push_front(value_type(i)); | |
1728 | } | |
1729 | ||
1730 | BOOST_TEST(a.get_alloc_count() == 1u); | |
1731 | ||
1732 | Devector b; | |
1733 | b.reserve_front(4); | |
1734 | b.reserve_front(6); | |
1735 | b.reserve_front(4); | |
1736 | b.reserve_front(8); | |
1737 | b.reserve_front(16); | |
1738 | } | |
1739 | ||
1740 | template <class Devector> void test_reserve_back() | |
1741 | { | |
1742 | Devector a; | |
1743 | typedef typename Devector::value_type value_type; | |
1744 | a.reserve_back(100); | |
1e59de90 | 1745 | for (int i = 0; i < 100; ++i) |
20effc67 TL |
1746 | { |
1747 | a.push_back(value_type(i)); | |
1748 | } | |
1749 | ||
1750 | BOOST_TEST(a.get_alloc_count() == 1u); | |
1751 | ||
1752 | Devector b; | |
1753 | b.reserve_back(4); | |
1754 | b.reserve_back(6); | |
1755 | b.reserve_back(4); | |
1756 | b.reserve_back(8); | |
1757 | b.reserve_back(16); | |
1758 | } | |
1759 | ||
1760 | template <typename Devector> | |
1761 | void test_shrink_to_fit_always() | |
1762 | { | |
1e59de90 | 1763 | typedef typename Devector::value_type value_type; |
20effc67 | 1764 | Devector a; |
1e59de90 | 1765 | a.reserve(100u); |
20effc67 | 1766 | |
1e59de90 TL |
1767 | a.push_back(value_type(1)); |
1768 | a.push_back(value_type(2)); | |
1769 | a.push_back(value_type(3)); | |
20effc67 TL |
1770 | |
1771 | a.shrink_to_fit(); | |
1772 | ||
1773 | boost::container::vector<unsigned> expected; | |
1e59de90 TL |
1774 | expected.push_back(1u); |
1775 | expected.push_back(2u); | |
1776 | expected.push_back(3u); | |
20effc67 TL |
1777 | test_equal_range(a, expected); |
1778 | ||
1779 | std::size_t exp_capacity = 3u; | |
1780 | BOOST_TEST(a.capacity() == exp_capacity); | |
1781 | } | |
1782 | ||
1783 | template <typename Devector> | |
1784 | void test_shrink_to_fit_never() | |
1785 | { | |
1786 | Devector a; | |
1787 | a.reserve(100); | |
1788 | ||
1789 | a.push_back(1); | |
1790 | a.push_back(2); | |
1791 | a.push_back(3); | |
1792 | ||
1793 | a.shrink_to_fit(); | |
1794 | ||
1795 | boost::container::vector<unsigned> expected; | |
1796 | expected.emplace_back(1); | |
1797 | expected.emplace_back(2); | |
1798 | expected.emplace_back(3); | |
1799 | test_equal_range(a, expected); | |
1800 | BOOST_TEST(a.capacity() == 100u); | |
1801 | } | |
1802 | ||
1803 | void shrink_to_fit() | |
1804 | { | |
1805 | typedef devector<unsigned> devector_u_shr; | |
1806 | typedef devector<unsigned> small_devector_u_shr; | |
1807 | test_shrink_to_fit_always<devector_u_shr>(); | |
1808 | test_shrink_to_fit_always<small_devector_u_shr>(); | |
1809 | } | |
1810 | ||
1811 | template <class Devector> void test_index_operator() | |
1812 | { | |
1813 | typedef typename Devector::value_type T; | |
1814 | ||
1815 | { // non-const [] | |
1816 | Devector a; get_range<Devector>(5, a); | |
1817 | ||
1818 | BOOST_TEST(a[0] == 1); | |
1819 | BOOST_TEST(a[4] == 5); | |
1820 | BOOST_TEST(&a[3] == &a[0] + 3); | |
1821 | ||
1822 | a[0] = T(100); | |
1823 | BOOST_TEST(a[0] == 100); | |
1824 | } | |
1825 | ||
1826 | { // const [] | |
1827 | Devector b; get_range<Devector>(5, b); | |
1828 | const Devector &a = b; | |
1829 | ||
1830 | BOOST_TEST(a[0] == 1); | |
1831 | BOOST_TEST(a[4] == 5); | |
1832 | BOOST_TEST(&a[3] == &a[0] + 3); | |
1833 | } | |
1834 | } | |
1835 | ||
1836 | template <class Devector> void test_at() | |
1837 | { | |
1838 | #ifndef BOOST_NO_EXCEPTIONS | |
1839 | typedef typename Devector::value_type T; | |
1840 | ||
1841 | { // non-const at | |
1842 | Devector a; get_range<Devector>(3, a); | |
1843 | ||
1844 | BOOST_TEST(a.at(0) == 1); | |
1845 | a.at(0) = T(100); | |
1846 | BOOST_TEST(a.at(0) == 100); | |
1847 | ||
1e59de90 | 1848 | BOOST_TEST_THROWS((void)a.at(3), out_of_range_t); |
20effc67 TL |
1849 | } |
1850 | ||
1851 | { // const at | |
1852 | Devector b; get_range<Devector>(3, b); | |
1853 | const Devector &a = b; | |
1854 | ||
1855 | BOOST_TEST(a.at(0) == 1); | |
1856 | ||
1e59de90 | 1857 | BOOST_TEST_THROWS((void)a.at(3), out_of_range_t); |
20effc67 TL |
1858 | } |
1859 | #endif //#ifndef BOOST_NO_EXCEPTIONS | |
1860 | } | |
1861 | ||
1862 | template <class Devector> void test_front() | |
1863 | { | |
1864 | typedef typename Devector::value_type T; | |
1865 | ||
1866 | { // non-const front | |
1867 | Devector a; get_range<Devector>(3, a); | |
1868 | BOOST_TEST(a.front() == 1); | |
1869 | a.front() = T(100); | |
1870 | BOOST_TEST(a.front() == 100); | |
1871 | } | |
1872 | ||
1873 | { // const front | |
1874 | Devector b; get_range<Devector>(3, b); const Devector &a = b; | |
1875 | BOOST_TEST(a.front() == 1); | |
1876 | } | |
1877 | } | |
1878 | ||
1879 | template <class Devector> void test_back() | |
1880 | { | |
1881 | typedef typename Devector::value_type T; | |
1882 | ||
1883 | { // non-const back | |
1884 | Devector a; get_range<Devector>(3, a); | |
1885 | BOOST_TEST(a.back() == 3); | |
1886 | a.back() = T(100); | |
1887 | BOOST_TEST(a.back() == 100); | |
1888 | } | |
1889 | ||
1890 | { // const back | |
1891 | Devector b; get_range<Devector>(3, b); const Devector &a = b; | |
1892 | BOOST_TEST(a.back() == 3); | |
1893 | } | |
1894 | } | |
1895 | ||
1896 | void test_data() | |
1897 | { | |
1898 | unsigned c_array[] = {1, 2, 3, 4}; | |
1899 | ||
1900 | { // non-const data | |
1901 | devector<unsigned> a(c_array, c_array + 4); | |
1902 | BOOST_TEST(a.data() == &a.front()); | |
1903 | ||
1904 | BOOST_TEST(std::memcmp(c_array, a.data(), 4 * sizeof(unsigned)) == 0); | |
1905 | ||
1906 | *(a.data()) = 100; | |
1907 | BOOST_TEST(a.front() == 100u); | |
1908 | } | |
1909 | ||
1910 | { // const data | |
1911 | const devector<unsigned> a(c_array, c_array + 4); | |
1912 | BOOST_TEST(a.data() == &a.front()); | |
1913 | ||
1914 | BOOST_TEST(std::memcmp(c_array, a.data(), 4 * sizeof(unsigned)) == 0); | |
1915 | } | |
1916 | } | |
1917 | ||
1918 | template <class Devector> void test_emplace_front(dtl::true_) | |
1919 | { | |
1920 | #ifndef BOOST_NO_EXCEPTIONS | |
1921 | typedef typename Devector::iterator iterator; | |
1922 | ||
1923 | Devector b; get_range<Devector>(4, b); | |
1924 | iterator origi_begin = b.begin(); | |
1925 | ||
1926 | test_elem_throw::on_ctor_after(1); | |
1927 | BOOST_TEST_THROWS(b.emplace_front(404), test_exception); | |
1928 | test_elem_throw::do_not_throw(); | |
1929 | ||
1930 | iterator new_begin = b.begin(); | |
1931 | ||
1932 | BOOST_TEST(origi_begin == new_begin); | |
1933 | BOOST_TEST(b.size() == 4u); | |
1934 | #endif //#ifndef BOOST_NO_EXCEPTIONS | |
1935 | } | |
1936 | ||
1937 | template <class Devector> void test_emplace_front(dtl::false_) | |
1938 | { | |
1939 | } | |
1940 | ||
1941 | template <class Devector> void test_emplace_front() | |
1942 | { | |
1943 | typedef typename Devector::value_type T; | |
1944 | ||
1945 | { | |
1946 | Devector a; | |
1947 | ||
1948 | a.emplace_front(3); | |
1949 | a.emplace_front(2); | |
1950 | a.emplace_front(1); | |
1951 | ||
1952 | boost::container::vector<int> expected; get_range<boost::container::vector<int> >(3, expected); | |
1953 | ||
1954 | test_equal_range(a, expected); | |
1955 | } | |
1956 | ||
1957 | test_emplace_front<Devector> | |
1958 | (dtl::bool_<!boost::move_detail::is_nothrow_default_constructible<T>::value>()); | |
1959 | } | |
1960 | ||
1961 | template <class Devector> void test_push_front() | |
1962 | { | |
1963 | typedef typename Devector::value_type T; | |
1964 | { | |
1965 | boost::container::vector<int> expected; get_range<boost::container::vector<int> >(16, expected); | |
1966 | std::reverse(expected.begin(), expected.end()); | |
1967 | Devector a; | |
1968 | ||
1969 | for (int i = 1; i <= 16; ++i) | |
1970 | { | |
1971 | T elem(i); | |
1972 | a.push_front(elem); | |
1973 | } | |
1974 | ||
1975 | test_equal_range(a, expected); | |
1976 | } | |
1977 | ||
1978 | #ifndef BOOST_NO_EXCEPTIONS | |
1979 | typedef typename Devector::iterator iterator; | |
1980 | if (! boost::move_detail::is_nothrow_copy_constructible<T>::value) | |
1981 | { | |
1982 | Devector b; get_range<Devector>(4, b); | |
1983 | iterator origi_begin = b.begin(); | |
1984 | ||
1985 | const T elem(404); | |
1986 | ||
1987 | test_elem_throw::on_copy_after(1); | |
1988 | BOOST_TEST_THROWS(b.push_front(elem), test_exception); | |
1989 | test_elem_throw::do_not_throw(); | |
1990 | ||
1991 | iterator new_begin = b.begin(); | |
1992 | ||
1993 | BOOST_TEST(origi_begin == new_begin); | |
1994 | BOOST_TEST(b.size() == 4u); | |
1995 | } | |
1996 | ||
1997 | // test when tmp is already inserted | |
1998 | { | |
1999 | Devector c; get_range<Devector>(4, c); | |
2000 | const T& tmp = *(c.begin() + 1); | |
2001 | c.push_front(tmp); | |
2002 | const int expected[] = {2, 1, 2, 3, 4}; | |
2003 | test_equal_range(c, expected); | |
2004 | } | |
2005 | #endif //#ifndef BOOST_NO_EXCEPTIONS | |
2006 | } | |
2007 | ||
2008 | template <class Devector> void test_push_front_rvalue_throwing(dtl::true_) | |
2009 | { | |
2010 | #ifndef BOOST_NO_EXCEPTIONS | |
2011 | typedef typename Devector::value_type T; | |
2012 | typedef typename Devector::iterator iterator; | |
2013 | ||
2014 | Devector b; get_range<Devector>(4, b); | |
2015 | iterator origi_begin = b.begin(); | |
2016 | ||
2017 | test_elem_throw::on_move_after(1); | |
2018 | BOOST_TEST_THROWS(b.push_front(T(404)), test_exception); | |
2019 | test_elem_throw::do_not_throw(); | |
2020 | ||
2021 | iterator new_begin = b.begin(); | |
2022 | ||
2023 | BOOST_TEST(origi_begin == new_begin); | |
2024 | BOOST_TEST(b.size() == 4u); | |
2025 | #endif //#ifndef BOOST_NO_EXCEPTIONS | |
2026 | } | |
2027 | ||
2028 | template <class Devector> void test_push_front_rvalue_throwing(dtl::false_) | |
2029 | {} | |
2030 | ||
2031 | template <class Devector> void test_push_front_rvalue() | |
2032 | { | |
2033 | typedef typename Devector::value_type T; | |
2034 | ||
2035 | { | |
2036 | boost::container::vector<int> expected; get_range<boost::container::vector<int> >(16, expected); | |
2037 | Devector a; | |
2038 | ||
2039 | for (int i = 16; i > 0; --i) | |
2040 | { | |
2041 | T elem(i); | |
2042 | a.push_front(boost::move(elem)); | |
2043 | } | |
2044 | ||
2045 | test_equal_range(a, expected); | |
2046 | } | |
2047 | ||
2048 | test_push_front_rvalue_throwing<Devector>(dtl::bool_<! boost::is_nothrow_move_constructible<T>::value>()); | |
2049 | } | |
2050 | ||
2051 | template <class Devector> void test_pop_front() | |
2052 | { | |
2053 | { | |
2054 | Devector a; | |
2055 | a.emplace_front(1); | |
2056 | a.pop_front(); | |
2057 | BOOST_TEST(a.empty()); | |
2058 | } | |
2059 | ||
2060 | { | |
2061 | Devector b; | |
2062 | ||
2063 | b.emplace_back(2); | |
2064 | b.pop_front(); | |
2065 | BOOST_TEST(b.empty()); | |
2066 | ||
2067 | b.emplace_front(3); | |
2068 | b.pop_front(); | |
2069 | BOOST_TEST(b.empty()); | |
2070 | } | |
2071 | ||
2072 | { | |
2073 | Devector c; get_range<Devector>(20, c); | |
2074 | for (int i = 0; i < 20; ++i) | |
2075 | { | |
2076 | BOOST_TEST(!c.empty()); | |
2077 | c.pop_front(); | |
2078 | } | |
2079 | BOOST_TEST(c.empty()); | |
2080 | } | |
2081 | } | |
2082 | ||
2083 | template <class Devector> void test_emplace_back_throwing(dtl::true_) | |
2084 | { | |
2085 | #ifndef BOOST_NO_EXCEPTIONS | |
2086 | typedef typename Devector::iterator iterator; | |
2087 | ||
2088 | Devector b; get_range<Devector>(4, b); | |
2089 | iterator origi_begin = b.begin(); | |
2090 | ||
2091 | test_elem_throw::on_ctor_after(1); | |
2092 | BOOST_TEST_THROWS(b.emplace_back(404), test_exception); | |
2093 | test_elem_throw::do_not_throw(); | |
2094 | ||
2095 | iterator new_begin = b.begin(); | |
2096 | ||
2097 | BOOST_TEST(origi_begin == new_begin); | |
2098 | BOOST_TEST(b.size() == 4u); | |
2099 | #endif //#ifndef BOOST_NO_EXCEPTIONS | |
2100 | } | |
2101 | ||
2102 | template <class Devector> void test_emplace_back_throwing(dtl::false_) | |
2103 | {} | |
2104 | ||
2105 | template <class Devector> void test_emplace_back() | |
2106 | { | |
2107 | typedef typename Devector::value_type T; | |
2108 | ||
2109 | { | |
2110 | Devector a; | |
2111 | ||
2112 | a.emplace_back(1); | |
2113 | a.emplace_back(2); | |
2114 | a.emplace_back(3); | |
2115 | ||
2116 | boost::container::vector<int> expected; get_range<boost::container::vector<int> >(3, expected); | |
2117 | ||
2118 | test_equal_range<Devector>(a, expected); | |
2119 | } | |
2120 | ||
2121 | test_emplace_back_throwing<Devector> | |
2122 | (dtl::bool_<! boost::move_detail::is_nothrow_default_constructible<T>::value>()); | |
2123 | } | |
2124 | ||
2125 | template <class Devector> void test_push_back_throwing(dtl::true_) | |
2126 | { | |
2127 | #ifndef BOOST_NO_EXCEPTIONS | |
2128 | typedef typename Devector::value_type T; | |
2129 | typedef typename Devector::iterator iterator; | |
2130 | ||
2131 | Devector b; get_range<Devector>(4, b); | |
2132 | iterator origi_begin = b.begin(); | |
2133 | ||
2134 | const T elem(404); | |
2135 | ||
2136 | test_elem_throw::on_copy_after(1); | |
2137 | BOOST_TEST_THROWS(b.push_back(elem), test_exception); | |
2138 | test_elem_throw::do_not_throw(); | |
2139 | ||
2140 | iterator new_begin = b.begin(); | |
2141 | ||
2142 | BOOST_TEST(origi_begin == new_begin); | |
2143 | BOOST_TEST(b.size() == 4u); | |
2144 | #endif //#ifndef BOOST_NO_EXCEPTIONS | |
2145 | } | |
2146 | ||
2147 | template <class Devector> void test_push_back_throwing(dtl::false_) | |
2148 | {} | |
2149 | ||
2150 | template <class Devector> void test_push_back() | |
2151 | { | |
2152 | typedef typename Devector::value_type T; | |
2153 | { | |
2154 | boost::container::vector<int> expected; get_range<boost::container::vector<int> >(16, expected); | |
2155 | Devector a; | |
2156 | ||
2157 | for (int i = 1; i <= 16; ++i) | |
2158 | { | |
2159 | T elem(i); | |
2160 | a.push_back(elem); | |
2161 | } | |
2162 | ||
2163 | test_equal_range(a, expected); | |
2164 | } | |
2165 | ||
2166 | test_push_back_throwing<Devector>(dtl::bool_<! boost::move_detail::is_nothrow_copy_constructible<T>::value>()); | |
2167 | ||
2168 | // test when tmp is already inserted | |
2169 | { | |
2170 | Devector c; get_range<Devector>(4, c); | |
2171 | const T& tmp = *(c.begin() + 1); | |
2172 | c.push_back(tmp); | |
2173 | const int expected[] = {1, 2, 3, 4, 2}; | |
2174 | test_equal_range(c, expected); | |
2175 | } | |
2176 | } | |
2177 | ||
2178 | template <class Devector> void test_push_back_rvalue_throwing(dtl::true_) | |
2179 | { | |
2180 | #ifndef BOOST_NO_EXCEPTIONS | |
2181 | typedef typename Devector::value_type T; | |
2182 | typedef typename Devector::iterator iterator; | |
2183 | ||
2184 | Devector b; get_range<Devector>(4, b); | |
2185 | iterator origi_begin = b.begin(); | |
2186 | ||
2187 | test_elem_throw::on_move_after(1); | |
2188 | BOOST_TEST_THROWS(b.push_back(T(404)), test_exception); | |
2189 | test_elem_throw::do_not_throw(); | |
2190 | ||
2191 | iterator new_begin = b.begin(); | |
2192 | ||
2193 | BOOST_TEST(origi_begin == new_begin); | |
2194 | BOOST_TEST(b.size() == 4u); | |
2195 | #endif //#ifndef BOOST_NO_EXCEPTIONS | |
2196 | } | |
2197 | ||
2198 | template <class Devector> void test_push_back_rvalue_throwing(dtl::false_) | |
2199 | {} | |
2200 | ||
2201 | template <class Devector> void test_push_back_rvalue() | |
2202 | { | |
2203 | typedef typename Devector::value_type T; | |
2204 | ||
2205 | { | |
2206 | boost::container::vector<int> expected; get_range<boost::container::vector<int> >(16, expected); | |
2207 | Devector a; | |
2208 | ||
2209 | for (int i = 1; i <= 16; ++i) | |
2210 | { | |
2211 | T elem(i); | |
2212 | a.push_back(boost::move(elem)); | |
2213 | } | |
2214 | ||
2215 | test_equal_range(a, expected); | |
2216 | } | |
2217 | ||
2218 | test_push_back_rvalue_throwing<Devector>(dtl::bool_<! boost::is_nothrow_move_constructible<T>::value>()); | |
2219 | } | |
2220 | ||
2221 | /* | |
2222 | template <class Devector> void test_unsafe_push_front() | |
2223 | { | |
2224 | typedef typename Devector::value_type T; | |
2225 | typedef typename Devector::iterator iterator; | |
2226 | ||
2227 | { | |
2228 | boost::container::vector<int> expected; get_range<boost::container::vector<int> >(16, expected); | |
2229 | std::reverse(expected.begin(), expected.end()); | |
2230 | Devector a; | |
2231 | a.reserve_front(16); | |
2232 | ||
2233 | for (std::size_t i = 1; i <= 16; ++i) | |
2234 | { | |
2235 | T elem(i); | |
2236 | a.unsafe_push_front(elem); | |
2237 | } | |
2238 | ||
2239 | test_equal_range(a, expected); | |
2240 | } | |
2241 | ||
2242 | #ifndef BOOST_NO_EXCEPTIONS | |
2243 | if (! boost::move_detail::is_nothrow_copy_constructible<T>::value) | |
2244 | { | |
2245 | Devector b; get_range<Devector>(4, b); | |
2246 | b.reserve_front(5); | |
2247 | iterator origi_begin = b.begin(); | |
2248 | ||
2249 | const T elem(404); | |
2250 | ||
2251 | test_elem_throw::on_copy_after(1); | |
2252 | BOOST_TEST_THROWS(b.unsafe_push_front(elem), test_exception); | |
2253 | test_elem_throw::do_not_throw(); | |
2254 | ||
2255 | iterator new_begin = b.begin(); | |
2256 | ||
2257 | BOOST_TEST(origi_begin == new_begin); | |
2258 | BOOST_TEST(b.size() == 4u); | |
2259 | } | |
2260 | #endif //#ifndef BOOST_NO_EXCEPTIONS | |
2261 | } | |
2262 | ||
2263 | template <class Devector> void test_unsafe_push_front_rvalue() | |
2264 | { | |
2265 | typedef typename Devector::value_type T; | |
2266 | ||
2267 | { | |
2268 | boost::container::vector<int> expected; get_range<boost::container::vector<int> >(16, expected); | |
2269 | std::reverse(expected.begin(), expected.end()); | |
2270 | Devector a; | |
2271 | a.reserve_front(16); | |
2272 | ||
2273 | for (std::size_t i = 1; i <= 16; ++i) | |
2274 | { | |
2275 | T elem(i); | |
2276 | a.unsafe_push_front(boost::move(elem)); | |
2277 | } | |
2278 | ||
2279 | test_equal_range(a, expected); | |
2280 | } | |
2281 | } | |
2282 | */ | |
2283 | /* | |
2284 | template <class Devector> void test_unsafe_push_back() | |
2285 | { | |
2286 | typedef typename Devector::value_type T; | |
2287 | typedef typename Devector::iterator iterator; | |
2288 | ||
2289 | { | |
2290 | boost::container::vector<int> expected; get_range<boost::container::vector<int> >(16, expected); | |
2291 | Devector a; | |
2292 | a.reserve(16); | |
2293 | ||
2294 | for (std::size_t i = 1; i <= 16; ++i) | |
2295 | { | |
2296 | T elem(i); | |
2297 | a.unsafe_push_back(elem); | |
2298 | } | |
2299 | ||
2300 | test_equal_range(a, expected); | |
2301 | } | |
2302 | ||
2303 | #ifndef BOOST_NO_EXCEPTIONS | |
2304 | if (! boost::move_detail::is_nothrow_copy_constructible<T>::value) | |
2305 | { | |
2306 | Devector b; get_range<Devector>(4, b); | |
2307 | b.reserve(5); | |
2308 | iterator origi_begin = b.begin(); | |
2309 | ||
2310 | const T elem(404); | |
2311 | ||
2312 | test_elem_throw::on_copy_after(1); | |
2313 | BOOST_TEST_THROWS(b.unsafe_push_back(elem), test_exception); | |
2314 | test_elem_throw::do_not_throw(); | |
2315 | ||
2316 | iterator new_begin = b.begin(); | |
2317 | ||
2318 | BOOST_TEST(origi_begin == new_begin); | |
2319 | BOOST_TEST(b.size() == 4u); | |
2320 | } | |
2321 | #endif | |
2322 | } | |
2323 | ||
2324 | template <class Devector> void test_unsafe_push_back_rvalue() | |
2325 | { | |
2326 | typedef typename Devector::value_type T; | |
2327 | ||
2328 | { | |
2329 | boost::container::vector<int> expected; get_range<boost::container::vector<int> >(16, expected); | |
2330 | Devector a; | |
2331 | a.reserve(16); | |
2332 | ||
2333 | for (std::size_t i = 1; i <= 16; ++i) | |
2334 | { | |
2335 | T elem(i); | |
2336 | a.unsafe_push_back(boost::move(elem)); | |
2337 | } | |
2338 | ||
2339 | test_equal_range(a, expected); | |
2340 | } | |
2341 | } | |
2342 | */ | |
2343 | template <class Devector> void test_pop_back() | |
2344 | { | |
2345 | { | |
2346 | Devector a; | |
2347 | a.emplace_back(1); | |
2348 | a.pop_back(); | |
2349 | BOOST_TEST(a.empty()); | |
2350 | } | |
2351 | ||
2352 | { | |
2353 | Devector b; | |
2354 | ||
2355 | b.emplace_front(2); | |
2356 | b.pop_back(); | |
2357 | BOOST_TEST(b.empty()); | |
2358 | ||
2359 | b.emplace_back(3); | |
2360 | b.pop_back(); | |
2361 | BOOST_TEST(b.empty()); | |
2362 | } | |
2363 | ||
2364 | { | |
2365 | Devector c; get_range<Devector>(20, c); | |
2366 | for (int i = 0; i < 20; ++i) | |
2367 | { | |
2368 | BOOST_TEST(!c.empty()); | |
2369 | c.pop_back(); | |
2370 | } | |
2371 | BOOST_TEST(c.empty()); | |
2372 | } | |
2373 | } | |
2374 | ||
2375 | template <class Devector> void test_emplace_throwing(dtl::true_) | |
2376 | { | |
2377 | #ifndef BOOST_NO_EXCEPTIONS | |
2378 | typedef typename Devector::iterator iterator; | |
2379 | ||
2380 | Devector j; get_range<Devector>(4, j); | |
2381 | iterator origi_begin = j.begin(); | |
2382 | ||
2383 | test_elem_throw::on_ctor_after(1); | |
2384 | BOOST_TEST_THROWS(j.emplace(j.begin() + 2, 404), test_exception); | |
2385 | test_elem_throw::do_not_throw(); | |
2386 | ||
2387 | const int expected[] = {1, 2, 3, 4}; | |
2388 | test_equal_range(j, expected); | |
2389 | BOOST_TEST(origi_begin == j.begin()); | |
2390 | #endif | |
2391 | } | |
2392 | ||
2393 | template <class Devector> void test_emplace_throwing(dtl::false_) | |
2394 | {} | |
2395 | ||
2396 | ||
2397 | template <class Devector> void test_emplace() | |
2398 | { | |
2399 | typedef typename Devector::iterator iterator; | |
2400 | ||
2401 | { | |
2402 | Devector a; get_range<Devector>(16, a); | |
2403 | typename Devector::iterator it = a.emplace(a.begin(), 123); | |
2404 | const int expected[] = {123, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; | |
2405 | test_equal_range(a, expected); | |
2406 | BOOST_TEST(*it == 123); | |
2407 | } | |
2408 | ||
2409 | { | |
2410 | Devector b; get_range<Devector>(16, b); | |
2411 | typename Devector::iterator it = b.emplace(b.end(), 123); | |
2412 | const int expected [] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 123}; | |
2413 | test_equal_range(b, expected); | |
2414 | BOOST_TEST(*it == 123); | |
2415 | } | |
2416 | ||
2417 | { | |
2418 | Devector c; get_range<Devector>(16, c); | |
2419 | c.pop_front(); | |
2420 | typename Devector::iterator it = c.emplace(c.begin(), 123); | |
2421 | const int expected [] = {123, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; | |
2422 | test_equal_range(c, expected); | |
2423 | BOOST_TEST(*it == 123); | |
2424 | } | |
2425 | ||
2426 | { | |
2427 | Devector d; get_range<Devector>(16, d); | |
2428 | d.pop_back(); | |
2429 | typename Devector::iterator it = d.emplace(d.end(), 123); | |
2430 | const int expected [] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 123}; | |
2431 | test_equal_range(d, expected); | |
2432 | BOOST_TEST(*it == 123); | |
2433 | } | |
2434 | ||
2435 | { | |
2436 | Devector e; get_range<Devector>(16, e); | |
2437 | typename Devector::iterator it = e.emplace(e.begin() + 5, 123); | |
2438 | const int expected [] = {1, 2, 3, 4, 5, 123, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; | |
2439 | test_equal_range(e, expected); | |
2440 | BOOST_TEST(*it == 123); | |
2441 | } | |
2442 | ||
2443 | { | |
2444 | Devector f; get_range<Devector>(16, f); | |
2445 | f.pop_front(); | |
2446 | f.pop_back(); | |
2447 | iterator valid = f.begin() + 1; | |
2448 | typename Devector::iterator it = f.emplace(f.begin() + 1, 123); | |
2449 | const int expected [] = {2, 123, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; | |
2450 | test_equal_range(f, expected); | |
2451 | BOOST_TEST(*it == 123); | |
2452 | BOOST_TEST(*valid == 3); | |
2453 | } | |
2454 | ||
2455 | { | |
2456 | Devector g; get_range<Devector>(16, g); | |
2457 | g.pop_front(); | |
2458 | g.pop_back(); | |
2459 | iterator valid = g.end() - 2; | |
2460 | typename Devector::iterator it = g.emplace(g.end() - 1, 123); | |
2461 | const int expected[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 123, 15}; | |
2462 | test_equal_range(g, expected); | |
2463 | BOOST_TEST(*it == 123); | |
2464 | BOOST_TEST(*valid == 14); | |
2465 | } | |
2466 | ||
2467 | { | |
2468 | Devector h; get_range<Devector>(16, h); | |
2469 | h.pop_front(); | |
2470 | h.pop_back(); | |
2471 | iterator valid = h.begin() + 7; | |
2472 | typename Devector::iterator it = h.emplace(h.begin() + 7, 123); | |
2473 | const int expected[] = {2, 3, 4, 5, 6, 7, 8, 123, 9, 10, 11, 12, 13, 14, 15}; | |
2474 | test_equal_range(h, expected); | |
2475 | BOOST_TEST(*it == 123); | |
2476 | BOOST_TEST(*valid == 9); | |
2477 | } | |
2478 | ||
2479 | { | |
2480 | Devector i; | |
2481 | i.emplace(i.begin(), 1); | |
2482 | i.emplace(i.end(), 10); | |
2483 | for (int j = 2; j < 10; ++j) | |
2484 | { | |
2485 | i.emplace(i.begin() + (j-1), j); | |
2486 | } | |
2487 | const int expected[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; | |
2488 | test_equal_range(i, expected); | |
2489 | } | |
2490 | ||
2491 | typedef typename Devector::value_type T; | |
2492 | test_emplace_throwing<Devector> | |
2493 | (dtl::bool_<! boost::move_detail::is_nothrow_default_constructible<T>::value>()); | |
2494 | } | |
2495 | ||
2496 | template <class Devector> void test_insert_throwing(dtl::true_) | |
2497 | { | |
2498 | #ifndef BOOST_NO_EXCEPTIONS | |
2499 | typedef typename Devector::value_type T; | |
2500 | typedef typename Devector::iterator iterator; | |
2501 | ||
2502 | T test_elem(123); | |
2503 | ||
2504 | Devector j; get_range<Devector>(4, j); | |
2505 | iterator origi_begin = j.begin(); | |
2506 | ||
2507 | test_elem_throw::on_copy_after(1); | |
2508 | BOOST_TEST_THROWS(j.insert(j.begin() + 2, test_elem), test_exception); | |
2509 | test_elem_throw::do_not_throw(); | |
2510 | ||
2511 | const int expected[] = {1, 2, 3, 4}; | |
2512 | test_equal_range(j, expected); | |
2513 | BOOST_TEST(origi_begin == j.begin()); | |
2514 | #endif //#ifndef BOOST_NO_EXCEPTIONS | |
2515 | } | |
2516 | ||
2517 | template <class Devector> void test_insert_throwing(dtl::false_) | |
2518 | {} | |
2519 | ||
2520 | template <class Devector> void test_insert() | |
2521 | { | |
2522 | typedef typename Devector::value_type T; | |
2523 | typedef typename Devector::iterator iterator; | |
2524 | ||
2525 | T test_elem(123); | |
2526 | ||
2527 | { | |
2528 | Devector a; get_range<Devector>(16, a); | |
2529 | typename Devector::iterator it = a.insert(a.begin(), test_elem); | |
2530 | const int expected[] = {123, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; | |
2531 | test_equal_range(a, expected); | |
2532 | BOOST_TEST(*it == 123); | |
2533 | } | |
2534 | ||
2535 | { | |
2536 | Devector b; get_range<Devector>(16, b); | |
2537 | typename Devector::iterator it = b.insert(b.end(), test_elem); | |
2538 | const int expected[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 123}; | |
2539 | test_equal_range(b, expected); | |
2540 | BOOST_TEST(*it == 123); | |
2541 | } | |
2542 | ||
2543 | { | |
2544 | Devector c; get_range<Devector>(16, c); | |
2545 | c.pop_front(); | |
2546 | typename Devector::iterator it = c.insert(c.begin(), test_elem); | |
2547 | const int expected[] = {123, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; | |
2548 | test_equal_range(c, expected); | |
2549 | BOOST_TEST(*it == 123); | |
2550 | } | |
2551 | ||
2552 | { | |
2553 | Devector d; get_range<Devector>(16, d); | |
2554 | d.pop_back(); | |
2555 | typename Devector::iterator it = d.insert(d.end(), test_elem); | |
2556 | const int expected[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 123}; | |
2557 | test_equal_range(d, expected); | |
2558 | BOOST_TEST(*it == 123); | |
2559 | } | |
2560 | ||
2561 | { | |
2562 | Devector e; get_range<Devector>(16, e); | |
2563 | typename Devector::iterator it = e.insert(e.begin() + 5, test_elem); | |
2564 | const int expected[] = {1, 2, 3, 4, 5, 123, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; | |
2565 | test_equal_range(e, expected); | |
2566 | BOOST_TEST(*it == 123); | |
2567 | } | |
2568 | ||
2569 | { | |
2570 | Devector f; get_range<Devector>(16, f); | |
2571 | f.pop_front(); | |
2572 | f.pop_back(); | |
2573 | iterator valid = f.begin() + 1; | |
2574 | typename Devector::iterator it = f.insert(f.begin() + 1, test_elem); | |
2575 | const int expected[] = {2, 123, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; | |
2576 | test_equal_range(f, expected); | |
2577 | BOOST_TEST(*it == 123); | |
2578 | BOOST_TEST(*valid == 3); | |
2579 | } | |
2580 | ||
2581 | { | |
2582 | Devector g; get_range<Devector>(16, g); | |
2583 | g.pop_front(); | |
2584 | g.pop_back(); | |
2585 | iterator valid = g.end() - 2; | |
2586 | typename Devector::iterator it = g.insert(g.end() - 1, test_elem); | |
2587 | const int expected[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 123, 15}; | |
2588 | test_equal_range(g, expected); | |
2589 | BOOST_TEST(*it == 123); | |
2590 | BOOST_TEST(*valid == 14); | |
2591 | } | |
2592 | ||
2593 | { | |
2594 | Devector h; get_range<Devector>(16, h); | |
2595 | h.pop_front(); | |
2596 | h.pop_back(); | |
2597 | iterator valid = h.begin() + 7; | |
2598 | typename Devector::iterator it = h.insert(h.begin() + 7, test_elem); | |
2599 | const int expected[] = {2, 3, 4, 5, 6, 7, 8, 123, 9, 10, 11, 12, 13, 14, 15}; | |
2600 | test_equal_range(h, expected); | |
2601 | BOOST_TEST(*it == 123); | |
2602 | BOOST_TEST(*valid == 9); | |
2603 | } | |
2604 | ||
2605 | { | |
2606 | Devector i; | |
2607 | i.insert(i.begin(), T(1)); | |
2608 | i.insert(i.end(), T(10)); | |
2609 | for (int j = 2; j < 10; ++j) | |
2610 | { | |
2611 | i.insert(i.begin() + (j-1), T(j)); | |
2612 | } | |
2613 | const int expected[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; | |
2614 | test_equal_range(i, expected); | |
2615 | } | |
2616 | ||
2617 | test_insert_throwing<Devector> | |
2618 | (dtl::bool_<! boost::move_detail::is_nothrow_copy_constructible<T>::value>()); | |
2619 | ||
2620 | // test when tmp is already inserted and there's free capacity | |
2621 | { | |
2622 | Devector c; get_range<Devector>(6, c); | |
2623 | c.pop_back(); | |
2624 | const T& tmp = *(c.begin() + 2); | |
2625 | c.insert(c.begin() + 1, tmp); | |
2626 | const int expected[] = {1, 3, 2, 3, 4, 5}; | |
2627 | test_equal_range(c, expected); | |
2628 | } | |
2629 | ||
2630 | // test when tmp is already inserted and maybe there's no free capacity | |
2631 | { | |
2632 | Devector c; get_range<Devector>(6, c); | |
2633 | const T& tmp = *(c.begin() + 2); | |
2634 | c.insert(c.begin() + 1, tmp); | |
2635 | const int expected[] = {1, 3, 2, 3, 4, 5, 6}; | |
2636 | test_equal_range(c, expected); | |
2637 | } | |
2638 | } | |
2639 | ||
2640 | template <class Devector> void test_insert_rvalue_throwing(dtl::true_) | |
2641 | { | |
2642 | #ifndef BOOST_NO_EXCEPTIONS | |
2643 | typedef typename Devector::value_type T; | |
2644 | typedef typename Devector::iterator iterator; | |
2645 | ||
2646 | Devector j; get_range<Devector>(4, j); | |
2647 | iterator origi_begin = j.begin(); | |
2648 | ||
2649 | test_elem_throw::on_ctor_after(1); | |
2650 | BOOST_TEST_THROWS(j.insert(j.begin() + 2, T(404)), test_exception); | |
2651 | test_elem_throw::do_not_throw(); | |
2652 | ||
2653 | const int expected[] = {1, 2, 3, 4}; | |
2654 | test_equal_range(j, expected); | |
2655 | BOOST_TEST(origi_begin == j.begin()); | |
2656 | #endif //#ifndef BOOST_NO_EXCEPTIONS | |
2657 | } | |
2658 | ||
2659 | template <class Devector> void test_insert_rvalue_throwing(dtl::false_) | |
2660 | {} | |
2661 | ||
2662 | ||
2663 | template <class Devector> void test_insert_rvalue() | |
2664 | { | |
2665 | typedef typename Devector::value_type T; | |
2666 | typedef typename Devector::iterator iterator; | |
2667 | ||
2668 | { | |
2669 | Devector a; get_range<Devector>(16, a); | |
2670 | typename Devector::iterator it = a.insert(a.begin(), T(123)); | |
2671 | const int expected[] = {123, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; | |
2672 | test_equal_range(a, expected); | |
2673 | BOOST_TEST(*it == 123); | |
2674 | } | |
2675 | ||
2676 | { | |
2677 | Devector b; get_range<Devector>(16, b); | |
2678 | typename Devector::iterator it = b.insert(b.end(), T(123)); | |
2679 | const int expected[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 123}; | |
2680 | test_equal_range(b, expected); | |
2681 | BOOST_TEST(*it == 123); | |
2682 | } | |
2683 | ||
2684 | { | |
2685 | Devector c; get_range<Devector>(16, c); | |
2686 | c.pop_front(); | |
2687 | typename Devector::iterator it = c.insert(c.begin(), T(123)); | |
2688 | const int expected[] = {123, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; | |
2689 | test_equal_range(c, expected); | |
2690 | BOOST_TEST(*it == 123); | |
2691 | } | |
2692 | ||
2693 | { | |
2694 | Devector d; get_range<Devector>(16, d); | |
2695 | d.pop_back(); | |
2696 | typename Devector::iterator it = d.insert(d.end(), T(123)); | |
2697 | const int expected[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 123}; | |
2698 | test_equal_range(d, expected); | |
2699 | BOOST_TEST(*it == 123); | |
2700 | } | |
2701 | ||
2702 | { | |
2703 | Devector e; get_range<Devector>(16, e); | |
2704 | typename Devector::iterator it = e.insert(e.begin() + 5, T(123)); | |
2705 | const int expected[] = {1, 2, 3, 4, 5, 123, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; | |
2706 | test_equal_range(e, expected); | |
2707 | BOOST_TEST(*it == 123); | |
2708 | } | |
2709 | ||
2710 | { | |
2711 | Devector f; get_range<Devector>(16, f); | |
2712 | f.pop_front(); | |
2713 | f.pop_back(); | |
2714 | iterator valid = f.begin() + 1; | |
2715 | typename Devector::iterator it = f.insert(f.begin() + 1, T(123)); | |
2716 | const int expected[] = {2, 123, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; | |
2717 | test_equal_range(f, expected); | |
2718 | BOOST_TEST(*it == 123); | |
2719 | BOOST_TEST(*valid == 3); | |
2720 | } | |
2721 | ||
2722 | { | |
2723 | Devector g; get_range<Devector>(16, g); | |
2724 | g.pop_front(); | |
2725 | g.pop_back(); | |
2726 | iterator valid = g.end() - 2; | |
2727 | typename Devector::iterator it = g.insert(g.end() - 1, T(123)); | |
2728 | const int expected[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 123, 15}; | |
2729 | test_equal_range(g, expected); | |
2730 | BOOST_TEST(*it == 123); | |
2731 | BOOST_TEST(*valid == 14); | |
2732 | } | |
2733 | ||
2734 | { | |
2735 | Devector h; get_range<Devector>(16, h); | |
2736 | h.pop_front(); | |
2737 | h.pop_back(); | |
2738 | iterator valid = h.begin() + 7; | |
2739 | typename Devector::iterator it = h.insert(h.begin() + 7, T(123)); | |
2740 | const int expected[] = {2, 3, 4, 5, 6, 7, 8, 123, 9, 10, 11, 12, 13, 14, 15}; | |
2741 | test_equal_range(h, expected); | |
2742 | BOOST_TEST(*it == 123); | |
2743 | BOOST_TEST(*valid == 9); | |
2744 | } | |
2745 | ||
2746 | { | |
2747 | Devector i; | |
2748 | i.insert(i.begin(), T(1)); | |
2749 | i.insert(i.end(), T(10)); | |
2750 | for (int j = 2; j < 10; ++j) | |
2751 | { | |
2752 | i.insert(i.begin() + (j-1), T(j)); | |
2753 | } | |
2754 | const int expected[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; | |
2755 | test_equal_range(i, expected); | |
2756 | } | |
2757 | ||
2758 | test_insert_rvalue_throwing<Devector> | |
2759 | (dtl::bool_<! boost::move_detail::is_nothrow_default_constructible<T>::value>()); | |
2760 | } | |
2761 | ||
2762 | template <class Devector> void test_insert_n_throwing(dtl::true_) | |
2763 | { | |
2764 | #ifndef BOOST_NO_EXCEPTIONS | |
2765 | typedef typename Devector::value_type T; | |
2766 | // insert at begin | |
2767 | { | |
2768 | Devector j; get_range<Devector>(4, j); | |
2769 | ||
2770 | const T x(404); | |
2771 | ||
2772 | test_elem_throw::on_copy_after(3); | |
2773 | BOOST_TEST_THROWS(j.insert(j.begin(), 4, x), test_exception); | |
2774 | test_elem_throw::do_not_throw(); | |
2775 | } | |
2776 | ||
2777 | // insert at end | |
2778 | { | |
2779 | Devector k; get_range<Devector>(4, k); | |
2780 | ||
2781 | const T x(404); | |
2782 | ||
2783 | test_elem_throw::on_copy_after(3); | |
2784 | BOOST_TEST_THROWS(k.insert(k.end(), 4, x), test_exception); | |
2785 | test_elem_throw::do_not_throw(); | |
2786 | } | |
2787 | #endif //#ifndef BOOST_NO_EXCEPTIONS | |
2788 | } | |
2789 | ||
2790 | template <class Devector> void test_insert_n_throwing(dtl::false_) | |
2791 | {} | |
2792 | ||
2793 | template <class Devector> void test_insert_n() | |
2794 | { | |
2795 | typedef typename Devector::value_type T; | |
2796 | typedef typename Devector::iterator iterator; | |
2797 | ||
2798 | { | |
2799 | Devector a; | |
2800 | const T x(123); | |
2801 | iterator ret = a.insert(a.end(), 5, x); | |
2802 | const int expected[] = {123, 123, 123, 123, 123}; | |
2803 | test_equal_range(a, expected); | |
2804 | BOOST_TEST(ret == a.begin()); | |
2805 | } | |
2806 | ||
2807 | { | |
2808 | Devector b; get_range<Devector>(8, b); | |
2809 | const T x(9); | |
2810 | iterator ret = b.insert(b.begin(), 3, x); | |
2811 | const int expected[] = {9, 9, 9, 1, 2, 3, 4, 5, 6, 7, 8}; | |
2812 | test_equal_range(b, expected); | |
2813 | BOOST_TEST(ret == b.begin()); | |
2814 | } | |
2815 | ||
2816 | { | |
2817 | Devector c; get_range<Devector>(8, c); | |
2818 | const T x(9); | |
2819 | iterator ret = c.insert(c.end(), 3, x); | |
2820 | const int expected[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 9}; | |
2821 | test_equal_range(c, expected); | |
2822 | BOOST_TEST(ret == c.begin() + 8); | |
2823 | } | |
2824 | ||
2825 | { | |
2826 | Devector d; get_range<Devector>(8, d); | |
2827 | ||
2828 | d.pop_front(); | |
2829 | d.pop_front(); | |
2830 | d.pop_front(); | |
2831 | ||
2832 | const T x(9); | |
2833 | iterator origi_end = d.end(); | |
2834 | iterator ret = d.insert(d.begin(), 3, x); | |
2835 | ||
2836 | const int expected[] = {9, 9, 9, 4, 5, 6, 7, 8}; | |
2837 | test_equal_range(d, expected); | |
2838 | BOOST_TEST(origi_end == d.end()); | |
2839 | BOOST_TEST(ret == d.begin()); | |
2840 | } | |
2841 | ||
2842 | { | |
2843 | Devector e; get_range<Devector>(8, e); | |
2844 | ||
2845 | e.pop_back(); | |
2846 | e.pop_back(); | |
2847 | e.pop_back(); | |
2848 | ||
2849 | const T x(9); | |
2850 | iterator origi_begin = e.begin(); | |
2851 | iterator ret = e.insert(e.end(), 3, x); | |
2852 | ||
2853 | const int expected[] = {1, 2, 3, 4, 5, 9, 9, 9}; | |
2854 | test_equal_range(e, expected); | |
2855 | BOOST_TEST(origi_begin == e.begin()); | |
2856 | BOOST_TEST(ret == e.begin() + 5); | |
2857 | } | |
2858 | ||
2859 | { | |
2860 | Devector f; get_range<Devector>(8, f); | |
2861 | f.reset_alloc_stats(); | |
2862 | ||
2863 | f.pop_front(); | |
2864 | f.pop_front(); | |
2865 | f.pop_back(); | |
2866 | f.pop_back(); | |
2867 | ||
2868 | const T x(9); | |
2869 | iterator ret = f.insert(f.begin() + 2, 4, x); | |
2870 | ||
2871 | const int expected[] = {3, 4, 9, 9, 9, 9, 5, 6}; | |
2872 | test_equal_range(f, expected); | |
2873 | BOOST_TEST(f.get_alloc_count() == 0u); | |
2874 | BOOST_TEST(ret == f.begin() + 2); | |
2875 | } | |
2876 | ||
2877 | { | |
2878 | Devector g; get_range<Devector>(8, g); | |
2879 | g.reset_alloc_stats(); | |
2880 | ||
2881 | g.pop_front(); | |
2882 | g.pop_front(); | |
2883 | g.pop_back(); | |
2884 | g.pop_back(); | |
2885 | g.pop_back(); | |
2886 | ||
2887 | const T x(9); | |
2888 | iterator ret = g.insert(g.begin() + 2, 5, x); | |
2889 | ||
2890 | const int expected[] = {3, 4, 9, 9, 9, 9, 9, 5}; | |
2891 | test_equal_range(g, expected); | |
2892 | BOOST_TEST(g.get_alloc_count() == 0u); | |
2893 | BOOST_TEST(ret == g.begin() + 2); | |
2894 | } | |
2895 | ||
2896 | { | |
2897 | Devector g; get_range<Devector>(8, g); | |
2898 | ||
2899 | const T x(9); | |
2900 | iterator ret = g.insert(g.begin() + 2, 5, x); | |
2901 | ||
2902 | const int expected[] = {1, 2, 9, 9, 9, 9, 9, 3, 4, 5, 6, 7, 8}; | |
2903 | test_equal_range(g, expected); | |
2904 | BOOST_TEST(ret == g.begin() + 2); | |
2905 | } | |
2906 | ||
2907 | { // n == 0 | |
2908 | Devector h; get_range<Devector>(8, h); | |
2909 | h.reset_alloc_stats(); | |
2910 | ||
2911 | const T x(9); | |
2912 | ||
2913 | iterator ret = h.insert(h.begin(), 0, x); | |
2914 | BOOST_TEST(ret == h.begin()); | |
2915 | ||
2916 | ret = h.insert(h.begin() + 4, 0, x); | |
2917 | BOOST_TEST(ret == h.begin() + 4); | |
2918 | ||
2919 | ret = h.insert(h.end(), 0, x); | |
2920 | BOOST_TEST(ret == h.end()); | |
2921 | ||
2922 | const int expected[] = {1, 2, 3, 4, 5, 6, 7, 8}; | |
2923 | test_equal_range(h, expected); | |
2924 | BOOST_TEST(h.get_alloc_count() == 0u); | |
2925 | } | |
2926 | ||
2927 | { // test insert already inserted | |
2928 | Devector i; get_range<Devector>(8, i); | |
2929 | i.reset_alloc_stats(); | |
2930 | ||
2931 | i.pop_front(); | |
2932 | i.pop_front(); | |
2933 | ||
2934 | iterator ret = i.insert(i.end() - 1, 2, *i.begin()); | |
2935 | ||
2936 | const int expected[] = {3, 4, 5, 6, 7, 3, 3, 8}; | |
2937 | test_equal_range(i, expected); | |
2938 | BOOST_TEST(i.get_alloc_count() == 0u); | |
2939 | BOOST_TEST(ret == i.begin() + 5); | |
2940 | } | |
2941 | ||
2942 | test_insert_n_throwing<Devector> | |
2943 | (dtl::bool_<! boost::move_detail::is_nothrow_copy_constructible<T>::value>()); | |
2944 | } | |
2945 | ||
2946 | template <class Devector> void test_insert_input_range() | |
2947 | { | |
2948 | typedef typename Devector::value_type T; | |
2949 | typedef typename Devector::iterator iterator; | |
2950 | ||
2951 | devector<T> x; | |
2952 | x.emplace_back(9); | |
2953 | x.emplace_back(9); | |
2954 | x.emplace_back(9); | |
2955 | x.emplace_back(9); | |
2956 | x.emplace_back(9); | |
2957 | ||
2958 | { | |
2959 | devector<T> input = x; | |
2960 | ||
2961 | input_iterator<Devector> input_begin = make_input_iterator(input, input.begin()); | |
2962 | input_iterator<Devector> input_end = make_input_iterator(input, input.begin() + 5); | |
2963 | ||
2964 | Devector a; | |
2965 | iterator ret = a.insert(a.end(), input_begin, input_end); | |
2966 | const int expected[] = {9, 9, 9, 9, 9}; | |
2967 | test_equal_range(a, expected); | |
2968 | BOOST_TEST(ret == a.begin()); | |
2969 | } | |
2970 | ||
2971 | { | |
2972 | devector<T> input = x; | |
2973 | ||
2974 | input_iterator<Devector> input_begin = make_input_iterator(input, input.begin()); | |
2975 | input_iterator<Devector> input_end = make_input_iterator(input, input.begin() + 3); | |
2976 | ||
2977 | Devector b; get_range<Devector>(8, b); | |
2978 | iterator ret = b.insert(b.begin(), input_begin, input_end); | |
2979 | const int expected[] = {9, 9, 9, 1, 2, 3, 4, 5, 6, 7, 8}; | |
2980 | test_equal_range(b, expected); | |
2981 | BOOST_TEST(ret == b.begin()); | |
2982 | } | |
2983 | ||
2984 | { | |
2985 | devector<T> input = x; | |
2986 | ||
2987 | input_iterator<Devector> input_begin = make_input_iterator(input, input.begin()); | |
2988 | input_iterator<Devector> input_end = make_input_iterator(input, input.begin() + 3); | |
2989 | ||
2990 | Devector c; get_range<Devector>(8, c); | |
2991 | iterator ret = c.insert(c.end(), input_begin, input_end); | |
2992 | const int expected[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 9}; | |
2993 | test_equal_range(c, expected); | |
2994 | BOOST_TEST(ret == c.begin() + 8); | |
2995 | } | |
2996 | ||
2997 | { | |
2998 | devector<T> input = x; | |
2999 | ||
3000 | input_iterator<Devector> input_begin = make_input_iterator(input, input.begin()); | |
3001 | input_iterator<Devector> input_end = make_input_iterator(input, input.begin() + 3); | |
3002 | ||
3003 | Devector d; get_range<Devector>(8, d); | |
3004 | ||
3005 | d.pop_front(); | |
3006 | d.pop_front(); | |
3007 | d.pop_front(); | |
3008 | ||
3009 | iterator ret = d.insert(d.begin(), input_begin, input_end); | |
3010 | const int expected[] = {9, 9, 9, 4, 5, 6, 7, 8}; | |
3011 | test_equal_range(d, expected); | |
3012 | BOOST_TEST(ret == d.begin()); | |
3013 | } | |
3014 | ||
3015 | { | |
3016 | devector<T> input = x; | |
3017 | ||
3018 | input_iterator<Devector> input_begin = make_input_iterator(input, input.begin()); | |
3019 | input_iterator<Devector> input_end = make_input_iterator(input, input.begin() + 3); | |
3020 | ||
3021 | Devector e; get_range<Devector>(8, e); | |
3022 | ||
3023 | e.pop_back(); | |
3024 | e.pop_back(); | |
3025 | e.pop_back(); | |
3026 | ||
3027 | iterator origi_begin = e.begin(); | |
3028 | iterator ret = e.insert(e.end(), input_begin, input_end); | |
3029 | const int expected[] = {1, 2, 3, 4, 5, 9, 9, 9}; | |
3030 | test_equal_range(e, expected); | |
3031 | BOOST_TEST(origi_begin == e.begin()); | |
3032 | BOOST_TEST(ret == e.begin() + 5); | |
3033 | } | |
3034 | ||
3035 | { | |
3036 | devector<T> input = x; | |
3037 | ||
3038 | input_iterator<Devector> input_begin = make_input_iterator(input, input.begin()); | |
3039 | input_iterator<Devector> input_end = make_input_iterator(input, input.begin() + 4); | |
3040 | ||
3041 | Devector f; get_range<Devector>(8, f); | |
3042 | f.reset_alloc_stats(); | |
3043 | ||
3044 | f.pop_front(); | |
3045 | f.pop_front(); | |
3046 | f.pop_back(); | |
3047 | f.pop_back(); | |
3048 | ||
3049 | iterator ret = f.insert(f.begin() + 2, input_begin, input_end); | |
3050 | ||
3051 | const int expected[] = {3, 4, 9, 9, 9, 9, 5, 6}; | |
3052 | test_equal_range(f, expected); | |
3053 | BOOST_TEST(ret == f.begin() + 2); | |
3054 | } | |
3055 | ||
3056 | { | |
3057 | devector<T> input = x; | |
3058 | ||
3059 | input_iterator<Devector> input_begin = make_input_iterator(input, input.begin()); | |
3060 | input_iterator<Devector> input_end = make_input_iterator(input, input.begin() + 5); | |
3061 | ||
3062 | Devector g; get_range<Devector>(8, g); | |
3063 | g.reset_alloc_stats(); | |
3064 | ||
3065 | g.pop_front(); | |
3066 | g.pop_front(); | |
3067 | g.pop_back(); | |
3068 | g.pop_back(); | |
3069 | g.pop_back(); | |
3070 | ||
3071 | iterator ret = g.insert(g.begin() + 2, input_begin, input_end); | |
3072 | ||
3073 | const int expected [] = {3, 4, 9, 9, 9, 9, 9, 5}; | |
3074 | test_equal_range(g, expected); | |
3075 | BOOST_TEST(ret == g.begin() + 2); | |
3076 | } | |
3077 | ||
3078 | { | |
3079 | devector<T> input = x; | |
3080 | ||
3081 | input_iterator<Devector> input_begin = make_input_iterator(input, input.begin()); | |
3082 | input_iterator<Devector> input_end = make_input_iterator(input, input.begin() + 5); | |
3083 | ||
3084 | Devector g; get_range<Devector>(8, g); | |
3085 | ||
3086 | iterator ret = g.insert(g.begin() + 2, input_begin, input_end); | |
3087 | ||
3088 | const int expected [] = {1, 2, 9, 9, 9, 9, 9, 3, 4, 5, 6, 7, 8}; | |
3089 | test_equal_range(g, expected); | |
3090 | BOOST_TEST(ret == g.begin() + 2); | |
3091 | } | |
3092 | ||
3093 | { // n == 0 | |
3094 | devector<T> input = x; | |
3095 | ||
3096 | input_iterator<Devector> input_begin = make_input_iterator(input, input.begin()); | |
3097 | ||
3098 | Devector h; get_range<Devector>(8, h); | |
3099 | h.reset_alloc_stats(); | |
3100 | ||
3101 | iterator ret = h.insert(h.begin(), input_begin, input_begin); | |
3102 | BOOST_TEST(ret == h.begin()); | |
3103 | ||
3104 | ret = h.insert(h.begin() + 4, input_begin, input_begin); | |
3105 | BOOST_TEST(ret == h.begin() + 4); | |
3106 | ||
3107 | ret = h.insert(h.end(), input_begin, input_begin); | |
3108 | BOOST_TEST(ret == h.end()); | |
3109 | ||
3110 | const int expected [] = {1, 2, 3, 4, 5, 6, 7, 8}; | |
3111 | test_equal_range(h, expected); | |
3112 | } | |
3113 | ||
3114 | #ifndef BOOST_NO_EXCEPTIONS | |
3115 | if (! boost::move_detail::is_nothrow_copy_constructible<T>::value) | |
3116 | { | |
3117 | // insert at begin | |
3118 | { | |
3119 | devector<T> input = x; | |
3120 | ||
3121 | input_iterator<Devector> input_begin = make_input_iterator(input, input.begin()); | |
3122 | input_iterator<Devector> input_end = make_input_iterator(input, input.begin() + 4); | |
3123 | ||
3124 | Devector j; get_range<Devector>(4, j); | |
3125 | ||
3126 | test_elem_throw::on_copy_after(3); | |
3127 | BOOST_TEST_THROWS(j.insert(j.begin(), input_begin, input_end), test_exception); | |
3128 | test_elem_throw::do_not_throw(); | |
3129 | } | |
3130 | ||
3131 | // insert at end | |
3132 | { | |
3133 | devector<T> input = x; | |
3134 | ||
3135 | input_iterator<Devector> input_begin = make_input_iterator(input, input.begin()); | |
3136 | input_iterator<Devector> input_end = make_input_iterator(input, input.begin() + 4); | |
3137 | ||
3138 | Devector k; get_range<Devector>(4, k); | |
3139 | ||
3140 | test_elem_throw::on_copy_after(3); | |
3141 | BOOST_TEST_THROWS(k.insert(k.end(), input_begin, input_end), test_exception); | |
3142 | test_elem_throw::do_not_throw(); | |
3143 | } | |
3144 | } | |
3145 | #endif //#ifndef BOOST_NO_EXCEPTIONS | |
3146 | } | |
3147 | ||
3148 | template <class Devector> void test_insert_range() | |
3149 | { | |
3150 | typedef typename Devector::value_type T; | |
3151 | typedef typename Devector::iterator iterator; | |
3152 | typedef boost::container::vector<T> Vector; | |
3153 | ||
3154 | Vector x; | |
3155 | x.emplace_back(9); | |
3156 | x.emplace_back(10); | |
3157 | x.emplace_back(11); | |
3158 | x.emplace_back(12); | |
3159 | x.emplace_back(13); | |
3160 | ||
3161 | typename Vector::iterator xb = x.begin(); | |
3162 | ||
3163 | { | |
3164 | Devector a; | |
3165 | iterator ret = a.insert(a.end(), xb, xb+5); | |
3166 | const int expected [] = {9, 10, 11, 12, 13}; | |
3167 | test_equal_range(a, expected); | |
3168 | BOOST_TEST(ret == a.begin()); | |
3169 | } | |
3170 | ||
3171 | { | |
3172 | Devector b; get_range<Devector>(8, b); | |
3173 | iterator ret = b.insert(b.begin(), xb, xb+3); | |
3174 | const int expected [] = {9, 10, 11, 1, 2, 3, 4, 5, 6, 7, 8}; | |
3175 | test_equal_range(b, expected); | |
3176 | BOOST_TEST(ret == b.begin()); | |
3177 | } | |
3178 | ||
3179 | { | |
3180 | Devector c; get_range<Devector>(8, c); | |
3181 | iterator ret = c.insert(c.end(), xb, xb+3); | |
3182 | const int expected [] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; | |
3183 | test_equal_range(c, expected); | |
3184 | BOOST_TEST(ret == c.begin() + 8); | |
3185 | } | |
3186 | ||
3187 | { | |
3188 | Devector d; get_range<Devector>(8, d); | |
3189 | ||
3190 | d.pop_front(); | |
3191 | d.pop_front(); | |
3192 | d.pop_front(); | |
3193 | ||
3194 | iterator origi_end = d.end(); | |
3195 | iterator ret = d.insert(d.begin(), xb, xb+3); | |
3196 | ||
3197 | const int expected [] = {9, 10, 11, 4, 5, 6, 7, 8}; | |
3198 | test_equal_range(d, expected); | |
3199 | ||
3200 | BOOST_TEST(origi_end == d.end()); | |
3201 | BOOST_TEST(ret == d.begin()); | |
3202 | } | |
3203 | ||
3204 | { | |
3205 | Devector e; get_range<Devector>(8, e); | |
3206 | ||
3207 | e.pop_back(); | |
3208 | e.pop_back(); | |
3209 | e.pop_back(); | |
3210 | ||
3211 | iterator origi_begin = e.begin(); | |
3212 | iterator ret = e.insert(e.end(), xb, xb+3); | |
3213 | ||
3214 | const int expected [] = {1, 2, 3, 4, 5, 9, 10, 11}; | |
3215 | test_equal_range(e, expected); | |
3216 | ||
3217 | BOOST_TEST(origi_begin == e.begin()); | |
3218 | BOOST_TEST(ret == e.begin() + 5); | |
3219 | } | |
3220 | ||
3221 | { | |
3222 | Devector f; get_range<Devector>(8, f); | |
3223 | f.reset_alloc_stats(); | |
3224 | ||
3225 | f.pop_front(); | |
3226 | f.pop_front(); | |
3227 | f.pop_back(); | |
3228 | f.pop_back(); | |
3229 | ||
3230 | iterator ret = f.insert(f.begin() + 2, xb, xb+4); | |
3231 | ||
3232 | const int expected [] = {3, 4, 9, 10, 11, 12, 5, 6}; | |
3233 | test_equal_range(f, expected); | |
3234 | ||
3235 | BOOST_TEST(f.get_alloc_count() == 0u); | |
3236 | BOOST_TEST(ret == f.begin() + 2); | |
3237 | } | |
3238 | ||
3239 | { | |
3240 | Devector g; get_range<Devector>(8, g); | |
3241 | g.reset_alloc_stats(); | |
3242 | ||
3243 | g.pop_front(); | |
3244 | g.pop_front(); | |
3245 | g.pop_back(); | |
3246 | g.pop_back(); | |
3247 | g.pop_back(); | |
3248 | ||
3249 | iterator ret = g.insert(g.begin() + 2, xb, xb+5); | |
3250 | ||
3251 | const int expected [] = {3, 4, 9, 10, 11, 12, 13, 5}; | |
3252 | test_equal_range(g, expected); | |
3253 | ||
3254 | BOOST_TEST(g.get_alloc_count() == 0u); | |
3255 | BOOST_TEST(ret == g.begin() + 2); | |
3256 | } | |
3257 | ||
3258 | { | |
3259 | Devector g; get_range<Devector>(8, g); | |
3260 | ||
3261 | iterator ret = g.insert(g.begin() + 2, xb, xb+5); | |
3262 | ||
3263 | const int expected [] = {1, 2, 9, 10, 11, 12, 13, 3, 4, 5, 6, 7, 8}; | |
3264 | test_equal_range(g, expected); | |
3265 | ||
3266 | BOOST_TEST(ret == g.begin() + 2); | |
3267 | } | |
3268 | ||
3269 | { // n == 0 | |
3270 | Devector h; get_range<Devector>(8, h); | |
3271 | h.reset_alloc_stats(); | |
3272 | ||
3273 | iterator ret = h.insert(h.begin(), xb, xb); | |
3274 | BOOST_TEST(ret == h.begin()); | |
3275 | ||
3276 | ret = h.insert(h.begin() + 4, xb, xb); | |
3277 | BOOST_TEST(ret == h.begin() + 4); | |
3278 | ||
3279 | ret = h.insert(h.end(), xb, xb); | |
3280 | BOOST_TEST(ret == h.end()); | |
3281 | ||
3282 | const int expected [] = {1, 2, 3, 4, 5, 6, 7, 8}; | |
3283 | test_equal_range(h, expected); | |
3284 | ||
3285 | BOOST_TEST(h.get_alloc_count() == 0u); | |
3286 | } | |
3287 | ||
3288 | #ifndef BOOST_NO_EXCEPTIONS | |
3289 | if (! boost::move_detail::is_nothrow_copy_constructible<T>::value) | |
3290 | { | |
3291 | // insert at begin | |
3292 | { | |
3293 | Devector j; get_range<Devector>(4, j); | |
3294 | ||
3295 | test_elem_throw::on_copy_after(3); | |
3296 | BOOST_TEST_THROWS(j.insert(j.begin(), xb, xb+4), test_exception); | |
3297 | test_elem_throw::do_not_throw(); | |
3298 | } | |
3299 | ||
3300 | // insert at end | |
3301 | { | |
3302 | Devector k; get_range<Devector>(4, k); | |
3303 | ||
3304 | test_elem_throw::on_copy_after(3); | |
3305 | BOOST_TEST_THROWS(k.insert(k.end(), xb, xb+4), test_exception); | |
3306 | test_elem_throw::do_not_throw(); | |
3307 | } | |
3308 | } | |
3309 | #endif //#ifndef BOOST_NO_EXCEPTIONS | |
3310 | } | |
3311 | ||
3312 | template <class Devector> void test_insert_init_list() | |
3313 | { | |
3314 | #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) | |
3315 | typedef typename Devector::value_type T; | |
3316 | typedef typename Devector::iterator iterator; | |
3317 | ||
3318 | { | |
3319 | Devector a; | |
3320 | iterator ret = a.insert(a.end(), {T(123), T(124), T(125), T(126), T(127)}); | |
3321 | test_equal_range(a, {123, 124, 125, 126, 127}); | |
3322 | BOOST_TEST(ret == a.begin()); | |
3323 | } | |
3324 | ||
3325 | { | |
3326 | Devector b; get_range<Devector>(8, b); | |
3327 | iterator ret = b.insert(b.begin(), {T(9), T(10), T(11)}); | |
3328 | test_equal_range(b, {9, 10, 11, 1, 2, 3, 4, 5, 6, 7, 8}); | |
3329 | BOOST_TEST(ret == b.begin()); | |
3330 | } | |
3331 | ||
3332 | { | |
3333 | Devector c; get_range<Devector>(8, c); | |
3334 | iterator ret = c.insert(c.end(), {T(9), T(10), T(11)}); | |
3335 | test_equal_range(c, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}); | |
3336 | BOOST_TEST(ret == c.begin() + 8); | |
3337 | } | |
3338 | ||
3339 | { | |
3340 | Devector d; get_range<Devector>(8, d); | |
3341 | ||
3342 | d.pop_front(); | |
3343 | d.pop_front(); | |
3344 | d.pop_front(); | |
3345 | ||
3346 | iterator origi_end = d.end(); | |
3347 | iterator ret = d.insert(d.begin(), {T(9), T(10), T(11)}); | |
3348 | ||
3349 | test_equal_range(d, {9, 10, 11, 4, 5, 6, 7, 8}); | |
3350 | BOOST_TEST(origi_end == d.end()); | |
3351 | BOOST_TEST(ret == d.begin()); | |
3352 | } | |
3353 | ||
3354 | { | |
3355 | Devector e; get_range<Devector>(8, e); | |
3356 | ||
3357 | e.pop_back(); | |
3358 | e.pop_back(); | |
3359 | e.pop_back(); | |
3360 | ||
3361 | iterator origi_begin = e.begin(); | |
3362 | iterator ret = e.insert(e.end(), {T(9), T(10), T(11)}); | |
3363 | ||
3364 | test_equal_range(e, {1, 2, 3, 4, 5, 9, 10, 11}); | |
3365 | BOOST_TEST(origi_begin == e.begin()); | |
3366 | BOOST_TEST(ret == e.begin() + 5); | |
3367 | } | |
3368 | ||
3369 | { | |
3370 | Devector f; get_range<Devector>(8, f); | |
3371 | f.reset_alloc_stats(); | |
3372 | ||
3373 | f.pop_front(); | |
3374 | f.pop_front(); | |
3375 | f.pop_back(); | |
3376 | f.pop_back(); | |
3377 | ||
3378 | iterator ret = f.insert(f.begin() + 2, {T(9), T(10), T(11), T(12)}); | |
3379 | ||
3380 | test_equal_range(f, {3, 4, 9, 10, 11, 12, 5, 6}); | |
3381 | BOOST_TEST(f.get_alloc_count() == 0u); | |
3382 | BOOST_TEST(ret == f.begin() + 2); | |
3383 | } | |
3384 | ||
3385 | { | |
3386 | Devector g; get_range<Devector>(8, g); | |
3387 | g.reset_alloc_stats(); | |
3388 | ||
3389 | g.pop_front(); | |
3390 | g.pop_front(); | |
3391 | g.pop_back(); | |
3392 | g.pop_back(); | |
3393 | g.pop_back(); | |
3394 | ||
3395 | iterator ret = g.insert(g.begin() + 2, {T(9), T(10), T(11), T(12), T(13)}); | |
3396 | ||
3397 | test_equal_range(g, {3, 4, 9, 10, 11, 12, 13, 5}); | |
3398 | BOOST_TEST(g.get_alloc_count() == 0u); | |
3399 | BOOST_TEST(ret == g.begin() + 2); | |
3400 | } | |
3401 | ||
3402 | { | |
3403 | Devector g; get_range<Devector>(8, g); | |
3404 | ||
3405 | iterator ret = g.insert(g.begin() + 2, {T(9), T(10), T(11), T(12), T(13)}); | |
3406 | ||
3407 | test_equal_range(g, {1, 2, 9, 10, 11, 12, 13, 3, 4, 5, 6, 7, 8}); | |
3408 | BOOST_TEST(ret == g.begin() + 2); | |
3409 | } | |
3410 | ||
3411 | #ifndef BOOST_NO_EXCEPTIONS | |
3412 | BOOST_IF_CONSTEXPR (! boost::move_detail::is_nothrow_copy_constructible<T>::value) | |
3413 | { | |
3414 | // insert at begin | |
3415 | { | |
3416 | Devector j; get_range<Devector>(4, j); | |
3417 | ||
3418 | test_elem_throw::on_copy_after(3); | |
3419 | BOOST_TEST_THROWS(j.insert(j.begin(), {T(9), T(9), T(9), T(9), T(9)}), test_exception); | |
3420 | test_elem_throw::do_not_throw(); | |
3421 | } | |
3422 | ||
3423 | // insert at end | |
3424 | { | |
3425 | Devector k; get_range<Devector>(4, k); | |
3426 | test_elem_throw::on_copy_after(3); | |
3427 | BOOST_TEST_THROWS(k.insert(k.end(), {T(9), T(9), T(9), T(9), T(9)}), test_exception); | |
3428 | test_elem_throw::do_not_throw(); | |
3429 | } | |
3430 | } | |
3431 | #endif //#ifndef BOOST_NO_EXCEPTIONS | |
3432 | #endif // #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) | |
3433 | } | |
3434 | ||
3435 | template <class Devector> void test_erase() | |
3436 | { | |
3437 | typedef typename Devector::iterator iterator; | |
3438 | { | |
3439 | Devector a; get_range<Devector>(4, a); | |
3440 | iterator ret = a.erase(a.begin()); | |
3441 | const int expected[] = {2, 3, 4}; | |
3442 | test_equal_range(a, expected); | |
3443 | BOOST_TEST(ret == a.begin()); | |
3444 | } | |
3445 | ||
3446 | { | |
3447 | Devector b; get_range<Devector>(4, b); | |
3448 | iterator ret = b.erase(b.end() - 1); | |
3449 | const int expected[] = {1, 2, 3}; | |
3450 | test_equal_range(b, expected); | |
3451 | BOOST_TEST(ret == b.end()); | |
3452 | } | |
3453 | ||
3454 | { | |
3455 | Devector c; get_range<Devector>(6, c); | |
3456 | iterator ret = c.erase(c.begin() + 2); | |
3457 | const int expected [] = {1, 2, 4, 5, 6}; | |
3458 | test_equal_range(c, expected); | |
3459 | BOOST_TEST(ret == c.begin() + 2); | |
3460 | BOOST_TEST(c.front_free_capacity() > 0u); | |
3461 | } | |
3462 | ||
3463 | { | |
3464 | Devector d; get_range<Devector>(6, d); | |
3465 | iterator ret = d.erase(d.begin() + 4); | |
3466 | const int expected [] = {1, 2, 3, 4, 6}; | |
3467 | test_equal_range(d, expected); | |
3468 | BOOST_TEST(ret == d.begin() + 4); | |
3469 | BOOST_TEST(d.back_free_capacity() > 0u); | |
3470 | } | |
3471 | } | |
3472 | ||
3473 | template <class Devector> void test_erase_range() | |
3474 | { | |
3475 | typedef typename Devector::iterator iterator; | |
3476 | { | |
3477 | Devector a; get_range<Devector>(4, a); | |
3478 | a.erase(a.end(), a.end()); | |
3479 | a.erase(a.begin(), a.begin()); | |
3480 | } | |
3481 | ||
3482 | { | |
3483 | Devector b; get_range<Devector>(8, b); | |
3484 | iterator ret = b.erase(b.begin(), b.begin() + 2); | |
3485 | const int expected [] = {3, 4, 5, 6, 7, 8}; | |
3486 | test_equal_range(b, expected); | |
3487 | BOOST_TEST(ret == b.begin()); | |
3488 | BOOST_TEST(b.front_free_capacity() > 0u); | |
3489 | } | |
3490 | ||
3491 | { | |
3492 | Devector c; get_range<Devector>(8, c); | |
3493 | iterator ret = c.erase(c.begin() + 1, c.begin() + 3); | |
3494 | const int expected [] = {1, 4, 5, 6, 7, 8}; | |
3495 | test_equal_range(c, expected); | |
3496 | BOOST_TEST(ret == c.begin() + 1); | |
3497 | BOOST_TEST(c.front_free_capacity() > 0u); | |
3498 | } | |
3499 | ||
3500 | { | |
3501 | Devector d; get_range<Devector>(8, d); | |
3502 | iterator ret = d.erase(d.end() - 2, d.end()); | |
3503 | const int expected [] = {1, 2, 3, 4, 5, 6}; | |
3504 | test_equal_range(d, expected); | |
3505 | BOOST_TEST(ret == d.end()); | |
3506 | BOOST_TEST(d.back_free_capacity() > 0u); | |
3507 | } | |
3508 | ||
3509 | { | |
3510 | Devector e; get_range<Devector>(8, e); | |
3511 | iterator ret = e.erase(e.end() - 3, e.end() - 1); | |
3512 | const int expected [] = {1, 2, 3, 4, 5, 8}; | |
3513 | test_equal_range(e, expected); | |
3514 | BOOST_TEST(ret == e.end() - 1); | |
3515 | BOOST_TEST(e.back_free_capacity() > 0u); | |
3516 | } | |
3517 | ||
3518 | { | |
3519 | Devector f; get_range<Devector>(8, f); | |
3520 | iterator ret = f.erase(f.begin(), f.end()); | |
3521 | test_equal_range(f); | |
3522 | BOOST_TEST(ret == f.end()); | |
3523 | } | |
3524 | } | |
3525 | ||
3526 | template <class Devector> void test_swap() | |
3527 | { | |
3528 | using std::swap; // test if ADL works | |
3529 | ||
3530 | // empty-empty | |
3531 | { | |
3532 | Devector a; | |
3533 | Devector b; | |
3534 | ||
3535 | swap(a, b); | |
3536 | ||
3537 | BOOST_TEST(a.empty()); | |
3538 | BOOST_TEST(b.empty()); | |
3539 | } | |
3540 | ||
3541 | // empty-not empty | |
3542 | { | |
3543 | Devector a; | |
3544 | Devector b; get_range<Devector>(4, b); | |
3545 | ||
3546 | swap(a, b); | |
3547 | ||
3548 | const int expected [] = {1, 2, 3, 4}; | |
3549 | { | |
3550 | BOOST_TEST(b.empty()); | |
3551 | test_equal_range(a, expected); | |
3552 | } | |
3553 | ||
3554 | swap(a, b); | |
3555 | { | |
3556 | BOOST_TEST(a.empty()); | |
3557 | test_equal_range(b, expected); | |
3558 | } | |
3559 | } | |
3560 | ||
3561 | // small-small / big-big | |
3562 | { | |
3563 | Devector a; get_range<Devector>(1, 5, 5, 7, a); | |
3564 | Devector b; get_range<Devector>(13, 15, 15, 19, b); | |
3565 | ||
3566 | swap(a, b); | |
3567 | ||
3568 | const int expected [] = {13, 14, 15, 16, 17, 18}; | |
3569 | test_equal_range(a, expected); | |
3570 | const int expected2 [] = {1, 2, 3, 4, 5, 6}; | |
3571 | test_equal_range(b, expected2); | |
3572 | ||
3573 | swap(a, b); | |
3574 | ||
3575 | const int expected3 [] = {13, 14, 15, 16, 17, 18}; | |
3576 | test_equal_range(b, expected3); | |
3577 | const int expected4 [] = {1, 2, 3, 4, 5, 6}; | |
3578 | test_equal_range(a, expected4); | |
3579 | } | |
3580 | ||
3581 | // big-small + small-big | |
3582 | { | |
3583 | Devector a; get_range<Devector>(10, a); | |
3584 | Devector b; get_range<Devector>(9, 11, 11, 17, b); | |
3585 | ||
3586 | swap(a, b); | |
3587 | ||
3588 | const int expected [] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; | |
3589 | test_equal_range(b, expected); | |
3590 | const int expected2 [] = {9, 10, 11, 12, 13, 14, 15, 16}; | |
3591 | test_equal_range(a, expected2); | |
3592 | ||
3593 | swap(a, b); | |
3594 | ||
3595 | const int expected3 [] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; | |
3596 | test_equal_range(a, expected3); | |
3597 | const int expected4 [] = {9, 10, 11, 12, 13, 14, 15, 16}; | |
3598 | test_equal_range(b, expected4); | |
3599 | } | |
3600 | ||
3601 | // self swap | |
3602 | { | |
3603 | Devector a; get_range<Devector>(10, a); | |
3604 | ||
3605 | swap(a, a); | |
3606 | ||
3607 | const int expected [] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; | |
3608 | test_equal_range(a, expected); | |
3609 | } | |
3610 | ||
3611 | // no overlap | |
3612 | { | |
3613 | Devector a; get_range<Devector>(1, 9, 0, 0, a); | |
3614 | Devector b; get_range<Devector>(0, 0, 11, 17, b); | |
3615 | ||
3616 | a.pop_back(); | |
3617 | a.pop_back(); | |
3618 | ||
3619 | b.pop_front(); | |
3620 | b.pop_front(); | |
3621 | ||
3622 | swap(a, b); | |
3623 | ||
3624 | const int expected [] = {13, 14, 15, 16}; | |
3625 | test_equal_range(a, expected); | |
3626 | const int expected2 [] = {1, 2, 3, 4, 5, 6}; | |
3627 | test_equal_range(b, expected2); | |
3628 | } | |
3629 | ||
3630 | // big-big does not copy or move | |
3631 | { | |
3632 | Devector a; get_range<Devector>(32, a); | |
3633 | Devector b; get_range<Devector>(32, b); | |
3634 | boost::container::vector<int> c; get_range<boost::container::vector<int> >(32, c); | |
3635 | ||
3636 | test_elem_throw::on_copy_after(1); | |
3637 | test_elem_throw::on_move_after(1); | |
3638 | ||
3639 | swap(a, b); | |
3640 | ||
3641 | test_elem_throw::do_not_throw(); | |
3642 | ||
3643 | test_equal_range(a, c); | |
3644 | test_equal_range(b, c); | |
3645 | } | |
3646 | } | |
3647 | ||
3648 | template <class Devector> void test_clear() | |
3649 | { | |
3650 | { | |
3651 | Devector a; | |
3652 | a.clear(); | |
3653 | BOOST_TEST(a.empty()); | |
3654 | } | |
3655 | ||
3656 | { | |
3657 | Devector a; get_range<Devector>(8, a); | |
3658 | typename Devector::size_type cp = a.capacity(); | |
3659 | a.clear(); | |
3660 | BOOST_TEST(a.empty()); | |
3661 | BOOST_TEST(cp == a.capacity()); | |
3662 | } | |
3663 | } | |
3664 | ||
3665 | template <class Devector> void test_op_eq() | |
3666 | { | |
3667 | { // equal | |
3668 | Devector a; get_range<Devector>(8, a); | |
3669 | Devector b; get_range<Devector>(8, b); | |
3670 | ||
3671 | BOOST_TEST(a == b); | |
3672 | } | |
3673 | ||
3674 | { // diff size | |
3675 | Devector a; get_range<Devector>(8, a); | |
3676 | Devector b; get_range<Devector>(9, b); | |
3677 | ||
3678 | BOOST_TEST(!(a == b)); | |
3679 | } | |
3680 | ||
3681 | { // diff content | |
3682 | Devector a; get_range<Devector>(8, a); | |
3683 | Devector b; get_range<Devector>(2,6,6,10, b); | |
3684 | ||
3685 | BOOST_TEST(!(a == b)); | |
3686 | } | |
3687 | } | |
3688 | ||
3689 | template <class Devector> void test_op_lt() | |
3690 | { | |
3691 | { // little than | |
3692 | Devector a; get_range<Devector>(7, a); | |
3693 | Devector b; get_range<Devector>(8, b); | |
3694 | ||
3695 | BOOST_TEST((a < b)); | |
3696 | } | |
3697 | ||
3698 | { // equal | |
3699 | Devector a; get_range<Devector>(8, a); | |
3700 | Devector b; get_range<Devector>(8, b); | |
3701 | ||
3702 | BOOST_TEST(!(a < b)); | |
3703 | } | |
3704 | ||
3705 | { // greater than | |
3706 | Devector a; get_range<Devector>(8, a); | |
3707 | Devector b; get_range<Devector>(7, b); | |
3708 | ||
3709 | BOOST_TEST(!(a < b)); | |
3710 | } | |
3711 | } | |
3712 | ||
3713 | template <class Devector> void test_op_ne() | |
3714 | { | |
3715 | { // equal | |
3716 | Devector a; get_range<Devector>(8, a); | |
3717 | Devector b; get_range<Devector>(8, b); | |
3718 | ||
3719 | BOOST_TEST(!(a != b)); | |
3720 | } | |
3721 | ||
3722 | { // diff size | |
3723 | Devector a; get_range<Devector>(8, a); | |
3724 | Devector b; get_range<Devector>(9, b); | |
3725 | ||
3726 | BOOST_TEST((a != b)); | |
3727 | } | |
3728 | ||
3729 | { // diff content | |
3730 | Devector a; get_range<Devector>(8, a); | |
3731 | Devector b; get_range<Devector>(2,6,6,10, b); | |
3732 | ||
3733 | BOOST_TEST((a != b)); | |
3734 | } | |
3735 | } | |
3736 | ||
3737 | ||
3738 | template <class Devector> void test_op_gt() | |
3739 | { | |
3740 | { // little than | |
3741 | Devector a; get_range<Devector>(7, a); | |
3742 | Devector b; get_range<Devector>(8, b); | |
3743 | ||
3744 | BOOST_TEST(!(a > b)); | |
3745 | } | |
3746 | ||
3747 | { // equal | |
3748 | Devector a; get_range<Devector>(8, a); | |
3749 | Devector b; get_range<Devector>(8, b); | |
3750 | ||
3751 | BOOST_TEST(!(a > b)); | |
3752 | } | |
3753 | ||
3754 | { // greater than | |
3755 | Devector a; get_range<Devector>(8, a); | |
3756 | Devector b; get_range<Devector>(7, b); | |
3757 | ||
3758 | BOOST_TEST((a > b)); | |
3759 | } | |
3760 | } | |
3761 | ||
3762 | template <class Devector> void test_op_ge() | |
3763 | { | |
3764 | { // little than | |
3765 | Devector a; get_range<Devector>(7, a); | |
3766 | Devector b; get_range<Devector>(8, b); | |
3767 | ||
3768 | BOOST_TEST(!(a >= b)); | |
3769 | } | |
3770 | ||
3771 | { // equal | |
3772 | Devector a; get_range<Devector>(8, a); | |
3773 | Devector b; get_range<Devector>(8, b); | |
3774 | ||
3775 | BOOST_TEST((a >= b)); | |
3776 | } | |
3777 | ||
3778 | { // greater than | |
3779 | Devector a; get_range<Devector>(8, a); | |
3780 | Devector b; get_range<Devector>(7, b); | |
3781 | ||
3782 | BOOST_TEST((a >= b)); | |
3783 | } | |
3784 | } | |
3785 | ||
3786 | template <class Devector> void test_op_le() | |
3787 | { | |
3788 | { // little than | |
3789 | Devector a; get_range<Devector>(7, a); | |
3790 | Devector b; get_range<Devector>(8, b); | |
3791 | ||
3792 | BOOST_TEST((a <= b)); | |
3793 | } | |
3794 | ||
3795 | { // equal | |
3796 | Devector a; get_range<Devector>(8, a); | |
3797 | Devector b; get_range<Devector>(8, b); | |
3798 | ||
3799 | BOOST_TEST((a <= b)); | |
3800 | } | |
3801 | ||
3802 | { // greater than | |
3803 | Devector a; get_range<Devector>(8, a); | |
3804 | Devector b; get_range<Devector>(7, b); | |
3805 | ||
3806 | BOOST_TEST(!(a <= b)); | |
3807 | } | |
3808 | } | |
3809 | ||
3810 | ||
3811 | template <class Devector> | |
3812 | void test_devector_default_constructible(dtl::true_) | |
3813 | { | |
3814 | test_constructor_n<Devector>(); | |
3815 | test_resize_front<Devector>(); | |
3816 | test_resize_back<Devector>(); | |
3817 | } | |
3818 | ||
3819 | template <class Devector> | |
3820 | void test_devector_default_constructible(dtl::false_) | |
3821 | {} | |
3822 | ||
3823 | template <class Devector> | |
3824 | void test_devector_copy_constructible(dtl::false_) | |
3825 | {} | |
3826 | ||
3827 | ||
3828 | template <class Devector> | |
3829 | void test_devector_copy_constructible(dtl::true_) | |
3830 | { | |
3831 | test_constructor_n_copy<Devector>(); | |
3832 | test_constructor_input_range<Devector>(); | |
3833 | test_constructor_forward_range<Devector>(); | |
3834 | test_constructor_pointer_range<Devector>(); | |
3835 | test_copy_constructor<Devector>(); | |
3836 | test_assignment<Devector>(); | |
3837 | test_assign_input_range<Devector>(); | |
3838 | test_assign_pointer_range<Devector>(); | |
3839 | test_assign_n<Devector>(); | |
3840 | test_resize_front_copy<Devector>(); | |
3841 | test_push_back<Devector>(); | |
3842 | //test_unsafe_push_back<Devector>(); | |
3843 | test_push_front<Devector>(); | |
3844 | //test_unsafe_push_front<Devector>(); | |
3845 | test_resize_back_copy<Devector>(); | |
3846 | test_insert<Devector>(); | |
3847 | test_insert_n<Devector>(); | |
3848 | test_insert_input_range<Devector>(); | |
3849 | test_insert_range<Devector>(); | |
3850 | test_insert_init_list<Devector>(); | |
3851 | } | |
3852 | ||
3853 | template <class Devector> | |
3854 | void test_devector() | |
3855 | { | |
3856 | test_devector_default_constructible<Devector>(dtl::bool_<boost::is_default_constructible<typename Devector::value_type>::value>()); | |
3857 | test_devector_copy_constructible<Devector>(dtl::bool_<boost::move_detail::is_copy_constructible<typename Devector::value_type>::value>()); | |
3858 | ||
3859 | test_constructor_default<Devector>(); | |
3860 | test_constructor_allocator<Devector>(); | |
3861 | ||
3862 | test_constructor_reserve_only<Devector>(); | |
3863 | test_constructor_reserve_only_front_back<Devector>(); | |
3864 | //test_constructor_unsafe_uninitialized<Devector>(); | |
3865 | ||
3866 | test_move_constructor<Devector>(); | |
3867 | test_destructor<Devector>(); | |
3868 | ||
3869 | test_move_assignment<Devector>(); | |
3870 | test_get_allocator<Devector>(); | |
3871 | test_begin_end<Devector>(); | |
3872 | test_empty<Devector>(); | |
3873 | test_size<Devector>(); | |
3874 | test_capacity<Devector>(); | |
3875 | ||
3876 | //test_unsafe_uninitialized_resize_front<Devector>(); | |
3877 | //test_unsafe_uninitialized_resize_back<Devector>(); | |
3878 | test_reserve_front<Devector>(); | |
3879 | test_reserve_back<Devector>(); | |
3880 | test_index_operator<Devector>(); | |
3881 | test_at<Devector>(); | |
3882 | test_front<Devector>(); | |
3883 | test_back<Devector>(); | |
3884 | test_emplace_front<Devector>(); | |
3885 | test_push_front_rvalue<Devector>(); | |
3886 | ||
3887 | //test_unsafe_push_front_rvalue<Devector>(); | |
3888 | test_pop_front<Devector>(); | |
3889 | test_emplace_back<Devector>(); | |
3890 | test_push_back_rvalue<Devector>(); | |
3891 | ||
3892 | //test_unsafe_push_back_rvalue<Devector>(); | |
3893 | test_pop_back<Devector>(); | |
3894 | test_emplace<Devector>(); | |
3895 | test_insert_rvalue<Devector>(); | |
3896 | ||
3897 | test_erase<Devector>(); | |
3898 | test_erase_range<Devector>(); | |
3899 | test_swap<Devector>(); | |
3900 | test_clear<Devector>(); | |
3901 | test_op_eq<Devector>(); | |
3902 | test_op_lt<Devector>(); | |
3903 | test_op_ne<Devector>(); | |
3904 | test_op_gt<Devector>(); | |
3905 | test_op_ge<Devector>(); | |
3906 | test_op_le<Devector>(); | |
3907 | } | |
3908 | ||
3909 | class recursive_devector | |
3910 | { | |
3911 | public: | |
3912 | recursive_devector(const recursive_devector &x) | |
3913 | : devector_(x.devector_) | |
3914 | {} | |
3915 | ||
3916 | recursive_devector & operator=(const recursive_devector &x) | |
3917 | { this->devector_ = x.devector_; return *this; } | |
3918 | ||
3919 | int id_; | |
3920 | devector<recursive_devector> devector_; | |
3921 | devector<recursive_devector>::iterator it_; | |
3922 | devector<recursive_devector>::const_iterator cit_; | |
3923 | devector<recursive_devector>::reverse_iterator rit_; | |
3924 | devector<recursive_devector>::const_reverse_iterator crit_; | |
3925 | }; | |
3926 | ||
3927 | void test_recursive_devector()//Test for recursive types | |
3928 | { | |
3929 | devector<recursive_devector> rdv; | |
3930 | BOOST_TEST(rdv.empty()); | |
3931 | BOOST_TEST(rdv.get_alloc_count() == 0u); | |
3932 | BOOST_TEST(rdv.capacity() == 0u); | |
3933 | } | |
3934 | ||
3935 | template<class VoidAllocator> | |
3936 | struct GetAllocatorCont | |
3937 | { | |
3938 | template<class ValueType> | |
3939 | struct apply | |
3940 | { | |
3941 | typedef vector< ValueType | |
3942 | , typename allocator_traits<VoidAllocator> | |
3943 | ::template portable_rebind_alloc<ValueType>::type | |
3944 | > type; | |
3945 | }; | |
3946 | }; | |
3947 | ||
3948 | #ifdef _MSC_VER | |
3949 | #pragma warning (pop) | |
3950 | #endif | |
3951 | ||
3952 | ||
3953 | void test_all() | |
3954 | {/* | |
3955 | test_recursive_devector(); | |
3956 | test_max_size(); | |
3957 | test_exceeding_max_size(); | |
3958 | shrink_to_fit(); | |
3959 | test_data(); | |
3960 | test_il_assignment< devector<int> >(); | |
3961 | test_assign_forward_range< devector<int> >(); | |
3962 | test_assign_il<devector<int> >(); | |
3963 | */ | |
3964 | //test_devector< devector<int> >(); | |
3965 | test_devector< devector<regular_elem> >(); | |
3966 | test_devector< devector<noex_move> >(); | |
3967 | test_devector< devector<noex_copy> >(); | |
3968 | test_devector< devector<only_movable> >(); | |
3969 | test_devector< devector<no_default_ctor> >(); | |
3970 | ||
3971 | //////////////////////////////////// | |
3972 | // Allocator propagation testing | |
3973 | //////////////////////////////////// | |
3974 | (void)boost::container::test::test_propagate_allocator<boost_container_devector>(); | |
3975 | } | |
3976 | ||
3977 | ||
3978 | boost::container::vector<only_movable> getom() | |
3979 | { | |
3980 | typedef boost::container::vector<only_movable> V; | |
3981 | V v; | |
3982 | return BOOST_MOVE_RET(V, v); | |
3983 | } | |
3984 | ||
3985 | ||
3986 | boost::container::vector<boost::container::test::movable_int> get() | |
3987 | { | |
3988 | typedef boost::container::vector<boost::container::test::movable_int> V; | |
3989 | V v; | |
3990 | return BOOST_MOVE_RET(V, v); | |
3991 | } | |
3992 | ||
3993 | int main() | |
3994 | { | |
3995 | // boost::container::vector<boost::container::test::movable_int>a(get()); | |
3996 | //boost::container::vector<only_movable> b(getom()); | |
3997 | //boost::container::vector<only_movable> c(get_range< boost::container::vector<only_movable> >(1, 5, 5, 9)); | |
3998 | test_all(); | |
3999 | return boost::report_errors(); | |
4000 | } |