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 #ifndef BOOST_CONTAINER_VECTOR_ITERATOR_IS_POINTER
45 template class vec_iterator
<int*, true >;
46 template class vec_iterator
<int*, false>;
48 #endif //BOOST_CONTAINER_VECTOR_ITERATOR_IS_POINTER
56 //Now test all back insertion possibilities
59 typedef test::expand_bwd_test_allocator
<int>
61 typedef vector
<int, int_allocator_type
>
63 if(!test::test_all_expand_bwd
<int_vector
>())
66 //Now user defined copyable int
67 typedef test::expand_bwd_test_allocator
<test::copyable_int
>
68 copyable_int_allocator_type
;
69 typedef vector
<test::copyable_int
, copyable_int_allocator_type
>
71 if(!test::test_all_expand_bwd
<copyable_int_vector
>())
77 class recursive_vector
80 recursive_vector
& operator=(const recursive_vector
&x
)
81 { this->vector_
= x
.vector_
; return *this; }
84 vector
<recursive_vector
> vector_
;
85 vector
<recursive_vector
>::iterator it_
;
86 vector
<recursive_vector
>::const_iterator cit_
;
87 vector
<recursive_vector
>::reverse_iterator rit_
;
88 vector
<recursive_vector
>::const_reverse_iterator crit_
;
91 void recursive_vector_test()//Test for recursive types
93 vector
<recursive_vector
> recursive_vector_vector
;
98 zero
, one
, two
, three
, four
, five
, six
101 template<class VoidAllocator
>
102 struct GetAllocatorCont
104 template<class ValueType
>
107 typedef vector
< ValueType
108 , typename allocator_traits
<VoidAllocator
>
109 ::template portable_rebind_alloc
<ValueType
>::type
114 template<class VoidAllocator
>
115 int test_cont_variants()
117 typedef typename GetAllocatorCont
<VoidAllocator
>::template apply
<int>::type MyCont
;
118 typedef typename GetAllocatorCont
<VoidAllocator
>::template apply
<test::movable_int
>::type MyMoveCont
;
119 typedef typename GetAllocatorCont
<VoidAllocator
>::template apply
<test::movable_and_copyable_int
>::type MyCopyMoveCont
;
120 typedef typename GetAllocatorCont
<VoidAllocator
>::template apply
<test::copyable_int
>::type MyCopyCont
;
122 if(test::vector_test
<MyCont
>())
124 if(test::vector_test
<MyMoveCont
>())
126 if(test::vector_test
<MyCopyMoveCont
>())
128 if(test::vector_test
<MyCopyCont
>())
134 struct boost_container_vector
;
136 namespace boost
{ namespace container
{ namespace test
{
139 struct alloc_propagate_base
<boost_container_vector
>
141 template <class T
, class Allocator
>
144 typedef boost::container::vector
<T
, Allocator
> type
;
148 }}} //namespace boost::container::test
153 const std::size_t positions_length
= 10;
154 std::size_t positions
[positions_length
];
155 vector
<int> vector_int
;
156 vector
<int> vector_int2(positions_length
);
157 for(std::size_t i
= 0; i
!= positions_length
; ++i
){
160 for(std::size_t i
= 0, max
= vector_int2
.size(); i
!= max
; ++i
){
161 vector_int2
[i
] = (int)i
;
164 vector_int
.insert(vector_int
.begin(), 999);
166 vector_int
.insert_ordered_at(positions_length
, positions
+ positions_length
, vector_int2
.end());
168 for(std::size_t i
= 0, max
= vector_int
.size(); i
!= max
; ++i
){
169 std::cout
<< vector_int
[i
] << std::endl
;
172 recursive_vector_test();
174 //Now test move semantics
175 vector
<recursive_vector
> original
;
176 vector
<recursive_vector
> move_ctor(boost::move(original
));
177 vector
<recursive_vector
> move_assign
;
178 move_assign
= boost::move(move_ctor
);
179 move_assign
.swap(original
);
182 ////////////////////////////////////
183 // Testing allocator implementations
184 ////////////////////////////////////
186 if(test_cont_variants
< std::allocator
<void> >()){
187 std::cerr
<< "test_cont_variants< std::allocator<void> > failed" << std::endl
;
190 // boost::container::allocator
191 if(test_cont_variants
< allocator
<void> >()){
192 std::cerr
<< "test_cont_variants< allocator<void> > failed" << std::endl
;
197 typedef vector
<Test
, std::allocator
<Test
> > MyEnumCont
;
201 v
.push_back(::boost::move(t
));
205 ////////////////////////////////////
206 // Backwards expansion test
207 ////////////////////////////////////
208 if(test_expand_bwd())
211 ////////////////////////////////////
213 ////////////////////////////////////
214 if(!test::default_init_test
< vector
<int, test::default_init_allocator
<int> > >()){
215 std::cerr
<< "Default init test failed" << std::endl
;
219 ////////////////////////////////////
221 ////////////////////////////////////
222 const test::EmplaceOptions Options
= (test::EmplaceOptions
)(test::EMPLACE_BACK
| test::EMPLACE_BEFORE
);
223 if(!boost::container::test::test_emplace
< vector
<test::EmplaceInt
>, Options
>()){
227 ////////////////////////////////////
228 // Allocator propagation testing
229 ////////////////////////////////////
230 if(!boost::container::test::test_propagate_allocator
<boost_container_vector
>()){
234 ////////////////////////////////////
235 // Initializer lists testing
236 ////////////////////////////////////
237 if(!boost::container::test::test_vector_methods_with_initializer_list_as_argument_for
<
238 boost::container::vector
<int>
243 ////////////////////////////////////
245 ////////////////////////////////////
247 typedef boost::container::vector
<int> cont_int
;
248 cont_int a
; a
.push_back(0); a
.push_back(1); a
.push_back(2);
249 boost::intrusive::test::test_iterator_random
< cont_int
>(a
);
250 if(boost::report_errors() != 0) {