]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/container/test/vector_test.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / container / test / vector_test.cpp
1 //////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga 2004-2013. Distributed under the Boost
4 // Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // See http://www.boost.org/libs/container for documentation.
8 //
9 //////////////////////////////////////////////////////////////////////////////
10 #include <memory>
11 #include <iostream>
12
13 #include <boost/container/vector.hpp>
14 #include <boost/container/allocator.hpp>
15
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"
26
27 using namespace boost::container;
28
29 namespace boost {
30 namespace container {
31
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> >;
36
37 template class boost::container::vector
38 < test::movable_and_copyable_int
39 , allocator<test::movable_and_copyable_int> >;
40
41 namespace container_detail {
42
43 #ifndef BOOST_CONTAINER_VECTOR_ITERATOR_IS_POINTER
44
45 template class vec_iterator<int*, true >;
46 template class vec_iterator<int*, false>;
47
48 #endif //BOOST_CONTAINER_VECTOR_ITERATOR_IS_POINTER
49
50 }
51
52 }}
53
54 int test_expand_bwd()
55 {
56 //Now test all back insertion possibilities
57
58 //First raw ints
59 typedef test::expand_bwd_test_allocator<int>
60 int_allocator_type;
61 typedef vector<int, int_allocator_type>
62 int_vector;
63 if(!test::test_all_expand_bwd<int_vector>())
64 return 1;
65
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>
70 copyable_int_vector;
71 if(!test::test_all_expand_bwd<copyable_int_vector>())
72 return 1;
73
74 return 0;
75 }
76
77 class recursive_vector
78 {
79 public:
80 recursive_vector & operator=(const recursive_vector &x)
81 { this->vector_ = x.vector_; return *this; }
82
83 int id_;
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_;
89 };
90
91 void recursive_vector_test()//Test for recursive types
92 {
93 vector<recursive_vector> recursive_vector_vector;
94 }
95
96 enum Test
97 {
98 zero, one, two, three, four, five, six
99 };
100
101 template<class VoidAllocator>
102 struct GetAllocatorCont
103 {
104 template<class ValueType>
105 struct apply
106 {
107 typedef vector< ValueType
108 , typename allocator_traits<VoidAllocator>
109 ::template portable_rebind_alloc<ValueType>::type
110 > type;
111 };
112 };
113
114 template<class VoidAllocator>
115 int test_cont_variants()
116 {
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;
121
122 if(test::vector_test<MyCont>())
123 return 1;
124 if(test::vector_test<MyMoveCont>())
125 return 1;
126 if(test::vector_test<MyCopyMoveCont>())
127 return 1;
128 if(test::vector_test<MyCopyCont>())
129 return 1;
130
131 return 0;
132 }
133
134 struct boost_container_vector;
135
136 namespace boost { namespace container { namespace test {
137
138 template<>
139 struct alloc_propagate_base<boost_container_vector>
140 {
141 template <class T, class Allocator>
142 struct apply
143 {
144 typedef boost::container::vector<T, Allocator> type;
145 };
146 };
147
148 }}} //namespace boost::container::test
149
150 int main()
151 {
152 {
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){
158 positions[i] = 0u;
159 }
160 for(std::size_t i = 0, max = vector_int2.size(); i != max; ++i){
161 vector_int2[i] = (int)i;
162 }
163
164 vector_int.insert(vector_int.begin(), 999);
165
166 vector_int.insert_ordered_at(positions_length, positions + positions_length, vector_int2.end());
167
168 for(std::size_t i = 0, max = vector_int.size(); i != max; ++i){
169 std::cout << vector_int[i] << std::endl;
170 }
171 }
172 recursive_vector_test();
173 {
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);
180 }
181
182 ////////////////////////////////////
183 // Testing allocator implementations
184 ////////////////////////////////////
185 // std:allocator
186 if(test_cont_variants< std::allocator<void> >()){
187 std::cerr << "test_cont_variants< std::allocator<void> > failed" << std::endl;
188 return 1;
189 }
190 // boost::container::allocator
191 if(test_cont_variants< allocator<void> >()){
192 std::cerr << "test_cont_variants< allocator<void> > failed" << std::endl;
193 return 1;
194 }
195
196 {
197 typedef vector<Test, std::allocator<Test> > MyEnumCont;
198 MyEnumCont v;
199 Test t;
200 v.push_back(t);
201 v.push_back(::boost::move(t));
202 v.push_back(Test());
203 }
204
205 ////////////////////////////////////
206 // Backwards expansion test
207 ////////////////////////////////////
208 if(test_expand_bwd())
209 return 1;
210
211 ////////////////////////////////////
212 // Default init test
213 ////////////////////////////////////
214 if(!test::default_init_test< vector<int, test::default_init_allocator<int> > >()){
215 std::cerr << "Default init test failed" << std::endl;
216 return 1;
217 }
218
219 ////////////////////////////////////
220 // Emplace testing
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>()){
224 return 1;
225 }
226
227 ////////////////////////////////////
228 // Allocator propagation testing
229 ////////////////////////////////////
230 if(!boost::container::test::test_propagate_allocator<boost_container_vector>()){
231 return 1;
232 }
233
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>
239 >()) {
240 return 1;
241 }
242
243 ////////////////////////////////////
244 // Iterator testing
245 ////////////////////////////////////
246 {
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) {
251 return 1;
252 }
253 }
254 return 0;
255 }