1 //////////////////////////////////////////////////////////////////////////////
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)
8 // See http://www.boost.org/libs/container for documentation.
10 //////////////////////////////////////////////////////////////////////////////
12 #include <boost/core/lightweight_test.hpp>
13 #include <cstring> // memcmp
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"
27 #include <boost/algorithm/cxx14/equal.hpp>
29 #define BOOST_CONTAINER_DEVECTOR_ALLOC_STATS
30 #include <boost/container/devector.hpp>
31 #undef BOOST_CONTAINER_DEVECTOR_ALLOC_STATS
33 #include "test_util.hpp"
34 #include "test_elem.hpp"
35 #include "input_iterator.hpp"
37 using namespace boost::container
;
39 struct boost_container_devector
;
42 #pragma warning (push)
43 #pragma warning (disable : 4127) // conditional expression is constant
51 struct alloc_propagate_base
<boost_container_devector
>
53 template <class T
, class Allocator
>
56 typedef devector
<T
, Allocator
> type
;
60 }}} //namespace boost::container::test {
62 struct different_growth_policy
64 template <typename SizeType
>
65 static SizeType
new_capacity(SizeType capacity
)
67 return (capacity
) ? capacity
* 4u : 32u;
73 template <class Devector
> void test_constructor_default()
77 BOOST_TEST(a
.empty());
78 BOOST_TEST(a
.get_alloc_count() == 0u);
79 BOOST_TEST(a
.capacity() == 0u);
82 template <class Devector
> void test_constructor_allocator()
84 typename
Devector::allocator_type alloc_template
;
86 Devector
a(alloc_template
);
88 BOOST_TEST(a
.empty());
89 BOOST_TEST(a
.get_alloc_count() == 0u);
90 BOOST_TEST(a
.capacity() == 0u);
93 template <class Devector
> void test_constructor_reserve_only()
96 Devector
a(16, reserve_only_tag_t());
97 BOOST_TEST(a
.size() == 0u);
98 BOOST_TEST(a
.capacity() >= 16u);
102 Devector
b(0, reserve_only_tag_t());
103 BOOST_TEST(b
.get_alloc_count() == 0u);
107 template <class Devector
> void test_constructor_reserve_only_front_back()
110 Devector
a(8, 8, reserve_only_tag_t());
111 BOOST_TEST(a
.size() == 0u);
112 BOOST_TEST(a
.capacity() >= 16u);
114 for (int i
= 8; i
; --i
)
119 for (int i
= 9; i
< 17; ++i
)
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);
130 Devector
b(0, 0, reserve_only_tag_t());
131 BOOST_TEST(b
.get_alloc_count() == 0u);
135 template <class Devector
> void test_constructor_n()
139 const int expected
[] = {0, 0, 0, 0, 0, 0, 0, 0};
140 test_equal_range(a
, expected
);
147 BOOST_TEST(b
.get_alloc_count() == 0u);
150 #ifndef BOOST_NO_EXCEPTIONS
151 typedef typename
Devector::value_type T
;
153 BOOST_IF_CONSTEXPR (! boost::move_detail::is_nothrow_default_constructible
<T
>::value
)
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();
160 #endif //#ifndef BOOST_NO_EXCEPTIONS
163 template <class Devector
> void test_constructor_n_copy_throwing(dtl::true_
)
165 #ifndef BOOST_NO_EXCEPTIONS
166 typedef typename
Devector::value_type T
;
167 test_elem_throw::on_copy_after(4);
169 BOOST_TEST_THROWS(Devector(8, x
), test_exception
);
170 test_elem_throw::do_not_throw();
171 #endif //#ifndef BOOST_NO_EXCEPTIONS
175 template <class Devector
> void test_constructor_n_copy_throwing(dtl::false_
)
178 template <class Devector
> void test_constructor_n_copy()
180 typedef typename
Devector::value_type T
;
184 const int expected
[] = {9, 9, 9, 9, 9, 9, 9, 9};
185 test_equal_range(a
, expected
);
193 BOOST_TEST(b
.get_alloc_count() == 0u);
196 test_constructor_n_copy_throwing
<Devector
>
197 (dtl::bool_
<! boost::move_detail::is_nothrow_copy_constructible
<T
>::value
>());
199 BOOST_TEST(test_elem_base::no_living_elem());
202 template <class Devector
> void test_constructor_input_range()
204 typedef typename
Devector::value_type T
;
206 devector
<T
> expected
; get_range
<devector
<T
> >(16, expected
);
207 devector
<T
> input
= expected
;
209 input_iterator
<Devector
> input_begin
= make_input_iterator(input
, input
.begin());
210 input_iterator
<Devector
> input_end
= make_input_iterator(input
, input
.end());
212 Devector
a(input_begin
, input_end
);
213 BOOST_TEST(a
== expected
);
218 input_iterator
<Devector
> input_begin
= make_input_iterator(input
, input
.begin());
220 Devector
b(input_begin
, input_begin
);
223 BOOST_TEST(b
.get_alloc_count() == 0u);
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)
231 devector<T> input; get_range<devector<T> >(16, input);
233 input_iterator<Devector> input_begin = make_input_iterator(input, input.begin());
234 input_iterator<Devector> input_end = make_input_iterator(input, input.end());
236 test_elem_throw::on_copy_after(4);
238 BOOST_TEST_THROWS(Devector c(input_begin, input_end), test_exception);
241 BOOST_TEST(test_elem_base::no_living_elem());
242 #endif //#ifndef BOOST_NO_EXCEPTIONS
247 void test_constructor_forward_range_throwing(dtl::true_
)
250 void test_constructor_forward_range_throwing(dtl::false_
)
253 template <class Devector
> void test_constructor_forward_range()
255 typedef typename
Devector::value_type T
;
256 boost::container::list
<T
> ncx
;
265 const boost::container::list
<T
> &x
= ncx
;
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();
276 Devector
b(x
.begin(), x
.begin());
279 BOOST_TEST(b
.get_alloc_count() == 0u);
282 #ifndef BOOST_NO_EXCEPTIONS
283 BOOST_IF_CONSTEXPR (! boost::move_detail::is_nothrow_copy_constructible
<T
>::value
)
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();
289 #endif //#ifndef BOOST_NO_EXCEPTIONS
292 template <class Devector
> void test_constructor_pointer_range()
294 typedef typename
Devector::value_type T
;
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();
301 Devector
a(xbeg
, xend
);
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);
309 Devector
b(xbeg
, xbeg
);
312 BOOST_TEST(b
.get_alloc_count() == 0u);
315 #ifndef BOOST_NO_EXCEPTIONS
316 if (! boost::move_detail::is_nothrow_copy_constructible
<T
>::value
)
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();
322 #endif //#ifndef BOOST_NO_EXCEPTIONS
325 template <class Devector
> void test_copy_constructor()
332 BOOST_TEST(b
.get_alloc_count() == 0u);
336 Devector a
; get_range
<Devector
>(8, 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);
343 #ifndef BOOST_NO_EXCEPTIONS
344 typedef typename
Devector::value_type T
;
346 if (! boost::move_detail::is_nothrow_copy_constructible
<T
>::value
)
348 Devector a
; get_range
<Devector
>(8, a
);
350 test_elem_throw::on_copy_after(4);
351 BOOST_TEST_THROWS(Devector
b(a
), test_exception
);
352 test_elem_throw::do_not_throw();
354 #endif //#ifndef BOOST_NO_EXCEPTIONS
357 template <class Devector
> void test_move_constructor()
361 Devector
b(boost::move(a
));
363 BOOST_TEST(a
.empty());
364 BOOST_TEST(b
.empty());
368 Devector a
; get_range
<Devector
>(1, 5, 5, 9, a
);
369 Devector
b(boost::move(a
));
371 const int expected
[] = {1, 2, 3, 4, 5, 6, 7, 8};
372 test_equal_range(b
, expected
);
374 // a is unspecified but valid state
376 BOOST_TEST(a
.empty());
380 Devector a
; get_range
<Devector
>(32, a
);
381 Devector
b(boost::move(a
));
383 boost::container::vector
<int> expected
; get_range
<boost::container::vector
<int> >(32, expected
);
384 test_equal_range(b
, expected
);
386 // a is unspecified but valid state
388 BOOST_TEST(a
.empty());
392 template <class Devector
> void test_destructor()
396 Devector b
; get_range
<Devector
>(3, b
);
399 template <class Devector
> void test_assignment()
401 const typename
Devector::size_type alloc_count
=
402 boost::container::allocator_traits
403 < typename
Devector::allocator_type
>::propagate_on_container_copy_assignment::value
;
405 { // assign to empty (maybe small)
407 Devector c
; get_range
<Devector
>(6, c
);
411 const int expected
[] = {1, 2, 3, 4, 5, 6};
412 test_equal_range(a
, expected
);
415 { // assign from empty
416 Devector a
; get_range
<Devector
>(6, a
);
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
;
430 const int expected
[] = {1, 2, 3, 4, 5, 6};
431 test_equal_range(a
, expected
);
434 { // assign to free front
435 Devector a
; get_range
<Devector
>(11, 15, 15, 19, a
);
437 a
.reset_alloc_stats();
439 Devector c
; get_range
<Devector
>(6, c
);
440 const Devector
&b
= c
;
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
);
448 { // assignment overlaps contents
449 Devector a
; get_range
<Devector
>(11, 15, 15, 19, a
);
451 a
.reset_alloc_stats();
453 Devector c
; get_range
<Devector
>(6, c
);
454 const Devector
&b
= c
;
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
);
462 { // assignment exceeds contents
463 Devector a
; get_range
<Devector
>(11, 13, 13, 15, a
);
466 a
.reset_alloc_stats();
468 Devector c
; get_range
<Devector
>(12, c
);
469 const Devector
&b
= c
;
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
);
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
)
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
;
486 test_elem_throw::on_copy_after(3);
487 BOOST_TEST_THROWS(a
= b
, test_exception
);
488 test_elem_throw::do_not_throw();
490 const int expected
[] = {1, 2, 3, 4, 5, 6};
491 test_equal_range(a
, expected
);
493 #endif //#ifndef BOOST_NO_EXCEPTIONS
496 template <class Devector
> void test_move_assignment_throwing(dtl::true_
)
497 // move should be used on the slow path
499 Devector a
; get_range
<Devector
>(11, 15, 15, 19, a
);
500 Devector b
; get_range
<Devector
>(6, b
);
502 test_elem_throw::on_copy_after(3);
504 test_elem_throw::do_not_throw();
506 const int expected
[] = {1, 2, 3, 4, 5, 6};
507 test_equal_range(a
, expected
);
513 template <class Devector
> void test_move_assignment_throwing(dtl::false_
)
516 template <class Devector
> void test_move_assignment()
518 { // assign to empty (maybe small)
520 Devector b
; get_range
<Devector
>(6, b
);
524 const int expected
[] = {1, 2, 3, 4, 5, 6};
525 test_equal_range(a
, expected
);
527 // b is in unspecified but valid state
532 { // assign from empty
533 Devector a
; get_range
<Devector
>(6, a
);
542 { // assign to non-empty
543 Devector a
; get_range
<Devector
>(11, 15, 15, 19, a
);
544 Devector b
; get_range
<Devector
>(6, b
);
547 const int expected
[] = {1, 2, 3, 4, 5, 6};
548 test_equal_range(a
, expected
);
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
>());
559 template <class Devector
> void test_il_assignment()
561 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
563 { // assign to empty (maybe small)
565 a
= {1, 2, 3, 4, 5, 6 };
566 test_equal_range(a
, {1, 2, 3, 4, 5, 6});
569 { // assign from empty
570 Devector a
; get_range
<Devector
>(6, a
);
576 { // assign to non-empty
577 Devector a
; get_range
<Devector
>(11, 15, 15, 19, a
);
579 a
= {1, 2, 3, 4, 5, 6};
581 test_equal_range(a
, {1, 2, 3, 4, 5, 6});
584 { // assign to free front
585 Devector a
; get_range
<Devector
>(11, 15, 15, 19, a
);
587 a
.reset_alloc_stats();
589 a
= {1, 2, 3, 4, 5, 6};
591 test_equal_range(a
, {1, 2, 3, 4, 5, 6});
592 BOOST_TEST(a
.get_alloc_count() == 0u);
595 { // assignment overlaps contents
596 Devector a
; get_range
<Devector
>(11, 15, 15, 19, a
);
598 a
.reset_alloc_stats();
600 a
= {1, 2, 3, 4, 5, 6};
602 test_equal_range(a
, {1, 2, 3, 4, 5, 6});
603 BOOST_TEST(a
.get_alloc_count() == 0u);
606 { // assignment exceeds contents
607 Devector a
; get_range
<Devector
>(11, 13, 13, 15, a
);
610 a
.reset_alloc_stats();
612 a
= {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
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);
618 #ifndef BOOST_NO_EXCEPTIONS
619 typedef typename
Devector::value_type T
;
620 if (! boost::move_detail::is_nothrow_copy_constructible
<T
>::value
)
622 // strong guarantee if reallocation is needed (no guarantee otherwise)
623 Devector a
; get_range
<Devector
>(6, a
);
625 test_elem_throw::on_copy_after(3);
629 a
= {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
632 BOOST_CATCH(const test_exception
&) {}
634 test_elem_throw::do_not_throw();
636 test_equal_range(a
, {1, 2, 3, 4, 5, 6});
638 #endif //BOOST_NO_EXCEPTIONS
639 #endif //#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
642 template <class Devector
> void test_assign_input_range()
644 typedef typename
Devector::value_type T
;
646 { // assign to empty, keep it small
647 devector
<T
> expected
; get_range
<Devector
>(1, 13, 13, 25, expected
);
648 devector
<T
> input
= expected
;
650 input_iterator
<Devector
> input_begin
= make_input_iterator(input
, input
.begin());
651 input_iterator
<Devector
> input_end
= make_input_iterator(input
, input
.end());
654 a
.reset_alloc_stats();
655 a
.assign(input_begin
, input_end
);
657 BOOST_TEST(a
== expected
);
660 { // assign to empty (maybe small)
661 devector
<T
> input
; get_range
<devector
<T
> >(6, input
);
663 input_iterator
<Devector
> input_begin
= make_input_iterator(input
, input
.begin());
664 input_iterator
<Devector
> input_end
= make_input_iterator(input
, input
.end());
668 a
.assign(input_begin
, input_end
);
669 const int expected
[] = {1, 2, 3, 4, 5, 6};
670 test_equal_range(a
, expected
);
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());
677 Devector a
; get_range
<Devector
>(6, a
);
678 a
.assign(input_begin
, input_begin
);
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());
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
);
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());
699 Devector a
; get_range
<Devector
>(11, 15, 15, 19, a
);
701 a
.reset_alloc_stats();
703 a
.assign(input_begin
, input_end
);
704 const int expected
[] = {1, 2, 3, 4, 5, 6};
705 test_equal_range(a
, expected
);
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());
713 Devector a
; get_range
<Devector
>(11, 15, 15, 19, a
);
715 a
.reset_alloc_stats();
717 a
.assign(input_begin
, input_end
);
718 const int expected
[] = {1, 2, 3, 4, 5, 6};
719 test_equal_range(a
, expected
);
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());
727 Devector a
; get_range
<Devector
>(11, 13, 13, 15, a
);
730 a
.reset_alloc_stats();
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
);
737 #ifndef BOOST_NO_EXCEPTIONS
738 if (! boost::move_detail::is_nothrow_copy_constructible
<T
>::value
)
740 // strong guarantee if reallocation is needed (no guarantee otherwise)
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());
746 Devector a
; get_range
<Devector
>(6, a
);
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();
752 const int expected
[] = {1, 2, 3, 4, 5, 6};
753 test_equal_range(a
, expected
);
755 #endif //#ifndef BOOST_NO_EXCEPTIONS
758 template <class Devector
> void test_assign_forward_range_throwing(dtl::false_
)
761 template <class Devector
> void test_assign_forward_range()
763 typedef typename
Devector::value_type T
;
764 typedef boost::container::list
<T
> List
;
766 boost::container::list
<T
> x
;
767 typedef typename
List::iterator list_iterator
;
781 list_iterator one
= x
.begin();
782 list_iterator six
= one
;
783 list_iterator twelve
= one
;
785 iterator_advance(six
, 6);
786 iterator_advance(twelve
, 12);
788 { // assign to empty (maybe small)
793 const int expected
[] = {1, 2, 3, 4, 5, 6};
794 test_equal_range(a
, expected
);
797 { // assign from empty
798 Devector a
; get_range
<Devector
>(6, a
);
805 { // assign to non-empty
806 Devector a
; get_range
<Devector
>(11, 15, 15, 19, a
);
810 const int expected
[] = {1, 2, 3, 4, 5, 6};
811 test_equal_range(a
, expected
);
814 { // assign to free front
815 Devector a
; get_range
<Devector
>(11, 15, 15, 19, a
);
817 a
.reset_alloc_stats();
821 const int expected
[] = {1, 2, 3, 4, 5, 6};
822 test_equal_range(a
, expected
);
823 BOOST_TEST(a
.get_alloc_count() == 0u);
826 { // assignment overlaps contents
827 Devector a
; get_range
<Devector
>(11, 15, 15, 19, a
);
829 a
.reset_alloc_stats();
833 const int expected
[] = {1, 2, 3, 4, 5, 6};
834 test_equal_range(a
, expected
);
835 BOOST_TEST(a
.get_alloc_count() == 0u);
838 { // assignment exceeds contents
839 Devector a
; get_range
<Devector
>(11, 13, 13, 15, a
);
842 a
.reset_alloc_stats();
844 a
.assign(one
, twelve
);
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);
851 #ifndef BOOST_NO_EXCEPTIONS
852 BOOST_IF_CONSTEXPR(! boost::move_detail::is_nothrow_copy_constructible
<T
>::value
)
854 // strong guarantee if reallocation is needed (no guarantee otherwise)
855 Devector a
; get_range
<Devector
>(6, a
);
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();
861 const int expected
[] = {1, 2, 3, 4, 5, 6};
862 test_equal_range(a
, expected
);
864 #endif //#ifndef BOOST_NO_EXCEPTIONS
867 template <class Devector
> void test_assign_pointer_range()
869 typedef typename
Devector::value_type T
;
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;
876 { // assign to empty (maybe small)
881 const int expected
[] = {1, 2, 3, 4, 5, 6};
882 test_equal_range(a
, expected
);
885 { // assign from empty
886 Devector a
; get_range
<Devector
>(6, a
);
893 { // assign to non-empty
894 Devector a
; get_range
<Devector
>(11, 15, 15, 19, a
);
898 const int expected
[] = {1, 2, 3, 4, 5, 6};
899 test_equal_range(a
, expected
);
902 { // assign to free front
903 Devector a
; get_range
<Devector
>(11, 15, 15, 19, a
);
905 a
.reset_alloc_stats();
909 const int expected
[] = {1, 2, 3, 4, 5, 6};
910 test_equal_range(a
, expected
);
911 BOOST_TEST(a
.get_alloc_count() == 0u);
914 { // assignment overlaps contents
915 Devector a
; get_range
<Devector
>(11, 15, 15, 19, a
);
917 a
.reset_alloc_stats();
921 const int expected
[] = {1, 2, 3, 4, 5, 6};
922 test_equal_range(a
, expected
);
923 BOOST_TEST(a
.get_alloc_count() == 0u);
926 { // assignment exceeds contents
927 Devector a
; get_range
<Devector
>(11, 13, 13, 15, a
);
930 a
.reset_alloc_stats();
932 a
.assign(one
, twelve
);
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);
939 #ifndef BOOST_NO_EXCEPTIONS
940 if (! boost::move_detail::is_nothrow_copy_constructible
<T
>::value
)
942 // strong guarantee if reallocation is needed (no guarantee otherwise)
943 Devector a
; get_range
<Devector
>(6, a
);
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();
949 const int expected
[] = {1, 2, 3, 4, 5, 6};
950 test_equal_range(a
, expected
);
952 #endif //#ifndef BOOST_NO_EXCEPTIONS
955 template <class Devector
> void test_assign_n()
957 typedef typename
Devector::value_type T
;
959 { // assign to empty (maybe small)
964 const int expected
[] = {9, 9, 9, 9, 9, 9};
965 test_equal_range(a
, expected
);
968 { // assign from empty
969 Devector a
; get_range
<Devector
>(6, a
);
976 { // assign to non-empty
977 Devector a
; get_range
<Devector
>(11, 15, 15, 19, a
);
981 const int expected
[] = {9, 9, 9, 9, 9, 9};
982 test_equal_range(a
, expected
);
985 { // assign to free front
986 Devector a
; get_range
<Devector
>(11, 15, 15, 19, a
);
988 a
.reset_alloc_stats();
992 const int expected
[] = {9, 9, 9, 9, 9, 9};
993 test_equal_range(a
, expected
);
994 BOOST_TEST(a
.get_alloc_count() == 0u);
997 { // assignment overlaps contents
998 Devector a
; get_range
<Devector
>(11, 15, 15, 19, a
);
1000 a
.reset_alloc_stats();
1004 const int expected
[] = {9, 9, 9, 9, 9, 9};
1005 test_equal_range(a
, expected
);
1006 BOOST_TEST(a
.get_alloc_count() == 0u);
1009 { // assignment exceeds contents
1010 Devector a
; get_range
<Devector
>(11, 13, 13, 15, a
);
1013 a
.reset_alloc_stats();
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);
1022 #ifndef BOOST_NO_EXCEPTIONS
1023 if (! boost::move_detail::is_nothrow_copy_constructible
<T
>::value
)
1025 // strong guarantee if reallocation is needed (no guarantee otherwise)
1026 Devector a
; get_range
<Devector
>(6, a
);
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();
1032 const int expected
[] = {1, 2, 3, 4, 5, 6};
1033 test_equal_range(a
, expected
);
1035 #endif //#ifndef BOOST_NO_EXCEPTIONS
1038 template <class Devector
> void test_assign_il()
1040 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
1042 { // assign to empty (maybe small)
1045 a
.assign({1, 2, 3, 4, 5, 6});
1047 test_equal_range(a
, {1, 2, 3, 4, 5, 6});
1050 { // assign from empty
1051 Devector a
; get_range
<Devector
>(6, a
);
1055 test_equal_range(a
);
1058 { // assign to non-empty
1059 Devector a
; get_range
<Devector
>(11, 15, 15, 19, a
);
1061 a
.assign({1, 2, 3, 4, 5, 6});
1063 test_equal_range(a
, {1, 2, 3, 4, 5, 6});
1066 { // assign to free front
1067 Devector a
; get_range
<Devector
>(11, 15, 15, 19, a
);
1069 a
.reset_alloc_stats();
1071 a
.assign({1, 2, 3, 4, 5, 6});
1073 test_equal_range(a
, {1, 2, 3, 4, 5, 6});
1074 BOOST_TEST(a
.get_alloc_count() == 0u);
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();
1082 a
.assign({1, 2, 3, 4, 5, 6});
1084 test_equal_range(a
, {1, 2, 3, 4, 5, 6});
1085 BOOST_TEST(a
.get_alloc_count() == 0u);
1088 { // assignment exceeds contents
1089 Devector a
; get_range
<Devector
>(11, 13, 13, 15, a
);
1092 a
.reset_alloc_stats();
1094 a
.assign({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12});
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);
1100 #ifndef BOOST_NO_EXCEPTIONS
1101 typedef typename
Devector::value_type T
;
1102 if (! boost::move_detail::is_nothrow_copy_constructible
<T
>::value
)
1104 // strong guarantee if reallocation is needed (no guarantee otherwise)
1105 Devector a
; get_range
<Devector
>(6, a
);
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();
1111 test_equal_range(a
, {1, 2, 3, 4, 5, 6});
1113 #endif //#ifndef BOOST_NO_EXCEPTIONS
1114 #endif //#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
1117 template <class Devector
> void test_get_allocator()
1120 (void) a
.get_allocator();
1123 template <class Devector
> void test_begin_end()
1125 boost::container::vector
<int> expected
; get_range
<boost::container::vector
<int> >(10, expected
);
1127 Devector actual
; get_range
<Devector
>(10, actual
);
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()));
1136 Devector cactual
; get_range
<Devector
>(10, cactual
);
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()));
1143 template <class Devector
> void test_empty()
1145 typedef typename
Devector::value_type T
;
1148 BOOST_TEST(a
.empty());
1151 BOOST_TEST(! a
.empty());
1154 BOOST_TEST(a
.empty());
1156 Devector
b(16, reserve_only_tag_t());
1157 BOOST_TEST(b
.empty());
1159 Devector c
; get_range
<Devector
>(3, c
);
1160 BOOST_TEST(! c
.empty());
1163 //template <typename ST>
1164 //using gp_devector = devector<unsigned, different_growth_policy>;
1166 void test_max_size()
1168 gp_devector<unsigned char> a;
1169 BOOST_TEST(a.max_size() == (std::numeric_limits<unsigned char>::max)());
1171 gp_devector<unsigned short> b;
1172 BOOST_TEST(b.max_size() == (std::numeric_limits<unsigned short>::max)());
1174 gp_devector<unsigned int> c;
1175 BOOST_TEST(c.max_size() >= b.max_size());
1177 gp_devector<std::size_t> d;
1178 BOOST_TEST(d.max_size() >= c.max_size());
1182 void test_exceeding_max_size()
1184 #ifndef BOOST_NO_EXCEPTIONS
1185 using Devector = gp_devector<unsigned char>;
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
1193 template <class Devector
> void test_size()
1195 typedef typename
Devector::value_type T
;
1198 BOOST_TEST(a
.size() == 0u);
1201 BOOST_TEST(a
.size() == 1u);
1204 BOOST_TEST(a
.size() == 0u);
1206 Devector
b(16, reserve_only_tag_t());
1207 BOOST_TEST(b
.size() == 0u);
1209 Devector c
; get_range
<Devector
>(3, c
);
1210 BOOST_TEST(c
.size() == 3u);
1213 template <class Devector
> void test_capacity()
1216 BOOST_TEST(a
.capacity() == 0u);
1218 Devector
b(128, reserve_only_tag_t());
1219 BOOST_TEST(b
.capacity() >= 128u);
1221 Devector c
; get_range
<Devector
>(10, c
);
1222 BOOST_TEST(c
.capacity() >= 10u);
1225 template <class Devector
> void test_resize_front_throwing(dtl::true_
)
1227 #ifndef BOOST_NO_EXCEPTIONS
1228 typedef typename
Devector::iterator iterator
;
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();
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();
1238 test_equal_range(d
, d_origi
);
1239 BOOST_TEST(origi_begin
== d
.begin());
1240 #endif //#ifndef BOOST_NO_EXCEPTIONS
1243 template <class Devector
> void test_resize_front_throwing(dtl::false_
)
1247 template <class Devector
> void test_resize_front()
1249 typedef typename
Devector::value_type T
;
1251 // size < required, alloc needed
1253 Devector a
; get_range
<Devector
>(5, a
);
1255 const int expected
[] = {0, 0, 0, 1, 2, 3, 4, 5};
1256 test_equal_range(a
, expected
);
1259 // size < required, but capacity provided
1261 Devector b
; get_range
<Devector
>(5, b
);
1262 b
.reserve_front(16);
1264 const int expected
[] = {0, 0, 0, 1, 2, 3, 4, 5};
1265 test_equal_range(b
, expected
);
1268 // size < required, move would throw
1269 if (! boost::is_nothrow_move_constructible<T>::value && std::is_copy_constructible<T>::value)
1271 Devector c; get_range<Devector>(5, c);
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();
1277 test_equal_range(c, {0, 0, 0, 1, 2, 3, 4, 5});
1281 test_resize_front_throwing
<Devector
>
1282 (dtl::bool_
<! boost::move_detail::is_nothrow_default_constructible
<T
>::value
>());
1286 Devector e
; get_range
<Devector
>(6, e
);
1288 const int expected
[] = {3, 4, 5, 6};
1289 test_equal_range(e
, expected
);
1292 // size < required, does not fit front small buffer
1294 boost::container::vector
<int> expected(128);
1296 g
.resize_front(128);
1297 test_equal_range(g
, expected
);
1302 Devector e
; get_range
<Devector
>(6, e
);
1304 const int expected
[] = {1, 2, 3, 4, 5, 6};
1305 test_equal_range(e
, expected
);
1309 template <class Devector
> void test_resize_front_copy_throwing(dtl::true_
)
1311 #ifndef BOOST_NO_EXCEPTIONS
1312 typedef typename
Devector::value_type T
;
1313 typedef typename
Devector::iterator iterator
;
1315 // size < required, copy throws
1317 Devector c
; get_range
<Devector
>(5, c
);
1318 boost::container::vector
<int> c_origi
; get_range
<boost::container::vector
<int> >(5, c_origi
);
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();
1324 test_equal_range(c
, c_origi
);
1327 // size < required, copy throws, but later
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();
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();
1337 test_equal_range(c
, c_origi
);
1338 BOOST_TEST(origi_begin
== c
.begin());
1340 #endif //#ifndef BOOST_NO_EXCEPTIONS
1343 template <class Devector
> void test_resize_front_copy_throwing(dtl::false_
)
1346 template <class Devector
> void test_resize_front_copy()
1348 typedef typename
Devector::value_type T
;
1350 // size < required, alloc needed
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
);
1358 // size < required, but capacity provided
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
);
1367 test_resize_front_copy_throwing
<Devector
>
1368 (dtl::bool_
<! boost::move_detail::is_nothrow_copy_constructible
<T
>::value
>());
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
);
1378 // size < required, does not fit front small buffer
1380 boost::container::vector
<int> expected(128, 9);
1382 g
.resize_front(128, T(9));
1383 test_equal_range(g
, expected
);
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
);
1394 // size < required, tmp is already inserted
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
);
1404 template <class Devector
> void test_resize_back_throwing(dtl::true_
)
1405 // size < required, constructor throws
1407 #ifndef BOOST_NO_EXCEPTIONS
1408 typedef typename
Devector::iterator iterator
;
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();
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();
1418 test_equal_range(d
, d_origi
);
1419 BOOST_TEST(origi_begin
== d
.begin());
1420 #endif //#ifndef BOOST_NO_EXCEPTIONS
1423 template <class Devector
> void test_resize_back_throwing(dtl::false_
)
1426 template <class Devector
> void test_resize_back()
1428 typedef typename
Devector::value_type T
;
1430 // size < required, alloc needed
1432 Devector a
; get_range
<Devector
>(5, a
);
1434 const int expected
[] = {1, 2, 3, 4, 5, 0, 0, 0};
1435 test_equal_range(a
, expected
);
1438 // size < required, but capacity provided
1440 Devector b
; get_range
<Devector
>(5, b
);
1443 const int expected
[] = {1, 2, 3, 4, 5, 0, 0, 0};
1444 test_equal_range(b
, expected
);
1447 // size < required, move would throw
1448 if (! boost::is_nothrow_move_constructible<T>::value && std::is_copy_constructible<T>::value)
1450 Devector c; get_range<Devector>(5, c);
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();
1456 test_equal_range(c, {1, 2, 3, 4, 5, 0, 0, 0});
1460 test_resize_back_throwing
<Devector
>
1461 (dtl::bool_
<! boost::move_detail::is_nothrow_default_constructible
<T
>::value
>());
1465 Devector e
; get_range
<Devector
>(6, e
);
1467 const int expected
[] = {1, 2, 3, 4};
1468 test_equal_range(e
, expected
);
1471 // size < required, does not fit front small buffer
1473 boost::container::vector
<int> expected(128);
1476 test_equal_range(g
, expected
);
1481 Devector e
; get_range
<Devector
>(6, e
);
1483 const int expected
[] = {1, 2, 3, 4, 5, 6};
1484 test_equal_range(e
, expected
);
1488 template <class Devector
> void test_resize_back_copy_throwing(dtl::true_
)
1490 #ifndef BOOST_NO_EXCEPTIONS
1491 typedef typename
Devector::value_type T
;
1492 typedef typename
Devector::iterator iterator
;
1494 // size < required, copy throws
1496 Devector c
; get_range
<Devector
>(5, c
);
1497 boost::container::vector
<int> c_origi
; get_range
<boost::container::vector
<int> >(5, c_origi
);
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();
1503 test_equal_range(c
, c_origi
);
1506 // size < required, copy throws, but later
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();
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();
1516 test_equal_range(c
, c_origi
);
1517 BOOST_TEST(origi_begin
== c
.begin());
1520 // size < required, copy throws
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();
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();
1530 test_equal_range(c
, c_origi
);
1531 BOOST_TEST(origi_begin
== c
.begin());
1533 #endif //#ifndef BOOST_NO_EXCEPTIONS
1536 template <class Devector
> void test_resize_back_copy_throwing(dtl::false_
)
1539 template <class Devector
> void test_resize_back_copy()
1541 typedef typename
Devector::value_type T
;
1543 // size < required, alloc needed
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
);
1551 // size < required, but capacity provided
1553 Devector b
; get_range
<Devector
>(5, b
);
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
);
1560 test_resize_back_copy_throwing
<Devector
>
1561 (dtl::bool_
<! boost::move_detail::is_nothrow_copy_constructible
<T
>::value
>());
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
);
1571 // size < required, does not fit front small buffer
1573 boost::container::vector
<int> expected(128, 9);
1575 g
.resize_back(128, T(9));
1576 test_equal_range(g
, expected
);
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
);
1587 // size < required, tmp is already inserted
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
);
1598 template <class Devector> void test_constructor_unsafe_uninitialized()
1601 Devector a(8, unsafe_uninitialized_tag_t());
1602 BOOST_TEST(a.size() == 8u);
1604 for (int i = 0; i < 8; ++i)
1606 new (a.data() + i) T(i+1);
1609 const int expected [] = {1, 2, 3, 4, 5, 6, 7, 8};
1610 test_equal_range(a, expected);
1614 Devector b(0, unsafe_uninitialized_tag_t());
1615 BOOST_TEST(b.get_alloc_count() == 0u);
1621 template <class Devector> void test_unsafe_uninitialized_resize_front()
1623 typedef typename Devector::value_type T;
1626 Devector a; get_range<Devector>(8, a);
1627 a.reset_alloc_stats();
1629 a.unsafe_uninitialized_resize_front(a.size());
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);
1636 { // grow (maybe has enough capacity)
1637 Devector b; get_range<Devector>(0, 0, 5, 9, b);
1639 b.unsafe_uninitialized_resize_front(8);
1641 for (int i = 0; i < 4; ++i)
1643 new (b.data() + i) T(i+1);
1646 const int expected [] = {1, 2, 3, 4, 5, 6, 7, 8};
1647 test_equal_range(b, expected);
1650 { // shrink uninitialized
1651 Devector c; get_range<Devector>(8, c);
1653 c.unsafe_uninitialized_resize_front(16);
1654 c.unsafe_uninitialized_resize_front(8);
1656 const int expected [] = {1, 2, 3, 4, 5, 6, 7, 8};
1657 test_equal_range(c, expected );
1660 if (std::is_trivially_destructible<T>::value)
1663 Devector d; get_range<Devector>(8, d);
1665 d.unsafe_uninitialized_resize_front(4);
1667 test_equal_range(d, {5, 6, 7, 8});
1671 template <class Devector> void test_unsafe_uninitialized_resize_back()
1673 typedef typename Devector::value_type T;
1676 Devector a; get_range<Devector>(8, a);
1677 a.reset_alloc_stats();
1679 a.unsafe_uninitialized_resize_back(a.size());
1681 test_equal_range(a, {1, 2, 3, 4, 5, 6, 7, 8});
1682 BOOST_TEST(a.get_alloc_count() == 0u);
1685 { // grow (maybe has enough capacity)
1686 Devector b; get_range<Devector>(1, 5, 0, 0, b);
1688 b.unsafe_uninitialized_resize_back(8);
1690 for (int i = 0; i < 4; ++i)
1692 new (b.data() + 4 + i) T(i+5);
1695 test_equal_range(b, {1, 2, 3, 4, 5, 6, 7, 8});
1698 { // shrink uninitialized
1699 Devector c; get_range<Devector>(8, c);
1701 c.unsafe_uninitialized_resize_back(16);
1702 c.unsafe_uninitialized_resize_back(8);
1704 test_equal_range(c, {1, 2, 3, 4, 5, 6, 7, 8});
1707 if (std::is_trivially_destructible<T>::value)
1710 Devector d; get_range<Devector>(8, d);
1712 d.unsafe_uninitialized_resize_back(4);
1714 test_equal_range(d, {1, 2, 3, 4});
1719 template <class Devector
> void test_reserve_front()
1721 typedef typename
Devector::value_type value_type
;
1724 a
.reserve_front(100);
1725 for (unsigned i
= 0; i
< 100u; ++i
)
1727 a
.push_front(value_type(i
));
1730 BOOST_TEST(a
.get_alloc_count() == 1u);
1737 b
.reserve_front(16);
1740 template <class Devector
> void test_reserve_back()
1743 typedef typename
Devector::value_type value_type
;
1744 a
.reserve_back(100);
1745 for (unsigned i
= 0; i
< 100; ++i
)
1747 a
.push_back(value_type(i
));
1750 BOOST_TEST(a
.get_alloc_count() == 1u);
1760 template <typename Devector
>
1761 void test_shrink_to_fit_always()
1772 boost::container::vector
<unsigned> expected
;
1773 expected
.push_back(1);
1774 expected
.push_back(2);
1775 expected
.push_back(3);
1776 test_equal_range(a
, expected
);
1778 std::size_t exp_capacity
= 3u;
1779 BOOST_TEST(a
.capacity() == exp_capacity
);
1782 template <typename Devector
>
1783 void test_shrink_to_fit_never()
1794 boost::container::vector
<unsigned> expected
;
1795 expected
.emplace_back(1);
1796 expected
.emplace_back(2);
1797 expected
.emplace_back(3);
1798 test_equal_range(a
, expected
);
1799 BOOST_TEST(a
.capacity() == 100u);
1802 void shrink_to_fit()
1804 typedef devector
<unsigned> devector_u_shr
;
1805 typedef devector
<unsigned> small_devector_u_shr
;
1806 test_shrink_to_fit_always
<devector_u_shr
>();
1807 test_shrink_to_fit_always
<small_devector_u_shr
>();
1810 template <class Devector
> void test_index_operator()
1812 typedef typename
Devector::value_type T
;
1815 Devector a
; get_range
<Devector
>(5, a
);
1817 BOOST_TEST(a
[0] == 1);
1818 BOOST_TEST(a
[4] == 5);
1819 BOOST_TEST(&a
[3] == &a
[0] + 3);
1822 BOOST_TEST(a
[0] == 100);
1826 Devector b
; get_range
<Devector
>(5, b
);
1827 const Devector
&a
= b
;
1829 BOOST_TEST(a
[0] == 1);
1830 BOOST_TEST(a
[4] == 5);
1831 BOOST_TEST(&a
[3] == &a
[0] + 3);
1835 template <class Devector
> void test_at()
1837 #ifndef BOOST_NO_EXCEPTIONS
1838 typedef typename
Devector::value_type T
;
1841 Devector a
; get_range
<Devector
>(3, a
);
1843 BOOST_TEST(a
.at(0) == 1);
1845 BOOST_TEST(a
.at(0) == 100);
1847 BOOST_TEST_THROWS(a
.at(3), std::out_of_range
);
1851 Devector b
; get_range
<Devector
>(3, b
);
1852 const Devector
&a
= b
;
1854 BOOST_TEST(a
.at(0) == 1);
1856 BOOST_TEST_THROWS(a
.at(3), std::out_of_range
);
1858 #endif //#ifndef BOOST_NO_EXCEPTIONS
1861 template <class Devector
> void test_front()
1863 typedef typename
Devector::value_type T
;
1865 { // non-const front
1866 Devector a
; get_range
<Devector
>(3, a
);
1867 BOOST_TEST(a
.front() == 1);
1869 BOOST_TEST(a
.front() == 100);
1873 Devector b
; get_range
<Devector
>(3, b
); const Devector
&a
= b
;
1874 BOOST_TEST(a
.front() == 1);
1878 template <class Devector
> void test_back()
1880 typedef typename
Devector::value_type T
;
1883 Devector a
; get_range
<Devector
>(3, a
);
1884 BOOST_TEST(a
.back() == 3);
1886 BOOST_TEST(a
.back() == 100);
1890 Devector b
; get_range
<Devector
>(3, b
); const Devector
&a
= b
;
1891 BOOST_TEST(a
.back() == 3);
1897 unsigned c_array
[] = {1, 2, 3, 4};
1900 devector
<unsigned> a(c_array
, c_array
+ 4);
1901 BOOST_TEST(a
.data() == &a
.front());
1903 BOOST_TEST(std::memcmp(c_array
, a
.data(), 4 * sizeof(unsigned)) == 0);
1906 BOOST_TEST(a
.front() == 100u);
1910 const devector
<unsigned> a(c_array
, c_array
+ 4);
1911 BOOST_TEST(a
.data() == &a
.front());
1913 BOOST_TEST(std::memcmp(c_array
, a
.data(), 4 * sizeof(unsigned)) == 0);
1917 template <class Devector
> void test_emplace_front(dtl::true_
)
1919 #ifndef BOOST_NO_EXCEPTIONS
1920 typedef typename
Devector::iterator iterator
;
1922 Devector b
; get_range
<Devector
>(4, b
);
1923 iterator origi_begin
= b
.begin();
1925 test_elem_throw::on_ctor_after(1);
1926 BOOST_TEST_THROWS(b
.emplace_front(404), test_exception
);
1927 test_elem_throw::do_not_throw();
1929 iterator new_begin
= b
.begin();
1931 BOOST_TEST(origi_begin
== new_begin
);
1932 BOOST_TEST(b
.size() == 4u);
1933 #endif //#ifndef BOOST_NO_EXCEPTIONS
1936 template <class Devector
> void test_emplace_front(dtl::false_
)
1940 template <class Devector
> void test_emplace_front()
1942 typedef typename
Devector::value_type T
;
1951 boost::container::vector
<int> expected
; get_range
<boost::container::vector
<int> >(3, expected
);
1953 test_equal_range(a
, expected
);
1956 test_emplace_front
<Devector
>
1957 (dtl::bool_
<!boost::move_detail::is_nothrow_default_constructible
<T
>::value
>());
1960 template <class Devector
> void test_push_front()
1962 typedef typename
Devector::value_type T
;
1964 boost::container::vector
<int> expected
; get_range
<boost::container::vector
<int> >(16, expected
);
1965 std::reverse(expected
.begin(), expected
.end());
1968 for (int i
= 1; i
<= 16; ++i
)
1974 test_equal_range(a
, expected
);
1977 #ifndef BOOST_NO_EXCEPTIONS
1978 typedef typename
Devector::iterator iterator
;
1979 if (! boost::move_detail::is_nothrow_copy_constructible
<T
>::value
)
1981 Devector b
; get_range
<Devector
>(4, b
);
1982 iterator origi_begin
= b
.begin();
1986 test_elem_throw::on_copy_after(1);
1987 BOOST_TEST_THROWS(b
.push_front(elem
), test_exception
);
1988 test_elem_throw::do_not_throw();
1990 iterator new_begin
= b
.begin();
1992 BOOST_TEST(origi_begin
== new_begin
);
1993 BOOST_TEST(b
.size() == 4u);
1996 // test when tmp is already inserted
1998 Devector c
; get_range
<Devector
>(4, c
);
1999 const T
& tmp
= *(c
.begin() + 1);
2001 const int expected
[] = {2, 1, 2, 3, 4};
2002 test_equal_range(c
, expected
);
2004 #endif //#ifndef BOOST_NO_EXCEPTIONS
2007 template <class Devector
> void test_push_front_rvalue_throwing(dtl::true_
)
2009 #ifndef BOOST_NO_EXCEPTIONS
2010 typedef typename
Devector::value_type T
;
2011 typedef typename
Devector::iterator iterator
;
2013 Devector b
; get_range
<Devector
>(4, b
);
2014 iterator origi_begin
= b
.begin();
2016 test_elem_throw::on_move_after(1);
2017 BOOST_TEST_THROWS(b
.push_front(T(404)), test_exception
);
2018 test_elem_throw::do_not_throw();
2020 iterator new_begin
= b
.begin();
2022 BOOST_TEST(origi_begin
== new_begin
);
2023 BOOST_TEST(b
.size() == 4u);
2024 #endif //#ifndef BOOST_NO_EXCEPTIONS
2027 template <class Devector
> void test_push_front_rvalue_throwing(dtl::false_
)
2030 template <class Devector
> void test_push_front_rvalue()
2032 typedef typename
Devector::value_type T
;
2035 boost::container::vector
<int> expected
; get_range
<boost::container::vector
<int> >(16, expected
);
2038 for (int i
= 16; i
> 0; --i
)
2041 a
.push_front(boost::move(elem
));
2044 test_equal_range(a
, expected
);
2047 test_push_front_rvalue_throwing
<Devector
>(dtl::bool_
<! boost::is_nothrow_move_constructible
<T
>::value
>());
2050 template <class Devector
> void test_pop_front()
2056 BOOST_TEST(a
.empty());
2064 BOOST_TEST(b
.empty());
2068 BOOST_TEST(b
.empty());
2072 Devector c
; get_range
<Devector
>(20, c
);
2073 for (int i
= 0; i
< 20; ++i
)
2075 BOOST_TEST(!c
.empty());
2078 BOOST_TEST(c
.empty());
2082 template <class Devector
> void test_emplace_back_throwing(dtl::true_
)
2084 #ifndef BOOST_NO_EXCEPTIONS
2085 typedef typename
Devector::iterator iterator
;
2087 Devector b
; get_range
<Devector
>(4, b
);
2088 iterator origi_begin
= b
.begin();
2090 test_elem_throw::on_ctor_after(1);
2091 BOOST_TEST_THROWS(b
.emplace_back(404), test_exception
);
2092 test_elem_throw::do_not_throw();
2094 iterator new_begin
= b
.begin();
2096 BOOST_TEST(origi_begin
== new_begin
);
2097 BOOST_TEST(b
.size() == 4u);
2098 #endif //#ifndef BOOST_NO_EXCEPTIONS
2101 template <class Devector
> void test_emplace_back_throwing(dtl::false_
)
2104 template <class Devector
> void test_emplace_back()
2106 typedef typename
Devector::value_type T
;
2115 boost::container::vector
<int> expected
; get_range
<boost::container::vector
<int> >(3, expected
);
2117 test_equal_range
<Devector
>(a
, expected
);
2120 test_emplace_back_throwing
<Devector
>
2121 (dtl::bool_
<! boost::move_detail::is_nothrow_default_constructible
<T
>::value
>());
2124 template <class Devector
> void test_push_back_throwing(dtl::true_
)
2126 #ifndef BOOST_NO_EXCEPTIONS
2127 typedef typename
Devector::value_type T
;
2128 typedef typename
Devector::iterator iterator
;
2130 Devector b
; get_range
<Devector
>(4, b
);
2131 iterator origi_begin
= b
.begin();
2135 test_elem_throw::on_copy_after(1);
2136 BOOST_TEST_THROWS(b
.push_back(elem
), test_exception
);
2137 test_elem_throw::do_not_throw();
2139 iterator new_begin
= b
.begin();
2141 BOOST_TEST(origi_begin
== new_begin
);
2142 BOOST_TEST(b
.size() == 4u);
2143 #endif //#ifndef BOOST_NO_EXCEPTIONS
2146 template <class Devector
> void test_push_back_throwing(dtl::false_
)
2149 template <class Devector
> void test_push_back()
2151 typedef typename
Devector::value_type T
;
2153 boost::container::vector
<int> expected
; get_range
<boost::container::vector
<int> >(16, expected
);
2156 for (int i
= 1; i
<= 16; ++i
)
2162 test_equal_range(a
, expected
);
2165 test_push_back_throwing
<Devector
>(dtl::bool_
<! boost::move_detail::is_nothrow_copy_constructible
<T
>::value
>());
2167 // test when tmp is already inserted
2169 Devector c
; get_range
<Devector
>(4, c
);
2170 const T
& tmp
= *(c
.begin() + 1);
2172 const int expected
[] = {1, 2, 3, 4, 2};
2173 test_equal_range(c
, expected
);
2177 template <class Devector
> void test_push_back_rvalue_throwing(dtl::true_
)
2179 #ifndef BOOST_NO_EXCEPTIONS
2180 typedef typename
Devector::value_type T
;
2181 typedef typename
Devector::iterator iterator
;
2183 Devector b
; get_range
<Devector
>(4, b
);
2184 iterator origi_begin
= b
.begin();
2186 test_elem_throw::on_move_after(1);
2187 BOOST_TEST_THROWS(b
.push_back(T(404)), test_exception
);
2188 test_elem_throw::do_not_throw();
2190 iterator new_begin
= b
.begin();
2192 BOOST_TEST(origi_begin
== new_begin
);
2193 BOOST_TEST(b
.size() == 4u);
2194 #endif //#ifndef BOOST_NO_EXCEPTIONS
2197 template <class Devector
> void test_push_back_rvalue_throwing(dtl::false_
)
2200 template <class Devector
> void test_push_back_rvalue()
2202 typedef typename
Devector::value_type T
;
2205 boost::container::vector
<int> expected
; get_range
<boost::container::vector
<int> >(16, expected
);
2208 for (int i
= 1; i
<= 16; ++i
)
2211 a
.push_back(boost::move(elem
));
2214 test_equal_range(a
, expected
);
2217 test_push_back_rvalue_throwing
<Devector
>(dtl::bool_
<! boost::is_nothrow_move_constructible
<T
>::value
>());
2221 template <class Devector> void test_unsafe_push_front()
2223 typedef typename Devector::value_type T;
2224 typedef typename Devector::iterator iterator;
2227 boost::container::vector<int> expected; get_range<boost::container::vector<int> >(16, expected);
2228 std::reverse(expected.begin(), expected.end());
2230 a.reserve_front(16);
2232 for (std::size_t i = 1; i <= 16; ++i)
2235 a.unsafe_push_front(elem);
2238 test_equal_range(a, expected);
2241 #ifndef BOOST_NO_EXCEPTIONS
2242 if (! boost::move_detail::is_nothrow_copy_constructible<T>::value)
2244 Devector b; get_range<Devector>(4, b);
2246 iterator origi_begin = b.begin();
2250 test_elem_throw::on_copy_after(1);
2251 BOOST_TEST_THROWS(b.unsafe_push_front(elem), test_exception);
2252 test_elem_throw::do_not_throw();
2254 iterator new_begin = b.begin();
2256 BOOST_TEST(origi_begin == new_begin);
2257 BOOST_TEST(b.size() == 4u);
2259 #endif //#ifndef BOOST_NO_EXCEPTIONS
2262 template <class Devector> void test_unsafe_push_front_rvalue()
2264 typedef typename Devector::value_type T;
2267 boost::container::vector<int> expected; get_range<boost::container::vector<int> >(16, expected);
2268 std::reverse(expected.begin(), expected.end());
2270 a.reserve_front(16);
2272 for (std::size_t i = 1; i <= 16; ++i)
2275 a.unsafe_push_front(boost::move(elem));
2278 test_equal_range(a, expected);
2283 template <class Devector> void test_unsafe_push_back()
2285 typedef typename Devector::value_type T;
2286 typedef typename Devector::iterator iterator;
2289 boost::container::vector<int> expected; get_range<boost::container::vector<int> >(16, expected);
2293 for (std::size_t i = 1; i <= 16; ++i)
2296 a.unsafe_push_back(elem);
2299 test_equal_range(a, expected);
2302 #ifndef BOOST_NO_EXCEPTIONS
2303 if (! boost::move_detail::is_nothrow_copy_constructible<T>::value)
2305 Devector b; get_range<Devector>(4, b);
2307 iterator origi_begin = b.begin();
2311 test_elem_throw::on_copy_after(1);
2312 BOOST_TEST_THROWS(b.unsafe_push_back(elem), test_exception);
2313 test_elem_throw::do_not_throw();
2315 iterator new_begin = b.begin();
2317 BOOST_TEST(origi_begin == new_begin);
2318 BOOST_TEST(b.size() == 4u);
2323 template <class Devector> void test_unsafe_push_back_rvalue()
2325 typedef typename Devector::value_type T;
2328 boost::container::vector<int> expected; get_range<boost::container::vector<int> >(16, expected);
2332 for (std::size_t i = 1; i <= 16; ++i)
2335 a.unsafe_push_back(boost::move(elem));
2338 test_equal_range(a, expected);
2342 template <class Devector
> void test_pop_back()
2348 BOOST_TEST(a
.empty());
2356 BOOST_TEST(b
.empty());
2360 BOOST_TEST(b
.empty());
2364 Devector c
; get_range
<Devector
>(20, c
);
2365 for (int i
= 0; i
< 20; ++i
)
2367 BOOST_TEST(!c
.empty());
2370 BOOST_TEST(c
.empty());
2374 template <class Devector
> void test_emplace_throwing(dtl::true_
)
2376 #ifndef BOOST_NO_EXCEPTIONS
2377 typedef typename
Devector::iterator iterator
;
2379 Devector j
; get_range
<Devector
>(4, j
);
2380 iterator origi_begin
= j
.begin();
2382 test_elem_throw::on_ctor_after(1);
2383 BOOST_TEST_THROWS(j
.emplace(j
.begin() + 2, 404), test_exception
);
2384 test_elem_throw::do_not_throw();
2386 const int expected
[] = {1, 2, 3, 4};
2387 test_equal_range(j
, expected
);
2388 BOOST_TEST(origi_begin
== j
.begin());
2392 template <class Devector
> void test_emplace_throwing(dtl::false_
)
2396 template <class Devector
> void test_emplace()
2398 typedef typename
Devector::iterator iterator
;
2401 Devector a
; get_range
<Devector
>(16, a
);
2402 typename
Devector::iterator it
= a
.emplace(a
.begin(), 123);
2403 const int expected
[] = {123, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
2404 test_equal_range(a
, expected
);
2405 BOOST_TEST(*it
== 123);
2409 Devector b
; get_range
<Devector
>(16, b
);
2410 typename
Devector::iterator it
= b
.emplace(b
.end(), 123);
2411 const int expected
[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 123};
2412 test_equal_range(b
, expected
);
2413 BOOST_TEST(*it
== 123);
2417 Devector c
; get_range
<Devector
>(16, c
);
2419 typename
Devector::iterator it
= c
.emplace(c
.begin(), 123);
2420 const int expected
[] = {123, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
2421 test_equal_range(c
, expected
);
2422 BOOST_TEST(*it
== 123);
2426 Devector d
; get_range
<Devector
>(16, d
);
2428 typename
Devector::iterator it
= d
.emplace(d
.end(), 123);
2429 const int expected
[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 123};
2430 test_equal_range(d
, expected
);
2431 BOOST_TEST(*it
== 123);
2435 Devector e
; get_range
<Devector
>(16, e
);
2436 typename
Devector::iterator it
= e
.emplace(e
.begin() + 5, 123);
2437 const int expected
[] = {1, 2, 3, 4, 5, 123, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
2438 test_equal_range(e
, expected
);
2439 BOOST_TEST(*it
== 123);
2443 Devector f
; get_range
<Devector
>(16, f
);
2446 iterator valid
= f
.begin() + 1;
2447 typename
Devector::iterator it
= f
.emplace(f
.begin() + 1, 123);
2448 const int expected
[] = {2, 123, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
2449 test_equal_range(f
, expected
);
2450 BOOST_TEST(*it
== 123);
2451 BOOST_TEST(*valid
== 3);
2455 Devector g
; get_range
<Devector
>(16, g
);
2458 iterator valid
= g
.end() - 2;
2459 typename
Devector::iterator it
= g
.emplace(g
.end() - 1, 123);
2460 const int expected
[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 123, 15};
2461 test_equal_range(g
, expected
);
2462 BOOST_TEST(*it
== 123);
2463 BOOST_TEST(*valid
== 14);
2467 Devector h
; get_range
<Devector
>(16, h
);
2470 iterator valid
= h
.begin() + 7;
2471 typename
Devector::iterator it
= h
.emplace(h
.begin() + 7, 123);
2472 const int expected
[] = {2, 3, 4, 5, 6, 7, 8, 123, 9, 10, 11, 12, 13, 14, 15};
2473 test_equal_range(h
, expected
);
2474 BOOST_TEST(*it
== 123);
2475 BOOST_TEST(*valid
== 9);
2480 i
.emplace(i
.begin(), 1);
2481 i
.emplace(i
.end(), 10);
2482 for (int j
= 2; j
< 10; ++j
)
2484 i
.emplace(i
.begin() + (j
-1), j
);
2486 const int expected
[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
2487 test_equal_range(i
, expected
);
2490 typedef typename
Devector::value_type T
;
2491 test_emplace_throwing
<Devector
>
2492 (dtl::bool_
<! boost::move_detail::is_nothrow_default_constructible
<T
>::value
>());
2495 template <class Devector
> void test_insert_throwing(dtl::true_
)
2497 #ifndef BOOST_NO_EXCEPTIONS
2498 typedef typename
Devector::value_type T
;
2499 typedef typename
Devector::iterator iterator
;
2503 Devector j
; get_range
<Devector
>(4, j
);
2504 iterator origi_begin
= j
.begin();
2506 test_elem_throw::on_copy_after(1);
2507 BOOST_TEST_THROWS(j
.insert(j
.begin() + 2, test_elem
), test_exception
);
2508 test_elem_throw::do_not_throw();
2510 const int expected
[] = {1, 2, 3, 4};
2511 test_equal_range(j
, expected
);
2512 BOOST_TEST(origi_begin
== j
.begin());
2513 #endif //#ifndef BOOST_NO_EXCEPTIONS
2516 template <class Devector
> void test_insert_throwing(dtl::false_
)
2519 template <class Devector
> void test_insert()
2521 typedef typename
Devector::value_type T
;
2522 typedef typename
Devector::iterator iterator
;
2527 Devector a
; get_range
<Devector
>(16, a
);
2528 typename
Devector::iterator it
= a
.insert(a
.begin(), test_elem
);
2529 const int expected
[] = {123, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
2530 test_equal_range(a
, expected
);
2531 BOOST_TEST(*it
== 123);
2535 Devector b
; get_range
<Devector
>(16, b
);
2536 typename
Devector::iterator it
= b
.insert(b
.end(), test_elem
);
2537 const int expected
[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 123};
2538 test_equal_range(b
, expected
);
2539 BOOST_TEST(*it
== 123);
2543 Devector c
; get_range
<Devector
>(16, c
);
2545 typename
Devector::iterator it
= c
.insert(c
.begin(), test_elem
);
2546 const int expected
[] = {123, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
2547 test_equal_range(c
, expected
);
2548 BOOST_TEST(*it
== 123);
2552 Devector d
; get_range
<Devector
>(16, d
);
2554 typename
Devector::iterator it
= d
.insert(d
.end(), test_elem
);
2555 const int expected
[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 123};
2556 test_equal_range(d
, expected
);
2557 BOOST_TEST(*it
== 123);
2561 Devector e
; get_range
<Devector
>(16, e
);
2562 typename
Devector::iterator it
= e
.insert(e
.begin() + 5, test_elem
);
2563 const int expected
[] = {1, 2, 3, 4, 5, 123, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
2564 test_equal_range(e
, expected
);
2565 BOOST_TEST(*it
== 123);
2569 Devector f
; get_range
<Devector
>(16, f
);
2572 iterator valid
= f
.begin() + 1;
2573 typename
Devector::iterator it
= f
.insert(f
.begin() + 1, test_elem
);
2574 const int expected
[] = {2, 123, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
2575 test_equal_range(f
, expected
);
2576 BOOST_TEST(*it
== 123);
2577 BOOST_TEST(*valid
== 3);
2581 Devector g
; get_range
<Devector
>(16, g
);
2584 iterator valid
= g
.end() - 2;
2585 typename
Devector::iterator it
= g
.insert(g
.end() - 1, test_elem
);
2586 const int expected
[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 123, 15};
2587 test_equal_range(g
, expected
);
2588 BOOST_TEST(*it
== 123);
2589 BOOST_TEST(*valid
== 14);
2593 Devector h
; get_range
<Devector
>(16, h
);
2596 iterator valid
= h
.begin() + 7;
2597 typename
Devector::iterator it
= h
.insert(h
.begin() + 7, test_elem
);
2598 const int expected
[] = {2, 3, 4, 5, 6, 7, 8, 123, 9, 10, 11, 12, 13, 14, 15};
2599 test_equal_range(h
, expected
);
2600 BOOST_TEST(*it
== 123);
2601 BOOST_TEST(*valid
== 9);
2606 i
.insert(i
.begin(), T(1));
2607 i
.insert(i
.end(), T(10));
2608 for (int j
= 2; j
< 10; ++j
)
2610 i
.insert(i
.begin() + (j
-1), T(j
));
2612 const int expected
[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
2613 test_equal_range(i
, expected
);
2616 test_insert_throwing
<Devector
>
2617 (dtl::bool_
<! boost::move_detail::is_nothrow_copy_constructible
<T
>::value
>());
2619 // test when tmp is already inserted and there's free capacity
2621 Devector c
; get_range
<Devector
>(6, c
);
2623 const T
& tmp
= *(c
.begin() + 2);
2624 c
.insert(c
.begin() + 1, tmp
);
2625 const int expected
[] = {1, 3, 2, 3, 4, 5};
2626 test_equal_range(c
, expected
);
2629 // test when tmp is already inserted and maybe there's no free capacity
2631 Devector c
; get_range
<Devector
>(6, c
);
2632 const T
& tmp
= *(c
.begin() + 2);
2633 c
.insert(c
.begin() + 1, tmp
);
2634 const int expected
[] = {1, 3, 2, 3, 4, 5, 6};
2635 test_equal_range(c
, expected
);
2639 template <class Devector
> void test_insert_rvalue_throwing(dtl::true_
)
2641 #ifndef BOOST_NO_EXCEPTIONS
2642 typedef typename
Devector::value_type T
;
2643 typedef typename
Devector::iterator iterator
;
2645 Devector j
; get_range
<Devector
>(4, j
);
2646 iterator origi_begin
= j
.begin();
2648 test_elem_throw::on_ctor_after(1);
2649 BOOST_TEST_THROWS(j
.insert(j
.begin() + 2, T(404)), test_exception
);
2650 test_elem_throw::do_not_throw();
2652 const int expected
[] = {1, 2, 3, 4};
2653 test_equal_range(j
, expected
);
2654 BOOST_TEST(origi_begin
== j
.begin());
2655 #endif //#ifndef BOOST_NO_EXCEPTIONS
2658 template <class Devector
> void test_insert_rvalue_throwing(dtl::false_
)
2662 template <class Devector
> void test_insert_rvalue()
2664 typedef typename
Devector::value_type T
;
2665 typedef typename
Devector::iterator iterator
;
2668 Devector a
; get_range
<Devector
>(16, a
);
2669 typename
Devector::iterator it
= a
.insert(a
.begin(), T(123));
2670 const int expected
[] = {123, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
2671 test_equal_range(a
, expected
);
2672 BOOST_TEST(*it
== 123);
2676 Devector b
; get_range
<Devector
>(16, b
);
2677 typename
Devector::iterator it
= b
.insert(b
.end(), T(123));
2678 const int expected
[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 123};
2679 test_equal_range(b
, expected
);
2680 BOOST_TEST(*it
== 123);
2684 Devector c
; get_range
<Devector
>(16, c
);
2686 typename
Devector::iterator it
= c
.insert(c
.begin(), T(123));
2687 const int expected
[] = {123, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
2688 test_equal_range(c
, expected
);
2689 BOOST_TEST(*it
== 123);
2693 Devector d
; get_range
<Devector
>(16, d
);
2695 typename
Devector::iterator it
= d
.insert(d
.end(), T(123));
2696 const int expected
[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 123};
2697 test_equal_range(d
, expected
);
2698 BOOST_TEST(*it
== 123);
2702 Devector e
; get_range
<Devector
>(16, e
);
2703 typename
Devector::iterator it
= e
.insert(e
.begin() + 5, T(123));
2704 const int expected
[] = {1, 2, 3, 4, 5, 123, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
2705 test_equal_range(e
, expected
);
2706 BOOST_TEST(*it
== 123);
2710 Devector f
; get_range
<Devector
>(16, f
);
2713 iterator valid
= f
.begin() + 1;
2714 typename
Devector::iterator it
= f
.insert(f
.begin() + 1, T(123));
2715 const int expected
[] = {2, 123, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
2716 test_equal_range(f
, expected
);
2717 BOOST_TEST(*it
== 123);
2718 BOOST_TEST(*valid
== 3);
2722 Devector g
; get_range
<Devector
>(16, g
);
2725 iterator valid
= g
.end() - 2;
2726 typename
Devector::iterator it
= g
.insert(g
.end() - 1, T(123));
2727 const int expected
[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 123, 15};
2728 test_equal_range(g
, expected
);
2729 BOOST_TEST(*it
== 123);
2730 BOOST_TEST(*valid
== 14);
2734 Devector h
; get_range
<Devector
>(16, h
);
2737 iterator valid
= h
.begin() + 7;
2738 typename
Devector::iterator it
= h
.insert(h
.begin() + 7, T(123));
2739 const int expected
[] = {2, 3, 4, 5, 6, 7, 8, 123, 9, 10, 11, 12, 13, 14, 15};
2740 test_equal_range(h
, expected
);
2741 BOOST_TEST(*it
== 123);
2742 BOOST_TEST(*valid
== 9);
2747 i
.insert(i
.begin(), T(1));
2748 i
.insert(i
.end(), T(10));
2749 for (int j
= 2; j
< 10; ++j
)
2751 i
.insert(i
.begin() + (j
-1), T(j
));
2753 const int expected
[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
2754 test_equal_range(i
, expected
);
2757 test_insert_rvalue_throwing
<Devector
>
2758 (dtl::bool_
<! boost::move_detail::is_nothrow_default_constructible
<T
>::value
>());
2761 template <class Devector
> void test_insert_n_throwing(dtl::true_
)
2763 #ifndef BOOST_NO_EXCEPTIONS
2764 typedef typename
Devector::value_type T
;
2767 Devector j
; get_range
<Devector
>(4, j
);
2771 test_elem_throw::on_copy_after(3);
2772 BOOST_TEST_THROWS(j
.insert(j
.begin(), 4, x
), test_exception
);
2773 test_elem_throw::do_not_throw();
2778 Devector k
; get_range
<Devector
>(4, k
);
2782 test_elem_throw::on_copy_after(3);
2783 BOOST_TEST_THROWS(k
.insert(k
.end(), 4, x
), test_exception
);
2784 test_elem_throw::do_not_throw();
2786 #endif //#ifndef BOOST_NO_EXCEPTIONS
2789 template <class Devector
> void test_insert_n_throwing(dtl::false_
)
2792 template <class Devector
> void test_insert_n()
2794 typedef typename
Devector::value_type T
;
2795 typedef typename
Devector::iterator iterator
;
2800 iterator ret
= a
.insert(a
.end(), 5, x
);
2801 const int expected
[] = {123, 123, 123, 123, 123};
2802 test_equal_range(a
, expected
);
2803 BOOST_TEST(ret
== a
.begin());
2807 Devector b
; get_range
<Devector
>(8, b
);
2809 iterator ret
= b
.insert(b
.begin(), 3, x
);
2810 const int expected
[] = {9, 9, 9, 1, 2, 3, 4, 5, 6, 7, 8};
2811 test_equal_range(b
, expected
);
2812 BOOST_TEST(ret
== b
.begin());
2816 Devector c
; get_range
<Devector
>(8, c
);
2818 iterator ret
= c
.insert(c
.end(), 3, x
);
2819 const int expected
[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 9};
2820 test_equal_range(c
, expected
);
2821 BOOST_TEST(ret
== c
.begin() + 8);
2825 Devector d
; get_range
<Devector
>(8, d
);
2832 iterator origi_end
= d
.end();
2833 iterator ret
= d
.insert(d
.begin(), 3, x
);
2835 const int expected
[] = {9, 9, 9, 4, 5, 6, 7, 8};
2836 test_equal_range(d
, expected
);
2837 BOOST_TEST(origi_end
== d
.end());
2838 BOOST_TEST(ret
== d
.begin());
2842 Devector e
; get_range
<Devector
>(8, e
);
2849 iterator origi_begin
= e
.begin();
2850 iterator ret
= e
.insert(e
.end(), 3, x
);
2852 const int expected
[] = {1, 2, 3, 4, 5, 9, 9, 9};
2853 test_equal_range(e
, expected
);
2854 BOOST_TEST(origi_begin
== e
.begin());
2855 BOOST_TEST(ret
== e
.begin() + 5);
2859 Devector f
; get_range
<Devector
>(8, f
);
2860 f
.reset_alloc_stats();
2868 iterator ret
= f
.insert(f
.begin() + 2, 4, x
);
2870 const int expected
[] = {3, 4, 9, 9, 9, 9, 5, 6};
2871 test_equal_range(f
, expected
);
2872 BOOST_TEST(f
.get_alloc_count() == 0u);
2873 BOOST_TEST(ret
== f
.begin() + 2);
2877 Devector g
; get_range
<Devector
>(8, g
);
2878 g
.reset_alloc_stats();
2887 iterator ret
= g
.insert(g
.begin() + 2, 5, x
);
2889 const int expected
[] = {3, 4, 9, 9, 9, 9, 9, 5};
2890 test_equal_range(g
, expected
);
2891 BOOST_TEST(g
.get_alloc_count() == 0u);
2892 BOOST_TEST(ret
== g
.begin() + 2);
2896 Devector g
; get_range
<Devector
>(8, g
);
2899 iterator ret
= g
.insert(g
.begin() + 2, 5, x
);
2901 const int expected
[] = {1, 2, 9, 9, 9, 9, 9, 3, 4, 5, 6, 7, 8};
2902 test_equal_range(g
, expected
);
2903 BOOST_TEST(ret
== g
.begin() + 2);
2907 Devector h
; get_range
<Devector
>(8, h
);
2908 h
.reset_alloc_stats();
2912 iterator ret
= h
.insert(h
.begin(), 0, x
);
2913 BOOST_TEST(ret
== h
.begin());
2915 ret
= h
.insert(h
.begin() + 4, 0, x
);
2916 BOOST_TEST(ret
== h
.begin() + 4);
2918 ret
= h
.insert(h
.end(), 0, x
);
2919 BOOST_TEST(ret
== h
.end());
2921 const int expected
[] = {1, 2, 3, 4, 5, 6, 7, 8};
2922 test_equal_range(h
, expected
);
2923 BOOST_TEST(h
.get_alloc_count() == 0u);
2926 { // test insert already inserted
2927 Devector i
; get_range
<Devector
>(8, i
);
2928 i
.reset_alloc_stats();
2933 iterator ret
= i
.insert(i
.end() - 1, 2, *i
.begin());
2935 const int expected
[] = {3, 4, 5, 6, 7, 3, 3, 8};
2936 test_equal_range(i
, expected
);
2937 BOOST_TEST(i
.get_alloc_count() == 0u);
2938 BOOST_TEST(ret
== i
.begin() + 5);
2941 test_insert_n_throwing
<Devector
>
2942 (dtl::bool_
<! boost::move_detail::is_nothrow_copy_constructible
<T
>::value
>());
2945 template <class Devector
> void test_insert_input_range()
2947 typedef typename
Devector::value_type T
;
2948 typedef typename
Devector::iterator iterator
;
2958 devector
<T
> input
= x
;
2960 input_iterator
<Devector
> input_begin
= make_input_iterator(input
, input
.begin());
2961 input_iterator
<Devector
> input_end
= make_input_iterator(input
, input
.begin() + 5);
2964 iterator ret
= a
.insert(a
.end(), input_begin
, input_end
);
2965 const int expected
[] = {9, 9, 9, 9, 9};
2966 test_equal_range(a
, expected
);
2967 BOOST_TEST(ret
== a
.begin());
2971 devector
<T
> input
= x
;
2973 input_iterator
<Devector
> input_begin
= make_input_iterator(input
, input
.begin());
2974 input_iterator
<Devector
> input_end
= make_input_iterator(input
, input
.begin() + 3);
2976 Devector b
; get_range
<Devector
>(8, b
);
2977 iterator ret
= b
.insert(b
.begin(), input_begin
, input_end
);
2978 const int expected
[] = {9, 9, 9, 1, 2, 3, 4, 5, 6, 7, 8};
2979 test_equal_range(b
, expected
);
2980 BOOST_TEST(ret
== b
.begin());
2984 devector
<T
> input
= x
;
2986 input_iterator
<Devector
> input_begin
= make_input_iterator(input
, input
.begin());
2987 input_iterator
<Devector
> input_end
= make_input_iterator(input
, input
.begin() + 3);
2989 Devector c
; get_range
<Devector
>(8, c
);
2990 iterator ret
= c
.insert(c
.end(), input_begin
, input_end
);
2991 const int expected
[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 9};
2992 test_equal_range(c
, expected
);
2993 BOOST_TEST(ret
== c
.begin() + 8);
2997 devector
<T
> input
= x
;
2999 input_iterator
<Devector
> input_begin
= make_input_iterator(input
, input
.begin());
3000 input_iterator
<Devector
> input_end
= make_input_iterator(input
, input
.begin() + 3);
3002 Devector d
; get_range
<Devector
>(8, d
);
3008 iterator ret
= d
.insert(d
.begin(), input_begin
, input_end
);
3009 const int expected
[] = {9, 9, 9, 4, 5, 6, 7, 8};
3010 test_equal_range(d
, expected
);
3011 BOOST_TEST(ret
== d
.begin());
3015 devector
<T
> input
= x
;
3017 input_iterator
<Devector
> input_begin
= make_input_iterator(input
, input
.begin());
3018 input_iterator
<Devector
> input_end
= make_input_iterator(input
, input
.begin() + 3);
3020 Devector e
; get_range
<Devector
>(8, e
);
3026 iterator origi_begin
= e
.begin();
3027 iterator ret
= e
.insert(e
.end(), input_begin
, input_end
);
3028 const int expected
[] = {1, 2, 3, 4, 5, 9, 9, 9};
3029 test_equal_range(e
, expected
);
3030 BOOST_TEST(origi_begin
== e
.begin());
3031 BOOST_TEST(ret
== e
.begin() + 5);
3035 devector
<T
> input
= x
;
3037 input_iterator
<Devector
> input_begin
= make_input_iterator(input
, input
.begin());
3038 input_iterator
<Devector
> input_end
= make_input_iterator(input
, input
.begin() + 4);
3040 Devector f
; get_range
<Devector
>(8, f
);
3041 f
.reset_alloc_stats();
3048 iterator ret
= f
.insert(f
.begin() + 2, input_begin
, input_end
);
3050 const int expected
[] = {3, 4, 9, 9, 9, 9, 5, 6};
3051 test_equal_range(f
, expected
);
3052 BOOST_TEST(ret
== f
.begin() + 2);
3056 devector
<T
> input
= x
;
3058 input_iterator
<Devector
> input_begin
= make_input_iterator(input
, input
.begin());
3059 input_iterator
<Devector
> input_end
= make_input_iterator(input
, input
.begin() + 5);
3061 Devector g
; get_range
<Devector
>(8, g
);
3062 g
.reset_alloc_stats();
3070 iterator ret
= g
.insert(g
.begin() + 2, input_begin
, input_end
);
3072 const int expected
[] = {3, 4, 9, 9, 9, 9, 9, 5};
3073 test_equal_range(g
, expected
);
3074 BOOST_TEST(ret
== g
.begin() + 2);
3078 devector
<T
> input
= x
;
3080 input_iterator
<Devector
> input_begin
= make_input_iterator(input
, input
.begin());
3081 input_iterator
<Devector
> input_end
= make_input_iterator(input
, input
.begin() + 5);
3083 Devector g
; get_range
<Devector
>(8, g
);
3085 iterator ret
= g
.insert(g
.begin() + 2, input_begin
, input_end
);
3087 const int expected
[] = {1, 2, 9, 9, 9, 9, 9, 3, 4, 5, 6, 7, 8};
3088 test_equal_range(g
, expected
);
3089 BOOST_TEST(ret
== g
.begin() + 2);
3093 devector
<T
> input
= x
;
3095 input_iterator
<Devector
> input_begin
= make_input_iterator(input
, input
.begin());
3097 Devector h
; get_range
<Devector
>(8, h
);
3098 h
.reset_alloc_stats();
3100 iterator ret
= h
.insert(h
.begin(), input_begin
, input_begin
);
3101 BOOST_TEST(ret
== h
.begin());
3103 ret
= h
.insert(h
.begin() + 4, input_begin
, input_begin
);
3104 BOOST_TEST(ret
== h
.begin() + 4);
3106 ret
= h
.insert(h
.end(), input_begin
, input_begin
);
3107 BOOST_TEST(ret
== h
.end());
3109 const int expected
[] = {1, 2, 3, 4, 5, 6, 7, 8};
3110 test_equal_range(h
, expected
);
3113 #ifndef BOOST_NO_EXCEPTIONS
3114 if (! boost::move_detail::is_nothrow_copy_constructible
<T
>::value
)
3118 devector
<T
> input
= x
;
3120 input_iterator
<Devector
> input_begin
= make_input_iterator(input
, input
.begin());
3121 input_iterator
<Devector
> input_end
= make_input_iterator(input
, input
.begin() + 4);
3123 Devector j
; get_range
<Devector
>(4, j
);
3125 test_elem_throw::on_copy_after(3);
3126 BOOST_TEST_THROWS(j
.insert(j
.begin(), input_begin
, input_end
), test_exception
);
3127 test_elem_throw::do_not_throw();
3132 devector
<T
> input
= x
;
3134 input_iterator
<Devector
> input_begin
= make_input_iterator(input
, input
.begin());
3135 input_iterator
<Devector
> input_end
= make_input_iterator(input
, input
.begin() + 4);
3137 Devector k
; get_range
<Devector
>(4, k
);
3139 test_elem_throw::on_copy_after(3);
3140 BOOST_TEST_THROWS(k
.insert(k
.end(), input_begin
, input_end
), test_exception
);
3141 test_elem_throw::do_not_throw();
3144 #endif //#ifndef BOOST_NO_EXCEPTIONS
3147 template <class Devector
> void test_insert_range()
3149 typedef typename
Devector::value_type T
;
3150 typedef typename
Devector::iterator iterator
;
3151 typedef boost::container::vector
<T
> Vector
;
3160 typename
Vector::iterator xb
= x
.begin();
3164 iterator ret
= a
.insert(a
.end(), xb
, xb
+5);
3165 const int expected
[] = {9, 10, 11, 12, 13};
3166 test_equal_range(a
, expected
);
3167 BOOST_TEST(ret
== a
.begin());
3171 Devector b
; get_range
<Devector
>(8, b
);
3172 iterator ret
= b
.insert(b
.begin(), xb
, xb
+3);
3173 const int expected
[] = {9, 10, 11, 1, 2, 3, 4, 5, 6, 7, 8};
3174 test_equal_range(b
, expected
);
3175 BOOST_TEST(ret
== b
.begin());
3179 Devector c
; get_range
<Devector
>(8, c
);
3180 iterator ret
= c
.insert(c
.end(), xb
, xb
+3);
3181 const int expected
[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
3182 test_equal_range(c
, expected
);
3183 BOOST_TEST(ret
== c
.begin() + 8);
3187 Devector d
; get_range
<Devector
>(8, d
);
3193 iterator origi_end
= d
.end();
3194 iterator ret
= d
.insert(d
.begin(), xb
, xb
+3);
3196 const int expected
[] = {9, 10, 11, 4, 5, 6, 7, 8};
3197 test_equal_range(d
, expected
);
3199 BOOST_TEST(origi_end
== d
.end());
3200 BOOST_TEST(ret
== d
.begin());
3204 Devector e
; get_range
<Devector
>(8, e
);
3210 iterator origi_begin
= e
.begin();
3211 iterator ret
= e
.insert(e
.end(), xb
, xb
+3);
3213 const int expected
[] = {1, 2, 3, 4, 5, 9, 10, 11};
3214 test_equal_range(e
, expected
);
3216 BOOST_TEST(origi_begin
== e
.begin());
3217 BOOST_TEST(ret
== e
.begin() + 5);
3221 Devector f
; get_range
<Devector
>(8, f
);
3222 f
.reset_alloc_stats();
3229 iterator ret
= f
.insert(f
.begin() + 2, xb
, xb
+4);
3231 const int expected
[] = {3, 4, 9, 10, 11, 12, 5, 6};
3232 test_equal_range(f
, expected
);
3234 BOOST_TEST(f
.get_alloc_count() == 0u);
3235 BOOST_TEST(ret
== f
.begin() + 2);
3239 Devector g
; get_range
<Devector
>(8, g
);
3240 g
.reset_alloc_stats();
3248 iterator ret
= g
.insert(g
.begin() + 2, xb
, xb
+5);
3250 const int expected
[] = {3, 4, 9, 10, 11, 12, 13, 5};
3251 test_equal_range(g
, expected
);
3253 BOOST_TEST(g
.get_alloc_count() == 0u);
3254 BOOST_TEST(ret
== g
.begin() + 2);
3258 Devector g
; get_range
<Devector
>(8, g
);
3260 iterator ret
= g
.insert(g
.begin() + 2, xb
, xb
+5);
3262 const int expected
[] = {1, 2, 9, 10, 11, 12, 13, 3, 4, 5, 6, 7, 8};
3263 test_equal_range(g
, expected
);
3265 BOOST_TEST(ret
== g
.begin() + 2);
3269 Devector h
; get_range
<Devector
>(8, h
);
3270 h
.reset_alloc_stats();
3272 iterator ret
= h
.insert(h
.begin(), xb
, xb
);
3273 BOOST_TEST(ret
== h
.begin());
3275 ret
= h
.insert(h
.begin() + 4, xb
, xb
);
3276 BOOST_TEST(ret
== h
.begin() + 4);
3278 ret
= h
.insert(h
.end(), xb
, xb
);
3279 BOOST_TEST(ret
== h
.end());
3281 const int expected
[] = {1, 2, 3, 4, 5, 6, 7, 8};
3282 test_equal_range(h
, expected
);
3284 BOOST_TEST(h
.get_alloc_count() == 0u);
3287 #ifndef BOOST_NO_EXCEPTIONS
3288 if (! boost::move_detail::is_nothrow_copy_constructible
<T
>::value
)
3292 Devector j
; get_range
<Devector
>(4, j
);
3294 test_elem_throw::on_copy_after(3);
3295 BOOST_TEST_THROWS(j
.insert(j
.begin(), xb
, xb
+4), test_exception
);
3296 test_elem_throw::do_not_throw();
3301 Devector k
; get_range
<Devector
>(4, k
);
3303 test_elem_throw::on_copy_after(3);
3304 BOOST_TEST_THROWS(k
.insert(k
.end(), xb
, xb
+4), test_exception
);
3305 test_elem_throw::do_not_throw();
3308 #endif //#ifndef BOOST_NO_EXCEPTIONS
3311 template <class Devector
> void test_insert_init_list()
3313 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
3314 typedef typename
Devector::value_type T
;
3315 typedef typename
Devector::iterator iterator
;
3319 iterator ret
= a
.insert(a
.end(), {T(123), T(124), T(125), T(126), T(127)});
3320 test_equal_range(a
, {123, 124, 125, 126, 127});
3321 BOOST_TEST(ret
== a
.begin());
3325 Devector b
; get_range
<Devector
>(8, b
);
3326 iterator ret
= b
.insert(b
.begin(), {T(9), T(10), T(11)});
3327 test_equal_range(b
, {9, 10, 11, 1, 2, 3, 4, 5, 6, 7, 8});
3328 BOOST_TEST(ret
== b
.begin());
3332 Devector c
; get_range
<Devector
>(8, c
);
3333 iterator ret
= c
.insert(c
.end(), {T(9), T(10), T(11)});
3334 test_equal_range(c
, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11});
3335 BOOST_TEST(ret
== c
.begin() + 8);
3339 Devector d
; get_range
<Devector
>(8, d
);
3345 iterator origi_end
= d
.end();
3346 iterator ret
= d
.insert(d
.begin(), {T(9), T(10), T(11)});
3348 test_equal_range(d
, {9, 10, 11, 4, 5, 6, 7, 8});
3349 BOOST_TEST(origi_end
== d
.end());
3350 BOOST_TEST(ret
== d
.begin());
3354 Devector e
; get_range
<Devector
>(8, e
);
3360 iterator origi_begin
= e
.begin();
3361 iterator ret
= e
.insert(e
.end(), {T(9), T(10), T(11)});
3363 test_equal_range(e
, {1, 2, 3, 4, 5, 9, 10, 11});
3364 BOOST_TEST(origi_begin
== e
.begin());
3365 BOOST_TEST(ret
== e
.begin() + 5);
3369 Devector f
; get_range
<Devector
>(8, f
);
3370 f
.reset_alloc_stats();
3377 iterator ret
= f
.insert(f
.begin() + 2, {T(9), T(10), T(11), T(12)});
3379 test_equal_range(f
, {3, 4, 9, 10, 11, 12, 5, 6});
3380 BOOST_TEST(f
.get_alloc_count() == 0u);
3381 BOOST_TEST(ret
== f
.begin() + 2);
3385 Devector g
; get_range
<Devector
>(8, g
);
3386 g
.reset_alloc_stats();
3394 iterator ret
= g
.insert(g
.begin() + 2, {T(9), T(10), T(11), T(12), T(13)});
3396 test_equal_range(g
, {3, 4, 9, 10, 11, 12, 13, 5});
3397 BOOST_TEST(g
.get_alloc_count() == 0u);
3398 BOOST_TEST(ret
== g
.begin() + 2);
3402 Devector g
; get_range
<Devector
>(8, g
);
3404 iterator ret
= g
.insert(g
.begin() + 2, {T(9), T(10), T(11), T(12), T(13)});
3406 test_equal_range(g
, {1, 2, 9, 10, 11, 12, 13, 3, 4, 5, 6, 7, 8});
3407 BOOST_TEST(ret
== g
.begin() + 2);
3410 #ifndef BOOST_NO_EXCEPTIONS
3411 BOOST_IF_CONSTEXPR (! boost::move_detail::is_nothrow_copy_constructible
<T
>::value
)
3415 Devector j
; get_range
<Devector
>(4, j
);
3417 test_elem_throw::on_copy_after(3);
3418 BOOST_TEST_THROWS(j
.insert(j
.begin(), {T(9), T(9), T(9), T(9), T(9)}), test_exception
);
3419 test_elem_throw::do_not_throw();
3424 Devector k
; get_range
<Devector
>(4, k
);
3425 test_elem_throw::on_copy_after(3);
3426 BOOST_TEST_THROWS(k
.insert(k
.end(), {T(9), T(9), T(9), T(9), T(9)}), test_exception
);
3427 test_elem_throw::do_not_throw();
3430 #endif //#ifndef BOOST_NO_EXCEPTIONS
3431 #endif // #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
3434 template <class Devector
> void test_erase()
3436 typedef typename
Devector::iterator iterator
;
3438 Devector a
; get_range
<Devector
>(4, a
);
3439 iterator ret
= a
.erase(a
.begin());
3440 const int expected
[] = {2, 3, 4};
3441 test_equal_range(a
, expected
);
3442 BOOST_TEST(ret
== a
.begin());
3446 Devector b
; get_range
<Devector
>(4, b
);
3447 iterator ret
= b
.erase(b
.end() - 1);
3448 const int expected
[] = {1, 2, 3};
3449 test_equal_range(b
, expected
);
3450 BOOST_TEST(ret
== b
.end());
3454 Devector c
; get_range
<Devector
>(6, c
);
3455 iterator ret
= c
.erase(c
.begin() + 2);
3456 const int expected
[] = {1, 2, 4, 5, 6};
3457 test_equal_range(c
, expected
);
3458 BOOST_TEST(ret
== c
.begin() + 2);
3459 BOOST_TEST(c
.front_free_capacity() > 0u);
3463 Devector d
; get_range
<Devector
>(6, d
);
3464 iterator ret
= d
.erase(d
.begin() + 4);
3465 const int expected
[] = {1, 2, 3, 4, 6};
3466 test_equal_range(d
, expected
);
3467 BOOST_TEST(ret
== d
.begin() + 4);
3468 BOOST_TEST(d
.back_free_capacity() > 0u);
3472 template <class Devector
> void test_erase_range()
3474 typedef typename
Devector::iterator iterator
;
3476 Devector a
; get_range
<Devector
>(4, a
);
3477 a
.erase(a
.end(), a
.end());
3478 a
.erase(a
.begin(), a
.begin());
3482 Devector b
; get_range
<Devector
>(8, b
);
3483 iterator ret
= b
.erase(b
.begin(), b
.begin() + 2);
3484 const int expected
[] = {3, 4, 5, 6, 7, 8};
3485 test_equal_range(b
, expected
);
3486 BOOST_TEST(ret
== b
.begin());
3487 BOOST_TEST(b
.front_free_capacity() > 0u);
3491 Devector c
; get_range
<Devector
>(8, c
);
3492 iterator ret
= c
.erase(c
.begin() + 1, c
.begin() + 3);
3493 const int expected
[] = {1, 4, 5, 6, 7, 8};
3494 test_equal_range(c
, expected
);
3495 BOOST_TEST(ret
== c
.begin() + 1);
3496 BOOST_TEST(c
.front_free_capacity() > 0u);
3500 Devector d
; get_range
<Devector
>(8, d
);
3501 iterator ret
= d
.erase(d
.end() - 2, d
.end());
3502 const int expected
[] = {1, 2, 3, 4, 5, 6};
3503 test_equal_range(d
, expected
);
3504 BOOST_TEST(ret
== d
.end());
3505 BOOST_TEST(d
.back_free_capacity() > 0u);
3509 Devector e
; get_range
<Devector
>(8, e
);
3510 iterator ret
= e
.erase(e
.end() - 3, e
.end() - 1);
3511 const int expected
[] = {1, 2, 3, 4, 5, 8};
3512 test_equal_range(e
, expected
);
3513 BOOST_TEST(ret
== e
.end() - 1);
3514 BOOST_TEST(e
.back_free_capacity() > 0u);
3518 Devector f
; get_range
<Devector
>(8, f
);
3519 iterator ret
= f
.erase(f
.begin(), f
.end());
3520 test_equal_range(f
);
3521 BOOST_TEST(ret
== f
.end());
3525 template <class Devector
> void test_swap()
3527 using std::swap
; // test if ADL works
3536 BOOST_TEST(a
.empty());
3537 BOOST_TEST(b
.empty());
3543 Devector b
; get_range
<Devector
>(4, b
);
3547 const int expected
[] = {1, 2, 3, 4};
3549 BOOST_TEST(b
.empty());
3550 test_equal_range(a
, expected
);
3555 BOOST_TEST(a
.empty());
3556 test_equal_range(b
, expected
);
3560 // small-small / big-big
3562 Devector a
; get_range
<Devector
>(1, 5, 5, 7, a
);
3563 Devector b
; get_range
<Devector
>(13, 15, 15, 19, b
);
3567 const int expected
[] = {13, 14, 15, 16, 17, 18};
3568 test_equal_range(a
, expected
);
3569 const int expected2
[] = {1, 2, 3, 4, 5, 6};
3570 test_equal_range(b
, expected2
);
3574 const int expected3
[] = {13, 14, 15, 16, 17, 18};
3575 test_equal_range(b
, expected3
);
3576 const int expected4
[] = {1, 2, 3, 4, 5, 6};
3577 test_equal_range(a
, expected4
);
3580 // big-small + small-big
3582 Devector a
; get_range
<Devector
>(10, a
);
3583 Devector b
; get_range
<Devector
>(9, 11, 11, 17, b
);
3587 const int expected
[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
3588 test_equal_range(b
, expected
);
3589 const int expected2
[] = {9, 10, 11, 12, 13, 14, 15, 16};
3590 test_equal_range(a
, expected2
);
3594 const int expected3
[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
3595 test_equal_range(a
, expected3
);
3596 const int expected4
[] = {9, 10, 11, 12, 13, 14, 15, 16};
3597 test_equal_range(b
, expected4
);
3602 Devector a
; get_range
<Devector
>(10, a
);
3606 const int expected
[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
3607 test_equal_range(a
, expected
);
3612 Devector a
; get_range
<Devector
>(1, 9, 0, 0, a
);
3613 Devector b
; get_range
<Devector
>(0, 0, 11, 17, b
);
3623 const int expected
[] = {13, 14, 15, 16};
3624 test_equal_range(a
, expected
);
3625 const int expected2
[] = {1, 2, 3, 4, 5, 6};
3626 test_equal_range(b
, expected2
);
3629 // big-big does not copy or move
3631 Devector a
; get_range
<Devector
>(32, a
);
3632 Devector b
; get_range
<Devector
>(32, b
);
3633 boost::container::vector
<int> c
; get_range
<boost::container::vector
<int> >(32, c
);
3635 test_elem_throw::on_copy_after(1);
3636 test_elem_throw::on_move_after(1);
3640 test_elem_throw::do_not_throw();
3642 test_equal_range(a
, c
);
3643 test_equal_range(b
, c
);
3647 template <class Devector
> void test_clear()
3652 BOOST_TEST(a
.empty());
3656 Devector a
; get_range
<Devector
>(8, a
);
3657 typename
Devector::size_type cp
= a
.capacity();
3659 BOOST_TEST(a
.empty());
3660 BOOST_TEST(cp
== a
.capacity());
3664 template <class Devector
> void test_op_eq()
3667 Devector a
; get_range
<Devector
>(8, a
);
3668 Devector b
; get_range
<Devector
>(8, b
);
3674 Devector a
; get_range
<Devector
>(8, a
);
3675 Devector b
; get_range
<Devector
>(9, b
);
3677 BOOST_TEST(!(a
== b
));
3681 Devector a
; get_range
<Devector
>(8, a
);
3682 Devector b
; get_range
<Devector
>(2,6,6,10, b
);
3684 BOOST_TEST(!(a
== b
));
3688 template <class Devector
> void test_op_lt()
3691 Devector a
; get_range
<Devector
>(7, a
);
3692 Devector b
; get_range
<Devector
>(8, b
);
3694 BOOST_TEST((a
< b
));
3698 Devector a
; get_range
<Devector
>(8, a
);
3699 Devector b
; get_range
<Devector
>(8, b
);
3701 BOOST_TEST(!(a
< b
));
3705 Devector a
; get_range
<Devector
>(8, a
);
3706 Devector b
; get_range
<Devector
>(7, b
);
3708 BOOST_TEST(!(a
< b
));
3712 template <class Devector
> void test_op_ne()
3715 Devector a
; get_range
<Devector
>(8, a
);
3716 Devector b
; get_range
<Devector
>(8, b
);
3718 BOOST_TEST(!(a
!= b
));
3722 Devector a
; get_range
<Devector
>(8, a
);
3723 Devector b
; get_range
<Devector
>(9, b
);
3725 BOOST_TEST((a
!= b
));
3729 Devector a
; get_range
<Devector
>(8, a
);
3730 Devector b
; get_range
<Devector
>(2,6,6,10, b
);
3732 BOOST_TEST((a
!= b
));
3737 template <class Devector
> void test_op_gt()
3740 Devector a
; get_range
<Devector
>(7, a
);
3741 Devector b
; get_range
<Devector
>(8, b
);
3743 BOOST_TEST(!(a
> b
));
3747 Devector a
; get_range
<Devector
>(8, a
);
3748 Devector b
; get_range
<Devector
>(8, b
);
3750 BOOST_TEST(!(a
> b
));
3754 Devector a
; get_range
<Devector
>(8, a
);
3755 Devector b
; get_range
<Devector
>(7, b
);
3757 BOOST_TEST((a
> b
));
3761 template <class Devector
> void test_op_ge()
3764 Devector a
; get_range
<Devector
>(7, a
);
3765 Devector b
; get_range
<Devector
>(8, b
);
3767 BOOST_TEST(!(a
>= b
));
3771 Devector a
; get_range
<Devector
>(8, a
);
3772 Devector b
; get_range
<Devector
>(8, b
);
3774 BOOST_TEST((a
>= b
));
3778 Devector a
; get_range
<Devector
>(8, a
);
3779 Devector b
; get_range
<Devector
>(7, b
);
3781 BOOST_TEST((a
>= b
));
3785 template <class Devector
> void test_op_le()
3788 Devector a
; get_range
<Devector
>(7, a
);
3789 Devector b
; get_range
<Devector
>(8, b
);
3791 BOOST_TEST((a
<= b
));
3795 Devector a
; get_range
<Devector
>(8, a
);
3796 Devector b
; get_range
<Devector
>(8, b
);
3798 BOOST_TEST((a
<= b
));
3802 Devector a
; get_range
<Devector
>(8, a
);
3803 Devector b
; get_range
<Devector
>(7, b
);
3805 BOOST_TEST(!(a
<= b
));
3810 template <class Devector
>
3811 void test_devector_default_constructible(dtl::true_
)
3813 test_constructor_n
<Devector
>();
3814 test_resize_front
<Devector
>();
3815 test_resize_back
<Devector
>();
3818 template <class Devector
>
3819 void test_devector_default_constructible(dtl::false_
)
3822 template <class Devector
>
3823 void test_devector_copy_constructible(dtl::false_
)
3827 template <class Devector
>
3828 void test_devector_copy_constructible(dtl::true_
)
3830 test_constructor_n_copy
<Devector
>();
3831 test_constructor_input_range
<Devector
>();
3832 test_constructor_forward_range
<Devector
>();
3833 test_constructor_pointer_range
<Devector
>();
3834 test_copy_constructor
<Devector
>();
3835 test_assignment
<Devector
>();
3836 test_assign_input_range
<Devector
>();
3837 test_assign_pointer_range
<Devector
>();
3838 test_assign_n
<Devector
>();
3839 test_resize_front_copy
<Devector
>();
3840 test_push_back
<Devector
>();
3841 //test_unsafe_push_back<Devector>();
3842 test_push_front
<Devector
>();
3843 //test_unsafe_push_front<Devector>();
3844 test_resize_back_copy
<Devector
>();
3845 test_insert
<Devector
>();
3846 test_insert_n
<Devector
>();
3847 test_insert_input_range
<Devector
>();
3848 test_insert_range
<Devector
>();
3849 test_insert_init_list
<Devector
>();
3852 template <class Devector
>
3853 void test_devector()
3855 test_devector_default_constructible
<Devector
>(dtl::bool_
<boost::is_default_constructible
<typename
Devector::value_type
>::value
>());
3856 test_devector_copy_constructible
<Devector
>(dtl::bool_
<boost::move_detail::is_copy_constructible
<typename
Devector::value_type
>::value
>());
3858 test_constructor_default
<Devector
>();
3859 test_constructor_allocator
<Devector
>();
3861 test_constructor_reserve_only
<Devector
>();
3862 test_constructor_reserve_only_front_back
<Devector
>();
3863 //test_constructor_unsafe_uninitialized<Devector>();
3865 test_move_constructor
<Devector
>();
3866 test_destructor
<Devector
>();
3868 test_move_assignment
<Devector
>();
3869 test_get_allocator
<Devector
>();
3870 test_begin_end
<Devector
>();
3871 test_empty
<Devector
>();
3872 test_size
<Devector
>();
3873 test_capacity
<Devector
>();
3875 //test_unsafe_uninitialized_resize_front<Devector>();
3876 //test_unsafe_uninitialized_resize_back<Devector>();
3877 test_reserve_front
<Devector
>();
3878 test_reserve_back
<Devector
>();
3879 test_index_operator
<Devector
>();
3880 test_at
<Devector
>();
3881 test_front
<Devector
>();
3882 test_back
<Devector
>();
3883 test_emplace_front
<Devector
>();
3884 test_push_front_rvalue
<Devector
>();
3886 //test_unsafe_push_front_rvalue<Devector>();
3887 test_pop_front
<Devector
>();
3888 test_emplace_back
<Devector
>();
3889 test_push_back_rvalue
<Devector
>();
3891 //test_unsafe_push_back_rvalue<Devector>();
3892 test_pop_back
<Devector
>();
3893 test_emplace
<Devector
>();
3894 test_insert_rvalue
<Devector
>();
3896 test_erase
<Devector
>();
3897 test_erase_range
<Devector
>();
3898 test_swap
<Devector
>();
3899 test_clear
<Devector
>();
3900 test_op_eq
<Devector
>();
3901 test_op_lt
<Devector
>();
3902 test_op_ne
<Devector
>();
3903 test_op_gt
<Devector
>();
3904 test_op_ge
<Devector
>();
3905 test_op_le
<Devector
>();
3908 class recursive_devector
3911 recursive_devector(const recursive_devector
&x
)
3912 : devector_(x
.devector_
)
3915 recursive_devector
& operator=(const recursive_devector
&x
)
3916 { this->devector_
= x
.devector_
; return *this; }
3919 devector
<recursive_devector
> devector_
;
3920 devector
<recursive_devector
>::iterator it_
;
3921 devector
<recursive_devector
>::const_iterator cit_
;
3922 devector
<recursive_devector
>::reverse_iterator rit_
;
3923 devector
<recursive_devector
>::const_reverse_iterator crit_
;
3926 void test_recursive_devector()//Test for recursive types
3928 devector
<recursive_devector
> rdv
;
3929 BOOST_TEST(rdv
.empty());
3930 BOOST_TEST(rdv
.get_alloc_count() == 0u);
3931 BOOST_TEST(rdv
.capacity() == 0u);
3934 template<class VoidAllocator
>
3935 struct GetAllocatorCont
3937 template<class ValueType
>
3940 typedef vector
< ValueType
3941 , typename allocator_traits
<VoidAllocator
>
3942 ::template portable_rebind_alloc
<ValueType
>::type
3948 #pragma warning (pop)
3954 test_recursive_devector();
3956 test_exceeding_max_size();
3959 test_il_assignment< devector<int> >();
3960 test_assign_forward_range< devector<int> >();
3961 test_assign_il<devector<int> >();
3963 //test_devector< devector<int> >();
3964 test_devector
< devector
<regular_elem
> >();
3965 test_devector
< devector
<noex_move
> >();
3966 test_devector
< devector
<noex_copy
> >();
3967 test_devector
< devector
<only_movable
> >();
3968 test_devector
< devector
<no_default_ctor
> >();
3970 ////////////////////////////////////
3971 // Allocator propagation testing
3972 ////////////////////////////////////
3973 (void)boost::container::test::test_propagate_allocator
<boost_container_devector
>();
3977 boost::container::vector
<only_movable
> getom()
3979 typedef boost::container::vector
<only_movable
> V
;
3981 return BOOST_MOVE_RET(V
, v
);
3985 boost::container::vector
<boost::container::test::movable_int
> get()
3987 typedef boost::container::vector
<boost::container::test::movable_int
> V
;
3989 return BOOST_MOVE_RET(V
, v
);
3994 // boost::container::vector<boost::container::test::movable_int>a(get());
3995 //boost::container::vector<only_movable> b(getom());
3996 //boost::container::vector<only_movable> c(get_range< boost::container::vector<only_movable> >(1, 5, 5, 9));
3998 return boost::report_errors();