]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/intrusive/test/slist_test.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / intrusive / test / slist_test.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Olaf Krzikalla 2004-2006.
4 // (C) Copyright Ion Gaztanaga 2006-2013.
5 //
6 // Distributed under the Boost Software License, Version 1.0.
7 // (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9 //
10 // See http://www.boost.org/libs/intrusive for documentation.
11 //
12 /////////////////////////////////////////////////////////////////////////////
13
14 #include <boost/intrusive/slist.hpp>
15 #include <boost/intrusive/pointer_traits.hpp>
16 #include "itestvalue.hpp"
17 #include "bptr_value.hpp"
18 #include "smart_ptr.hpp"
19 #include "common_functors.hpp"
20 #include <vector>
21 #include <boost/core/lightweight_test.hpp>
22 #include "test_macros.hpp"
23 #include "test_container.hpp"
24 #include <typeinfo>
25
26 using namespace boost::intrusive;
27
28 template<class VoidPointer>
29 struct hooks
30 {
31 typedef slist_base_hook<void_pointer<VoidPointer> > base_hook_type;
32 typedef slist_base_hook< link_mode<auto_unlink>
33 , void_pointer<VoidPointer>, tag<void> > auto_base_hook_type;
34 typedef slist_member_hook<void_pointer<VoidPointer>, tag<void> > member_hook_type;
35 typedef slist_member_hook< link_mode<auto_unlink>
36 , void_pointer<VoidPointer> > auto_member_hook_type;
37 typedef nonhook_node_member< slist_node_traits< VoidPointer >,
38 circular_slist_algorithms
39 > nonhook_node_member_type;
40 };
41
42 template < typename ListType, typename ValueContainer >
43 struct test_slist
44 {
45 typedef ListType list_type;
46 typedef typename list_type::value_traits value_traits;
47 typedef typename value_traits::value_type value_type;
48 typedef typename list_type::node_algorithms node_algorithms;
49
50 static void test_all(ValueContainer&);
51 static void test_front(ValueContainer&);
52 static void test_back(ValueContainer&, detail::true_type);
53 static void test_back(ValueContainer&, detail::false_type) {}
54 static void test_sort(ValueContainer&);
55 static void test_merge(ValueContainer&);
56 static void test_remove_unique(ValueContainer&);
57 static void test_insert(ValueContainer&);
58 static void test_shift(ValueContainer&);
59 static void test_swap(ValueContainer&);
60 static void test_slow_insert(ValueContainer&);
61 static void test_clone(ValueContainer&);
62 static void test_container_from_end(ValueContainer&, detail::true_type);
63 static void test_container_from_end(ValueContainer&, detail::false_type) {}
64 };
65
66 template < typename ListType, typename ValueContainer >
67 void test_slist< ListType, ValueContainer >
68 ::test_all (ValueContainer& values)
69 {
70 {
71 list_type list(values.begin(), values.end());
72 test::test_container(list);
73 list.clear();
74 list.insert(list.end(), values.begin(), values.end());
75 test::test_sequence_container(list, values);
76 }
77 {
78 list_type list(values.begin(), values.end());
79 test::test_iterator_forward(list);
80 }
81 test_front(values);
82 test_back(values, detail::bool_< list_type::cache_last >());
83 test_sort(values);
84 test_merge (values);
85 test_remove_unique(values);
86 test_insert(values);
87 test_shift(values);
88 test_slow_insert (values);
89 test_swap(values);
90 test_clone(values);
91 test_container_from_end(values, detail::bool_< !list_type::linear && list_type::has_container_from_iterator >());
92 }
93
94 //test: push_front, pop_front, front, size, empty:
95 template < typename ListType, typename ValueContainer >
96 void test_slist< ListType, ValueContainer >
97 ::test_front(ValueContainer& values)
98 {
99 list_type testlist;
100 BOOST_TEST (testlist.empty());
101
102 testlist.push_front (values[0]);
103 BOOST_TEST (testlist.size() == 1);
104 BOOST_TEST (&testlist.front() == &values[0]);
105
106 testlist.push_front (values[1]);
107 BOOST_TEST (testlist.size() == 2);
108 BOOST_TEST (&testlist.front() == &values[1]);
109
110 testlist.pop_front();
111 BOOST_TEST (testlist.size() == 1);
112 BOOST_TEST (&testlist.front() == &values[0]);
113
114 testlist.pop_front();
115 BOOST_TEST (testlist.empty());
116 }
117
118 //test: push_front, pop_front, front, size, empty:
119 template < typename ListType, typename ValueContainer >
120 void test_slist< ListType, ValueContainer >
121 ::test_back(ValueContainer& values, detail::true_type)
122 {
123 list_type testlist;
124 BOOST_TEST (testlist.empty());
125
126 testlist.push_back (values[0]);
127 BOOST_TEST (testlist.size() == 1);
128 BOOST_TEST (&testlist.front() == &values[0]);
129 BOOST_TEST (&testlist.back() == &values[0]);
130 testlist.push_back(values[1]);
131 BOOST_TEST(*testlist.previous(testlist.end()) == values[1]);
132 BOOST_TEST (&testlist.front() == &values[0]);
133 BOOST_TEST (&testlist.back() == &values[1]);
134 }
135
136 //test: merge due to error in merge implementation:
137 template < typename ListType, typename ValueContainer >
138 void test_slist< ListType, ValueContainer >
139 ::test_merge (ValueContainer& values)
140 {
141 list_type testlist1, testlist2;
142 testlist1.push_front (values[0]);
143 testlist2.push_front (values[4]);
144 testlist2.push_front (values[3]);
145 testlist2.push_front (values[2]);
146 testlist1.merge (testlist2);
147
148 int init_values [] = { 1, 3, 4, 5 };
149 TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() );
150 }
151
152 //test: merge due to error in merge implementation:
153 template < typename ListType, typename ValueContainer >
154 void test_slist< ListType, ValueContainer >
155 ::test_remove_unique (ValueContainer& values)
156 {
157 {
158 list_type list(values.begin(), values.end());
159 list.remove_if(is_even());
160 int init_values [] = { 1, 3, 5 };
161 TEST_INTRUSIVE_SEQUENCE( init_values, list.begin() );
162 }
163 {
164 list_type list(values.begin(), values.end());
165 list.remove_if(is_odd());
166 int init_values [] = { 2, 4 };
167 TEST_INTRUSIVE_SEQUENCE( init_values, list.begin() );
168 }
169 {
170 list_type list(values.begin(), values.end());
171 list.remove_and_dispose_if(is_even(), test::empty_disposer());
172 int init_values [] = { 1, 3, 5 };
173 TEST_INTRUSIVE_SEQUENCE( init_values, list.begin() );
174 }
175 {
176 list_type list(values.begin(), values.end());
177 list.remove_and_dispose_if(is_odd(), test::empty_disposer());
178 int init_values [] = { 2, 4 };
179 TEST_INTRUSIVE_SEQUENCE( init_values, list.begin() );
180 }
181 {
182 ValueContainer values2(values);
183 list_type list(values.begin(), values.end());
184 list.insert_after(list.before_begin(), values2.begin(), values2.end());
185 list.sort();
186 int init_values [] = { 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 };
187 TEST_INTRUSIVE_SEQUENCE( init_values, list.begin() );
188 list.unique();
189 int init_values2 [] = { 1, 2, 3, 4, 5 };
190 TEST_INTRUSIVE_SEQUENCE( init_values2, list.begin() );
191 }
192 }
193
194 //test: constructor, iterator, sort, reverse:
195 template < typename ListType, typename ValueContainer >
196 void test_slist< ListType, ValueContainer >
197 ::test_sort(ValueContainer& values)
198 {
199 list_type testlist (values.begin(), values.end());
200
201 { int init_values [] = { 1, 2, 3, 4, 5 };
202 TEST_INTRUSIVE_SEQUENCE( init_values, testlist.begin() ); }
203
204 testlist.sort (even_odd());
205 { int init_values [] = { 2, 4, 1, 3, 5 };
206 TEST_INTRUSIVE_SEQUENCE( init_values, testlist.begin() ); }
207
208 testlist.reverse();
209 { int init_values [] = { 5, 3, 1, 4, 2 };
210 TEST_INTRUSIVE_SEQUENCE( init_values, testlist.begin() ); }
211 }
212
213 //test: assign, insert_after, const_iterator, erase_after, s_iterator_to, previous:
214 template < typename ListType, typename ValueContainer >
215 void test_slist< ListType, ValueContainer >
216 ::test_insert(ValueContainer& values)
217 {
218 list_type testlist;
219 testlist.assign (values.begin() + 2, values.begin() + 5);
220
221 const list_type& const_testlist = testlist;
222 { int init_values [] = { 3, 4, 5 };
223 TEST_INTRUSIVE_SEQUENCE( init_values, const_testlist.begin() ); }
224
225 typename list_type::iterator i = ++testlist.begin();
226 BOOST_TEST (i->value_ == 4);
227
228 testlist.insert_after (i, values[0]);
229 { int init_values [] = { 3, 4, 1, 5 };
230 TEST_INTRUSIVE_SEQUENCE( init_values, const_testlist.begin() ); }
231
232 i = testlist.iterator_to (values[4]);
233 BOOST_TEST (&*i == &values[4]);
234 i = list_type::s_iterator_to (values[4]);
235 BOOST_TEST (&*i == &values[4]);
236
237 typename list_type::const_iterator ic;
238 ic = testlist.iterator_to (static_cast< typename list_type::const_reference >(values[4]));
239 BOOST_TEST (&*ic == &values[4]);
240 ic = list_type::s_iterator_to (static_cast< typename list_type::const_reference >(values[4]));
241 BOOST_TEST (&*ic == &values[4]);
242
243 i = testlist.previous (i);
244 BOOST_TEST (&*i == &values[0]);
245
246 testlist.erase_after (i);
247 BOOST_TEST (&*i == &values[0]);
248 { int init_values [] = { 3, 4, 1 };
249 TEST_INTRUSIVE_SEQUENCE( init_values, const_testlist.begin() ); }
250 }
251
252 //test: insert, const_iterator, erase, siterator_to:
253 template < typename ListType, typename ValueContainer >
254 void test_slist< ListType, ValueContainer >
255 ::test_slow_insert (ValueContainer& values)
256 {
257 list_type testlist;
258 testlist.push_front (values[4]);
259 testlist.insert (testlist.begin(), values.begin() + 2, values.begin() + 4);
260
261 const list_type& const_testlist = testlist;
262 { int init_values [] = { 3, 4, 5 };
263 TEST_INTRUSIVE_SEQUENCE( init_values, const_testlist.begin() ); }
264
265 typename list_type::iterator i = ++testlist.begin();
266 BOOST_TEST (i->value_ == 4);
267
268 testlist.insert (i, values[0]);
269 { int init_values [] = { 3, 1, 4, 5 };
270 TEST_INTRUSIVE_SEQUENCE( init_values, const_testlist.begin() ); }
271
272 i = testlist.iterator_to (values[4]);
273 BOOST_TEST (&*i == &values[4]);
274
275 i = list_type::s_iterator_to (values[4]);
276 BOOST_TEST (&*i == &values[4]);
277
278 i = testlist.erase (i);
279 BOOST_TEST (i == testlist.end());
280
281 { int init_values [] = { 3, 1, 4 };
282 TEST_INTRUSIVE_SEQUENCE( init_values, const_testlist.begin() ); }
283
284 testlist.erase (++testlist.begin(), testlist.end());
285 BOOST_TEST (testlist.size() == 1);
286 BOOST_TEST (testlist.begin()->value_ == 3);
287 }
288
289 template < typename ListType, typename ValueContainer >
290 void test_slist< ListType, ValueContainer >
291 ::test_shift(ValueContainer& values)
292 {
293 list_type testlist;
294 const std::size_t num_values = values.size();
295 std::vector<int> expected_values(num_values);
296
297 //Shift forward all possible positions 3 times
298 for(std::size_t s = 1; s <= num_values; ++s){
299 expected_values.resize(s);
300 for(std::size_t i = 0; i < s*3u; ++i){
301 testlist.insert_after(testlist.before_begin(), values.begin(), values.begin() + std::ptrdiff_t(s));
302 testlist.shift_forward(i);
303 for(std::size_t j = 0; j < s; ++j){
304 expected_values[(j + s - i%s) % s] = int(j + 1);
305 }
306
307 TEST_INTRUSIVE_SEQUENCE_EXPECTED(expected_values, testlist.begin())
308 testlist.clear();
309 }
310
311 //Shift backwards all possible positions
312 for(std::size_t i = 0; i < s*3u; ++i){
313 testlist.insert_after(testlist.before_begin(), values.begin(), values.begin() + std::ptrdiff_t(s));
314 testlist.shift_backwards(i);
315 for(std::size_t j = 0; j < s; ++j){
316 expected_values[(j + i) % s] = int(j + 1);
317 }
318
319 TEST_INTRUSIVE_SEQUENCE_EXPECTED(expected_values, testlist.begin())
320 testlist.clear();
321 }
322 }
323 }
324
325 //test: insert_after (seq-version), swap, splice_after:
326 template < typename ListType, typename ValueContainer >
327 void test_slist< ListType, ValueContainer >
328 ::test_swap(ValueContainer& values)
329 {
330 {
331 list_type testlist1 (values.begin(), values.begin() + 2);
332 list_type testlist2;
333 testlist2.insert_after (testlist2.before_begin(), values.begin() + 2, values.begin() + 5);
334 testlist1.swap(testlist2);
335 { int init_values [] = { 3, 4, 5 };
336 TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); }
337 { int init_values [] = { 1, 2 };
338 TEST_INTRUSIVE_SEQUENCE( init_values, testlist2.begin() ); }
339 testlist2.splice_after (testlist2.begin(), testlist1);
340 { int init_values [] = { 1, 3, 4, 5, 2 };
341 TEST_INTRUSIVE_SEQUENCE( init_values, testlist2.begin() ); }
342 BOOST_TEST (testlist1.empty());
343
344 testlist1.splice_after (testlist1.before_begin(), testlist2, ++testlist2.begin());
345 { int init_values [] = { 4 };
346 TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); }
347 { int init_values [] = { 1, 3, 5, 2 };
348 TEST_INTRUSIVE_SEQUENCE( init_values, testlist2.begin() ); }
349
350 testlist1.splice_after (testlist1.begin(), testlist2,
351 testlist2.before_begin(), ++++testlist2.begin());
352 { int init_values [] = { 4, 1, 3, 5 };
353 TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); }
354 { int init_values [] = { 2 };
355 TEST_INTRUSIVE_SEQUENCE( init_values, testlist2.begin() ); }
356 }
357
358 { //splice in the same list
359 list_type testlist1 (values.begin(), values.begin() + 5);
360
361 { int init_values [] = { 1, 2, 3, 4, 5 };
362 TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); }
363
364 //nop 1
365 testlist1.splice_after (testlist1.before_begin(), testlist1, testlist1.before_begin(), ++testlist1.before_begin());
366 { int init_values [] = { 1, 2, 3, 4, 5 };
367 TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); }
368
369 //nop 2
370 testlist1.splice_after (++testlist1.before_begin(), testlist1, testlist1.before_begin(), ++testlist1.before_begin());
371 { int init_values [] = { 1, 2, 3, 4, 5 };
372 TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); }
373
374 //nop 3
375 testlist1.splice_after (testlist1.before_begin(), testlist1, ++testlist1.before_begin(), ++testlist1.before_begin());
376 { int init_values [] = { 1, 2, 3, 4, 5 };
377 TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); }
378
379 testlist1.splice_after (testlist1.before_begin(), testlist1, ++testlist1.before_begin(), ++++testlist1.before_begin());
380 { int init_values [] = { 2, 1, 3, 4, 5 };
381 TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); }
382
383 testlist1.splice_after (testlist1.before_begin(), testlist1, ++testlist1.before_begin(), ++++++testlist1.before_begin());
384 { int init_values [] = { 1, 3, 2, 4, 5 };
385 TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); }
386
387 testlist1.splice_after (++++++++testlist1.before_begin(), testlist1, testlist1.before_begin(), ++++testlist1.before_begin());
388 { int init_values [] = { 2, 4, 1, 3, 5 };
389 TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); }
390 }
391
392 { //Now test swap when testlist2 is empty
393 list_type testlist1 (values.begin(), values.begin() + 2);
394 list_type testlist2;
395 testlist1.swap(testlist2);
396 BOOST_TEST (testlist1.empty());
397 { int init_values [] = { 1, 2 };
398 TEST_INTRUSIVE_SEQUENCE( init_values, testlist2.begin() ); }
399 }
400 { //Now test swap when testlist1 is empty
401 list_type testlist2 (values.begin(), values.begin() + 2);
402 list_type testlist1;
403 testlist1.swap(testlist2);
404 BOOST_TEST (testlist2.empty());
405 { int init_values [] = { 1, 2 };
406 TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); }
407 }
408 { //Now test when both are empty
409 list_type testlist1, testlist2;
410 testlist2.swap(testlist1);
411 BOOST_TEST (testlist1.empty() && testlist2.empty());
412 }
413
414 if(!list_type::linear)
415 {
416 list_type testlist1 (values.begin(), values.begin() + 2);
417 list_type testlist2 (values.begin() + 3, values.begin() + 5);
418
419 swap_nodes< node_algorithms >(values[0], values[2]);
420 { int init_values [] = { 3, 2 };
421 TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); }
422
423 swap_nodes< node_algorithms >(values[2], values[4]);
424 { int init_values [] = { 5, 2 };
425 TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); }
426 { int init_values [] = { 4, 3 };
427 TEST_INTRUSIVE_SEQUENCE( init_values, testlist2.begin() ); }
428 }
429 if(!list_type::linear)
430 {
431 list_type testlist1 (values.begin(), values.begin()+1);
432 if(testlist1.size() != 1){
433 abort();
434 }
435 { int init_values [] = { 1 };
436 TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); }
437
438 swap_nodes< node_algorithms >(values[1], values[2]);
439
440 BOOST_TEST(testlist1.size() == 1);
441 BOOST_TEST(!(&values[1])->is_linked());
442 BOOST_TEST(!(&values[2])->is_linked());
443 { int init_values [] = { 1 };
444 TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); }
445
446 swap_nodes< node_algorithms >(values[0], values[2]);
447 BOOST_TEST(testlist1.size() == 1);
448 BOOST_TEST((&values[2])->is_linked());
449 BOOST_TEST(!(&values[0])->is_linked());
450 { int init_values [] = { 3 };
451 TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); }
452
453 swap_nodes< node_algorithms >(values[0], values[2]);
454 BOOST_TEST(testlist1.size() == 1);
455 BOOST_TEST(!(&values[2])->is_linked());
456 BOOST_TEST((&values[0])->is_linked());
457 { int init_values [] = { 1 };
458 TEST_INTRUSIVE_SEQUENCE( init_values, testlist1.begin() ); }
459 }
460 }
461
462 template < typename ListType, typename ValueContainer >
463 void test_slist< ListType, ValueContainer >
464 ::test_clone(ValueContainer& values)
465 {
466 list_type testlist1 (values.begin(), values.begin() + std::ptrdiff_t(values.size()));
467 list_type testlist2;
468
469 testlist2.clone_from(testlist1, test::new_cloner<value_type>(), test::delete_disposer<value_type>());
470 BOOST_TEST (testlist2 == testlist1);
471 testlist2.clear_and_dispose(test::delete_disposer<value_type>());
472 BOOST_TEST (testlist2.empty());
473 }
474
475 template < typename ListType, typename ValueContainer >
476 void test_slist< ListType, ValueContainer >
477 ::test_container_from_end(ValueContainer& values, detail::true_type)
478 {
479 list_type testlist1 (values.begin(), values.begin() + std::ptrdiff_t(values.size()));
480 BOOST_TEST (testlist1 == list_type::container_from_end_iterator(testlist1.end()));
481 BOOST_TEST (testlist1 == list_type::container_from_end_iterator(testlist1.cend()));
482 }
483
484 template < typename ValueTraits, bool ConstantTimeSize, bool Linear, bool CacheLast, bool Default_Holder, typename ValueContainer >
485 struct make_and_test_slist
486 : test_slist< slist< typename ValueTraits::value_type,
487 value_traits< ValueTraits >,
488 size_type< std::size_t >,
489 constant_time_size< ConstantTimeSize >,
490 linear<Linear>,
491 cache_last<CacheLast>
492 >,
493 ValueContainer
494 >
495 {};
496
497 template < typename ValueTraits, bool ConstantTimeSize, bool Linear, bool CacheLast, typename ValueContainer >
498 struct make_and_test_slist< ValueTraits, ConstantTimeSize, Linear, CacheLast, false, ValueContainer >
499 : test_slist< slist< typename ValueTraits::value_type,
500 value_traits< ValueTraits >,
501 size_type< std::size_t >,
502 constant_time_size< ConstantTimeSize >,
503 linear<Linear>,
504 cache_last<CacheLast>,
505 header_holder_type< heap_node_holder< typename ValueTraits::pointer > >
506 >,
507 ValueContainer
508 >
509 {};
510
511 template<class VoidPointer, bool constant_time_size, bool Default_Holder>
512 class test_main_template
513 {
514 public:
515 int operator()()
516 {
517 typedef testvalue< hooks<VoidPointer> > value_type;
518 std::vector< value_type > data (5);
519 for (std::size_t i = 0; i < 5u; ++i)
520 data[i].value_ = (int)i + 1;
521
522 make_and_test_slist < typename detail::get_base_value_traits
523 < value_type
524 , typename hooks<VoidPointer>::base_hook_type
525 >::type
526 , constant_time_size
527 , false
528 , false
529 , Default_Holder
530 , std::vector< value_type >
531 >::test_all(data);
532 make_and_test_slist < nonhook_node_member_value_traits< value_type,
533 typename hooks<VoidPointer>::nonhook_node_member_type,
534 &value_type::nhn_member_,
535 safe_link
536 >
537 , constant_time_size
538 , false
539 , false
540 , Default_Holder
541 , std::vector< value_type >
542 >::test_all(data);
543
544 //Now linear slists
545 make_and_test_slist < typename detail::get_member_value_traits
546 < member_hook< value_type
547 , typename hooks<VoidPointer>::member_hook_type
548 , &value_type::node_
549 >
550 >::type
551 , constant_time_size
552 , true
553 , false
554 , Default_Holder
555 , std::vector< value_type >
556 >::test_all(data);
557
558 //Now the same but caching the last node
559 make_and_test_slist < typename detail::get_base_value_traits
560 < value_type
561 , typename hooks<VoidPointer>::base_hook_type
562 >::type
563 , constant_time_size
564 , false
565 , true
566 , Default_Holder
567 , std::vector< value_type >
568 >::test_all(data);
569
570 //Now linear slists
571 make_and_test_slist < typename detail::get_base_value_traits
572 < value_type
573 , typename hooks<VoidPointer>::base_hook_type
574 >::type
575 , constant_time_size
576 , true
577 , true
578 , Default_Holder
579 , std::vector< value_type >
580 >::test_all(data);
581 return 0;
582 }
583 };
584
585 template<class VoidPointer, bool Default_Holder>
586 class test_main_template<VoidPointer, false, Default_Holder>
587 {
588 public:
589 int operator()()
590 {
591 typedef testvalue< hooks<VoidPointer> > value_type;
592 std::vector< value_type > data (5);
593 for (std::size_t i = 0; i < 5u; ++i)
594 data[i].value_ = (int)i + 1;
595
596 make_and_test_slist < typename detail::get_base_value_traits
597 < value_type
598 , typename hooks<VoidPointer>::auto_base_hook_type
599 >::type
600 , false
601 , false
602 , false
603 , Default_Holder
604 , std::vector< value_type >
605 >::test_all(data);
606
607 make_and_test_slist < nonhook_node_member_value_traits< value_type,
608 typename hooks<VoidPointer>::nonhook_node_member_type,
609 &value_type::nhn_member_,
610 safe_link
611 >
612 , false
613 , false
614 , true
615 , Default_Holder
616 , std::vector< value_type >
617 >::test_all(data);
618
619 make_and_test_slist < typename detail::get_member_value_traits
620 < member_hook< value_type
621 , typename hooks<VoidPointer>::member_hook_type
622 , &value_type::node_
623 >
624 >::type
625 , false
626 , true
627 , false
628 , Default_Holder
629 , std::vector< value_type >
630 >::test_all(data);
631
632 make_and_test_slist < typename detail::get_base_value_traits
633 < value_type
634 , typename hooks<VoidPointer>::base_hook_type
635 >::type
636 , false
637 , true
638 , true
639 , Default_Holder
640 , std::vector< value_type >
641 >::test_all(data);
642
643 return 0;
644 }
645 };
646
647 template < bool ConstantTimeSize >
648 struct test_main_template_bptr
649 {
650 int operator()()
651 {
652 typedef BPtr_Value value_type;
653 typedef BPtr_Value_Traits< List_BPtr_Node_Traits > list_value_traits;
654 typedef typename list_value_traits::node_ptr node_ptr;
655 typedef bounded_allocator< value_type > allocator_type;
656
657 bounded_allocator_scope<allocator_type> bounded_scope; (void)bounded_scope;
658 allocator_type allocator;
659
660 {
661 bounded_reference_cont< value_type > ref_cont;
662 for (std::size_t i = 0; i < 5u; ++i)
663 {
664 node_ptr tmp = allocator.allocate(1);
665 new (tmp.raw()) value_type((int)i + 1);
666 ref_cont.push_back(*tmp);
667 }
668
669 test_slist < slist < value_type,
670 value_traits< list_value_traits >,
671 size_type< std::size_t >,
672 constant_time_size< ConstantTimeSize >,
673 header_holder_type< bounded_pointer_holder< value_type > >
674 >,
675 bounded_reference_cont< value_type >
676 >::test_all(ref_cont);
677 }
678 return 0;
679 }
680 };
681
682 int main(int, char* [])
683 {
684 // test (plain/smart pointers) x (nonconst/const size) x (void node allocator)
685 test_main_template<void*, false, true>()();
686 test_main_template<boost::intrusive::smart_ptr<void>, false, true>()();
687 test_main_template<void*, true, true>()();
688 test_main_template<boost::intrusive::smart_ptr<void>, true, true>()();
689 // test (bounded pointers) x ((nonconst/const size) x (special node allocator)
690 test_main_template_bptr< true >()();
691 test_main_template_bptr< false >()();
692
693
694 return boost::report_errors();
695 }