slist_test.cpp 24 KB

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