]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/container/test/vector_test.cpp
update sources to ceph Nautilus 14.2.1
[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//////////////////////////////////////////////////////////////////////////////
11fdf7f2
TL
10
11// the tests trigger deprecation warnings when compiled with msvc in C++17 mode
12#if defined(_MSVC_LANG) && _MSVC_LANG > 201402
13// warning STL4009: std::allocator<void> is deprecated in C++17
14# define _SILENCE_CXX17_ALLOCATOR_VOID_DEPRECATION_WARNING
15#endif
16
7c673cae
FG
17#include <memory>
18#include <iostream>
19
20#include <boost/container/vector.hpp>
21#include <boost/container/allocator.hpp>
22
23#include <boost/move/utility_core.hpp>
24#include "check_equal_containers.hpp"
25#include "movable_int.hpp"
26#include "expand_bwd_test_allocator.hpp"
27#include "expand_bwd_test_template.hpp"
28#include "dummy_test_allocator.hpp"
29#include "propagate_allocator_test.hpp"
30#include "vector_test.hpp"
31#include "default_init_test.hpp"
32#include "../../intrusive/test/iterator_test.hpp"
33
34using namespace boost::container;
35
36namespace boost {
37namespace container {
38
39//Explicit instantiation to detect compilation errors
40template class boost::container::vector
41 < test::movable_and_copyable_int
42 , test::simple_allocator<test::movable_and_copyable_int> >;
43
44template class boost::container::vector
45 < test::movable_and_copyable_int
46 , allocator<test::movable_and_copyable_int> >;
47
7c673cae
FG
48template class vec_iterator<int*, true >;
49template class vec_iterator<int*, false>;
50
7c673cae
FG
51}}
52
53int test_expand_bwd()
54{
55 //Now test all back insertion possibilities
56
57 //First raw ints
58 typedef test::expand_bwd_test_allocator<int>
59 int_allocator_type;
60 typedef vector<int, int_allocator_type>
61 int_vector;
62 if(!test::test_all_expand_bwd<int_vector>())
63 return 1;
64
65 //Now user defined copyable int
66 typedef test::expand_bwd_test_allocator<test::copyable_int>
67 copyable_int_allocator_type;
68 typedef vector<test::copyable_int, copyable_int_allocator_type>
69 copyable_int_vector;
70 if(!test::test_all_expand_bwd<copyable_int_vector>())
71 return 1;
72
73 return 0;
74}
75
76class recursive_vector
77{
78 public:
79 recursive_vector & operator=(const recursive_vector &x)
80 { this->vector_ = x.vector_; return *this; }
81
82 int id_;
83 vector<recursive_vector> vector_;
84 vector<recursive_vector>::iterator it_;
85 vector<recursive_vector>::const_iterator cit_;
86 vector<recursive_vector>::reverse_iterator rit_;
87 vector<recursive_vector>::const_reverse_iterator crit_;
88};
89
90void recursive_vector_test()//Test for recursive types
91{
92 vector<recursive_vector> recursive_vector_vector;
93}
94
95enum Test
96{
97 zero, one, two, three, four, five, six
98};
99
100template<class VoidAllocator>
101struct GetAllocatorCont
102{
103 template<class ValueType>
104 struct apply
105 {
106 typedef vector< ValueType
107 , typename allocator_traits<VoidAllocator>
108 ::template portable_rebind_alloc<ValueType>::type
109 > type;
110 };
111};
112
113template<class VoidAllocator>
114int test_cont_variants()
115{
116 typedef typename GetAllocatorCont<VoidAllocator>::template apply<int>::type MyCont;
117 typedef typename GetAllocatorCont<VoidAllocator>::template apply<test::movable_int>::type MyMoveCont;
118 typedef typename GetAllocatorCont<VoidAllocator>::template apply<test::movable_and_copyable_int>::type MyCopyMoveCont;
119 typedef typename GetAllocatorCont<VoidAllocator>::template apply<test::copyable_int>::type MyCopyCont;
120
121 if(test::vector_test<MyCont>())
122 return 1;
123 if(test::vector_test<MyMoveCont>())
124 return 1;
125 if(test::vector_test<MyCopyMoveCont>())
126 return 1;
127 if(test::vector_test<MyCopyCont>())
128 return 1;
129
130 return 0;
131}
132
133struct boost_container_vector;
134
135namespace boost { namespace container { namespace test {
136
137template<>
138struct alloc_propagate_base<boost_container_vector>
139{
140 template <class T, class Allocator>
141 struct apply
142 {
143 typedef boost::container::vector<T, Allocator> type;
144 };
145};
146
147}}} //namespace boost::container::test
148
149int main()
150{
151 {
152 const std::size_t positions_length = 10;
153 std::size_t positions[positions_length];
154 vector<int> vector_int;
155 vector<int> vector_int2(positions_length);
156 for(std::size_t i = 0; i != positions_length; ++i){
157 positions[i] = 0u;
158 }
159 for(std::size_t i = 0, max = vector_int2.size(); i != max; ++i){
160 vector_int2[i] = (int)i;
161 }
162
163 vector_int.insert(vector_int.begin(), 999);
164
165 vector_int.insert_ordered_at(positions_length, positions + positions_length, vector_int2.end());
166
167 for(std::size_t i = 0, max = vector_int.size(); i != max; ++i){
168 std::cout << vector_int[i] << std::endl;
169 }
170 }
171 recursive_vector_test();
172 {
173 //Now test move semantics
174 vector<recursive_vector> original;
175 vector<recursive_vector> move_ctor(boost::move(original));
176 vector<recursive_vector> move_assign;
177 move_assign = boost::move(move_ctor);
178 move_assign.swap(original);
179 }
180
181 ////////////////////////////////////
182 // Testing allocator implementations
183 ////////////////////////////////////
184 // std:allocator
185 if(test_cont_variants< std::allocator<void> >()){
186 std::cerr << "test_cont_variants< std::allocator<void> > failed" << std::endl;
187 return 1;
188 }
189 // boost::container::allocator
190 if(test_cont_variants< allocator<void> >()){
191 std::cerr << "test_cont_variants< allocator<void> > failed" << std::endl;
192 return 1;
193 }
194
195 {
196 typedef vector<Test, std::allocator<Test> > MyEnumCont;
197 MyEnumCont v;
198 Test t;
199 v.push_back(t);
200 v.push_back(::boost::move(t));
201 v.push_back(Test());
202 }
203
204 ////////////////////////////////////
205 // Backwards expansion test
206 ////////////////////////////////////
207 if(test_expand_bwd())
208 return 1;
209
210 ////////////////////////////////////
211 // Default init test
212 ////////////////////////////////////
213 if(!test::default_init_test< vector<int, test::default_init_allocator<int> > >()){
214 std::cerr << "Default init test failed" << std::endl;
215 return 1;
216 }
217
218 ////////////////////////////////////
219 // Emplace testing
220 ////////////////////////////////////
221 const test::EmplaceOptions Options = (test::EmplaceOptions)(test::EMPLACE_BACK | test::EMPLACE_BEFORE);
222 if(!boost::container::test::test_emplace< vector<test::EmplaceInt>, Options>()){
223 return 1;
224 }
225
226 ////////////////////////////////////
227 // Allocator propagation testing
228 ////////////////////////////////////
229 if(!boost::container::test::test_propagate_allocator<boost_container_vector>()){
230 return 1;
231 }
232
233 ////////////////////////////////////
234 // Initializer lists testing
235 ////////////////////////////////////
236 if(!boost::container::test::test_vector_methods_with_initializer_list_as_argument_for<
237 boost::container::vector<int>
238 >()) {
239 return 1;
240 }
241
242 ////////////////////////////////////
243 // Iterator testing
244 ////////////////////////////////////
245 {
246 typedef boost::container::vector<int> cont_int;
247 cont_int a; a.push_back(0); a.push_back(1); a.push_back(2);
248 boost::intrusive::test::test_iterator_random< cont_int >(a);
249 if(boost::report_errors() != 0) {
250 return 1;
251 }
252 }
253 return 0;
254}