]>
Commit | Line | Data |
---|---|---|
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 | ||
11 | #ifndef BOOST_CONTAINER_TEST_SET_TEST_HEADER | |
12 | #define BOOST_CONTAINER_TEST_SET_TEST_HEADER | |
13 | ||
14 | #include <boost/container/detail/config_begin.hpp> | |
15 | #include "check_equal_containers.hpp" | |
16 | #include "print_container.hpp" | |
17 | #include <boost/move/utility_core.hpp> | |
18 | #include <boost/move/iterator.hpp> | |
19 | #include <boost/move/make_unique.hpp> | |
20 | ||
21 | #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME rebalance | |
22 | #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEG namespace boost { namespace container { namespace test { | |
23 | #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END }}} | |
24 | #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MIN 0 | |
25 | #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_MAX 0 | |
26 | #include <boost/intrusive/detail/has_member_function_callable_with.hpp> | |
27 | ||
28 | namespace boost{ | |
29 | namespace container { | |
30 | namespace test{ | |
31 | ||
32 | template<class C> | |
33 | void set_test_rebalanceable(C &, boost::container::container_detail::false_type) | |
34 | {} | |
35 | ||
36 | template<class C> | |
37 | void set_test_rebalanceable(C &c, boost::container::container_detail::true_type) | |
38 | { | |
39 | c.rebalance(); | |
40 | } | |
41 | ||
42 | template<class MyBoostSet | |
43 | ,class MyStdSet | |
44 | ,class MyBoostMultiSet | |
45 | ,class MyStdMultiSet> | |
46 | int set_test_copyable(boost::container::container_detail::false_type) | |
47 | { return 0; } | |
48 | ||
49 | const int MaxElem = 50; | |
50 | ||
51 | template<class MyBoostSet | |
52 | ,class MyStdSet | |
53 | ,class MyBoostMultiSet | |
54 | ,class MyStdMultiSet> | |
55 | int set_test_copyable(boost::container::container_detail::true_type) | |
56 | { | |
57 | typedef typename MyBoostSet::value_type IntType; | |
58 | ||
59 | ::boost::movelib::unique_ptr<MyBoostSet> const pboostset = ::boost::movelib::make_unique<MyBoostSet>(); | |
60 | ::boost::movelib::unique_ptr<MyStdSet> const pstdset = ::boost::movelib::make_unique<MyStdSet>(); | |
61 | ::boost::movelib::unique_ptr<MyBoostMultiSet> const pboostmultiset = ::boost::movelib::make_unique<MyBoostMultiSet>(); | |
62 | ::boost::movelib::unique_ptr<MyStdMultiSet> const pstdmultiset = ::boost::movelib::make_unique<MyStdMultiSet>(); | |
63 | ||
64 | MyBoostSet &boostset = *pboostset; | |
65 | MyStdSet &stdset = *pstdset; | |
66 | MyBoostMultiSet &boostmultiset = *pboostmultiset; | |
67 | MyStdMultiSet &stdmultiset = *pstdmultiset; | |
68 | ||
69 | //Just to test move aware catch conversions | |
70 | boostset.insert(boostset.cbegin(), boostset.cend()); | |
71 | boostmultiset.insert(boostmultiset.cbegin(), boostmultiset.cend()); | |
72 | boostset.insert(boostset.begin(), boostset.end()); | |
73 | boostmultiset.insert(boostmultiset.begin(), boostmultiset.end()); | |
74 | ||
75 | for(int i = 0; i < MaxElem; ++i){ | |
76 | IntType move_me(i); | |
77 | boostset.insert(boost::move(move_me)); | |
78 | stdset.insert(i); | |
79 | IntType move_me2(i); | |
80 | boostmultiset.insert(boost::move(move_me2)); | |
81 | stdmultiset.insert(i); | |
82 | } | |
83 | if(!CheckEqualContainers(boostset, stdset)) return 1; | |
84 | if(!CheckEqualContainers(boostmultiset, stdmultiset)) return 1; | |
85 | ||
86 | { | |
87 | //Now, test copy constructor | |
88 | MyBoostSet boostsetcopy(boostset); | |
89 | MyStdSet stdsetcopy(stdset); | |
90 | ||
91 | if(!CheckEqualContainers(boostsetcopy, stdsetcopy)) | |
92 | return 1; | |
93 | ||
94 | MyBoostMultiSet boostmsetcopy(boostmultiset); | |
95 | MyStdMultiSet stdmsetcopy(stdmultiset); | |
96 | ||
97 | if(!CheckEqualContainers(boostmsetcopy, stdmsetcopy)) | |
98 | return 1; | |
99 | ||
100 | //And now assignment | |
101 | boostsetcopy =boostset; | |
102 | stdsetcopy = stdset; | |
103 | ||
104 | if(!CheckEqualContainers(boostsetcopy, stdsetcopy)) | |
105 | return 1; | |
106 | ||
107 | boostmsetcopy = boostmultiset; | |
108 | stdmsetcopy = stdmultiset; | |
109 | ||
110 | if(!CheckEqualContainers(boostmsetcopy, stdmsetcopy)) | |
111 | return 1; | |
112 | } | |
113 | { | |
114 | //Now, test copy constructor | |
115 | MyBoostSet boostsetcopy(boostset, typename MyBoostSet::allocator_type()); | |
116 | MyStdSet stdsetcopy(stdset); | |
117 | ||
118 | if(!CheckEqualContainers(boostsetcopy, stdsetcopy)) | |
119 | return 1; | |
120 | ||
121 | MyBoostMultiSet boostmsetcopy(boostmultiset, typename MyBoostSet::allocator_type()); | |
122 | MyStdMultiSet stdmsetcopy(stdmultiset); | |
123 | ||
124 | if(!CheckEqualContainers(boostmsetcopy, stdmsetcopy)) | |
125 | return 1; | |
126 | } | |
127 | return 0; | |
128 | } | |
129 | ||
130 | ||
131 | template<class MyBoostSet | |
132 | ,class MyStdSet | |
133 | ,class MyBoostMultiSet | |
134 | ,class MyStdMultiSet> | |
135 | int set_test () | |
136 | { | |
137 | typedef typename MyBoostSet::value_type IntType; | |
138 | ||
139 | ::boost::movelib::unique_ptr<MyBoostSet> const pboostset = ::boost::movelib::make_unique<MyBoostSet>(); | |
140 | ::boost::movelib::unique_ptr<MyStdSet> const pstdset = ::boost::movelib::make_unique<MyStdSet>(); | |
141 | ::boost::movelib::unique_ptr<MyBoostMultiSet> const pboostmultiset = ::boost::movelib::make_unique<MyBoostMultiSet>(); | |
142 | ::boost::movelib::unique_ptr<MyStdMultiSet> const pstdmultiset = ::boost::movelib::make_unique<MyStdMultiSet>(); | |
143 | ||
144 | MyBoostSet &boostset = *pboostset; | |
145 | MyStdSet &stdset = *pstdset; | |
146 | MyBoostMultiSet &boostmultiset = *pboostmultiset; | |
147 | MyStdMultiSet &stdmultiset = *pstdmultiset; | |
148 | ||
149 | //Test construction from a range | |
150 | { //Set(beg, end, compare) | |
151 | IntType aux_vect[50]; | |
152 | for(int i = 0; i < 50; ++i){ | |
153 | IntType move_me(i/2); | |
154 | aux_vect[i] = boost::move(move_me); | |
155 | } | |
156 | int aux_vect2[50]; | |
157 | for(int i = 0; i < 50; ++i){ | |
158 | aux_vect2[i] = i/2; | |
159 | } | |
160 | IntType aux_vect3[50]; | |
161 | for(int i = 0; i < 50; ++i){ | |
162 | IntType move_me(i/2); | |
163 | aux_vect3[i] = boost::move(move_me); | |
164 | } | |
165 | ::boost::movelib::unique_ptr<MyBoostSet> const pboostset2 = ::boost::movelib::make_unique<MyBoostSet> | |
166 | (boost::make_move_iterator(&aux_vect[0]), boost::make_move_iterator(&aux_vect[0]+50), typename MyBoostSet::key_compare()); | |
167 | ::boost::movelib::unique_ptr<MyStdSet> const pstdset2 = ::boost::movelib::make_unique<MyStdSet>(&aux_vect2[0], &aux_vect2[0]+50); | |
168 | if(!test::CheckEqualContainers(*pboostset2, *pstdset2)) return 1; | |
169 | ::boost::movelib::unique_ptr<MyBoostMultiSet> const pboostmultiset2 = ::boost::movelib::make_unique<MyBoostMultiSet> | |
170 | (boost::make_move_iterator(&aux_vect3[0]), boost::make_move_iterator(&aux_vect3[0]+50), typename MyBoostMultiSet::key_compare()); | |
171 | ::boost::movelib::unique_ptr<MyStdMultiSet> const pstdmultiset2 = ::boost::movelib::make_unique<MyStdMultiSet>(&aux_vect2[0], &aux_vect2[0]+50); | |
172 | if(!test::CheckEqualContainers(*pboostmultiset2, *pstdmultiset2)) return 1; | |
173 | } | |
174 | { //Set(beg, end, alloc) | |
175 | IntType aux_vect[50]; | |
176 | for(int i = 0; i < 50; ++i){ | |
177 | IntType move_me(i/2); | |
178 | aux_vect[i] = boost::move(move_me); | |
179 | } | |
180 | int aux_vect2[50]; | |
181 | for(int i = 0; i < 50; ++i){ | |
182 | aux_vect2[i] = i/2; | |
183 | } | |
184 | IntType aux_vect3[50]; | |
185 | for(int i = 0; i < 50; ++i){ | |
186 | IntType move_me(i/2); | |
187 | aux_vect3[i] = boost::move(move_me); | |
188 | } | |
189 | ::boost::movelib::unique_ptr<MyBoostSet> const pboostset2 = ::boost::movelib::make_unique<MyBoostSet> | |
190 | (boost::make_move_iterator(&aux_vect[0]), boost::make_move_iterator(&aux_vect[0]+50), typename MyBoostSet::allocator_type()); | |
191 | ::boost::movelib::unique_ptr<MyStdSet> const pstdset2 = ::boost::movelib::make_unique<MyStdSet>(&aux_vect2[0], &aux_vect2[0]+50); | |
192 | if(!test::CheckEqualContainers(*pboostset2, *pstdset2)) return 1; | |
193 | ::boost::movelib::unique_ptr<MyBoostMultiSet> const pboostmultiset2 = ::boost::movelib::make_unique<MyBoostMultiSet> | |
194 | (boost::make_move_iterator(&aux_vect3[0]), boost::make_move_iterator(&aux_vect3[0]+50), typename MyBoostMultiSet::allocator_type()); | |
195 | ::boost::movelib::unique_ptr<MyStdMultiSet> const pstdmultiset2 = ::boost::movelib::make_unique<MyStdMultiSet>(&aux_vect2[0], &aux_vect2[0]+50); | |
196 | if(!test::CheckEqualContainers(*pboostmultiset2, *pstdmultiset2)) return 1; | |
197 | } | |
198 | { | |
199 | IntType aux_vect[50]; | |
200 | for(int i = 0; i < 50; ++i){ | |
201 | IntType move_me(i/2); | |
202 | aux_vect[i] = boost::move(move_me); | |
203 | } | |
204 | int aux_vect2[50]; | |
205 | for(int i = 0; i < 50; ++i){ | |
206 | aux_vect2[i] = i/2; | |
207 | } | |
208 | IntType aux_vect3[50]; | |
209 | for(int i = 0; i < 50; ++i){ | |
210 | IntType move_me(i/2); | |
211 | aux_vect3[i] = boost::move(move_me); | |
212 | } | |
213 | ||
214 | ::boost::movelib::unique_ptr<MyBoostSet> const pboostset2 = ::boost::movelib::make_unique<MyBoostSet> | |
215 | ( boost::make_move_iterator(&aux_vect[0]) | |
216 | , boost::make_move_iterator(aux_vect + 50)); | |
217 | ::boost::movelib::unique_ptr<MyStdSet> const pstdset2 = ::boost::movelib::make_unique<MyStdSet> | |
218 | (&aux_vect2[0], &aux_vect2[0] + 50); | |
219 | ::boost::movelib::unique_ptr<MyBoostMultiSet> const pboostmultiset2 = ::boost::movelib::make_unique<MyBoostMultiSet> | |
220 | ( boost::make_move_iterator(&aux_vect3[0]) | |
221 | , boost::make_move_iterator(aux_vect3 + 50)); | |
222 | ::boost::movelib::unique_ptr<MyStdMultiSet> const pstdmultiset2 = ::boost::movelib::make_unique<MyStdMultiSet> | |
223 | (&aux_vect2[0], &aux_vect2[0] + 50); | |
224 | ||
225 | MyBoostSet &boostset2 = *pboostset2; | |
226 | MyStdSet &stdset2 = *pstdset2; | |
227 | MyBoostMultiSet &boostmultiset2 = *pboostmultiset2; | |
228 | MyStdMultiSet &stdmultiset2 = *pstdmultiset2; | |
229 | ||
230 | if(!CheckEqualContainers(boostset2, stdset2)){ | |
231 | std::cout << "Error in construct<MyBoostSet>(MyBoostSet2)" << std::endl; | |
232 | return 1; | |
233 | } | |
234 | if(!CheckEqualContainers(boostmultiset2, stdmultiset2)){ | |
235 | std::cout << "Error in construct<MyBoostMultiSet>(MyBoostMultiSet2)" << std::endl; | |
236 | return 1; | |
237 | } | |
238 | ||
239 | //ordered range insertion | |
240 | for(int i = 0; i < 50; ++i){ | |
241 | IntType move_me(i); | |
242 | aux_vect[i] = boost::move(move_me); | |
243 | } | |
244 | ||
245 | for(int i = 0; i < 50; ++i){ | |
246 | aux_vect2[i] = i; | |
247 | } | |
248 | ||
249 | for(int i = 0; i < 50; ++i){ | |
250 | IntType move_me(i); | |
251 | aux_vect3[i] = boost::move(move_me); | |
252 | } | |
253 | ||
254 | //some comparison operators | |
255 | if(!(boostset2 == boostset2)) | |
256 | return 1; | |
257 | if(boostset2 != boostset2) | |
258 | return 1; | |
259 | if(boostset2 < boostset2) | |
260 | return 1; | |
261 | if(boostset2 > boostset2) | |
262 | return 1; | |
263 | if(!(boostset2 <= boostset2)) | |
264 | return 1; | |
265 | if(!(boostset2 >= boostset2)) | |
266 | return 1; | |
267 | ||
268 | ::boost::movelib::unique_ptr<MyBoostSet> const pboostset3 = ::boost::movelib::make_unique<MyBoostSet> | |
269 | ( ordered_unique_range | |
270 | , boost::make_move_iterator(&aux_vect[0]) | |
271 | , boost::make_move_iterator(&aux_vect[0] + 50)); | |
272 | ::boost::movelib::unique_ptr<MyStdSet> const pstdset3 = ::boost::movelib::make_unique<MyStdSet> | |
273 | (&aux_vect2[0], &aux_vect2[0] + 50); | |
274 | ::boost::movelib::unique_ptr<MyBoostMultiSet> const pboostmultiset3 = ::boost::movelib::make_unique<MyBoostMultiSet> | |
275 | ( ordered_range | |
276 | , boost::make_move_iterator(&aux_vect3[0]) | |
277 | , boost::make_move_iterator(aux_vect3 + 50)); | |
278 | ::boost::movelib::unique_ptr<MyStdMultiSet> const pstdmultiset3 = ::boost::movelib::make_unique<MyStdMultiSet> | |
279 | (&aux_vect2[0], &aux_vect2[0] + 50); | |
280 | ||
281 | MyBoostSet &boostset3 = *pboostset3; | |
282 | MyStdSet &stdset3 = *pstdset3; | |
283 | MyBoostMultiSet &boostmultiset3 = *pboostmultiset3; | |
284 | MyStdMultiSet &stdmultiset3 = *pstdmultiset3; | |
285 | ||
286 | if(!CheckEqualContainers(boostset3, stdset3)){ | |
287 | std::cout << "Error in construct<MyBoostSet>(MyBoostSet3)" << std::endl; | |
288 | return 1; | |
289 | } | |
290 | if(!CheckEqualContainers(boostmultiset3, stdmultiset3)){ | |
291 | std::cout << "Error in construct<MyBoostMultiSet>(MyBoostMultiSet3)" << std::endl; | |
292 | return 1; | |
293 | } | |
294 | } | |
295 | ||
296 | for(int i = 0; i < MaxElem; ++i){ | |
297 | IntType move_me(i); | |
298 | boostset.insert(boost::move(move_me)); | |
299 | stdset.insert(i); | |
300 | boostset.insert(IntType(i)); | |
301 | stdset.insert(i); | |
302 | IntType move_me2(i); | |
303 | boostmultiset.insert(boost::move(move_me2)); | |
304 | stdmultiset.insert(i); | |
305 | boostmultiset.insert(IntType(i)); | |
306 | stdmultiset.insert(i); | |
307 | } | |
308 | ||
309 | if(!CheckEqualContainers(boostset, stdset)){ | |
310 | std::cout << "Error in boostset.insert(boost::move(move_me)" << std::endl; | |
311 | return 1; | |
312 | } | |
313 | ||
314 | if(!CheckEqualContainers(boostmultiset, stdmultiset)){ | |
315 | std::cout << "Error in boostmultiset.insert(boost::move(move_me)" << std::endl; | |
316 | return 1; | |
317 | } | |
318 | ||
319 | typename MyBoostSet::iterator it = boostset.begin(); | |
320 | typename MyBoostSet::const_iterator cit = it; | |
321 | (void)cit; | |
322 | ||
323 | boostset.erase(boostset.begin()); | |
324 | stdset.erase(stdset.begin()); | |
325 | boostmultiset.erase(boostmultiset.begin()); | |
326 | stdmultiset.erase(stdmultiset.begin()); | |
327 | if(!CheckEqualContainers(boostset, stdset)){ | |
328 | std::cout << "Error in boostset.erase(boostset.begin())" << std::endl; | |
329 | return 1; | |
330 | } | |
331 | if(!CheckEqualContainers(boostmultiset, stdmultiset)){ | |
332 | std::cout << "Error in boostmultiset.erase(boostmultiset.begin())" << std::endl; | |
333 | return 1; | |
334 | } | |
335 | ||
336 | boostset.erase(boostset.begin()); | |
337 | stdset.erase(stdset.begin()); | |
338 | boostmultiset.erase(boostmultiset.begin()); | |
339 | stdmultiset.erase(stdmultiset.begin()); | |
340 | if(!CheckEqualContainers(boostset, stdset)){ | |
341 | std::cout << "Error in boostset.erase(boostset.begin())" << std::endl; | |
342 | return 1; | |
343 | } | |
344 | if(!CheckEqualContainers(boostmultiset, stdmultiset)){ | |
345 | std::cout << "Error in boostmultiset.erase(boostmultiset.begin())" << std::endl; | |
346 | return 1; | |
347 | } | |
348 | ||
349 | //Swapping test | |
350 | MyBoostSet tmpboosteset2; | |
351 | MyStdSet tmpstdset2; | |
352 | MyBoostMultiSet tmpboostemultiset2; | |
353 | MyStdMultiSet tmpstdmultiset2; | |
354 | boostset.swap(tmpboosteset2); | |
355 | stdset.swap(tmpstdset2); | |
356 | boostmultiset.swap(tmpboostemultiset2); | |
357 | stdmultiset.swap(tmpstdmultiset2); | |
358 | boostset.swap(tmpboosteset2); | |
359 | stdset.swap(tmpstdset2); | |
360 | boostmultiset.swap(tmpboostemultiset2); | |
361 | stdmultiset.swap(tmpstdmultiset2); | |
362 | if(!CheckEqualContainers(boostset, stdset)){ | |
363 | std::cout << "Error in boostset.swap(tmpboosteset2)" << std::endl; | |
364 | return 1; | |
365 | } | |
366 | if(!CheckEqualContainers(boostmultiset, stdmultiset)){ | |
367 | std::cout << "Error in boostmultiset.swap(tmpboostemultiset2)" << std::endl; | |
368 | return 1; | |
369 | } | |
370 | ||
371 | //Insertion from other container | |
372 | //Initialize values | |
373 | { | |
374 | IntType aux_vect[50]; | |
375 | for(int i = 0; i < 50; ++i){ | |
376 | IntType move_me(-1); | |
377 | aux_vect[i] = boost::move(move_me); | |
378 | } | |
379 | int aux_vect2[50]; | |
380 | for(int i = 0; i < 50; ++i){ | |
381 | aux_vect2[i] = -1; | |
382 | } | |
383 | IntType aux_vect3[50]; | |
384 | for(int i = 0; i < 50; ++i){ | |
385 | IntType move_me(-1); | |
386 | aux_vect3[i] = boost::move(move_me); | |
387 | } | |
388 | ||
389 | boostset.insert(boost::make_move_iterator(&aux_vect[0]), boost::make_move_iterator(&aux_vect[0] + 50)); | |
390 | stdset.insert(&aux_vect2[0], &aux_vect2[0] + 50); | |
391 | boostmultiset.insert(boost::make_move_iterator(&aux_vect3[0]), boost::make_move_iterator(aux_vect3 + 50)); | |
392 | stdmultiset.insert(&aux_vect2[0], &aux_vect2[0] + 50); | |
393 | if(!CheckEqualContainers(boostset, stdset)){ | |
394 | std::cout << "Error in boostset.insert(boost::make_move_iterator(&aux_vect[0])..." << std::endl; | |
395 | return 1; | |
396 | } | |
397 | if(!CheckEqualContainers(boostmultiset, stdmultiset)){ | |
398 | std::cout << "Error in boostmultiset.insert(boost::make_move_iterator(&aux_vect3[0]), ..." << std::endl; | |
399 | return 1; | |
400 | } | |
401 | ||
402 | for(int i = 0, j = static_cast<int>(boostset.size()); i < j; ++i){ | |
403 | IntType erase_me(i); | |
404 | boostset.erase(erase_me); | |
405 | stdset.erase(i); | |
406 | boostmultiset.erase(erase_me); | |
407 | stdmultiset.erase(i); | |
408 | if(!CheckEqualContainers(boostset, stdset)){ | |
409 | std::cout << "Error in boostset.erase(erase_me)" << boostset.size() << " " << stdset.size() << std::endl; | |
410 | return 1; | |
411 | } | |
412 | if(!CheckEqualContainers(boostmultiset, stdmultiset)){ | |
413 | std::cout << "Error in boostmultiset.erase(erase_me)" << std::endl; | |
414 | return 1; | |
415 | } | |
416 | } | |
417 | } | |
418 | { | |
419 | IntType aux_vect[50]; | |
420 | for(int i = 0; i < 50; ++i){ | |
421 | IntType move_me(-1); | |
422 | aux_vect[i] = boost::move(move_me); | |
423 | } | |
424 | int aux_vect2[50]; | |
425 | for(int i = 0; i < 50; ++i){ | |
426 | aux_vect2[i] = -1; | |
427 | } | |
428 | IntType aux_vect3[50]; | |
429 | for(int i = 0; i < 50; ++i){ | |
430 | IntType move_me(-1); | |
431 | aux_vect3[i] = boost::move(move_me); | |
432 | } | |
433 | ||
434 | IntType aux_vect4[50]; | |
435 | for(int i = 0; i < 50; ++i){ | |
436 | IntType move_me(-1); | |
437 | aux_vect4[i] = boost::move(move_me); | |
438 | } | |
439 | ||
440 | IntType aux_vect5[50]; | |
441 | for(int i = 0; i < 50; ++i){ | |
442 | IntType move_me(-1); | |
443 | aux_vect5[i] = boost::move(move_me); | |
444 | } | |
445 | ||
446 | boostset.insert(boost::make_move_iterator(&aux_vect[0]), boost::make_move_iterator(&aux_vect[0] + 50)); | |
447 | boostset.insert(boost::make_move_iterator(&aux_vect3[0]), boost::make_move_iterator(&aux_vect3[0] + 50)); | |
448 | stdset.insert(&aux_vect2[0], &aux_vect2[0] + 50); | |
449 | stdset.insert(&aux_vect2[0], &aux_vect2[0] + 50); | |
450 | boostmultiset.insert(boost::make_move_iterator(&aux_vect4[0]), boost::make_move_iterator(&aux_vect4[0] + 50)); | |
451 | boostmultiset.insert(boost::make_move_iterator(&aux_vect5[0]), boost::make_move_iterator(&aux_vect5[0] + 50)); | |
452 | stdmultiset.insert(&aux_vect2[0], &aux_vect2[0] + 50); | |
453 | stdmultiset.insert(&aux_vect2[0], &aux_vect2[0] + 50); | |
454 | if(!CheckEqualContainers(boostset, stdset)){ | |
455 | std::cout << "Error in boostset.insert(boost::make_move_iterator(&aux_vect3[0])..." << std::endl; | |
456 | return 1; | |
457 | } | |
458 | if(!CheckEqualContainers(boostmultiset, stdmultiset)){ | |
459 | std::cout << "Error in boostmultiset.insert(boost::make_move_iterator(&aux_vect5[0])..." << std::endl; | |
460 | return 1; | |
461 | } | |
462 | ||
463 | boostset.erase(*boostset.begin()); | |
464 | stdset.erase(*stdset.begin()); | |
465 | boostmultiset.erase(*boostmultiset.begin()); | |
466 | stdmultiset.erase(*stdmultiset.begin()); | |
467 | if(!CheckEqualContainers(boostset, stdset)){ | |
468 | std::cout << "Error in boostset.erase(*boostset.begin())" << std::endl; | |
469 | return 1; | |
470 | } | |
471 | if(!CheckEqualContainers(boostmultiset, stdmultiset)){ | |
472 | std::cout << "Error in boostmultiset.erase(*boostmultiset.begin())" << std::endl; | |
473 | return 1; | |
474 | } | |
475 | } | |
476 | ||
477 | for(int i = 0; i < MaxElem; ++i){ | |
478 | IntType move_me(i); | |
479 | boostset.insert(boost::move(move_me)); | |
480 | stdset.insert(i); | |
481 | IntType move_me2(i); | |
482 | boostmultiset.insert(boost::move(move_me2)); | |
483 | stdmultiset.insert(i); | |
484 | } | |
485 | ||
486 | if(!CheckEqualContainers(boostset, stdset)){ | |
487 | std::cout << "Error in boostset.insert(boost::move(move_me)) try 2" << std::endl; | |
488 | return 1; | |
489 | } | |
490 | if(!CheckEqualContainers(boostmultiset, stdmultiset)){ | |
491 | std::cout << "Error in boostmultiset.insert(boost::move(move_me2)) try 2" << std::endl; | |
492 | return 1; | |
493 | } | |
494 | ||
495 | for(int i = 0; i < MaxElem; ++i){ | |
496 | { | |
497 | IntType move_me(i); | |
498 | boostset.insert(boostset.begin(), boost::move(move_me)); | |
499 | stdset.insert(stdset.begin(), i); | |
500 | //PrintContainers(boostset, stdset); | |
501 | IntType move_me2(i); | |
502 | boostmultiset.insert(boostmultiset.begin(), boost::move(move_me2)); | |
503 | stdmultiset.insert(stdmultiset.begin(), i); | |
504 | //PrintContainers(boostmultiset, stdmultiset); | |
505 | if(!CheckEqualContainers(boostset, stdset)){ | |
506 | std::cout << "Error in boostset.insert(boostset.begin(), boost::move(move_me))" << std::endl; | |
507 | return 1; | |
508 | } | |
509 | if(!CheckEqualContainers(boostmultiset, stdmultiset)){ | |
510 | std::cout << "Error in boostmultiset.insert(boostmultiset.begin(), boost::move(move_me2))" << std::endl; | |
511 | return 1; | |
512 | } | |
513 | ||
514 | IntType move_me3(i); | |
515 | boostset.insert(boostset.end(), boost::move(move_me3)); | |
516 | stdset.insert(stdset.end(), i); | |
517 | IntType move_me4(i); | |
518 | boostmultiset.insert(boostmultiset.end(), boost::move(move_me4)); | |
519 | stdmultiset.insert(stdmultiset.end(), i); | |
520 | if(!CheckEqualContainers(boostset, stdset)){ | |
521 | std::cout << "Error in boostset.insert(boostset.end(), boost::move(move_me3))" << std::endl; | |
522 | return 1; | |
523 | } | |
524 | if(!CheckEqualContainers(boostmultiset, stdmultiset)){ | |
525 | std::cout << "Error in boostmultiset.insert(boostmultiset.end(), boost::move(move_me4))" << std::endl; | |
526 | return 1; | |
527 | } | |
528 | } | |
529 | { | |
530 | IntType move_me(i); | |
531 | boostset.insert(boostset.upper_bound(move_me), boost::move(move_me)); | |
532 | stdset.insert(stdset.upper_bound(i), i); | |
533 | //PrintContainers(boostset, stdset); | |
534 | IntType move_me2(i); | |
535 | boostmultiset.insert(boostmultiset.upper_bound(move_me2), boost::move(move_me2)); | |
536 | stdmultiset.insert(stdmultiset.upper_bound(i), i); | |
537 | //PrintContainers(boostmultiset, stdmultiset); | |
538 | if(!CheckEqualContainers(boostset, stdset)){ | |
539 | std::cout << "Error in boostset.insert(boostset.upper_bound(move_me), boost::move(move_me))" << std::endl; | |
540 | return 1; | |
541 | } | |
542 | if(!CheckEqualContainers(boostmultiset, stdmultiset)){ | |
543 | std::cout << "Error in boostmultiset.insert(boostmultiset.upper_bound(move_me2), boost::move(move_me2))" << std::endl; | |
544 | return 1; | |
545 | } | |
546 | ||
547 | } | |
548 | { | |
549 | IntType move_me(i); | |
550 | IntType move_me2(i); | |
551 | boostset.insert(boostset.lower_bound(move_me), boost::move(move_me2)); | |
552 | stdset.insert(stdset.lower_bound(i), i); | |
553 | //PrintContainers(boostset, stdset); | |
554 | move_me2 = i; | |
555 | boostmultiset.insert(boostmultiset.lower_bound(move_me2), boost::move(move_me2)); | |
556 | stdmultiset.insert(stdmultiset.lower_bound(i), i); | |
557 | //PrintContainers(boostmultiset, stdmultiset); | |
558 | if(!CheckEqualContainers(boostset, stdset)){ | |
559 | std::cout << "Error in boostset.insert(boostset.lower_bound(move_me), boost::move(move_me2))" << std::endl; | |
560 | return 1; | |
561 | } | |
562 | if(!CheckEqualContainers(boostmultiset, stdmultiset)){ | |
563 | std::cout << "Error in boostmultiset.insert(boostmultiset.lower_bound(move_me2), boost::move(move_me2))" << std::endl; | |
564 | return 1; | |
565 | } | |
566 | set_test_rebalanceable(boostset | |
567 | , container_detail::bool_<has_member_function_callable_with_rebalance<MyBoostSet>::value>()); | |
568 | if(!CheckEqualContainers(boostset, stdset)){ | |
569 | std::cout << "Error in boostset.rebalance()" << std::endl; | |
570 | return 1; | |
571 | } | |
572 | set_test_rebalanceable(boostmultiset | |
573 | , container_detail::bool_<has_member_function_callable_with_rebalance<MyBoostMultiSet>::value>()); | |
574 | if(!CheckEqualContainers(boostmultiset, stdmultiset)){ | |
575 | std::cout << "Error in boostmultiset.rebalance()" << std::endl; | |
576 | return 1; | |
577 | } | |
578 | } | |
579 | } | |
580 | ||
581 | //Compare count with std containers | |
582 | for(int i = 0; i < MaxElem; ++i){ | |
583 | IntType count_me(i); | |
584 | if(boostset.count(count_me) != stdset.count(i)){ | |
585 | return -1; | |
586 | } | |
587 | if(boostmultiset.count(count_me) != stdmultiset.count(i)){ | |
588 | return -1; | |
589 | } | |
590 | } | |
591 | ||
592 | //Compare find/lower_bound/upper_bound in set | |
593 | { | |
594 | typename MyBoostSet::iterator bs_b = boostset.begin(); | |
595 | typename MyBoostSet::iterator bs_e = boostset.end(); | |
596 | typename MyStdSet::iterator ss_b = stdset.begin(); | |
597 | ||
598 | std::size_t i = 0; | |
599 | while(bs_b != bs_e){ | |
600 | ++i; | |
601 | typename MyBoostSet::iterator bs_i; | |
602 | typename MyStdSet::iterator ss_i; | |
603 | //find | |
604 | bs_i = boostset.find(*bs_b); | |
605 | ss_i = stdset.find(*ss_b); | |
606 | if(!CheckEqualIt(bs_i, ss_i, boostset, stdset)){ | |
607 | return -1; | |
608 | } | |
609 | //lower bound | |
610 | bs_i = boostset.lower_bound(*bs_b); | |
611 | ss_i = stdset.lower_bound(*ss_b); | |
612 | if(!CheckEqualIt(bs_i, ss_i, boostset, stdset)){ | |
613 | return -1; | |
614 | } | |
615 | //upper bound | |
616 | bs_i = boostset.upper_bound(*bs_b); | |
617 | ss_i = stdset.upper_bound(*ss_b); | |
618 | if(!CheckEqualIt(bs_i, ss_i, boostset, stdset)){ | |
619 | return -1; | |
620 | } | |
621 | //equal range | |
622 | std::pair<typename MyBoostSet::iterator | |
623 | ,typename MyBoostSet::iterator> bs_ip; | |
624 | std::pair<typename MyStdSet::iterator | |
625 | ,typename MyStdSet::iterator> ss_ip; | |
626 | bs_ip = boostset.equal_range(*bs_b); | |
627 | ss_ip = stdset.equal_range(*ss_b); | |
628 | if(!CheckEqualIt(bs_ip.first, ss_ip.first, boostset, stdset)){ | |
629 | return -1; | |
630 | } | |
631 | if(!CheckEqualIt(bs_ip.second, ss_ip.second, boostset, stdset)){ | |
632 | return -1; | |
633 | } | |
634 | ++bs_b; | |
635 | ++ss_b; | |
636 | } | |
637 | } | |
638 | //Compare find/lower_bound/upper_bound in multiset | |
639 | { | |
640 | typename MyBoostMultiSet::iterator bm_b = boostmultiset.begin(); | |
641 | typename MyBoostMultiSet::iterator bm_e = boostmultiset.end(); | |
642 | typename MyStdMultiSet::iterator sm_b = stdmultiset.begin(); | |
643 | ||
644 | while(bm_b != bm_e){ | |
645 | typename MyBoostMultiSet::iterator bm_i; | |
646 | typename MyStdMultiSet::iterator sm_i; | |
647 | //find | |
648 | bm_i = boostmultiset.find(*bm_b); | |
649 | sm_i = stdmultiset.find(*sm_b); | |
650 | if(!CheckEqualIt(bm_i, sm_i, boostmultiset, stdmultiset)){ | |
651 | return -1; | |
652 | } | |
653 | //lower bound | |
654 | bm_i = boostmultiset.lower_bound(*bm_b); | |
655 | sm_i = stdmultiset.lower_bound(*sm_b); | |
656 | if(!CheckEqualIt(bm_i, sm_i, boostmultiset, stdmultiset)){ | |
657 | return -1; | |
658 | } | |
659 | //upper bound | |
660 | bm_i = boostmultiset.upper_bound(*bm_b); | |
661 | sm_i = stdmultiset.upper_bound(*sm_b); | |
662 | if(!CheckEqualIt(bm_i, sm_i, boostmultiset, stdmultiset)){ | |
663 | return -1; | |
664 | } | |
665 | //equal range | |
666 | std::pair<typename MyBoostMultiSet::iterator | |
667 | ,typename MyBoostMultiSet::iterator> bm_ip; | |
668 | std::pair<typename MyStdMultiSet::iterator | |
669 | ,typename MyStdMultiSet::iterator> sm_ip; | |
670 | bm_ip = boostmultiset.equal_range(*bm_b); | |
671 | sm_ip = stdmultiset.equal_range(*sm_b); | |
672 | if(!CheckEqualIt(bm_ip.first, sm_ip.first, boostmultiset, stdmultiset)){ | |
673 | return -1; | |
674 | } | |
675 | if(!CheckEqualIt(bm_ip.second, sm_ip.second, boostmultiset, stdmultiset)){ | |
676 | return -1; | |
677 | } | |
678 | ++bm_b; | |
679 | ++sm_b; | |
680 | } | |
681 | } | |
682 | ||
683 | //Now do count exercise | |
684 | boostset.erase(boostset.begin(), boostset.end()); | |
685 | boostmultiset.erase(boostmultiset.begin(), boostmultiset.end()); | |
686 | boostset.clear(); | |
687 | boostmultiset.clear(); | |
688 | ||
689 | for(int j = 0; j < 3; ++j) | |
690 | for(int i = 0; i < 100; ++i){ | |
691 | IntType move_me(i); | |
692 | boostset.insert(boost::move(move_me)); | |
693 | IntType move_me2(i); | |
694 | boostmultiset.insert(boost::move(move_me2)); | |
695 | IntType count_me(i); | |
696 | if(boostset.count(count_me) != typename MyBoostMultiSet::size_type(1)){ | |
697 | std::cout << "Error in boostset.count(count_me)" << std::endl; | |
698 | return 1; | |
699 | } | |
700 | if(boostmultiset.count(count_me) != typename MyBoostMultiSet::size_type(j+1)){ | |
701 | std::cout << "Error in boostmultiset.count(count_me)" << std::endl; | |
702 | return 1; | |
703 | } | |
704 | } | |
705 | ||
706 | { //merge | |
707 | ::boost::movelib::unique_ptr<MyBoostSet> const pboostset2 = ::boost::movelib::make_unique<MyBoostSet>(); | |
708 | ::boost::movelib::unique_ptr<MyBoostMultiSet> const pboostmultiset2 = ::boost::movelib::make_unique<MyBoostMultiSet>(); | |
709 | ||
710 | MyBoostSet &boostset2 = *pboostset2; | |
711 | MyBoostMultiSet &boostmultiset2 = *pboostmultiset2; | |
712 | ||
713 | boostset.clear(); | |
714 | boostset2.clear(); | |
715 | boostmultiset.clear(); | |
716 | boostmultiset2.clear(); | |
717 | stdset.clear(); | |
718 | stdmultiset.clear(); | |
719 | ||
720 | { | |
721 | IntType aux_vect[MaxElem]; | |
722 | for(int i = 0; i < MaxElem; ++i){ | |
723 | aux_vect[i] = i; | |
724 | } | |
725 | ||
726 | IntType aux_vect2[MaxElem]; | |
727 | for(int i = 0; i < MaxElem; ++i){ | |
728 | aux_vect2[i] = MaxElem/2+i; | |
729 | } | |
730 | IntType aux_vect3[MaxElem]; | |
731 | for(int i = 0; i < MaxElem; ++i){ | |
732 | aux_vect3[i] = MaxElem*2/2+i; | |
733 | } | |
734 | boostset.insert(boost::make_move_iterator(&aux_vect[0]), boost::make_move_iterator(&aux_vect[0] + MaxElem)); | |
735 | boostset2.insert(boost::make_move_iterator(&aux_vect2[0]), boost::make_move_iterator(&aux_vect2[0] + MaxElem)); | |
736 | boostmultiset2.insert(boost::make_move_iterator(&aux_vect3[0]), boost::make_move_iterator(&aux_vect3[0] + MaxElem)); | |
737 | } | |
738 | for(int i = 0; i < MaxElem; ++i){ | |
739 | stdset.insert(i); | |
740 | } | |
741 | for(int i = 0; i < MaxElem; ++i){ | |
742 | stdset.insert(MaxElem/2+i); | |
743 | } | |
744 | ||
745 | boostset.merge(boost::move(boostset2)); | |
746 | if(!CheckEqualContainers(boostset, stdset)) return 1; | |
747 | ||
748 | for(int i = 0; i < MaxElem; ++i){ | |
749 | stdset.insert(MaxElem*2/2+i); | |
750 | } | |
751 | ||
752 | boostset.merge(boost::move(boostmultiset2)); | |
753 | if(!CheckEqualContainers(boostset, stdset)) return 1; | |
754 | ||
755 | boostset.clear(); | |
756 | boostset2.clear(); | |
757 | boostmultiset.clear(); | |
758 | boostmultiset2.clear(); | |
759 | stdset.clear(); | |
760 | stdmultiset.clear(); | |
761 | { | |
762 | IntType aux_vect[MaxElem]; | |
763 | for(int i = 0; i < MaxElem; ++i){ | |
764 | aux_vect[i] = i; | |
765 | } | |
766 | ||
767 | IntType aux_vect2[MaxElem]; | |
768 | for(int i = 0; i < MaxElem; ++i){ | |
769 | aux_vect2[i] = MaxElem/2+i; | |
770 | } | |
771 | IntType aux_vect3[MaxElem]; | |
772 | for(int i = 0; i < MaxElem; ++i){ | |
773 | aux_vect3[i] = MaxElem*2/2+i; | |
774 | } | |
775 | boostmultiset.insert(boost::make_move_iterator(&aux_vect[0]), boost::make_move_iterator(&aux_vect[0] + MaxElem)); | |
776 | boostmultiset2.insert(boost::make_move_iterator(&aux_vect2[0]), boost::make_move_iterator(&aux_vect2[0] + MaxElem)); | |
777 | boostset2.insert(boost::make_move_iterator(&aux_vect3[0]), boost::make_move_iterator(&aux_vect3[0] + MaxElem)); | |
778 | } | |
779 | for(int i = 0; i < MaxElem; ++i){ | |
780 | stdmultiset.insert(i); | |
781 | } | |
782 | for(int i = 0; i < MaxElem; ++i){ | |
783 | stdmultiset.insert(MaxElem/2+i); | |
784 | } | |
785 | boostmultiset.merge(boost::move(boostmultiset2)); | |
786 | if(!CheckEqualContainers(boostmultiset, stdmultiset)) return 1; | |
787 | ||
788 | for(int i = 0; i < MaxElem; ++i){ | |
789 | stdmultiset.insert(MaxElem*2/2+i); | |
790 | } | |
791 | ||
792 | boostmultiset.merge(boost::move(boostset2)); | |
793 | if(!CheckEqualContainers(boostmultiset, stdmultiset)) return 1; | |
794 | } | |
795 | ||
796 | if(set_test_copyable<MyBoostSet, MyStdSet, MyBoostMultiSet, MyStdMultiSet> | |
797 | (container_detail::bool_<boost::container::test::is_copyable<IntType>::value>())){ | |
798 | return 1; | |
799 | } | |
800 | ||
801 | return 0; | |
802 | } | |
803 | ||
804 | template<typename SetType> | |
805 | bool test_set_methods_with_initializer_list_as_argument_for() | |
806 | { | |
807 | #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) | |
808 | std::initializer_list<int> il = { 1, 2, 3, 4, 5, 5 }; | |
809 | std::initializer_list<int> ilu = { 1, 2, 3, 4, 5 }; | |
810 | SetType expected(il.begin(), il.end()); | |
811 | SetType expectedu(ilu.begin(), ilu.end()); | |
812 | { | |
813 | SetType sil((il)); | |
814 | if (sil != expected) | |
815 | return false; | |
816 | ||
817 | SetType sila(il, typename SetType::allocator_type()); | |
818 | if (sila != expected) | |
819 | return false; | |
820 | ||
821 | SetType silca(il, typename SetType::key_compare(), typename SetType::allocator_type()); | |
822 | if (silca != expected) | |
823 | return false; | |
824 | ||
825 | SetType sil_ordered(ordered_unique_range, ilu); | |
826 | if (sil_ordered != expectedu) | |
827 | return false; | |
828 | ||
829 | SetType sil_assign = { 99, 100, 101, 102, 103, 104, 105 }; | |
830 | sil_assign = il; | |
831 | if (sil_assign != expected) | |
832 | return false; | |
833 | } | |
834 | { | |
835 | SetType sil; | |
836 | sil.insert(il); | |
837 | if (sil != expected) | |
838 | return false; | |
839 | } | |
840 | return true; | |
841 | #endif | |
842 | return true; | |
843 | } | |
844 | ||
845 | template<typename SetType, typename MultisetType> | |
846 | bool instantiate_constructors() | |
847 | { | |
848 | { | |
849 | typedef typename SetType::value_type value_type; | |
850 | typename SetType::key_compare comp; | |
851 | typename SetType::allocator_type a; | |
852 | value_type value; | |
853 | { | |
854 | SetType s0; | |
855 | SetType s1(comp); | |
856 | SetType s2(a); | |
857 | SetType s3(comp, a); | |
858 | } | |
859 | { | |
860 | SetType s0(&value, &value); | |
861 | SetType s1(&value, &value ,comp); | |
862 | SetType s2(&value, &value ,a); | |
863 | SetType s3(&value, &value ,comp, a); | |
864 | } | |
865 | #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) | |
866 | { | |
867 | SetType s0({ 0 }); | |
868 | SetType s1({ 0 },comp); | |
869 | SetType s2({ 0 },a); | |
870 | SetType s3({ 0 },comp, a); | |
871 | } | |
872 | { | |
873 | std::initializer_list<value_type> il{0}; | |
874 | SetType s0(ordered_unique_range, il); | |
875 | SetType s1(ordered_unique_range, il,comp); | |
876 | SetType s3(ordered_unique_range, il,comp, a); | |
877 | } | |
878 | #endif | |
879 | { | |
880 | SetType s0(ordered_unique_range, &value, &value); | |
881 | SetType s1(ordered_unique_range, &value, &value ,comp); | |
882 | SetType s2(ordered_unique_range, &value, &value ,comp, a); | |
883 | } | |
884 | } | |
885 | ||
886 | { | |
887 | typedef typename MultisetType::value_type value_type; | |
888 | typename MultisetType::key_compare comp; | |
889 | typename MultisetType::allocator_type a; | |
890 | value_type value; | |
891 | { | |
892 | MultisetType s0; | |
893 | MultisetType s1(comp); | |
894 | MultisetType s2(a); | |
895 | MultisetType s3(comp, a); | |
896 | } | |
897 | { | |
898 | MultisetType s0(&value, &value); | |
899 | MultisetType s1(&value, &value ,comp); | |
900 | MultisetType s2(&value, &value ,a); | |
901 | MultisetType s3(&value, &value ,comp, a); | |
902 | } | |
903 | #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) | |
904 | { | |
905 | MultisetType s0({ 0 }); | |
906 | MultisetType s1({ 0 },comp); | |
907 | MultisetType s2({ 0 },a); | |
908 | MultisetType s3({ 0 },comp, a); | |
909 | } | |
910 | { | |
911 | std::initializer_list<value_type>il{0}; | |
912 | MultisetType s0(ordered_range, il); | |
913 | MultisetType s1(ordered_range, il,comp); | |
914 | MultisetType s3(ordered_range, il,comp, a); | |
915 | } | |
916 | #endif | |
917 | { | |
918 | MultisetType s0(ordered_range, &value, &value); | |
919 | MultisetType s1(ordered_range, &value, &value ,comp); | |
920 | MultisetType s2(ordered_range, &value, &value ,comp, a); | |
921 | } | |
922 | } | |
923 | return true; | |
924 | } | |
925 | ||
926 | } //namespace test{ | |
927 | } //namespace container { | |
928 | } //namespace boost{ | |
929 | ||
930 | #include <boost/container/detail/config_end.hpp> | |
931 | ||
932 | #endif |