]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/container/test/vector_test.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / container / test / vector_test.cpp
CommitLineData
7c673cae
FG
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
27using namespace boost::container;
28
29namespace boost {
30namespace container {
31
32//Explicit instantiation to detect compilation errors
33template class boost::container::vector
34 < test::movable_and_copyable_int
35 , test::simple_allocator<test::movable_and_copyable_int> >;
36
37template class boost::container::vector
38 < test::movable_and_copyable_int
39 , allocator<test::movable_and_copyable_int> >;
40
41namespace container_detail {
42
7c673cae
FG
43template class vec_iterator<int*, true >;
44template class vec_iterator<int*, false>;
45
7c673cae
FG
46}
47
48}}
49
50int test_expand_bwd()
51{
52 //Now test all back insertion possibilities
53
54 //First raw ints
55 typedef test::expand_bwd_test_allocator<int>
56 int_allocator_type;
57 typedef vector<int, int_allocator_type>
58 int_vector;
59 if(!test::test_all_expand_bwd<int_vector>())
60 return 1;
61
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>
66 copyable_int_vector;
67 if(!test::test_all_expand_bwd<copyable_int_vector>())
68 return 1;
69
70 return 0;
71}
72
73class recursive_vector
74{
75 public:
76 recursive_vector & operator=(const recursive_vector &x)
77 { this->vector_ = x.vector_; return *this; }
78
79 int id_;
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_;
85};
86
87void recursive_vector_test()//Test for recursive types
88{
89 vector<recursive_vector> recursive_vector_vector;
90}
91
92enum Test
93{
94 zero, one, two, three, four, five, six
95};
96
97template<class VoidAllocator>
98struct GetAllocatorCont
99{
100 template<class ValueType>
101 struct apply
102 {
103 typedef vector< ValueType
104 , typename allocator_traits<VoidAllocator>
105 ::template portable_rebind_alloc<ValueType>::type
106 > type;
107 };
108};
109
110template<class VoidAllocator>
111int test_cont_variants()
112{
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;
117
118 if(test::vector_test<MyCont>())
119 return 1;
120 if(test::vector_test<MyMoveCont>())
121 return 1;
122 if(test::vector_test<MyCopyMoveCont>())
123 return 1;
124 if(test::vector_test<MyCopyCont>())
125 return 1;
126
127 return 0;
128}
129
130struct boost_container_vector;
131
132namespace boost { namespace container { namespace test {
133
134template<>
135struct alloc_propagate_base<boost_container_vector>
136{
137 template <class T, class Allocator>
138 struct apply
139 {
140 typedef boost::container::vector<T, Allocator> type;
141 };
142};
143
144}}} //namespace boost::container::test
145
146int main()
147{
148 {
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){
154 positions[i] = 0u;
155 }
156 for(std::size_t i = 0, max = vector_int2.size(); i != max; ++i){
157 vector_int2[i] = (int)i;
158 }
159
160 vector_int.insert(vector_int.begin(), 999);
161
162 vector_int.insert_ordered_at(positions_length, positions + positions_length, vector_int2.end());
163
164 for(std::size_t i = 0, max = vector_int.size(); i != max; ++i){
165 std::cout << vector_int[i] << std::endl;
166 }
167 }
168 recursive_vector_test();
169 {
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);
176 }
177
178 ////////////////////////////////////
179 // Testing allocator implementations
180 ////////////////////////////////////
181 // std:allocator
182 if(test_cont_variants< std::allocator<void> >()){
183 std::cerr << "test_cont_variants< std::allocator<void> > failed" << std::endl;
184 return 1;
185 }
186 // boost::container::allocator
187 if(test_cont_variants< allocator<void> >()){
188 std::cerr << "test_cont_variants< allocator<void> > failed" << std::endl;
189 return 1;
190 }
191
192 {
193 typedef vector<Test, std::allocator<Test> > MyEnumCont;
194 MyEnumCont v;
195 Test t;
196 v.push_back(t);
197 v.push_back(::boost::move(t));
198 v.push_back(Test());
199 }
200
201 ////////////////////////////////////
202 // Backwards expansion test
203 ////////////////////////////////////
204 if(test_expand_bwd())
205 return 1;
206
207 ////////////////////////////////////
208 // Default init test
209 ////////////////////////////////////
210 if(!test::default_init_test< vector<int, test::default_init_allocator<int> > >()){
211 std::cerr << "Default init test failed" << std::endl;
212 return 1;
213 }
214
215 ////////////////////////////////////
216 // Emplace testing
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>()){
220 return 1;
221 }
222
223 ////////////////////////////////////
224 // Allocator propagation testing
225 ////////////////////////////////////
226 if(!boost::container::test::test_propagate_allocator<boost_container_vector>()){
227 return 1;
228 }
229
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>
235 >()) {
236 return 1;
237 }
238
239 ////////////////////////////////////
240 // Iterator testing
241 ////////////////////////////////////
242 {
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) {
247 return 1;
248 }
249 }
250 return 0;
251}