slist.hpp 83 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223
  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. #ifndef BOOST_INTRUSIVE_SLIST_HPP
  14. #define BOOST_INTRUSIVE_SLIST_HPP
  15. #include <boost/intrusive/detail/config_begin.hpp>
  16. #include <boost/static_assert.hpp>
  17. #include <boost/intrusive/detail/assert.hpp>
  18. #include <boost/intrusive/intrusive_fwd.hpp>
  19. #include <boost/intrusive/slist_hook.hpp>
  20. #include <boost/intrusive/circular_slist_algorithms.hpp>
  21. #include <boost/intrusive/linear_slist_algorithms.hpp>
  22. #include <boost/intrusive/pointer_traits.hpp>
  23. #include <boost/intrusive/detail/clear_on_destructor_base.hpp>
  24. #include <boost/intrusive/link_mode.hpp>
  25. #include <boost/intrusive/options.hpp>
  26. #include <boost/intrusive/detail/utilities.hpp>
  27. #include <iterator>
  28. #include <functional>
  29. #include <algorithm>
  30. #include <cstddef> //std::size_t
  31. #include <utility> //std::pair
  32. #include <boost/move/move.hpp>
  33. namespace boost {
  34. namespace intrusive {
  35. /// @cond
  36. template<class Node, class NodePtr, bool>
  37. struct root_plus_last
  38. {
  39. Node root_;
  40. NodePtr last_;
  41. };
  42. template<class Node, class NodePtr>
  43. struct root_plus_last<Node, NodePtr, false>
  44. {
  45. Node root_;
  46. };
  47. struct slist_defaults
  48. {
  49. typedef detail::default_slist_hook proto_value_traits;
  50. static const bool constant_time_size = true;
  51. static const bool linear = false;
  52. typedef std::size_t size_type;
  53. static const bool cache_last = false;
  54. };
  55. struct slist_bool_flags
  56. {
  57. static const std::size_t linear_pos = 1u;
  58. static const std::size_t constant_time_size_pos = 2u;
  59. static const std::size_t cache_last_pos = 4u;
  60. };
  61. /// @endcond
  62. //! The class template slist is an intrusive container, that encapsulates
  63. //! a singly-linked list. You can use such a list to squeeze the last bit
  64. //! of performance from your application. Unfortunately, the little gains
  65. //! come with some huge drawbacks. A lot of member functions can't be
  66. //! implemented as efficiently as for standard containers. To overcome
  67. //! this limitation some other member functions with rather unusual semantics
  68. //! have to be introduced.
  69. //!
  70. //! The template parameter \c T is the type to be managed by the container.
  71. //! The user can specify additional options and if no options are provided
  72. //! default options are used.
  73. //!
  74. //! The container supports the following options:
  75. //! \c base_hook<>/member_hook<>/value_traits<>,
  76. //! \c constant_time_size<>, \c size_type<>,
  77. //! \c linear<> and \c cache_last<>.
  78. //!
  79. //! The iterators of slist are forward iterators. slist provides a static
  80. //! function called "previous" to compute the previous iterator of a given iterator.
  81. //! This function has linear complexity. To improve the usability esp. with
  82. //! the '*_after' functions, ++end() == begin() and previous(begin()) == end()
  83. //! are defined. An new special function "before_begin()" is defined, which returns
  84. //! an iterator that points one less the beginning of the list: ++before_begin() == begin()
  85. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
  86. template<class T, class ...Options>
  87. #else
  88. template<class ValueTraits, class SizeType, std::size_t BoolFlags>
  89. #endif
  90. class slist_impl
  91. : private detail::clear_on_destructor_base
  92. < slist_impl<ValueTraits, SizeType, BoolFlags>
  93. , is_safe_autounlink<detail::get_real_value_traits<ValueTraits>::type::link_mode>::value
  94. >
  95. {
  96. template<class C, bool> friend class detail::clear_on_destructor_base;
  97. //Public typedefs
  98. public:
  99. typedef ValueTraits value_traits;
  100. /// @cond
  101. static const bool external_value_traits =
  102. detail::external_value_traits_bool_is_true<value_traits>::value;
  103. typedef typename detail::get_real_value_traits<ValueTraits>::type real_value_traits;
  104. /// @endcond
  105. typedef typename real_value_traits::pointer pointer;
  106. typedef typename real_value_traits::const_pointer const_pointer;
  107. typedef typename pointer_traits<pointer>::element_type value_type;
  108. typedef typename pointer_traits<pointer>::reference reference;
  109. typedef typename pointer_traits<const_pointer>::reference const_reference;
  110. typedef typename pointer_traits<pointer>::difference_type difference_type;
  111. typedef SizeType size_type;
  112. typedef slist_iterator<real_value_traits, false> iterator;
  113. typedef slist_iterator<real_value_traits, true> const_iterator;
  114. typedef typename real_value_traits::node_traits node_traits;
  115. typedef typename node_traits::node node;
  116. typedef typename node_traits::node_ptr node_ptr;
  117. typedef typename node_traits::const_node_ptr const_node_ptr;
  118. static const bool constant_time_size = 0 != (BoolFlags & slist_bool_flags::constant_time_size_pos);
  119. static const bool stateful_value_traits = detail::is_stateful_value_traits<real_value_traits>::value;
  120. static const bool linear = 0 != (BoolFlags & slist_bool_flags::linear_pos);
  121. static const bool cache_last = 0 != (BoolFlags & slist_bool_flags::cache_last_pos);
  122. typedef typename detail::if_c
  123. < linear
  124. , linear_slist_algorithms<node_traits>
  125. , circular_slist_algorithms<node_traits>
  126. >::type node_algorithms;
  127. /// @cond
  128. private:
  129. typedef detail::size_holder<constant_time_size, size_type> size_traits;
  130. //noncopyable
  131. BOOST_MOVABLE_BUT_NOT_COPYABLE(slist_impl)
  132. static const bool safemode_or_autounlink = is_safe_autounlink<real_value_traits::link_mode>::value;
  133. //Constant-time size is incompatible with auto-unlink hooks!
  134. BOOST_STATIC_ASSERT(!(constant_time_size && ((int)real_value_traits::link_mode == (int)auto_unlink)));
  135. //Linear singly linked lists are incompatible with auto-unlink hooks!
  136. BOOST_STATIC_ASSERT(!(linear && ((int)real_value_traits::link_mode == (int)auto_unlink)));
  137. //A list with cached last node is incompatible with auto-unlink hooks!
  138. BOOST_STATIC_ASSERT(!(cache_last && ((int)real_value_traits::link_mode == (int)auto_unlink)));
  139. node_ptr get_end_node()
  140. { return node_ptr(linear ? node_ptr() : this->get_root_node()); }
  141. const_node_ptr get_end_node() const
  142. {
  143. return const_node_ptr
  144. (linear ? const_node_ptr() : this->get_root_node()); }
  145. node_ptr get_root_node()
  146. { return pointer_traits<node_ptr>::pointer_to(data_.root_plus_size_.root_); }
  147. const_node_ptr get_root_node() const
  148. { return pointer_traits<const_node_ptr>::pointer_to(data_.root_plus_size_.root_); }
  149. node_ptr get_last_node()
  150. { return this->get_last_node(detail::bool_<cache_last>()); }
  151. const_node_ptr get_last_node() const
  152. { return this->get_last_node(detail::bool_<cache_last>()); }
  153. void set_last_node(const node_ptr &n)
  154. { return this->set_last_node(n, detail::bool_<cache_last>()); }
  155. static node_ptr get_last_node(detail::bool_<false>)
  156. {
  157. //This function shall not be used if cache_last is not true
  158. BOOST_INTRUSIVE_INVARIANT_ASSERT(cache_last);
  159. return node_ptr();
  160. }
  161. static void set_last_node(const node_ptr &, detail::bool_<false>)
  162. {
  163. //This function shall not be used if cache_last is not true
  164. BOOST_INTRUSIVE_INVARIANT_ASSERT(cache_last);
  165. }
  166. node_ptr get_last_node(detail::bool_<true>)
  167. { return node_ptr(data_.root_plus_size_.last_); }
  168. const_node_ptr get_last_node(detail::bool_<true>) const
  169. { return const_node_ptr(data_.root_plus_size_.last_); }
  170. void set_last_node(const node_ptr & n, detail::bool_<true>)
  171. { data_.root_plus_size_.last_ = n; }
  172. void set_default_constructed_state()
  173. {
  174. node_algorithms::init_header(this->get_root_node());
  175. this->priv_size_traits().set_size(size_type(0));
  176. if(cache_last){
  177. this->set_last_node(this->get_root_node());
  178. }
  179. }
  180. struct root_plus_size
  181. : public size_traits
  182. , public root_plus_last<node, node_ptr, cache_last>
  183. {};
  184. struct data_t
  185. : public slist_impl::value_traits
  186. {
  187. typedef typename slist_impl::value_traits value_traits;
  188. explicit data_t(const value_traits &val_traits)
  189. : value_traits(val_traits)
  190. {}
  191. root_plus_size root_plus_size_;
  192. } data_;
  193. size_traits &priv_size_traits()
  194. { return data_.root_plus_size_; }
  195. const size_traits &priv_size_traits() const
  196. { return data_.root_plus_size_; }
  197. const real_value_traits &get_real_value_traits(detail::bool_<false>) const
  198. { return data_; }
  199. const real_value_traits &get_real_value_traits(detail::bool_<true>) const
  200. { return data_.get_value_traits(*this); }
  201. real_value_traits &get_real_value_traits(detail::bool_<false>)
  202. { return data_; }
  203. real_value_traits &get_real_value_traits(detail::bool_<true>)
  204. { return data_.get_value_traits(*this); }
  205. const value_traits &priv_value_traits() const
  206. { return data_; }
  207. value_traits &priv_value_traits()
  208. { return data_; }
  209. protected:
  210. node &prot_root_node()
  211. { return data_.root_plus_size_.root_; }
  212. node const &prot_root_node() const
  213. { return data_.root_plus_size_.root_; }
  214. void prot_set_size(size_type s)
  215. { data_.root_plus_size_.set_size(s); }
  216. /// @endcond
  217. public:
  218. const real_value_traits &get_real_value_traits() const
  219. { return this->get_real_value_traits(detail::bool_<external_value_traits>()); }
  220. real_value_traits &get_real_value_traits()
  221. { return this->get_real_value_traits(detail::bool_<external_value_traits>()); }
  222. typedef typename pointer_traits<node_ptr>::template rebind_pointer<const real_value_traits>::type const_real_value_traits_ptr;
  223. const_real_value_traits_ptr real_value_traits_ptr() const
  224. { return pointer_traits<const_real_value_traits_ptr>::pointer_to(this->get_real_value_traits()); }
  225. public:
  226. ///@cond
  227. //! <b>Requires</b>: f and before_l belong to another slist.
  228. //!
  229. //! <b>Effects</b>: Transfers the range [f, before_l] to this
  230. //! list, after the element pointed by prev_pos.
  231. //! No destructors or copy constructors are called.
  232. //!
  233. //! <b>Throws</b>: Nothing.
  234. //!
  235. //! <b>Complexity</b>: Linear to the number of elements transferred
  236. //! if constant_time_size is true. Constant-time otherwise.
  237. //!
  238. //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
  239. //! list. Iterators of this list and all the references are not invalidated.
  240. //!
  241. //! <b>Warning</b>: Experimental function, don't use it!
  242. slist_impl( const node_ptr & f, const node_ptr & before_l
  243. , size_type n, const value_traits &v_traits = value_traits())
  244. : data_(v_traits)
  245. {
  246. if(n){
  247. this->priv_size_traits().set_size(n);
  248. if(cache_last){
  249. this->set_last_node(before_l);
  250. }
  251. node_traits::set_next(this->get_root_node(), f);
  252. node_traits::set_next(before_l, this->get_end_node());
  253. }
  254. else{
  255. this->set_default_constructed_state();
  256. }
  257. }
  258. ///@endcond
  259. //! <b>Effects</b>: constructs an empty list.
  260. //!
  261. //! <b>Complexity</b>: Constant
  262. //!
  263. //! <b>Throws</b>: If value_traits::node_traits::node
  264. //! constructor throws (this does not happen with predefined Boost.Intrusive hooks).
  265. explicit slist_impl(const value_traits &v_traits = value_traits())
  266. : data_(v_traits)
  267. { this->set_default_constructed_state(); }
  268. //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type.
  269. //!
  270. //! <b>Effects</b>: Constructs a list equal to [b ,e).
  271. //!
  272. //! <b>Complexity</b>: Linear in std::distance(b, e). No copy constructors are called.
  273. //!
  274. //! <b>Throws</b>: If value_traits::node_traits::node
  275. //! constructor throws (this does not happen with predefined Boost.Intrusive hooks).
  276. template<class Iterator>
  277. slist_impl(Iterator b, Iterator e, const value_traits &v_traits = value_traits())
  278. : data_(v_traits)
  279. {
  280. this->set_default_constructed_state();
  281. this->insert_after(this->cbefore_begin(), b, e);
  282. }
  283. //! <b>Effects</b>: to-do
  284. //!
  285. slist_impl(BOOST_RV_REF(slist_impl) x)
  286. : data_(::boost::move(x.priv_value_traits()))
  287. {
  288. this->priv_size_traits().set_size(size_type(0));
  289. node_algorithms::init_header(this->get_root_node());
  290. this->swap(x);
  291. }
  292. //! <b>Effects</b>: to-do
  293. //!
  294. slist_impl& operator=(BOOST_RV_REF(slist_impl) x)
  295. { this->swap(x); return *this; }
  296. #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  297. //! <b>Effects</b>: If it's a safe-mode
  298. //! or auto-unlink value, the destructor does nothing
  299. //! (ie. no code is generated). Otherwise it detaches all elements from this.
  300. //! In this case the objects in the list are not deleted (i.e. no destructors
  301. //! are called), but the hooks according to the value_traits template parameter
  302. //! are set to their default value.
  303. //!
  304. //! <b>Complexity</b>: Linear to the number of elements in the list, if
  305. //! it's a safe-mode or auto-unlink value. Otherwise constant.
  306. ~slist_impl()
  307. {}
  308. #endif
  309. //! <b>Effects</b>: Erases all the elements of the container.
  310. //!
  311. //! <b>Throws</b>: Nothing.
  312. //!
  313. //! <b>Complexity</b>: Linear to the number of elements of the list.
  314. //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
  315. //!
  316. //! <b>Note</b>: Invalidates the iterators (but not the references) to the erased elements.
  317. void clear()
  318. {
  319. if(safemode_or_autounlink){
  320. this->clear_and_dispose(detail::null_disposer());
  321. }
  322. else{
  323. this->set_default_constructed_state();
  324. }
  325. }
  326. //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
  327. //!
  328. //! <b>Effects</b>: Erases all the elements of the container
  329. //! Disposer::operator()(pointer) is called for the removed elements.
  330. //!
  331. //! <b>Throws</b>: Nothing.
  332. //!
  333. //! <b>Complexity</b>: Linear to the number of elements of the list.
  334. //!
  335. //! <b>Note</b>: Invalidates the iterators to the erased elements.
  336. template <class Disposer>
  337. void clear_and_dispose(Disposer disposer)
  338. {
  339. const_iterator it(this->begin()), itend(this->end());
  340. while(it != itend){
  341. node_ptr to_erase(it.pointed_node());
  342. ++it;
  343. if(safemode_or_autounlink)
  344. node_algorithms::init(to_erase);
  345. disposer(get_real_value_traits().to_value_ptr(to_erase));
  346. }
  347. this->set_default_constructed_state();
  348. }
  349. //! <b>Requires</b>: value must be an lvalue.
  350. //!
  351. //! <b>Effects</b>: Inserts the value in the front of the list.
  352. //! No copy constructors are called.
  353. //!
  354. //! <b>Throws</b>: Nothing.
  355. //!
  356. //! <b>Complexity</b>: Constant.
  357. //!
  358. //! <b>Note</b>: Does not affect the validity of iterators and references.
  359. void push_front(reference value)
  360. {
  361. node_ptr to_insert = get_real_value_traits().to_node_ptr(value);
  362. if(safemode_or_autounlink)
  363. BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::inited(to_insert));
  364. if(cache_last){
  365. if(this->empty()){
  366. this->set_last_node(to_insert);
  367. }
  368. }
  369. node_algorithms::link_after(this->get_root_node(), to_insert);
  370. this->priv_size_traits().increment();
  371. }
  372. //! <b>Requires</b>: value must be an lvalue.
  373. //!
  374. //! <b>Effects</b>: Inserts the value in the back of the list.
  375. //! No copy constructors are called.
  376. //!
  377. //! <b>Throws</b>: Nothing.
  378. //!
  379. //! <b>Complexity</b>: Constant.
  380. //!
  381. //! <b>Note</b>: Does not affect the validity of iterators and references.
  382. //! This function is only available is cache_last<> is true.
  383. void push_back(reference value)
  384. {
  385. BOOST_STATIC_ASSERT((cache_last));
  386. node_ptr n = get_real_value_traits().to_node_ptr(value);
  387. if(safemode_or_autounlink)
  388. BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::inited(n));
  389. node_algorithms::link_after(this->get_last_node(), n);
  390. if(cache_last){
  391. this->set_last_node(n);
  392. }
  393. this->priv_size_traits().increment();
  394. }
  395. //! <b>Effects</b>: Erases the first element of the list.
  396. //! No destructors are called.
  397. //!
  398. //! <b>Throws</b>: Nothing.
  399. //!
  400. //! <b>Complexity</b>: Constant.
  401. //!
  402. //! <b>Note</b>: Invalidates the iterators (but not the references) to the erased element.
  403. void pop_front()
  404. { return this->pop_front_and_dispose(detail::null_disposer()); }
  405. //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
  406. //!
  407. //! <b>Effects</b>: Erases the first element of the list.
  408. //! Disposer::operator()(pointer) is called for the removed element.
  409. //!
  410. //! <b>Throws</b>: Nothing.
  411. //!
  412. //! <b>Complexity</b>: Constant.
  413. //!
  414. //! <b>Note</b>: Invalidates the iterators to the erased element.
  415. template<class Disposer>
  416. void pop_front_and_dispose(Disposer disposer)
  417. {
  418. node_ptr to_erase = node_traits::get_next(this->get_root_node());
  419. node_algorithms::unlink_after(this->get_root_node());
  420. this->priv_size_traits().decrement();
  421. if(safemode_or_autounlink)
  422. node_algorithms::init(to_erase);
  423. disposer(get_real_value_traits().to_value_ptr(to_erase));
  424. if(cache_last){
  425. if(this->empty()){
  426. this->set_last_node(this->get_root_node());
  427. }
  428. }
  429. }
  430. //! <b>Effects</b>: Returns a reference to the first element of the list.
  431. //!
  432. //! <b>Throws</b>: Nothing.
  433. //!
  434. //! <b>Complexity</b>: Constant.
  435. reference front()
  436. { return *this->get_real_value_traits().to_value_ptr(node_traits::get_next(this->get_root_node())); }
  437. //! <b>Effects</b>: Returns a const_reference to the first element of the list.
  438. //!
  439. //! <b>Throws</b>: Nothing.
  440. //!
  441. //! <b>Complexity</b>: Constant.
  442. const_reference front() const
  443. { return *this->get_real_value_traits().to_value_ptr(detail::uncast(node_traits::get_next(this->get_root_node()))); }
  444. //! <b>Effects</b>: Returns a reference to the last element of the list.
  445. //!
  446. //! <b>Throws</b>: Nothing.
  447. //!
  448. //! <b>Complexity</b>: Constant.
  449. //!
  450. //! <b>Note</b>: Does not affect the validity of iterators and references.
  451. //! This function is only available is cache_last<> is true.
  452. reference back()
  453. {
  454. BOOST_STATIC_ASSERT((cache_last));
  455. return *this->get_real_value_traits().to_value_ptr(this->get_last_node());
  456. }
  457. //! <b>Effects</b>: Returns a const_reference to the last element of the list.
  458. //!
  459. //! <b>Throws</b>: Nothing.
  460. //!
  461. //! <b>Complexity</b>: Constant.
  462. //!
  463. //! <b>Note</b>: Does not affect the validity of iterators and references.
  464. //! This function is only available is cache_last<> is true.
  465. const_reference back() const
  466. {
  467. BOOST_STATIC_ASSERT((cache_last));
  468. return *this->get_real_value_traits().to_value_ptr(this->get_last_node());
  469. }
  470. //! <b>Effects</b>: Returns an iterator to the first element contained in the list.
  471. //!
  472. //! <b>Throws</b>: Nothing.
  473. //!
  474. //! <b>Complexity</b>: Constant.
  475. iterator begin()
  476. { return iterator (node_traits::get_next(this->get_root_node()), this->real_value_traits_ptr()); }
  477. //! <b>Effects</b>: Returns a const_iterator to the first element contained in the list.
  478. //!
  479. //! <b>Throws</b>: Nothing.
  480. //!
  481. //! <b>Complexity</b>: Constant.
  482. const_iterator begin() const
  483. { return const_iterator (node_traits::get_next(this->get_root_node()), this->real_value_traits_ptr()); }
  484. //! <b>Effects</b>: Returns a const_iterator to the first element contained in the list.
  485. //!
  486. //! <b>Throws</b>: Nothing.
  487. //!
  488. //! <b>Complexity</b>: Constant.
  489. const_iterator cbegin() const
  490. { return const_iterator(node_traits::get_next(this->get_root_node()), this->real_value_traits_ptr()); }
  491. //! <b>Effects</b>: Returns an iterator to the end of the list.
  492. //!
  493. //! <b>Throws</b>: Nothing.
  494. //!
  495. //! <b>Complexity</b>: Constant.
  496. iterator end()
  497. { return iterator(this->get_end_node(), this->real_value_traits_ptr()); }
  498. //! <b>Effects</b>: Returns a const_iterator to the end of the list.
  499. //!
  500. //! <b>Throws</b>: Nothing.
  501. //!
  502. //! <b>Complexity</b>: Constant.
  503. const_iterator end() const
  504. { return const_iterator(detail::uncast(this->get_end_node()), this->real_value_traits_ptr()); }
  505. //! <b>Effects</b>: Returns a const_iterator to the end of the list.
  506. //!
  507. //! <b>Throws</b>: Nothing.
  508. //!
  509. //! <b>Complexity</b>: Constant.
  510. const_iterator cend() const
  511. { return this->end(); }
  512. //! <b>Effects</b>: Returns an iterator that points to a position
  513. //! before the first element. Equivalent to "end()"
  514. //!
  515. //! <b>Throws</b>: Nothing.
  516. //!
  517. //! <b>Complexity</b>: Constant.
  518. iterator before_begin()
  519. { return iterator(this->get_root_node(), this->real_value_traits_ptr()); }
  520. //! <b>Effects</b>: Returns an iterator that points to a position
  521. //! before the first element. Equivalent to "end()"
  522. //!
  523. //! <b>Throws</b>: Nothing.
  524. //!
  525. //! <b>Complexity</b>: Constant.
  526. const_iterator before_begin() const
  527. { return const_iterator(detail::uncast(this->get_root_node()), this->real_value_traits_ptr()); }
  528. //! <b>Effects</b>: Returns an iterator that points to a position
  529. //! before the first element. Equivalent to "end()"
  530. //!
  531. //! <b>Throws</b>: Nothing.
  532. //!
  533. //! <b>Complexity</b>: Constant.
  534. const_iterator cbefore_begin() const
  535. { return this->before_begin(); }
  536. //! <b>Effects</b>: Returns an iterator to the last element contained in the list.
  537. //!
  538. //! <b>Throws</b>: Nothing.
  539. //!
  540. //! <b>Complexity</b>: Constant.
  541. //!
  542. //! <b>Note</b>: This function is present only if cached_last<> option is true.
  543. iterator last()
  544. {
  545. //This function shall not be used if cache_last is not true
  546. BOOST_INTRUSIVE_INVARIANT_ASSERT(cache_last);
  547. return iterator (this->get_last_node(), this->real_value_traits_ptr());
  548. }
  549. //! <b>Effects</b>: Returns a const_iterator to the last element contained in the list.
  550. //!
  551. //! <b>Throws</b>: Nothing.
  552. //!
  553. //! <b>Complexity</b>: Constant.
  554. //!
  555. //! <b>Note</b>: This function is present only if cached_last<> option is true.
  556. const_iterator last() const
  557. {
  558. //This function shall not be used if cache_last is not true
  559. BOOST_INTRUSIVE_INVARIANT_ASSERT(cache_last);
  560. return const_iterator (this->get_last_node(), this->real_value_traits_ptr());
  561. }
  562. //! <b>Effects</b>: Returns a const_iterator to the last element contained in the list.
  563. //!
  564. //! <b>Throws</b>: Nothing.
  565. //!
  566. //! <b>Complexity</b>: Constant.
  567. //!
  568. //! <b>Note</b>: This function is present only if cached_last<> option is true.
  569. const_iterator clast() const
  570. { return const_iterator(this->get_last_node(), this->real_value_traits_ptr()); }
  571. //! <b>Precondition</b>: end_iterator must be a valid end iterator
  572. //! of slist.
  573. //!
  574. //! <b>Effects</b>: Returns a const reference to the slist associated to the end iterator
  575. //!
  576. //! <b>Throws</b>: Nothing.
  577. //!
  578. //! <b>Complexity</b>: Constant.
  579. static slist_impl &container_from_end_iterator(iterator end_iterator)
  580. { return slist_impl::priv_container_from_end_iterator(end_iterator); }
  581. //! <b>Precondition</b>: end_iterator must be a valid end const_iterator
  582. //! of slist.
  583. //!
  584. //! <b>Effects</b>: Returns a const reference to the slist associated to the end iterator
  585. //!
  586. //! <b>Throws</b>: Nothing.
  587. //!
  588. //! <b>Complexity</b>: Constant.
  589. static const slist_impl &container_from_end_iterator(const_iterator end_iterator)
  590. { return slist_impl::priv_container_from_end_iterator(end_iterator); }
  591. //! <b>Effects</b>: Returns the number of the elements contained in the list.
  592. //!
  593. //! <b>Throws</b>: Nothing.
  594. //!
  595. //! <b>Complexity</b>: Linear to the number of elements contained in the list.
  596. //! if constant_time_size is false. Constant time otherwise.
  597. //!
  598. //! <b>Note</b>: Does not affect the validity of iterators and references.
  599. size_type size() const
  600. {
  601. if(constant_time_size)
  602. return this->priv_size_traits().get_size();
  603. else
  604. return node_algorithms::count(this->get_root_node()) - 1;
  605. }
  606. //! <b>Effects</b>: Returns true if the list contains no elements.
  607. //!
  608. //! <b>Throws</b>: Nothing.
  609. //!
  610. //! <b>Complexity</b>: Constant.
  611. //!
  612. //! <b>Note</b>: Does not affect the validity of iterators and references.
  613. bool empty() const
  614. { return node_algorithms::unique(this->get_root_node()); }
  615. //! <b>Effects</b>: Swaps the elements of x and *this.
  616. //!
  617. //! <b>Throws</b>: Nothing.
  618. //!
  619. //! <b>Complexity</b>: Linear to the number of elements of both lists.
  620. //! Constant-time if linear<> and/or cache_last<> options are used.
  621. //!
  622. //! <b>Note</b>: Does not affect the validity of iterators and references.
  623. void swap(slist_impl& other)
  624. {
  625. if(cache_last){
  626. priv_swap_cache_last(this, &other);
  627. }
  628. else{
  629. this->priv_swap_lists(this->get_root_node(), other.get_root_node(), detail::bool_<linear>());
  630. }
  631. if(constant_time_size){
  632. size_type backup = this->priv_size_traits().get_size();
  633. this->priv_size_traits().set_size(other.priv_size_traits().get_size());
  634. other.priv_size_traits().set_size(backup);
  635. }
  636. }
  637. //! <b>Effects</b>: Moves backwards all the elements, so that the first
  638. //! element becomes the second, the second becomes the third...
  639. //! the last element becomes the first one.
  640. //!
  641. //! <b>Throws</b>: Nothing.
  642. //!
  643. //! <b>Complexity</b>: Linear to the number of elements plus the number shifts.
  644. //!
  645. //! <b>Note</b>: Iterators Does not affect the validity of iterators and references.
  646. void shift_backwards(size_type n = 1)
  647. { this->priv_shift_backwards(n, detail::bool_<linear>()); }
  648. //! <b>Effects</b>: Moves forward all the elements, so that the second
  649. //! element becomes the first, the third becomes the second...
  650. //! the first element becomes the last one.
  651. //!
  652. //! <b>Throws</b>: Nothing.
  653. //!
  654. //! <b>Complexity</b>: Linear to the number of elements plus the number shifts.
  655. //!
  656. //! <b>Note</b>: Does not affect the validity of iterators and references.
  657. void shift_forward(size_type n = 1)
  658. { this->priv_shift_forward(n, detail::bool_<linear>()); }
  659. //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
  660. //! Cloner should yield to nodes equivalent to the original nodes.
  661. //!
  662. //! <b>Effects</b>: Erases all the elements from *this
  663. //! calling Disposer::operator()(pointer), clones all the
  664. //! elements from src calling Cloner::operator()(const_reference )
  665. //! and inserts them on *this.
  666. //!
  667. //! If cloner throws, all cloned elements are unlinked and disposed
  668. //! calling Disposer::operator()(pointer).
  669. //!
  670. //! <b>Complexity</b>: Linear to erased plus inserted elements.
  671. //!
  672. //! <b>Throws</b>: If cloner throws.
  673. template <class Cloner, class Disposer>
  674. void clone_from(const slist_impl &src, Cloner cloner, Disposer disposer)
  675. {
  676. this->clear_and_dispose(disposer);
  677. detail::exception_disposer<slist_impl, Disposer>
  678. rollback(*this, disposer);
  679. const_iterator prev(this->cbefore_begin());
  680. const_iterator b(src.begin()), e(src.end());
  681. for(; b != e; ++b){
  682. prev = this->insert_after(prev, *cloner(*b));
  683. }
  684. rollback.release();
  685. }
  686. //! <b>Requires</b>: value must be an lvalue and prev_p must point to an element
  687. //! contained by the list or to end().
  688. //!
  689. //! <b>Effects</b>: Inserts the value after the position pointed by prev_p.
  690. //! No copy constructor is called.
  691. //!
  692. //! <b>Returns</b>: An iterator to the inserted element.
  693. //!
  694. //! <b>Throws</b>: Nothing.
  695. //!
  696. //! <b>Complexity</b>: Constant.
  697. //!
  698. //! <b>Note</b>: Does not affect the validity of iterators and references.
  699. iterator insert_after(const_iterator prev_p, reference value)
  700. {
  701. node_ptr n = get_real_value_traits().to_node_ptr(value);
  702. if(safemode_or_autounlink)
  703. BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::inited(n));
  704. node_ptr prev_n(prev_p.pointed_node());
  705. node_algorithms::link_after(prev_n, n);
  706. if(cache_last && (this->get_last_node() == prev_n)){
  707. this->set_last_node(n);
  708. }
  709. this->priv_size_traits().increment();
  710. return iterator (n, this->real_value_traits_ptr());
  711. }
  712. //! <b>Requires</b>: Dereferencing iterator must yield
  713. //! an lvalue of type value_type and prev_p must point to an element
  714. //! contained by the list or to the end node.
  715. //!
  716. //! <b>Effects</b>: Inserts the [f, l)
  717. //! after the position prev_p.
  718. //!
  719. //! <b>Throws</b>: Nothing.
  720. //!
  721. //! <b>Complexity</b>: Linear to the number of elements inserted.
  722. //!
  723. //! <b>Note</b>: Does not affect the validity of iterators and references.
  724. template<class Iterator>
  725. void insert_after(const_iterator prev_p, Iterator f, Iterator l)
  726. {
  727. //Insert first nodes avoiding cache and size checks
  728. size_type count = 0;
  729. node_ptr prev_n(prev_p.pointed_node());
  730. for (; f != l; ++f, ++count){
  731. const node_ptr n = get_real_value_traits().to_node_ptr(*f);
  732. if(safemode_or_autounlink)
  733. BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::inited(n));
  734. node_algorithms::link_after(prev_n, n);
  735. prev_n = n;
  736. }
  737. //Now fix special cases if needed
  738. if(cache_last && (this->get_last_node() == prev_p.pointed_node())){
  739. this->set_last_node(prev_n);
  740. }
  741. if(constant_time_size){
  742. this->priv_size_traits().increase(count);
  743. }
  744. }
  745. //! <b>Requires</b>: value must be an lvalue and p must point to an element
  746. //! contained by the list or to end().
  747. //!
  748. //! <b>Effects</b>: Inserts the value before the position pointed by p.
  749. //! No copy constructor is called.
  750. //!
  751. //! <b>Throws</b>: Nothing.
  752. //!
  753. //! <b>Complexity</b>: Linear to the number of elements before p.
  754. //! Constant-time if cache_last<> is true and p == end().
  755. //!
  756. //! <b>Note</b>: Does not affect the validity of iterators and references.
  757. iterator insert(const_iterator p, reference value)
  758. { return this->insert_after(this->previous(p), value); }
  759. //! <b>Requires</b>: Dereferencing iterator must yield
  760. //! an lvalue of type value_type and p must point to an element
  761. //! contained by the list or to the end node.
  762. //!
  763. //! <b>Effects</b>: Inserts the pointed by b and e
  764. //! before the position p. No copy constructors are called.
  765. //!
  766. //! <b>Throws</b>: Nothing.
  767. //!
  768. //! <b>Complexity</b>: Linear to the number of elements inserted plus linear
  769. //! to the elements before b.
  770. //! Linear to the number of elements to insert if cache_last<> option is true and p == end().
  771. //!
  772. //! <b>Note</b>: Does not affect the validity of iterators and references.
  773. template<class Iterator>
  774. void insert(const_iterator p, Iterator b, Iterator e)
  775. { return this->insert_after(this->previous(p), b, e); }
  776. //! <b>Effects</b>: Erases the element after the element pointed by prev of
  777. //! the list. No destructors are called.
  778. //!
  779. //! <b>Returns</b>: the first element remaining beyond the removed elements,
  780. //! or end() if no such element exists.
  781. //!
  782. //! <b>Throws</b>: Nothing.
  783. //!
  784. //! <b>Complexity</b>: Constant.
  785. //!
  786. //! <b>Note</b>: Invalidates the iterators (but not the references) to the
  787. //! erased element.
  788. iterator erase_after(const_iterator prev)
  789. { return this->erase_after_and_dispose(prev, detail::null_disposer()); }
  790. //! <b>Effects</b>: Erases the range (before_f, l) from
  791. //! the list. No destructors are called.
  792. //!
  793. //! <b>Returns</b>: the first element remaining beyond the removed elements,
  794. //! or end() if no such element exists.
  795. //!
  796. //! <b>Throws</b>: Nothing.
  797. //!
  798. //! <b>Complexity</b>: Linear to the number of erased elements if it's a safe-mode
  799. //! , auto-unlink value or constant-time size is activated. Constant time otherwise.
  800. //!
  801. //! <b>Note</b>: Invalidates the iterators (but not the references) to the
  802. //! erased element.
  803. iterator erase_after(const_iterator before_f, const_iterator l)
  804. {
  805. if(safemode_or_autounlink || constant_time_size){
  806. return this->erase_after_and_dispose(before_f, l, detail::null_disposer());
  807. }
  808. else{
  809. const node_ptr bfp = before_f.pointed_node();
  810. const node_ptr lp = l.pointed_node();
  811. if(cache_last){
  812. if(lp == this->get_end_node()){
  813. this->set_last_node(bfp);
  814. }
  815. }
  816. node_algorithms::unlink_after(bfp, lp);
  817. return l.unconst();
  818. }
  819. }
  820. //! <b>Effects</b>: Erases the range (before_f, l) from
  821. //! the list. n must be std::distance(before_f, l) - 1.
  822. //! No destructors are called.
  823. //!
  824. //! <b>Returns</b>: the first element remaining beyond the removed elements,
  825. //! or end() if no such element exists.
  826. //!
  827. //! <b>Throws</b>: Nothing.
  828. //!
  829. //! <b>Complexity</b>: constant-time if link_mode is normal_link.
  830. //! Linear to the elements (l - before_f) otherwise.
  831. //!
  832. //! <b>Note</b>: Invalidates the iterators (but not the references) to the
  833. //! erased element.
  834. iterator erase_after(const_iterator before_f, const_iterator l, size_type n)
  835. {
  836. BOOST_INTRUSIVE_INVARIANT_ASSERT(std::distance(++const_iterator(before_f), l) == difference_type(n));
  837. if(safemode_or_autounlink){
  838. return this->erase_after(before_f, l);
  839. }
  840. else{
  841. const node_ptr bfp = before_f.pointed_node();
  842. const node_ptr lp = l.pointed_node();
  843. if(cache_last){
  844. if((lp == this->get_end_node())){
  845. this->set_last_node(bfp);
  846. }
  847. }
  848. node_algorithms::unlink_after(bfp, lp);
  849. if(constant_time_size){
  850. this->priv_size_traits().decrease(n);
  851. }
  852. return l.unconst();
  853. }
  854. }
  855. //! <b>Effects</b>: Erases the element pointed by i of the list.
  856. //! No destructors are called.
  857. //!
  858. //! <b>Returns</b>: the first element remaining beyond the removed element,
  859. //! or end() if no such element exists.
  860. //!
  861. //! <b>Throws</b>: Nothing.
  862. //!
  863. //! <b>Complexity</b>: Linear to the elements before i.
  864. //!
  865. //! <b>Note</b>: Invalidates the iterators (but not the references) to the
  866. //! erased element.
  867. iterator erase(const_iterator i)
  868. { return this->erase_after(this->previous(i)); }
  869. //! <b>Requires</b>: f and l must be valid iterator to elements in *this.
  870. //!
  871. //! <b>Effects</b>: Erases the range pointed by b and e.
  872. //! No destructors are called.
  873. //!
  874. //! <b>Returns</b>: the first element remaining beyond the removed elements,
  875. //! or end() if no such element exists.
  876. //!
  877. //! <b>Throws</b>: Nothing.
  878. //!
  879. //! <b>Complexity</b>: Linear to the elements before l.
  880. //!
  881. //! <b>Note</b>: Invalidates the iterators (but not the references) to the
  882. //! erased elements.
  883. iterator erase(const_iterator f, const_iterator l)
  884. { return this->erase_after(this->previous(f), l); }
  885. //! <b>Effects</b>: Erases the range [f, l) from
  886. //! the list. n must be std::distance(f, l).
  887. //! No destructors are called.
  888. //!
  889. //! <b>Returns</b>: the first element remaining beyond the removed elements,
  890. //! or end() if no such element exists.
  891. //!
  892. //! <b>Throws</b>: Nothing.
  893. //!
  894. //! <b>Complexity</b>: linear to the elements before f if link_mode is normal_link
  895. //! and constant_time_size is activated. Linear to the elements before l otherwise.
  896. //!
  897. //! <b>Note</b>: Invalidates the iterators (but not the references) to the
  898. //! erased element.
  899. iterator erase(const_iterator f, const_iterator l, size_type n)
  900. { return this->erase_after(this->previous(f), l, n); }
  901. //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
  902. //!
  903. //! <b>Effects</b>: Erases the element after the element pointed by prev of
  904. //! the list.
  905. //! Disposer::operator()(pointer) is called for the removed element.
  906. //!
  907. //! <b>Returns</b>: the first element remaining beyond the removed elements,
  908. //! or end() if no such element exists.
  909. //!
  910. //! <b>Throws</b>: Nothing.
  911. //!
  912. //! <b>Complexity</b>: Constant.
  913. //!
  914. //! <b>Note</b>: Invalidates the iterators to the erased element.
  915. template<class Disposer>
  916. iterator erase_after_and_dispose(const_iterator prev, Disposer disposer)
  917. {
  918. const_iterator it(prev);
  919. ++it;
  920. node_ptr to_erase(it.pointed_node());
  921. ++it;
  922. node_ptr prev_n(prev.pointed_node());
  923. node_algorithms::unlink_after(prev_n);
  924. if(cache_last && (to_erase == this->get_last_node())){
  925. this->set_last_node(prev_n);
  926. }
  927. if(safemode_or_autounlink)
  928. node_algorithms::init(to_erase);
  929. disposer(get_real_value_traits().to_value_ptr(to_erase));
  930. this->priv_size_traits().decrement();
  931. return it.unconst();
  932. }
  933. /// @cond
  934. template<class Disposer>
  935. static iterator s_erase_after_and_dispose(const_iterator prev, Disposer disposer)
  936. {
  937. BOOST_STATIC_ASSERT(((!cache_last)&&(!constant_time_size)&&(!stateful_value_traits)));
  938. const_iterator it(prev);
  939. ++it;
  940. node_ptr to_erase(it.pointed_node());
  941. ++it;
  942. node_ptr prev_n(prev.pointed_node());
  943. node_algorithms::unlink_after(prev_n);
  944. if(safemode_or_autounlink)
  945. node_algorithms::init(to_erase);
  946. disposer(real_value_traits::to_value_ptr(to_erase));
  947. return it.unconst();
  948. }
  949. static iterator s_erase_after(const_iterator prev)
  950. { return s_erase_after_and_dispose(prev, detail::null_disposer()); }
  951. /// @endcond
  952. //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
  953. //!
  954. //! <b>Effects</b>: Erases the range (before_f, l) from
  955. //! the list.
  956. //! Disposer::operator()(pointer) is called for the removed elements.
  957. //!
  958. //! <b>Returns</b>: the first element remaining beyond the removed elements,
  959. //! or end() if no such element exists.
  960. //!
  961. //! <b>Throws</b>: Nothing.
  962. //!
  963. //! <b>Complexity</b>: Lineal to the elements (l - before_f + 1).
  964. //!
  965. //! <b>Note</b>: Invalidates the iterators to the erased element.
  966. template<class Disposer>
  967. iterator erase_after_and_dispose(const_iterator before_f, const_iterator l, Disposer disposer)
  968. {
  969. node_ptr bfp(before_f.pointed_node()), lp(l.pointed_node());
  970. node_ptr fp(node_traits::get_next(bfp));
  971. node_algorithms::unlink_after(bfp, lp);
  972. while(fp != lp){
  973. node_ptr to_erase(fp);
  974. fp = node_traits::get_next(fp);
  975. if(safemode_or_autounlink)
  976. node_algorithms::init(to_erase);
  977. disposer(get_real_value_traits().to_value_ptr(to_erase));
  978. this->priv_size_traits().decrement();
  979. }
  980. if(cache_last && (node_traits::get_next(bfp) == this->get_end_node())){
  981. this->set_last_node(bfp);
  982. }
  983. return l.unconst();
  984. }
  985. //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
  986. //!
  987. //! <b>Effects</b>: Erases the element pointed by i of the list.
  988. //! No destructors are called.
  989. //! Disposer::operator()(pointer) is called for the removed element.
  990. //!
  991. //! <b>Returns</b>: the first element remaining beyond the removed element,
  992. //! or end() if no such element exists.
  993. //!
  994. //! <b>Throws</b>: Nothing.
  995. //!
  996. //! <b>Complexity</b>: Linear to the elements before i.
  997. //!
  998. //! <b>Note</b>: Invalidates the iterators (but not the references) to the
  999. //! erased element.
  1000. template<class Disposer>
  1001. iterator erase_and_dispose(const_iterator i, Disposer disposer)
  1002. { return this->erase_after_and_dispose(this->previous(i), disposer); }
  1003. #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
  1004. template<class Disposer>
  1005. iterator erase_and_dispose(iterator i, Disposer disposer)
  1006. { return this->erase_and_dispose(const_iterator(i), disposer); }
  1007. #endif
  1008. //! <b>Requires</b>: f and l must be valid iterator to elements in *this.
  1009. //! Disposer::operator()(pointer) shouldn't throw.
  1010. //!
  1011. //! <b>Effects</b>: Erases the range pointed by b and e.
  1012. //! No destructors are called.
  1013. //! Disposer::operator()(pointer) is called for the removed elements.
  1014. //!
  1015. //! <b>Returns</b>: the first element remaining beyond the removed elements,
  1016. //! or end() if no such element exists.
  1017. //!
  1018. //! <b>Throws</b>: Nothing.
  1019. //!
  1020. //! <b>Complexity</b>: Linear to the number of erased elements plus linear
  1021. //! to the elements before f.
  1022. //!
  1023. //! <b>Note</b>: Invalidates the iterators (but not the references) to the
  1024. //! erased elements.
  1025. template<class Disposer>
  1026. iterator erase_and_dispose(const_iterator f, const_iterator l, Disposer disposer)
  1027. { return this->erase_after_and_dispose(this->previous(f), l, disposer); }
  1028. //! <b>Requires</b>: Dereferencing iterator must yield
  1029. //! an lvalue of type value_type.
  1030. //!
  1031. //! <b>Effects</b>: Clears the list and inserts the range pointed by b and e.
  1032. //! No destructors or copy constructors are called.
  1033. //!
  1034. //! <b>Throws</b>: Nothing.
  1035. //!
  1036. //! <b>Complexity</b>: Linear to the number of elements inserted plus
  1037. //! linear to the elements contained in the list if it's a safe-mode
  1038. //! or auto-unlink value.
  1039. //! Linear to the number of elements inserted in the list otherwise.
  1040. //!
  1041. //! <b>Note</b>: Invalidates the iterators (but not the references)
  1042. //! to the erased elements.
  1043. template<class Iterator>
  1044. void assign(Iterator b, Iterator e)
  1045. {
  1046. this->clear();
  1047. this->insert_after(this->cbefore_begin(), b, e);
  1048. }
  1049. //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
  1050. //!
  1051. //! <b>Requires</b>: Dereferencing iterator must yield
  1052. //! an lvalue of type value_type.
  1053. //!
  1054. //! <b>Effects</b>: Clears the list and inserts the range pointed by b and e.
  1055. //! No destructors or copy constructors are called.
  1056. //! Disposer::operator()(pointer) is called for the removed elements.
  1057. //!
  1058. //! <b>Throws</b>: Nothing.
  1059. //!
  1060. //! <b>Complexity</b>: Linear to the number of elements inserted plus
  1061. //! linear to the elements contained in the list.
  1062. //!
  1063. //! <b>Note</b>: Invalidates the iterators (but not the references)
  1064. //! to the erased elements.
  1065. template<class Iterator, class Disposer>
  1066. void dispose_and_assign(Disposer disposer, Iterator b, Iterator e)
  1067. {
  1068. this->clear_and_dispose(disposer);
  1069. this->insert_after(this->cbefore_begin(), b, e, disposer);
  1070. }
  1071. //! <b>Requires</b>: prev must point to an element contained by this list or
  1072. //! to the before_begin() element
  1073. //!
  1074. //! <b>Effects</b>: Transfers all the elements of list x to this list, after the
  1075. //! the element pointed by prev. No destructors or copy constructors are called.
  1076. //!
  1077. //! <b>Returns</b>: Nothing.
  1078. //!
  1079. //! <b>Throws</b>: Nothing.
  1080. //!
  1081. //! <b>Complexity</b>: In general, linear to the elements contained in x.
  1082. //! Constant-time if cache_last<> option is true and also constant-time if
  1083. //! linear<> option is true "this" is empty and "l" is not used.
  1084. //!
  1085. //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
  1086. //! list. Iterators of this list and all the references are not invalidated.
  1087. //!
  1088. //! <b>Additional note</b>: If the optional parameter "l" is provided, it will be
  1089. //! assigned to the last spliced element or prev if x is empty.
  1090. //! This iterator can be used as new "prev" iterator for a new splice_after call.
  1091. //! that will splice new values after the previously spliced values.
  1092. void splice_after(const_iterator prev, slist_impl &x, const_iterator *l = 0)
  1093. {
  1094. if(x.empty()){
  1095. if(l) *l = prev;
  1096. }
  1097. else if(linear && this->empty()){
  1098. this->swap(x);
  1099. if(l) *l = this->previous(this->cend());
  1100. }
  1101. else{
  1102. const_iterator last_x(x.previous(x.end())); //<- constant time if cache_last is active
  1103. node_ptr prev_n(prev.pointed_node());
  1104. node_ptr last_x_n(last_x.pointed_node());
  1105. if(cache_last){
  1106. x.set_last_node(x.get_root_node());
  1107. if(node_traits::get_next(prev_n) == this->get_end_node()){
  1108. this->set_last_node(last_x_n);
  1109. }
  1110. }
  1111. node_algorithms::transfer_after( prev_n, x.before_begin().pointed_node(), last_x_n);
  1112. this->priv_size_traits().increase(x.priv_size_traits().get_size());
  1113. x.priv_size_traits().set_size(size_type(0));
  1114. if(l) *l = last_x;
  1115. }
  1116. }
  1117. //! <b>Requires</b>: prev must point to an element contained by this list or
  1118. //! to the before_begin() element. prev_ele must point to an element contained in list
  1119. //! x or must be x.before_begin().
  1120. //!
  1121. //! <b>Effects</b>: Transfers the element after prev_ele, from list x to this list,
  1122. //! after the element pointed by prev. No destructors or copy constructors are called.
  1123. //!
  1124. //! <b>Throws</b>: Nothing.
  1125. //!
  1126. //! <b>Complexity</b>: Constant.
  1127. //!
  1128. //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
  1129. //! list. Iterators of this list and all the references are not invalidated.
  1130. void splice_after(const_iterator prev_pos, slist_impl &x, const_iterator prev_ele)
  1131. {
  1132. const_iterator elem = prev_ele;
  1133. this->splice_after(prev_pos, x, prev_ele, ++elem, 1);
  1134. }
  1135. //! <b>Requires</b>: prev_pos must be a dereferenceable iterator in *this or be
  1136. //! before_begin(), and before_f and before_l belong to x and
  1137. //! ++before_f != x.end() && before_l != x.end().
  1138. //!
  1139. //! <b>Effects</b>: Transfers the range (before_f, before_l] from list x to this
  1140. //! list, after the element pointed by prev_pos.
  1141. //! No destructors or copy constructors are called.
  1142. //!
  1143. //! <b>Throws</b>: Nothing.
  1144. //!
  1145. //! <b>Complexity</b>: Linear to the number of elements transferred
  1146. //! if constant_time_size is true. Constant-time otherwise.
  1147. //!
  1148. //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
  1149. //! list. Iterators of this list and all the references are not invalidated.
  1150. void splice_after(const_iterator prev_pos, slist_impl &x, const_iterator before_f, const_iterator before_l)
  1151. {
  1152. if(constant_time_size)
  1153. this->splice_after(prev_pos, x, before_f, before_l, std::distance(before_f, before_l));
  1154. else
  1155. this->priv_splice_after
  1156. (prev_pos.pointed_node(), x, before_f.pointed_node(), before_l.pointed_node());
  1157. }
  1158. //! <b>Requires</b>: prev_pos must be a dereferenceable iterator in *this or be
  1159. //! before_begin(), and before_f and before_l belong to x and
  1160. //! ++before_f != x.end() && before_l != x.end() and
  1161. //! n == std::distance(before_f, before_l).
  1162. //!
  1163. //! <b>Effects</b>: Transfers the range (before_f, before_l] from list x to this
  1164. //! list, after the element pointed by p. No destructors or copy constructors are called.
  1165. //!
  1166. //! <b>Throws</b>: Nothing.
  1167. //!
  1168. //! <b>Complexity</b>: Constant time.
  1169. //!
  1170. //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
  1171. //! list. Iterators of this list and all the references are not invalidated.
  1172. void splice_after(const_iterator prev_pos, slist_impl &x, const_iterator before_f, const_iterator before_l, size_type n)
  1173. {
  1174. BOOST_INTRUSIVE_INVARIANT_ASSERT(std::distance(before_f, before_l) == difference_type(n));
  1175. this->priv_splice_after
  1176. (prev_pos.pointed_node(), x, before_f.pointed_node(), before_l.pointed_node());
  1177. if(constant_time_size){
  1178. this->priv_size_traits().increase(n);
  1179. x.priv_size_traits().decrease(n);
  1180. }
  1181. }
  1182. //! <b>Requires</b>: it is an iterator to an element in *this.
  1183. //!
  1184. //! <b>Effects</b>: Transfers all the elements of list x to this list, before the
  1185. //! the element pointed by it. No destructors or copy constructors are called.
  1186. //!
  1187. //! <b>Returns</b>: Nothing.
  1188. //!
  1189. //! <b>Throws</b>: Nothing.
  1190. //!
  1191. //! <b>Complexity</b>: Linear to the elements contained in x plus linear to
  1192. //! the elements before it.
  1193. //! Linear to the elements before it if cache_last<> option is true.
  1194. //! Constant-time if cache_last<> option is true and it == end().
  1195. //!
  1196. //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
  1197. //! list. Iterators of this list and all the references are not invalidated.
  1198. //!
  1199. //! <b>Additional note</b>: If the optional parameter "l" is provided, it will be
  1200. //! assigned to the last spliced element or prev if x is empty.
  1201. //! This iterator can be used as new "prev" iterator for a new splice_after call.
  1202. //! that will splice new values after the previously spliced values.
  1203. void splice(const_iterator it, slist_impl &x, const_iterator *l = 0)
  1204. { this->splice_after(this->previous(it), x, l); }
  1205. //! <b>Requires</b>: it p must be a valid iterator of *this.
  1206. //! elem must point to an element contained in list
  1207. //! x.
  1208. //!
  1209. //! <b>Effects</b>: Transfers the element elem, from list x to this list,
  1210. //! before the element pointed by pos. No destructors or copy constructors are called.
  1211. //!
  1212. //! <b>Throws</b>: Nothing.
  1213. //!
  1214. //! <b>Complexity</b>: Linear to the elements before pos and before elem.
  1215. //! Linear to the elements before elem if cache_last<> option is true and pos == end().
  1216. //!
  1217. //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
  1218. //! list. Iterators of this list and all the references are not invalidated.
  1219. void splice(const_iterator pos, slist_impl &x, const_iterator elem)
  1220. { return this->splice_after(this->previous(pos), x, x.previous(elem)); }
  1221. //! <b>Requires</b>: pos must be a dereferenceable iterator in *this
  1222. //! and f and f belong to x and f and f a valid range on x.
  1223. //!
  1224. //! <b>Effects</b>: Transfers the range [f, l) from list x to this
  1225. //! list, before the element pointed by pos.
  1226. //! No destructors or copy constructors are called.
  1227. //!
  1228. //! <b>Throws</b>: Nothing.
  1229. //!
  1230. //! <b>Complexity</b>: Linear to the sum of elements before pos, f, and l
  1231. //! plus linear to the number of elements transferred if constant_time_size is true.
  1232. //! Linear to the sum of elements before f, and l
  1233. //! plus linear to the number of elements transferred if constant_time_size is true
  1234. //! if cache_last<> is true and pos == end()
  1235. //!
  1236. //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
  1237. //! list. Iterators of this list and all the references are not invalidated.
  1238. void splice(const_iterator pos, slist_impl &x, const_iterator f, const_iterator l)
  1239. { return this->splice_after(this->previous(pos), x, x.previous(f), x.previous(l)); }
  1240. //! <b>Requires</b>: pos must be a dereferenceable iterator in *this
  1241. //! and f and l belong to x and f and l a valid range on x.
  1242. //! n == std::distance(f, l).
  1243. //!
  1244. //! <b>Effects</b>: Transfers the range [f, l) from list x to this
  1245. //! list, before the element pointed by pos.
  1246. //! No destructors or copy constructors are called.
  1247. //!
  1248. //! <b>Throws</b>: Nothing.
  1249. //!
  1250. //! <b>Complexity</b>: Linear to the sum of elements before pos, f, and l.
  1251. //! Linear to the sum of elements before f and l
  1252. //! if cache_last<> is true and pos == end().
  1253. //!
  1254. //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
  1255. //! list. Iterators of this list and all the references are not invalidated.
  1256. void splice(const_iterator pos, slist_impl &x, const_iterator f, const_iterator l, size_type n)
  1257. { return this->splice_after(this->previous(pos), x, x.previous(f), x.previous(l), n); }
  1258. //! <b>Effects</b>: This function sorts the list *this according to std::less<value_type>.
  1259. //! The sort is stable, that is, the relative order of equivalent elements is preserved.
  1260. //!
  1261. //! <b>Throws</b>: If value_traits::node_traits::node
  1262. //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
  1263. //! or the predicate throws. Basic guarantee.
  1264. //!
  1265. //! <b>Complexity</b>: The number of comparisons is approximately N log N, where N
  1266. //! is the list's size.
  1267. //!
  1268. //! <b>Note</b>: Iterators and references are not invalidated
  1269. template<class Predicate>
  1270. void sort(Predicate p)
  1271. {
  1272. if (node_traits::get_next(node_traits::get_next(this->get_root_node()))
  1273. != this->get_root_node()) {
  1274. slist_impl carry(this->priv_value_traits());
  1275. detail::array_initializer<slist_impl, 64> counter(this->priv_value_traits());
  1276. int fill = 0;
  1277. const_iterator last_inserted;
  1278. while(!this->empty()){
  1279. last_inserted = this->cbegin();
  1280. carry.splice_after(carry.cbefore_begin(), *this, this->cbefore_begin());
  1281. int i = 0;
  1282. while(i < fill && !counter[i].empty()) {
  1283. carry.swap(counter[i]);
  1284. carry.merge(counter[i++], p, &last_inserted);
  1285. }
  1286. BOOST_INTRUSIVE_INVARIANT_ASSERT(counter[i].empty());
  1287. const_iterator last_element(carry.previous(last_inserted, carry.end()));
  1288. if(constant_time_size){
  1289. counter[i].splice_after( counter[i].cbefore_begin(), carry
  1290. , carry.cbefore_begin(), last_element
  1291. , carry.size());
  1292. }
  1293. else{
  1294. counter[i].splice_after( counter[i].cbefore_begin(), carry
  1295. , carry.cbefore_begin(), last_element);
  1296. }
  1297. if(i == fill)
  1298. ++fill;
  1299. }
  1300. for (int i = 1; i < fill; ++i)
  1301. counter[i].merge(counter[i-1], p, &last_inserted);
  1302. --fill;
  1303. const_iterator last_element(counter[fill].previous(last_inserted, counter[fill].end()));
  1304. if(constant_time_size){
  1305. this->splice_after( cbefore_begin(), counter[fill], counter[fill].cbefore_begin()
  1306. , last_element, counter[fill].size());
  1307. }
  1308. else{
  1309. this->splice_after( cbefore_begin(), counter[fill], counter[fill].cbefore_begin()
  1310. , last_element);
  1311. }
  1312. }
  1313. }
  1314. //! <b>Requires</b>: p must be a comparison function that induces a strict weak
  1315. //! ordering and both *this and x must be sorted according to that ordering
  1316. //! The lists x and *this must be distinct.
  1317. //!
  1318. //! <b>Effects</b>: This function removes all of x's elements and inserts them
  1319. //! in order into *this. The merge is stable; that is, if an element from *this is
  1320. //! equivalent to one from x, then the element from *this will precede the one from x.
  1321. //!
  1322. //! <b>Throws</b>: If value_traits::node_traits::node
  1323. //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
  1324. //! or std::less<value_type> throws. Basic guarantee.
  1325. //!
  1326. //! <b>Complexity</b>: This function is linear time: it performs at most
  1327. //! size() + x.size() - 1 comparisons.
  1328. //!
  1329. //! <b>Note</b>: Iterators and references are not invalidated.
  1330. void sort()
  1331. { this->sort(std::less<value_type>()); }
  1332. //! <b>Requires</b>: p must be a comparison function that induces a strict weak
  1333. //! ordering and both *this and x must be sorted according to that ordering
  1334. //! The lists x and *this must be distinct.
  1335. //!
  1336. //! <b>Effects</b>: This function removes all of x's elements and inserts them
  1337. //! in order into *this. The merge is stable; that is, if an element from *this is
  1338. //! equivalent to one from x, then the element from *this will precede the one from x.
  1339. //!
  1340. //! <b>Returns</b>: Nothing.
  1341. //!
  1342. //! <b>Throws</b>: If the predicate throws. Basic guarantee.
  1343. //!
  1344. //! <b>Complexity</b>: This function is linear time: it performs at most
  1345. //! size() + x.size() - 1 comparisons.
  1346. //!
  1347. //! <b>Note</b>: Iterators and references are not invalidated.
  1348. //!
  1349. //! <b>Additional note</b>: If optional "l" argument is passed, it is assigned
  1350. //! to an iterator to the last transferred value or end() is x is empty.
  1351. template<class Predicate>
  1352. void merge(slist_impl& x, Predicate p, const_iterator *l = 0)
  1353. {
  1354. const_iterator e(this->cend()), ex(x.cend()), bb(this->cbefore_begin()),
  1355. bb_next;
  1356. if(l) *l = e.unconst();
  1357. while(!x.empty()){
  1358. const_iterator ibx_next(x.cbefore_begin()), ibx(ibx_next++);
  1359. while (++(bb_next = bb) != e && !p(*ibx_next, *bb_next)){
  1360. bb = bb_next;
  1361. }
  1362. if(bb_next == e){
  1363. //Now transfer the rest to the end of the container
  1364. this->splice_after(bb, x, l);
  1365. break;
  1366. }
  1367. else{
  1368. size_type n(0);
  1369. do{
  1370. ibx = ibx_next; ++n;
  1371. } while(++(ibx_next = ibx) != ex && p(*ibx_next, *bb_next));
  1372. this->splice_after(bb, x, x.before_begin(), ibx, n);
  1373. if(l) *l = ibx;
  1374. }
  1375. }
  1376. }
  1377. //! <b>Effects</b>: This function removes all of x's elements and inserts them
  1378. //! in order into *this according to std::less<value_type>. The merge is stable;
  1379. //! that is, if an element from *this is equivalent to one from x, then the element
  1380. //! from *this will precede the one from x.
  1381. //!
  1382. //! <b>Throws</b>: if std::less<value_type> throws. Basic guarantee.
  1383. //!
  1384. //! <b>Complexity</b>: This function is linear time: it performs at most
  1385. //! size() + x.size() - 1 comparisons.
  1386. //!
  1387. //! <b>Note</b>: Iterators and references are not invalidated
  1388. void merge(slist_impl& x)
  1389. { this->merge(x, std::less<value_type>()); }
  1390. //! <b>Effects</b>: Reverses the order of elements in the list.
  1391. //!
  1392. //! <b>Throws</b>: Nothing.
  1393. //!
  1394. //! <b>Complexity</b>: This function is linear to the contained elements.
  1395. //!
  1396. //! <b>Note</b>: Iterators and references are not invalidated
  1397. void reverse()
  1398. {
  1399. if(cache_last && !this->empty()){
  1400. this->set_last_node(node_traits::get_next(this->get_root_node()));
  1401. }
  1402. this->priv_reverse(detail::bool_<linear>());
  1403. }
  1404. //! <b>Effects</b>: Removes all the elements that compare equal to value.
  1405. //! No destructors are called.
  1406. //!
  1407. //! <b>Throws</b>: If std::equal_to<value_type> throws. Basic guarantee.
  1408. //!
  1409. //! <b>Complexity</b>: Linear time. It performs exactly size() comparisons for equality.
  1410. //!
  1411. //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
  1412. //! and iterators to elements that are not removed remain valid. This function is
  1413. //! linear time: it performs exactly size() comparisons for equality.
  1414. void remove(const_reference value)
  1415. { this->remove_if(detail::equal_to_value<const_reference>(value)); }
  1416. //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
  1417. //!
  1418. //! <b>Effects</b>: Removes all the elements that compare equal to value.
  1419. //! Disposer::operator()(pointer) is called for every removed element.
  1420. //!
  1421. //! <b>Throws</b>: If std::equal_to<value_type> throws. Basic guarantee.
  1422. //!
  1423. //! <b>Complexity</b>: Linear time. It performs exactly size() comparisons for equality.
  1424. //!
  1425. //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
  1426. //! and iterators to elements that are not removed remain valid.
  1427. template<class Disposer>
  1428. void remove_and_dispose(const_reference value, Disposer disposer)
  1429. { this->remove_and_dispose_if(detail::equal_to_value<const_reference>(value), disposer); }
  1430. //! <b>Effects</b>: Removes all the elements for which a specified
  1431. //! predicate is satisfied. No destructors are called.
  1432. //!
  1433. //! <b>Throws</b>: If pred throws. Basic guarantee.
  1434. //!
  1435. //! <b>Complexity</b>: Linear time. It performs exactly size() calls to the predicate.
  1436. //!
  1437. //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
  1438. //! and iterators to elements that are not removed remain valid.
  1439. template<class Pred>
  1440. void remove_if(Pred pred)
  1441. { this->remove_and_dispose_if(pred, detail::null_disposer()); }
  1442. //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
  1443. //!
  1444. //! <b>Effects</b>: Removes all the elements for which a specified
  1445. //! predicate is satisfied.
  1446. //! Disposer::operator()(pointer) is called for every removed element.
  1447. //!
  1448. //! <b>Throws</b>: If pred throws. Basic guarantee.
  1449. //!
  1450. //! <b>Complexity</b>: Linear time. It performs exactly size() comparisons for equality.
  1451. //!
  1452. //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
  1453. //! and iterators to elements that are not removed remain valid.
  1454. template<class Pred, class Disposer>
  1455. void remove_and_dispose_if(Pred pred, Disposer disposer)
  1456. {
  1457. const_iterator bcur(this->before_begin()), cur(this->begin()), e(this->end());
  1458. while(cur != e){
  1459. if (pred(*cur)){
  1460. cur = this->erase_after_and_dispose(bcur, disposer);
  1461. }
  1462. else{
  1463. bcur = cur;
  1464. ++cur;
  1465. }
  1466. }
  1467. if(cache_last){
  1468. this->set_last_node(bcur.pointed_node());
  1469. }
  1470. }
  1471. //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
  1472. //! elements that are equal from the list. No destructors are called.
  1473. //!
  1474. //! <b>Throws</b>: If std::equal_to<value_type> throws. Basic guarantee.
  1475. //!
  1476. //! <b>Complexity</b>: Linear time (size()-1) comparisons calls to pred()).
  1477. //!
  1478. //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
  1479. //! and iterators to elements that are not removed remain valid.
  1480. void unique()
  1481. { this->unique_and_dispose(std::equal_to<value_type>(), detail::null_disposer()); }
  1482. //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
  1483. //! elements that satisfy some binary predicate from the list.
  1484. //! No destructors are called.
  1485. //!
  1486. //! <b>Throws</b>: If the predicate throws. Basic guarantee.
  1487. //!
  1488. //! <b>Complexity</b>: Linear time (size()-1) comparisons equality comparisons.
  1489. //!
  1490. //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
  1491. //! and iterators to elements that are not removed remain valid.
  1492. template<class BinaryPredicate>
  1493. void unique(BinaryPredicate pred)
  1494. { this->unique_and_dispose(pred, detail::null_disposer()); }
  1495. //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
  1496. //!
  1497. //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
  1498. //! elements that satisfy some binary predicate from the list.
  1499. //! Disposer::operator()(pointer) is called for every removed element.
  1500. //!
  1501. //! <b>Throws</b>: If std::equal_to<value_type> throws. Basic guarantee.
  1502. //!
  1503. //! <b>Complexity</b>: Linear time (size()-1) comparisons equality comparisons.
  1504. //!
  1505. //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
  1506. //! and iterators to elements that are not removed remain valid.
  1507. template<class Disposer>
  1508. void unique_and_dispose(Disposer disposer)
  1509. { this->unique(std::equal_to<value_type>(), disposer); }
  1510. //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
  1511. //!
  1512. //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
  1513. //! elements that satisfy some binary predicate from the list.
  1514. //! Disposer::operator()(pointer) is called for every removed element.
  1515. //!
  1516. //! <b>Throws</b>: If the predicate throws. Basic guarantee.
  1517. //!
  1518. //! <b>Complexity</b>: Linear time (size()-1) comparisons equality comparisons.
  1519. //!
  1520. //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
  1521. //! and iterators to elements that are not removed remain valid.
  1522. template<class BinaryPredicate, class Disposer>
  1523. void unique_and_dispose(BinaryPredicate pred, Disposer disposer)
  1524. {
  1525. const_iterator end_n(this->cend());
  1526. const_iterator bcur(this->cbegin());
  1527. if(bcur != end_n){
  1528. const_iterator cur(bcur);
  1529. ++cur;
  1530. while(cur != end_n) {
  1531. if (pred(*bcur, *cur)){
  1532. cur = this->erase_after_and_dispose(bcur, disposer);
  1533. }
  1534. else{
  1535. bcur = cur;
  1536. ++cur;
  1537. }
  1538. }
  1539. if(cache_last){
  1540. this->set_last_node(bcur.pointed_node());
  1541. }
  1542. }
  1543. }
  1544. //! <b>Requires</b>: value must be a reference to a value inserted in a list.
  1545. //!
  1546. //! <b>Effects</b>: This function returns a const_iterator pointing to the element
  1547. //!
  1548. //! <b>Throws</b>: Nothing.
  1549. //!
  1550. //! <b>Complexity</b>: Constant time.
  1551. //!
  1552. //! <b>Note</b>: Iterators and references are not invalidated.
  1553. //! This static function is available only if the <i>value traits</i>
  1554. //! is stateless.
  1555. static iterator s_iterator_to(reference value)
  1556. {
  1557. BOOST_STATIC_ASSERT((!stateful_value_traits));
  1558. //BOOST_INTRUSIVE_INVARIANT_ASSERT (!node_algorithms::inited(value_traits::to_node_ptr(value)));
  1559. return iterator (value_traits::to_node_ptr(value), const_real_value_traits_ptr());
  1560. }
  1561. //! <b>Requires</b>: value must be a const reference to a value inserted in a list.
  1562. //!
  1563. //! <b>Effects</b>: This function returns an iterator pointing to the element.
  1564. //!
  1565. //! <b>Throws</b>: Nothing.
  1566. //!
  1567. //! <b>Complexity</b>: Constant time.
  1568. //!
  1569. //! <b>Note</b>: Iterators and references are not invalidated.
  1570. //! This static function is available only if the <i>value traits</i>
  1571. //! is stateless.
  1572. static const_iterator s_iterator_to(const_reference value)
  1573. {
  1574. BOOST_STATIC_ASSERT((!stateful_value_traits));
  1575. //BOOST_INTRUSIVE_INVARIANT_ASSERT (!node_algorithms::inited(value_traits::to_node_ptr(const_cast<reference> (value))));
  1576. return const_iterator (value_traits::to_node_ptr(const_cast<reference> (value)), const_real_value_traits_ptr());
  1577. }
  1578. //! <b>Requires</b>: value must be a reference to a value inserted in a list.
  1579. //!
  1580. //! <b>Effects</b>: This function returns a const_iterator pointing to the element
  1581. //!
  1582. //! <b>Throws</b>: Nothing.
  1583. //!
  1584. //! <b>Complexity</b>: Constant time.
  1585. //!
  1586. //! <b>Note</b>: Iterators and references are not invalidated.
  1587. iterator iterator_to(reference value)
  1588. {
  1589. //BOOST_INTRUSIVE_INVARIANT_ASSERT (!node_algorithms::inited(value_traits::to_node_ptr(value)));
  1590. return iterator (value_traits::to_node_ptr(value), this->real_value_traits_ptr());
  1591. }
  1592. //! <b>Requires</b>: value must be a const reference to a value inserted in a list.
  1593. //!
  1594. //! <b>Effects</b>: This function returns an iterator pointing to the element.
  1595. //!
  1596. //! <b>Throws</b>: Nothing.
  1597. //!
  1598. //! <b>Complexity</b>: Constant time.
  1599. //!
  1600. //! <b>Note</b>: Iterators and references are not invalidated.
  1601. const_iterator iterator_to(const_reference value) const
  1602. {
  1603. //BOOST_INTRUSIVE_INVARIANT_ASSERT (!node_algorithms::inited(value_traits::to_node_ptr(const_cast<reference> (value))));
  1604. return const_iterator (value_traits::to_node_ptr(const_cast<reference> (value)), this->real_value_traits_ptr());
  1605. }
  1606. //! <b>Returns</b>: The iterator to the element before i in the list.
  1607. //! Returns the end-iterator, if either i is the begin-iterator or the
  1608. //! list is empty.
  1609. //!
  1610. //! <b>Throws</b>: Nothing.
  1611. //!
  1612. //! <b>Complexity</b>: Linear to the number of elements before i.
  1613. //! Constant if cache_last<> is true and i == end().
  1614. iterator previous(iterator i)
  1615. { return this->previous(this->cbefore_begin(), i); }
  1616. //! <b>Returns</b>: The const_iterator to the element before i in the list.
  1617. //! Returns the end-const_iterator, if either i is the begin-const_iterator or
  1618. //! the list is empty.
  1619. //!
  1620. //! <b>Throws</b>: Nothing.
  1621. //!
  1622. //! <b>Complexity</b>: Linear to the number of elements before i.
  1623. //! Constant if cache_last<> is true and i == end().
  1624. const_iterator previous(const_iterator i) const
  1625. { return this->previous(this->cbefore_begin(), i); }
  1626. //! <b>Returns</b>: The iterator to the element before i in the list,
  1627. //! starting the search on element after prev_from.
  1628. //! Returns the end-iterator, if either i is the begin-iterator or the
  1629. //! list is empty.
  1630. //!
  1631. //! <b>Throws</b>: Nothing.
  1632. //!
  1633. //! <b>Complexity</b>: Linear to the number of elements before i.
  1634. //! Constant if cache_last<> is true and i == end().
  1635. iterator previous(const_iterator prev_from, iterator i)
  1636. { return this->previous(prev_from, const_iterator(i)).unconst(); }
  1637. //! <b>Returns</b>: The const_iterator to the element before i in the list,
  1638. //! starting the search on element after prev_from.
  1639. //! Returns the end-const_iterator, if either i is the begin-const_iterator or
  1640. //! the list is empty.
  1641. //!
  1642. //! <b>Throws</b>: Nothing.
  1643. //!
  1644. //! <b>Complexity</b>: Linear to the number of elements before i.
  1645. //! Constant if cache_last<> is true and i == end().
  1646. const_iterator previous(const_iterator prev_from, const_iterator i) const
  1647. {
  1648. if(cache_last && (i.pointed_node() == this->get_end_node())){
  1649. return const_iterator(detail::uncast(this->get_last_node()), this->real_value_traits_ptr());
  1650. }
  1651. return const_iterator
  1652. (node_algorithms::get_previous_node
  1653. (prev_from.pointed_node(), i.pointed_node()), this->real_value_traits_ptr());
  1654. }
  1655. ///@cond
  1656. //! <b>Requires</b>: prev_pos must be a dereferenceable iterator in *this or be
  1657. //! before_begin(), and f and before_l belong to another slist.
  1658. //!
  1659. //! <b>Effects</b>: Transfers the range [f, before_l] to this
  1660. //! list, after the element pointed by prev_pos.
  1661. //! No destructors or copy constructors are called.
  1662. //!
  1663. //! <b>Throws</b>: Nothing.
  1664. //!
  1665. //! <b>Complexity</b>: Linear to the number of elements transferred
  1666. //! if constant_time_size is true. Constant-time otherwise.
  1667. //!
  1668. //! <b>Note</b>: Iterators of values obtained from the list that owned f and before_l now
  1669. //! point to elements of this list. Iterators of this list and all the references are not invalidated.
  1670. //!
  1671. //! <b>Warning</b>: Experimental function, don't use it!
  1672. void incorporate_after(const_iterator prev_pos, const node_ptr & f, const node_ptr & before_l)
  1673. {
  1674. if(constant_time_size)
  1675. this->incorporate_after(prev_pos, f, before_l, std::distance(f, before_l)+1);
  1676. else
  1677. this->priv_incorporate_after(prev_pos.pointed_node(), f, before_l);
  1678. }
  1679. //! <b>Requires</b>: prev_pos must be a dereferenceable iterator in *this or be
  1680. //! before_begin(), and f and before_l belong to another slist.
  1681. //! n == std::distance(f, before_l) + 1.
  1682. //!
  1683. //! <b>Effects</b>: Transfers the range [f, before_l] to this
  1684. //! list, after the element pointed by prev_pos.
  1685. //! No destructors or copy constructors are called.
  1686. //!
  1687. //! <b>Throws</b>: Nothing.
  1688. //!
  1689. //! <b>Complexity</b>: Constant time.
  1690. //!
  1691. //! <b>Note</b>: Iterators of values obtained from the list that owned f and before_l now
  1692. //! point to elements of this list. Iterators of this list and all the references are not invalidated.
  1693. //!
  1694. //! <b>Warning</b>: Experimental function, don't use it!
  1695. void incorporate_after(const_iterator prev_pos, const node_ptr & f, const node_ptr & before_l, size_type n)
  1696. {
  1697. if(n){
  1698. BOOST_INTRUSIVE_INVARIANT_ASSERT(n > 0);
  1699. BOOST_INTRUSIVE_INVARIANT_ASSERT
  1700. (size_type(std::distance
  1701. ( iterator(f, this->real_value_traits_ptr())
  1702. , iterator(before_l, this->real_value_traits_ptr())))
  1703. +1 == n);
  1704. this->priv_incorporate_after(prev_pos.pointed_node(), f, before_l);
  1705. if(constant_time_size){
  1706. this->priv_size_traits().increase(n);
  1707. }
  1708. }
  1709. }
  1710. ///@endcond
  1711. private:
  1712. void priv_splice_after(const node_ptr & prev_pos_n, slist_impl &x, const node_ptr & before_f_n, const node_ptr & before_l_n)
  1713. {
  1714. if (cache_last && (before_f_n != before_l_n)){
  1715. if(prev_pos_n == this->get_last_node()){
  1716. this->set_last_node(before_l_n);
  1717. }
  1718. if(&x != this && node_traits::get_next(before_l_n) == x.get_end_node()){
  1719. x.set_last_node(before_f_n);
  1720. }
  1721. }
  1722. node_algorithms::transfer_after(prev_pos_n, before_f_n, before_l_n);
  1723. }
  1724. void priv_incorporate_after(const node_ptr & prev_pos_n, const node_ptr & first_n, const node_ptr & before_l_n)
  1725. {
  1726. if(cache_last){
  1727. if(prev_pos_n == this->get_last_node()){
  1728. this->set_last_node(before_l_n);
  1729. }
  1730. }
  1731. node_algorithms::incorporate_after(prev_pos_n, first_n, before_l_n);
  1732. }
  1733. void priv_reverse(detail::bool_<false>)
  1734. { node_algorithms::reverse(this->get_root_node()); }
  1735. void priv_reverse(detail::bool_<true>)
  1736. {
  1737. node_ptr new_first = node_algorithms::reverse
  1738. (node_traits::get_next(this->get_root_node()));
  1739. node_traits::set_next(this->get_root_node(), new_first);
  1740. }
  1741. void priv_shift_backwards(size_type n, detail::bool_<false>)
  1742. {
  1743. node_ptr l = node_algorithms::move_forward(this->get_root_node(), (std::size_t)n);
  1744. if(cache_last && l){
  1745. this->set_last_node(l);
  1746. }
  1747. }
  1748. void priv_shift_backwards(size_type n, detail::bool_<true>)
  1749. {
  1750. std::pair<node_ptr, node_ptr> ret(
  1751. node_algorithms::move_first_n_forward
  1752. (node_traits::get_next(this->get_root_node()), (std::size_t)n));
  1753. if(ret.first){
  1754. node_traits::set_next(this->get_root_node(), ret.first);
  1755. if(cache_last){
  1756. this->set_last_node(ret.second);
  1757. }
  1758. }
  1759. }
  1760. void priv_shift_forward(size_type n, detail::bool_<false>)
  1761. {
  1762. node_ptr l = node_algorithms::move_backwards(this->get_root_node(), (std::size_t)n);
  1763. if(cache_last && l){
  1764. this->set_last_node(l);
  1765. }
  1766. }
  1767. void priv_shift_forward(size_type n, detail::bool_<true>)
  1768. {
  1769. std::pair<node_ptr, node_ptr> ret(
  1770. node_algorithms::move_first_n_backwards
  1771. (node_traits::get_next(this->get_root_node()), (std::size_t)n));
  1772. if(ret.first){
  1773. node_traits::set_next(this->get_root_node(), ret.first);
  1774. if(cache_last){
  1775. this->set_last_node(ret.second);
  1776. }
  1777. }
  1778. }
  1779. static void priv_swap_cache_last(slist_impl *this_impl, slist_impl *other_impl)
  1780. {
  1781. bool other_was_empty = false;
  1782. if(this_impl->empty()){
  1783. //Check if both are empty or
  1784. if(other_impl->empty())
  1785. return;
  1786. //If this is empty swap pointers
  1787. slist_impl *tmp = this_impl;
  1788. this_impl = other_impl;
  1789. other_impl = tmp;
  1790. other_was_empty = true;
  1791. }
  1792. else{
  1793. other_was_empty = other_impl->empty();
  1794. }
  1795. //Precondition: this is not empty
  1796. node_ptr other_old_last(other_impl->get_last_node());
  1797. node_ptr other_bfirst(other_impl->get_root_node());
  1798. node_ptr this_bfirst(this_impl->get_root_node());
  1799. node_ptr this_old_last(this_impl->get_last_node());
  1800. //Move all nodes from this to other's beginning
  1801. node_algorithms::transfer_after(other_bfirst, this_bfirst, this_old_last);
  1802. other_impl->set_last_node(this_old_last);
  1803. if(other_was_empty){
  1804. this_impl->set_last_node(this_bfirst);
  1805. }
  1806. else{
  1807. //Move trailing nodes from other to this
  1808. node_algorithms::transfer_after(this_bfirst, this_old_last, other_old_last);
  1809. this_impl->set_last_node(other_old_last);
  1810. }
  1811. }
  1812. //circular version
  1813. static void priv_swap_lists(const node_ptr & this_node, const node_ptr & other_node, detail::bool_<false>)
  1814. { node_algorithms::swap_nodes(this_node, other_node); }
  1815. //linear version
  1816. static void priv_swap_lists(const node_ptr & this_node, const node_ptr & other_node, detail::bool_<true>)
  1817. { node_algorithms::swap_trailing_nodes(this_node, other_node); }
  1818. static slist_impl &priv_container_from_end_iterator(const const_iterator &end_iterator)
  1819. {
  1820. //Obtaining the container from the end iterator is not possible with linear
  1821. //singly linked lists (because "end" is represented by the null pointer)
  1822. BOOST_STATIC_ASSERT(!linear);
  1823. root_plus_size *r = detail::parent_from_member<root_plus_size, node>
  1824. ( boost::intrusive::detail::to_raw_pointer(end_iterator.pointed_node()), (&root_plus_size::root_));
  1825. data_t *d = detail::parent_from_member<data_t, root_plus_size>
  1826. ( r, &data_t::root_plus_size_);
  1827. slist_impl *s = detail::parent_from_member<slist_impl, data_t>(d, &slist_impl::data_);
  1828. return *s;
  1829. }
  1830. };
  1831. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
  1832. template<class T, class ...Options>
  1833. #else
  1834. template<class ValueTraits, class SizeType, std::size_t BoolFlags>
  1835. #endif
  1836. inline bool operator<
  1837. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
  1838. (const slist_impl<T, Options...> &x, const slist_impl<T, Options...> &y)
  1839. #else
  1840. ( const slist_impl<ValueTraits, SizeType, BoolFlags> &x
  1841. , const slist_impl<ValueTraits, SizeType, BoolFlags> &y)
  1842. #endif
  1843. { return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); }
  1844. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
  1845. template<class T, class ...Options>
  1846. #else
  1847. template<class ValueTraits, class SizeType, std::size_t BoolFlags>
  1848. #endif
  1849. bool operator==
  1850. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
  1851. (const slist_impl<T, Options...> &x, const slist_impl<T, Options...> &y)
  1852. #else
  1853. ( const slist_impl<ValueTraits, SizeType, BoolFlags> &x
  1854. , const slist_impl<ValueTraits, SizeType, BoolFlags> &y)
  1855. #endif
  1856. {
  1857. typedef slist_impl<ValueTraits, SizeType, BoolFlags> slist_type;
  1858. typedef typename slist_type::const_iterator const_iterator;
  1859. const bool C = slist_type::constant_time_size;
  1860. if(C && x.size() != y.size()){
  1861. return false;
  1862. }
  1863. const_iterator end1 = x.end();
  1864. const_iterator i1 = x.begin();
  1865. const_iterator i2 = y.begin();
  1866. if(C){
  1867. while (i1 != end1 && *i1 == *i2) {
  1868. ++i1;
  1869. ++i2;
  1870. }
  1871. return i1 == end1;
  1872. }
  1873. else{
  1874. const_iterator end2 = y.end();
  1875. while (i1 != end1 && i2 != end2 && *i1 == *i2) {
  1876. ++i1;
  1877. ++i2;
  1878. }
  1879. return i1 == end1 && i2 == end2;
  1880. }
  1881. }
  1882. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
  1883. template<class T, class ...Options>
  1884. #else
  1885. template<class ValueTraits, class SizeType, std::size_t BoolFlags>
  1886. #endif
  1887. inline bool operator!=
  1888. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
  1889. (const slist_impl<T, Options...> &x, const slist_impl<T, Options...> &y)
  1890. #else
  1891. ( const slist_impl<ValueTraits, SizeType, BoolFlags> &x
  1892. , const slist_impl<ValueTraits, SizeType, BoolFlags> &y)
  1893. #endif
  1894. { return !(x == y); }
  1895. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
  1896. template<class T, class ...Options>
  1897. #else
  1898. template<class ValueTraits, class SizeType, std::size_t BoolFlags>
  1899. #endif
  1900. inline bool operator>
  1901. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
  1902. (const slist_impl<T, Options...> &x, const slist_impl<T, Options...> &y)
  1903. #else
  1904. ( const slist_impl<ValueTraits, SizeType, BoolFlags> &x
  1905. , const slist_impl<ValueTraits, SizeType, BoolFlags> &y)
  1906. #endif
  1907. { return y < x; }
  1908. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
  1909. template<class T, class ...Options>
  1910. #else
  1911. template<class ValueTraits, class SizeType, std::size_t BoolFlags>
  1912. #endif
  1913. inline bool operator<=
  1914. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
  1915. (const slist_impl<T, Options...> &x, const slist_impl<T, Options...> &y)
  1916. #else
  1917. ( const slist_impl<ValueTraits, SizeType, BoolFlags> &x
  1918. , const slist_impl<ValueTraits, SizeType, BoolFlags> &y)
  1919. #endif
  1920. { return !(y < x); }
  1921. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
  1922. template<class T, class ...Options>
  1923. #else
  1924. template<class ValueTraits, class SizeType, std::size_t BoolFlags>
  1925. #endif
  1926. inline bool operator>=
  1927. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
  1928. (const slist_impl<T, Options...> &x, const slist_impl<T, Options...> &y)
  1929. #else
  1930. ( const slist_impl<ValueTraits, SizeType, BoolFlags> &x
  1931. , const slist_impl<ValueTraits, SizeType, BoolFlags> &y)
  1932. #endif
  1933. { return !(x < y); }
  1934. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
  1935. template<class T, class ...Options>
  1936. #else
  1937. template<class ValueTraits, class SizeType, std::size_t BoolFlags>
  1938. #endif
  1939. inline void swap
  1940. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
  1941. (slist_impl<T, Options...> &x, slist_impl<T, Options...> &y)
  1942. #else
  1943. ( slist_impl<ValueTraits, SizeType, BoolFlags> &x
  1944. , slist_impl<ValueTraits, SizeType, BoolFlags> &y)
  1945. #endif
  1946. { x.swap(y); }
  1947. //! Helper metafunction to define a \c slist that yields to the same type when the
  1948. //! same options (either explicitly or implicitly) are used.
  1949. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  1950. template<class T, class ...Options>
  1951. #else
  1952. template<class T, class O1 = void, class O2 = void, class O3 = void, class O4 = void, class O5 = void>
  1953. #endif
  1954. struct make_slist
  1955. {
  1956. /// @cond
  1957. typedef typename pack_options
  1958. < slist_defaults,
  1959. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  1960. O1, O2, O3, O4, O5
  1961. #else
  1962. Options...
  1963. #endif
  1964. >::type packed_options;
  1965. typedef typename detail::get_value_traits
  1966. <T, typename packed_options::proto_value_traits>::type value_traits;
  1967. typedef slist_impl
  1968. < value_traits
  1969. , typename packed_options::size_type
  1970. , (std::size_t(packed_options::linear)*slist_bool_flags::linear_pos)
  1971. |(std::size_t(packed_options::constant_time_size)*slist_bool_flags::constant_time_size_pos)
  1972. |(std::size_t(packed_options::cache_last)*slist_bool_flags::cache_last_pos)
  1973. > implementation_defined;
  1974. /// @endcond
  1975. typedef implementation_defined type;
  1976. };
  1977. #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  1978. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  1979. template<class T, class O1, class O2, class O3, class O4, class O5>
  1980. #else
  1981. template<class T, class ...Options>
  1982. #endif
  1983. class slist
  1984. : public make_slist<T,
  1985. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  1986. O1, O2, O3, O4, O5
  1987. #else
  1988. Options...
  1989. #endif
  1990. >::type
  1991. {
  1992. typedef typename make_slist
  1993. <T,
  1994. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  1995. O1, O2, O3, O4, O5
  1996. #else
  1997. Options...
  1998. #endif
  1999. >::type Base;
  2000. typedef typename Base::real_value_traits real_value_traits;
  2001. //Assert if passed value traits are compatible with the type
  2002. BOOST_STATIC_ASSERT((detail::is_same<typename real_value_traits::value_type, T>::value));
  2003. BOOST_MOVABLE_BUT_NOT_COPYABLE(slist)
  2004. public:
  2005. typedef typename Base::value_traits value_traits;
  2006. typedef typename Base::iterator iterator;
  2007. typedef typename Base::const_iterator const_iterator;
  2008. typedef typename Base::size_type size_type;
  2009. typedef typename Base::node_ptr node_ptr;
  2010. explicit slist(const value_traits &v_traits = value_traits())
  2011. : Base(v_traits)
  2012. {}
  2013. struct incorporate_t{};
  2014. slist( const node_ptr & f, const node_ptr & before_l
  2015. , size_type n, const value_traits &v_traits = value_traits())
  2016. : Base(f, before_l, n, v_traits)
  2017. {}
  2018. template<class Iterator>
  2019. slist(Iterator b, Iterator e, const value_traits &v_traits = value_traits())
  2020. : Base(b, e, v_traits)
  2021. {}
  2022. slist(BOOST_RV_REF(slist) x)
  2023. : Base(::boost::move(static_cast<Base&>(x)))
  2024. {}
  2025. slist& operator=(BOOST_RV_REF(slist) x)
  2026. { return static_cast<slist &>(this->Base::operator=(::boost::move(static_cast<Base&>(x)))); }
  2027. static slist &container_from_end_iterator(iterator end_iterator)
  2028. { return static_cast<slist &>(Base::container_from_end_iterator(end_iterator)); }
  2029. static const slist &container_from_end_iterator(const_iterator end_iterator)
  2030. { return static_cast<const slist &>(Base::container_from_end_iterator(end_iterator)); }
  2031. };
  2032. #endif
  2033. } //namespace intrusive
  2034. } //namespace boost
  2035. #include <boost/intrusive/detail/config_end.hpp>
  2036. #endif //BOOST_INTRUSIVE_SLIST_HPP