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