1 //////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2004-2013. Distributed under the Boost
4 // Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 // See http://www.boost.org/libs/container for documentation.
9 //////////////////////////////////////////////////////////////////////////////
13 #include <boost/container/vector.hpp>
14 #include <boost/container/allocator.hpp>
16 #include <boost/move/utility_core.hpp>
17 #include "check_equal_containers.hpp"
18 #include "movable_int.hpp"
19 #include "expand_bwd_test_allocator.hpp"
20 #include "expand_bwd_test_template.hpp"
21 #include "dummy_test_allocator.hpp"
22 #include "propagate_allocator_test.hpp"
23 #include "vector_test.hpp"
24 #include "default_init_test.hpp"
25 #include "../../intrusive/test/iterator_test.hpp"
27 using namespace boost::container
;
32 //Explicit instantiation to detect compilation errors
33 template class boost::container::vector
34 < test::movable_and_copyable_int
35 , test::simple_allocator
<test::movable_and_copyable_int
> >;
37 template class boost::container::vector
38 < test::movable_and_copyable_int
39 , allocator
<test::movable_and_copyable_int
> >;
41 namespace container_detail
{
43 template class vec_iterator
<int*, true >;
44 template class vec_iterator
<int*, false>;
52 //Now test all back insertion possibilities
55 typedef test::expand_bwd_test_allocator
<int>
57 typedef vector
<int, int_allocator_type
>
59 if(!test::test_all_expand_bwd
<int_vector
>())
62 //Now user defined copyable int
63 typedef test::expand_bwd_test_allocator
<test::copyable_int
>
64 copyable_int_allocator_type
;
65 typedef vector
<test::copyable_int
, copyable_int_allocator_type
>
67 if(!test::test_all_expand_bwd
<copyable_int_vector
>())
73 class recursive_vector
76 recursive_vector
& operator=(const recursive_vector
&x
)
77 { this->vector_
= x
.vector_
; return *this; }
80 vector
<recursive_vector
> vector_
;
81 vector
<recursive_vector
>::iterator it_
;
82 vector
<recursive_vector
>::const_iterator cit_
;
83 vector
<recursive_vector
>::reverse_iterator rit_
;
84 vector
<recursive_vector
>::const_reverse_iterator crit_
;
87 void recursive_vector_test()//Test for recursive types
89 vector
<recursive_vector
> recursive_vector_vector
;
94 zero
, one
, two
, three
, four
, five
, six
97 template<class VoidAllocator
>
98 struct GetAllocatorCont
100 template<class ValueType
>
103 typedef vector
< ValueType
104 , typename allocator_traits
<VoidAllocator
>
105 ::template portable_rebind_alloc
<ValueType
>::type
110 template<class VoidAllocator
>
111 int test_cont_variants()
113 typedef typename GetAllocatorCont
<VoidAllocator
>::template apply
<int>::type MyCont
;
114 typedef typename GetAllocatorCont
<VoidAllocator
>::template apply
<test::movable_int
>::type MyMoveCont
;
115 typedef typename GetAllocatorCont
<VoidAllocator
>::template apply
<test::movable_and_copyable_int
>::type MyCopyMoveCont
;
116 typedef typename GetAllocatorCont
<VoidAllocator
>::template apply
<test::copyable_int
>::type MyCopyCont
;
118 if(test::vector_test
<MyCont
>())
120 if(test::vector_test
<MyMoveCont
>())
122 if(test::vector_test
<MyCopyMoveCont
>())
124 if(test::vector_test
<MyCopyCont
>())
130 struct boost_container_vector
;
132 namespace boost
{ namespace container
{ namespace test
{
135 struct alloc_propagate_base
<boost_container_vector
>
137 template <class T
, class Allocator
>
140 typedef boost::container::vector
<T
, Allocator
> type
;
144 }}} //namespace boost::container::test
149 const std::size_t positions_length
= 10;
150 std::size_t positions
[positions_length
];
151 vector
<int> vector_int
;
152 vector
<int> vector_int2(positions_length
);
153 for(std::size_t i
= 0; i
!= positions_length
; ++i
){
156 for(std::size_t i
= 0, max
= vector_int2
.size(); i
!= max
; ++i
){
157 vector_int2
[i
] = (int)i
;
160 vector_int
.insert(vector_int
.begin(), 999);
162 vector_int
.insert_ordered_at(positions_length
, positions
+ positions_length
, vector_int2
.end());
164 for(std::size_t i
= 0, max
= vector_int
.size(); i
!= max
; ++i
){
165 std::cout
<< vector_int
[i
] << std::endl
;
168 recursive_vector_test();
170 //Now test move semantics
171 vector
<recursive_vector
> original
;
172 vector
<recursive_vector
> move_ctor(boost::move(original
));
173 vector
<recursive_vector
> move_assign
;
174 move_assign
= boost::move(move_ctor
);
175 move_assign
.swap(original
);
178 ////////////////////////////////////
179 // Testing allocator implementations
180 ////////////////////////////////////
182 if(test_cont_variants
< std::allocator
<void> >()){
183 std::cerr
<< "test_cont_variants< std::allocator<void> > failed" << std::endl
;
186 // boost::container::allocator
187 if(test_cont_variants
< allocator
<void> >()){
188 std::cerr
<< "test_cont_variants< allocator<void> > failed" << std::endl
;
193 typedef vector
<Test
, std::allocator
<Test
> > MyEnumCont
;
197 v
.push_back(::boost::move(t
));
201 ////////////////////////////////////
202 // Backwards expansion test
203 ////////////////////////////////////
204 if(test_expand_bwd())
207 ////////////////////////////////////
209 ////////////////////////////////////
210 if(!test::default_init_test
< vector
<int, test::default_init_allocator
<int> > >()){
211 std::cerr
<< "Default init test failed" << std::endl
;
215 ////////////////////////////////////
217 ////////////////////////////////////
218 const test::EmplaceOptions Options
= (test::EmplaceOptions
)(test::EMPLACE_BACK
| test::EMPLACE_BEFORE
);
219 if(!boost::container::test::test_emplace
< vector
<test::EmplaceInt
>, Options
>()){
223 ////////////////////////////////////
224 // Allocator propagation testing
225 ////////////////////////////////////
226 if(!boost::container::test::test_propagate_allocator
<boost_container_vector
>()){
230 ////////////////////////////////////
231 // Initializer lists testing
232 ////////////////////////////////////
233 if(!boost::container::test::test_vector_methods_with_initializer_list_as_argument_for
<
234 boost::container::vector
<int>
239 ////////////////////////////////////
241 ////////////////////////////////////
243 typedef boost::container::vector
<int> cont_int
;
244 cont_int a
; a
.push_back(0); a
.push_back(1); a
.push_back(2);
245 boost::intrusive::test::test_iterator_random
< cont_int
>(a
);
246 if(boost::report_errors() != 0) {