slist.hpp 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2004-2015. Distributed under the Boost
  4. // Software License, Version 1.0. (See accompanying file
  5. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // See http://www.boost.org/libs/container for documentation.
  8. //
  9. //////////////////////////////////////////////////////////////////////////////
  10. #ifndef BOOST_CONTAINER_SLIST_HPP
  11. #define BOOST_CONTAINER_SLIST_HPP
  12. #ifndef BOOST_CONFIG_HPP
  13. # include <boost/config.hpp>
  14. #endif
  15. #if defined(BOOST_HAS_PRAGMA_ONCE)
  16. # pragma once
  17. #endif
  18. #include <boost/container/detail/config_begin.hpp>
  19. #include <boost/container/detail/workaround.hpp>
  20. // container
  21. #include <boost/container/container_fwd.hpp>
  22. #include <boost/container/new_allocator.hpp> //new_allocator
  23. #include <boost/container/throw_exception.hpp>
  24. // container/detail
  25. #include <boost/container/detail/algorithm.hpp> //algo_equal(), algo_lexicographical_compare
  26. #include <boost/container/detail/compare_functors.hpp>
  27. #include <boost/container/detail/iterator.hpp>
  28. #include <boost/container/detail/iterators.hpp>
  29. #include <boost/container/detail/mpl.hpp>
  30. #include <boost/container/detail/node_alloc_holder.hpp>
  31. #include <boost/container/detail/type_traits.hpp>
  32. #include <boost/container/detail/value_functors.hpp>
  33. // intrusive
  34. #include <boost/intrusive/pointer_traits.hpp>
  35. #include <boost/intrusive/slist.hpp>
  36. // move
  37. #include <boost/move/iterator.hpp>
  38. #include <boost/move/traits.hpp>
  39. #include <boost/move/utility_core.hpp>
  40. // move/detail
  41. #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  42. #include <boost/move/detail/fwd_macros.hpp>
  43. #endif
  44. #include <boost/move/detail/move_helpers.hpp>
  45. // std
  46. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  47. #include <initializer_list>
  48. #endif
  49. namespace boost {
  50. namespace container {
  51. #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  52. template <class T, class Allocator>
  53. class slist;
  54. namespace dtl {
  55. template<class VoidPointer>
  56. struct slist_hook
  57. {
  58. typedef typename dtl::bi::make_slist_base_hook
  59. <dtl::bi::void_pointer<VoidPointer>, dtl::bi::link_mode<dtl::bi::normal_link> >::type type;
  60. };
  61. template <class T, class VoidPointer>
  62. struct iiterator_node_value_type< base_node<T, slist_hook<VoidPointer> > >
  63. {
  64. typedef T type;
  65. };
  66. template<class Allocator>
  67. struct intrusive_slist_type
  68. {
  69. typedef boost::container::allocator_traits<Allocator> allocator_traits_type;
  70. typedef typename allocator_traits_type::value_type value_type;
  71. typedef typename boost::intrusive::pointer_traits
  72. <typename allocator_traits_type::pointer>::template
  73. rebind_pointer<void>::type
  74. void_pointer;
  75. typedef base_node<value_type, slist_hook<void_pointer> > node_type;
  76. typedef typename dtl::bi::make_slist
  77. <node_type
  78. ,dtl::bi::base_hook<typename slist_hook<void_pointer>::type>
  79. ,dtl::bi::constant_time_size<true>
  80. , dtl::bi::size_type
  81. <typename allocator_traits_type::size_type>
  82. >::type container_type;
  83. typedef container_type type ;
  84. };
  85. } //namespace dtl {
  86. #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  87. //! An slist is a singly linked list: a list where each element is linked to the next
  88. //! element, but not to the previous element. That is, it is a Sequence that
  89. //! supports forward but not backward traversal, and (amortized) constant time
  90. //! insertion and removal of elements. Slists, like lists, have the important
  91. //! property that insertion and splicing do not invalidate iterators to list elements,
  92. //! and that even removal invalidates only the iterators that point to the elements
  93. //! that are removed. The ordering of iterators may be changed (that is,
  94. //! slist<T>::iterator might have a different predecessor or successor after a list
  95. //! operation than it did before), but the iterators themselves will not be invalidated
  96. //! or made to point to different elements unless that invalidation or mutation is explicit.
  97. //!
  98. //! The main difference between slist and list is that list's iterators are bidirectional
  99. //! iterators, while slist's iterators are forward iterators. This means that slist is
  100. //! less versatile than list; frequently, however, bidirectional iterators are
  101. //! unnecessary. You should usually use slist unless you actually need the extra
  102. //! functionality of list, because singly linked lists are smaller and faster than double
  103. //! linked lists.
  104. //!
  105. //! Important performance note: like every other Sequence, slist defines the member
  106. //! functions insert and erase. Using these member functions carelessly, however, can
  107. //! result in disastrously slow programs. The problem is that insert's first argument is
  108. //! an iterator p, and that it inserts the new element(s) before p. This means that
  109. //! insert must find the iterator just before p; this is a constant-time operation
  110. //! for list, since list has bidirectional iterators, but for slist it must find that
  111. //! iterator by traversing the list from the beginning up to p. In other words:
  112. //! insert and erase are slow operations anywhere but near the beginning of the slist.
  113. //!
  114. //! Slist provides the member functions insert_after and erase_after, which are constant
  115. //! time operations: you should always use insert_after and erase_after whenever
  116. //! possible. If you find that insert_after and erase_after aren't adequate for your
  117. //! needs, and that you often need to use insert and erase in the middle of the list,
  118. //! then you should probably use list instead of slist.
  119. //!
  120. //! \tparam T The type of object that is stored in the list
  121. //! \tparam Allocator The allocator used for all internal memory management, use void
  122. //! for the default allocator
  123. #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
  124. template <class T, class Allocator = void >
  125. #else
  126. template <class T, class Allocator>
  127. #endif
  128. class slist
  129. : protected dtl::node_alloc_holder
  130. < typename real_allocator<T, Allocator>::type
  131. , typename dtl::intrusive_slist_type<typename real_allocator<T, Allocator>::type>::type>
  132. {
  133. #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  134. typedef typename real_allocator<T, Allocator>::type ValueAllocator;
  135. typedef typename
  136. dtl::intrusive_slist_type<ValueAllocator>::type Icont;
  137. typedef dtl::node_alloc_holder<ValueAllocator, Icont> AllocHolder;
  138. typedef typename AllocHolder::NodePtr NodePtr;
  139. typedef typename AllocHolder::NodeAlloc NodeAlloc;
  140. typedef typename AllocHolder::ValAlloc ValAlloc;
  141. typedef typename AllocHolder::Node Node;
  142. typedef dtl::allocator_node_destroyer<NodeAlloc> Destroyer;
  143. typedef typename AllocHolder::alloc_version alloc_version;
  144. typedef boost::container::
  145. allocator_traits<ValueAllocator> allocator_traits_type;
  146. typedef boost::container::equal_to_value
  147. <typename allocator_traits_type::value_type> equal_to_value_type;
  148. BOOST_COPYABLE_AND_MOVABLE(slist)
  149. typedef dtl::iterator_from_iiterator<typename Icont::iterator, false> iterator_impl;
  150. typedef dtl::iterator_from_iiterator<typename Icont::iterator, true > const_iterator_impl;
  151. #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  152. public:
  153. //////////////////////////////////////////////
  154. //
  155. // types
  156. //
  157. //////////////////////////////////////////////
  158. typedef T value_type;
  159. typedef typename ::boost::container::allocator_traits<ValueAllocator>::pointer pointer;
  160. typedef typename ::boost::container::allocator_traits<ValueAllocator>::const_pointer const_pointer;
  161. typedef typename ::boost::container::allocator_traits<ValueAllocator>::reference reference;
  162. typedef typename ::boost::container::allocator_traits<ValueAllocator>::const_reference const_reference;
  163. typedef typename ::boost::container::allocator_traits<ValueAllocator>::size_type size_type;
  164. typedef typename ::boost::container::allocator_traits<ValueAllocator>::difference_type difference_type;
  165. typedef ValueAllocator allocator_type;
  166. typedef BOOST_CONTAINER_IMPDEF(NodeAlloc) stored_allocator_type;
  167. typedef BOOST_CONTAINER_IMPDEF(iterator_impl) iterator;
  168. typedef BOOST_CONTAINER_IMPDEF(const_iterator_impl) const_iterator;
  169. public:
  170. //////////////////////////////////////////////
  171. //
  172. // constructFr/copy/destroy
  173. //
  174. //////////////////////////////////////////////
  175. //! <b>Effects</b>: Constructs a list taking the allocator as parameter.
  176. //!
  177. //! <b>Throws</b>: If allocator_type's copy constructor throws.
  178. //!
  179. //! <b>Complexity</b>: Constant.
  180. slist() BOOST_NOEXCEPT_IF(dtl::is_nothrow_default_constructible<ValueAllocator>::value)
  181. : AllocHolder()
  182. {}
  183. //! <b>Effects</b>: Constructs a list taking the allocator as parameter.
  184. //!
  185. //! <b>Throws</b>: Nothing
  186. //!
  187. //! <b>Complexity</b>: Constant.
  188. explicit slist(const allocator_type& a) BOOST_NOEXCEPT_OR_NOTHROW
  189. : AllocHolder(a)
  190. {}
  191. //! <b>Effects</b>: Constructs a list
  192. //! and inserts n value-initialized value_types.
  193. //!
  194. //! <b>Throws</b>: If allocator_type's default constructor
  195. //! throws or T's default or copy constructor throws.
  196. //!
  197. //! <b>Complexity</b>: Linear to n.
  198. explicit slist(size_type n)
  199. : AllocHolder(allocator_type())
  200. { this->resize(n); }
  201. //! <b>Effects</b>: Constructs a list that will use a copy of allocator a
  202. //! and inserts n copies of value.
  203. //!
  204. //! <b>Throws</b>: If allocator_type's default constructor
  205. //! throws or T's default or copy constructor throws.
  206. //!
  207. //! <b>Complexity</b>: Linear to n.
  208. slist(size_type n, const allocator_type &a)
  209. : AllocHolder(a)
  210. { this->resize(n); }
  211. //! <b>Effects</b>: Constructs a list that will use a copy of allocator a
  212. //! and inserts n copies of value.
  213. //!
  214. //! <b>Throws</b>: If allocator_type's default constructor
  215. //! throws or T's default or copy constructor throws.
  216. //!
  217. //! <b>Complexity</b>: Linear to n.
  218. explicit slist(size_type n, const value_type& x, const allocator_type& a = allocator_type())
  219. : AllocHolder(a)
  220. { this->insert_after(this->cbefore_begin(), n, x); }
  221. //! <b>Effects</b>: Constructs a list that will use a copy of allocator a
  222. //! and inserts a copy of the range [first, last) in the list.
  223. //!
  224. //! <b>Throws</b>: If allocator_type's default constructor
  225. //! throws or T's constructor taking a dereferenced InIt throws.
  226. //!
  227. //! <b>Complexity</b>: Linear to the range [first, last).
  228. template <class InpIt>
  229. slist(InpIt first, InpIt last, const allocator_type& a = allocator_type())
  230. : AllocHolder(a)
  231. { this->insert_after(this->cbefore_begin(), first, last); }
  232. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  233. //! <b>Effects</b>: Constructs a list that will use a copy of allocator a
  234. //! and inserts a copy of the range [il.begin(), il.end()) in the list.
  235. //!
  236. //! <b>Throws</b>: If allocator_type's default constructor
  237. //! throws or T's constructor taking a dereferenced std::initializer_list iterator throws.
  238. //!
  239. //! <b>Complexity</b>: Linear to the range [il.begin(), il.end()).
  240. slist(std::initializer_list<value_type> il, const allocator_type& a = allocator_type())
  241. : AllocHolder(a)
  242. { this->insert_after(this->cbefore_begin(), il.begin(), il.end()); }
  243. #endif
  244. //! <b>Effects</b>: Copy constructs a list.
  245. //!
  246. //! <b>Postcondition</b>: x == *this.
  247. //!
  248. //! <b>Throws</b>: If allocator_type's default constructor
  249. //!
  250. //! <b>Complexity</b>: Linear to the elements x contains.
  251. slist(const slist& x)
  252. : AllocHolder(x)
  253. { this->insert_after(this->cbefore_begin(), x.begin(), x.end()); }
  254. //! <b>Effects</b>: Move constructor. Moves x's resources to *this.
  255. //!
  256. //! <b>Throws</b>: If allocator_type's copy constructor throws.
  257. //!
  258. //! <b>Complexity</b>: Constant.
  259. slist(BOOST_RV_REF(slist) x) BOOST_NOEXCEPT_OR_NOTHROW
  260. : AllocHolder(BOOST_MOVE_BASE(AllocHolder, x))
  261. {}
  262. //! <b>Effects</b>: Copy constructs a list using the specified allocator.
  263. //!
  264. //! <b>Postcondition</b>: x == *this.
  265. //!
  266. //! <b>Throws</b>: If allocator_type's default constructor
  267. //!
  268. //! <b>Complexity</b>: Linear to the elements x contains.
  269. slist(const slist& x, const allocator_type &a)
  270. : AllocHolder(a)
  271. { this->insert_after(this->cbefore_begin(), x.begin(), x.end()); }
  272. //! <b>Effects</b>: Move constructor using the specified allocator.
  273. //! Moves x's resources to *this.
  274. //!
  275. //! <b>Throws</b>: If allocation or value_type's copy constructor throws.
  276. //!
  277. //! <b>Complexity</b>: Constant if a == x.get_allocator(), linear otherwise.
  278. slist(BOOST_RV_REF(slist) x, const allocator_type &a)
  279. : AllocHolder(a)
  280. {
  281. slist & sr = x;
  282. if(this->node_alloc() == sr.node_alloc()){
  283. this->icont().swap(sr.icont());
  284. }
  285. else{
  286. this->insert_after(this->cbefore_begin(), boost::make_move_iterator(sr.begin()), boost::make_move_iterator(sr.end()));
  287. }
  288. }
  289. //! <b>Effects</b>: Destroys the list. All stored values are destroyed
  290. //! and used memory is deallocated.
  291. //!
  292. //! <b>Throws</b>: Nothing.
  293. //!
  294. //! <b>Complexity</b>: Linear to the number of elements.
  295. ~slist() BOOST_NOEXCEPT_OR_NOTHROW
  296. {} //AllocHolder clears the slist
  297. //! <b>Effects</b>: Makes *this contain the same elements as x.
  298. //!
  299. //! <b>Postcondition</b>: this->size() == x.size(). *this contains a copy
  300. //! of each of x's elements.
  301. //!
  302. //! <b>Throws</b>: If memory allocation throws or T's copy constructor throws.
  303. //!
  304. //! <b>Complexity</b>: Linear to the number of elements in x.
  305. slist& operator= (BOOST_COPY_ASSIGN_REF(slist) x)
  306. {
  307. if (BOOST_LIKELY(this != &x)) {
  308. NodeAlloc &this_alloc = this->node_alloc();
  309. const NodeAlloc &x_alloc = x.node_alloc();
  310. dtl::bool_<allocator_traits_type::
  311. propagate_on_container_copy_assignment::value> flag;
  312. if(flag && this_alloc != x_alloc){
  313. this->clear();
  314. }
  315. this->AllocHolder::copy_assign_alloc(x);
  316. this->assign(x.begin(), x.end());
  317. }
  318. return *this;
  319. }
  320. //! <b>Effects</b>: Makes *this contain the same elements as x.
  321. //!
  322. //! <b>Postcondition</b>: this->size() == x.size(). *this contains a copy
  323. //! of each of x's elements.
  324. //!
  325. //! <b>Throws</b>: If allocator_traits_type::propagate_on_container_move_assignment
  326. //! is false and (allocation throws or value_type's move constructor throws)
  327. //!
  328. //! <b>Complexity</b>: Constant if allocator_traits_type::
  329. //! propagate_on_container_move_assignment is true or
  330. //! this->get>allocator() == x.get_allocator(). Linear otherwise.
  331. slist& operator=(BOOST_RV_REF(slist) x)
  332. BOOST_NOEXCEPT_IF(allocator_traits_type::propagate_on_container_move_assignment::value
  333. || allocator_traits_type::is_always_equal::value)
  334. {
  335. if (BOOST_LIKELY(this != &x)) {
  336. //We know resources can be transferred at comiple time if both allocators are
  337. //always equal or the allocator is going to be propagated
  338. const bool can_steal_resources_alloc
  339. = allocator_traits_type::propagate_on_container_move_assignment::value
  340. || allocator_traits_type::is_always_equal::value;
  341. dtl::bool_<can_steal_resources_alloc> flag;
  342. this->priv_move_assign(boost::move(x), flag);
  343. }
  344. return *this;
  345. }
  346. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  347. //! <b>Effects</b>: Makes *this contain the same elements as in il.
  348. //!
  349. //! <b>Postcondition</b>: this->size() == il.size(). *this contains a copy
  350. //! of each of il's elements.
  351. //!
  352. //! <b>Throws</b>: If allocator_traits_type::propagate_on_container_move_assignment
  353. //! is false and (allocation throws or value_type's move constructor throws)
  354. slist& operator=(std::initializer_list<value_type> il)
  355. {
  356. assign(il.begin(), il.end());
  357. return *this;
  358. }
  359. #endif
  360. //! <b>Effects</b>: Assigns the n copies of val to *this.
  361. //!
  362. //! <b>Throws</b>: If memory allocation throws or T's copy constructor throws.
  363. //!
  364. //! <b>Complexity</b>: Linear to n.
  365. void assign(size_type n, const T& val)
  366. {
  367. typedef constant_iterator<value_type> cvalue_iterator;
  368. return this->assign(cvalue_iterator(val, n), cvalue_iterator());
  369. }
  370. //! <b>Effects</b>: Assigns the range [first, last) to *this.
  371. //!
  372. //! <b>Throws</b>: If memory allocation throws or
  373. //! T's constructor from dereferencing InpIt throws.
  374. //!
  375. //! <b>Complexity</b>: Linear to n.
  376. template <class InpIt>
  377. void assign(InpIt first, InpIt last
  378. #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  379. , typename dtl::disable_if_convertible<InpIt, size_type>::type * = 0
  380. #endif
  381. )
  382. {
  383. iterator end_n(this->end());
  384. iterator prev(this->before_begin());
  385. iterator node(this->begin());
  386. while (node != end_n && first != last){
  387. *node = *first;
  388. prev = node;
  389. ++node;
  390. ++first;
  391. }
  392. if (first != last)
  393. this->insert_after(prev, first, last);
  394. else
  395. this->erase_after(prev, end_n);
  396. }
  397. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  398. //! <b>Effects</b>: Assigns the range [il.begin(), il.end()) to *this.
  399. //!
  400. //! <b>Throws</b>: If memory allocation throws or
  401. //! T's constructor from dereferencing std::initializer_list iterator throws.
  402. //!
  403. //! <b>Complexity</b>: Linear to range [il.begin(), il.end()).
  404. void assign(std::initializer_list<value_type> il)
  405. {
  406. assign(il.begin(), il.end());
  407. }
  408. #endif
  409. //! <b>Effects</b>: Returns a copy of the internal allocator.
  410. //!
  411. //! <b>Throws</b>: If allocator's copy constructor throws.
  412. //!
  413. //! <b>Complexity</b>: Constant.
  414. BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
  415. allocator_type get_allocator() const BOOST_NOEXCEPT_OR_NOTHROW
  416. { return allocator_type(this->node_alloc()); }
  417. //! <b>Effects</b>: Returns a reference to the internal allocator.
  418. //!
  419. //! <b>Throws</b>: Nothing
  420. //!
  421. //! <b>Complexity</b>: Constant.
  422. //!
  423. //! <b>Note</b>: Non-standard extension.
  424. BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
  425. stored_allocator_type &get_stored_allocator() BOOST_NOEXCEPT_OR_NOTHROW
  426. { return this->node_alloc(); }
  427. //! <b>Effects</b>: Returns a reference to the internal allocator.
  428. //!
  429. //! <b>Throws</b>: Nothing
  430. //!
  431. //! <b>Complexity</b>: Constant.
  432. //!
  433. //! <b>Note</b>: Non-standard extension.
  434. BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
  435. const stored_allocator_type &get_stored_allocator() const BOOST_NOEXCEPT_OR_NOTHROW
  436. { return this->node_alloc(); }
  437. //////////////////////////////////////////////
  438. //
  439. // iterators
  440. //
  441. //////////////////////////////////////////////
  442. //! <b>Effects</b>: Returns a non-dereferenceable iterator that,
  443. //! when incremented, yields begin(). This iterator may be used
  444. //! as the argument to insert_after, erase_after, etc.
  445. //!
  446. //! <b>Throws</b>: Nothing.
  447. //!
  448. //! <b>Complexity</b>: Constant.
  449. BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
  450. iterator before_begin() BOOST_NOEXCEPT_OR_NOTHROW
  451. { return iterator(end()); }
  452. //! <b>Effects</b>: Returns a non-dereferenceable const_iterator
  453. //! that, when incremented, yields begin(). This iterator may be used
  454. //! as the argument to insert_after, erase_after, etc.
  455. //!
  456. //! <b>Throws</b>: Nothing.
  457. //!
  458. //! <b>Complexity</b>: Constant.
  459. BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
  460. const_iterator before_begin() const BOOST_NOEXCEPT_OR_NOTHROW
  461. { return this->cbefore_begin(); }
  462. //! <b>Effects</b>: Returns an iterator to the first element contained in the list.
  463. //!
  464. //! <b>Throws</b>: Nothing.
  465. //!
  466. //! <b>Complexity</b>: Constant.
  467. BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
  468. iterator begin() BOOST_NOEXCEPT_OR_NOTHROW
  469. { return iterator(this->icont().begin()); }
  470. //! <b>Effects</b>: Returns a const_iterator to the first element contained in the list.
  471. //!
  472. //! <b>Throws</b>: Nothing.
  473. //!
  474. //! <b>Complexity</b>: Constant.
  475. BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
  476. const_iterator begin() const BOOST_NOEXCEPT_OR_NOTHROW
  477. { return this->cbegin(); }
  478. //! <b>Effects</b>: Returns an iterator to the end of the list.
  479. //!
  480. //! <b>Throws</b>: Nothing.
  481. //!
  482. //! <b>Complexity</b>: Constant.
  483. BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
  484. iterator end() BOOST_NOEXCEPT_OR_NOTHROW
  485. { return iterator(this->icont().end()); }
  486. //! <b>Effects</b>: Returns a const_iterator to the end of the list.
  487. //!
  488. //! <b>Throws</b>: Nothing.
  489. //!
  490. //! <b>Complexity</b>: Constant.
  491. BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
  492. const_iterator end() const BOOST_NOEXCEPT_OR_NOTHROW
  493. { return this->cend(); }
  494. //! <b>Effects</b>: Returns a non-dereferenceable const_iterator
  495. //! that, when incremented, yields begin(). This iterator may be used
  496. //! as the argument to insert_after, erase_after, etc.
  497. //!
  498. //! <b>Throws</b>: Nothing.
  499. //!
  500. //! <b>Complexity</b>: Constant.
  501. BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
  502. const_iterator cbefore_begin() const BOOST_NOEXCEPT_OR_NOTHROW
  503. { return const_iterator(end()); }
  504. //! <b>Effects</b>: Returns a const_iterator to the first element contained in the list.
  505. //!
  506. //! <b>Throws</b>: Nothing.
  507. //!
  508. //! <b>Complexity</b>: Constant.
  509. BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
  510. const_iterator cbegin() const BOOST_NOEXCEPT_OR_NOTHROW
  511. { return const_iterator(this->non_const_icont().begin()); }
  512. //! <b>Effects</b>: Returns a const_iterator to the end of the list.
  513. //!
  514. //! <b>Throws</b>: Nothing.
  515. //!
  516. //! <b>Complexity</b>: Constant.
  517. BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
  518. const_iterator cend() const BOOST_NOEXCEPT_OR_NOTHROW
  519. { return const_iterator(this->non_const_icont().end()); }
  520. //! <b>Returns</b>: The iterator to the element before i in the sequence.
  521. //! Returns the end-iterator, if either i is the begin-iterator or the
  522. //! sequence is empty.
  523. //!
  524. //! <b>Throws</b>: Nothing.
  525. //!
  526. //! <b>Complexity</b>: Linear to the number of elements before i.
  527. //!
  528. //! <b>Note</b>: Non-standard extension.
  529. BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
  530. iterator previous(iterator p) BOOST_NOEXCEPT_OR_NOTHROW
  531. { return iterator(this->icont().previous(p.get())); }
  532. //! <b>Returns</b>: The const_iterator to the element before i in the sequence.
  533. //! Returns the end-const_iterator, if either i is the begin-const_iterator or
  534. //! the sequence is empty.
  535. //!
  536. //! <b>Throws</b>: Nothing.
  537. //!
  538. //! <b>Complexity</b>: Linear to the number of elements before i.
  539. //!
  540. //! <b>Note</b>: Non-standard extension.
  541. BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
  542. const_iterator previous(const_iterator p)
  543. { return const_iterator(this->icont().previous(p.get())); }
  544. //////////////////////////////////////////////
  545. //
  546. // capacity
  547. //
  548. //////////////////////////////////////////////
  549. //! <b>Effects</b>: Returns true if the list contains no elements.
  550. //!
  551. //! <b>Throws</b>: Nothing.
  552. //!
  553. //! <b>Complexity</b>: Constant.
  554. BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
  555. bool empty() const
  556. { return !this->size(); }
  557. //! <b>Effects</b>: Returns the number of the elements contained in the list.
  558. //!
  559. //! <b>Throws</b>: Nothing.
  560. //!
  561. //! <b>Complexity</b>: Constant.
  562. BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
  563. size_type size() const
  564. { return this->icont().size(); }
  565. //! <b>Effects</b>: Returns the largest possible size of the list.
  566. //!
  567. //! <b>Throws</b>: Nothing.
  568. //!
  569. //! <b>Complexity</b>: Constant.
  570. BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
  571. size_type max_size() const
  572. { return AllocHolder::max_size(); }
  573. //! <b>Effects</b>: Inserts or erases elements at the end such that
  574. //! the size becomes n. New elements are value initialized.
  575. //!
  576. //! <b>Throws</b>: If memory allocation throws, or T's copy constructor throws.
  577. //!
  578. //! <b>Complexity</b>: Linear to the difference between size() and new_size.
  579. void resize(size_type new_size)
  580. {
  581. const_iterator last_pos;
  582. if(!priv_try_shrink(new_size, last_pos)){
  583. typedef value_init_construct_iterator<value_type> value_init_iterator;
  584. this->insert_after(last_pos, value_init_iterator(new_size - this->size()), value_init_iterator());
  585. }
  586. }
  587. //! <b>Effects</b>: Inserts or erases elements at the end such that
  588. //! the size becomes n. New elements are copy constructed from x.
  589. //!
  590. //! <b>Throws</b>: If memory allocation throws, or T's copy constructor throws.
  591. //!
  592. //! <b>Complexity</b>: Linear to the difference between size() and new_size.
  593. void resize(size_type new_size, const T& x)
  594. {
  595. const_iterator last_pos;
  596. if(!priv_try_shrink(new_size, last_pos)){
  597. this->insert_after(last_pos, new_size, x);
  598. }
  599. }
  600. //////////////////////////////////////////////
  601. //
  602. // element access
  603. //
  604. //////////////////////////////////////////////
  605. //! <b>Requires</b>: !empty()
  606. //!
  607. //! <b>Effects</b>: Returns a reference to the first element
  608. //! from the beginning of the container.
  609. //!
  610. //! <b>Throws</b>: Nothing.
  611. //!
  612. //! <b>Complexity</b>: Constant.
  613. BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
  614. reference front()
  615. {
  616. BOOST_ASSERT(!this->empty());
  617. return *this->begin();
  618. }
  619. //! <b>Requires</b>: !empty()
  620. //!
  621. //! <b>Effects</b>: Returns a const reference to the first element
  622. //! from the beginning of the container.
  623. //!
  624. //! <b>Throws</b>: Nothing.
  625. //!
  626. //! <b>Complexity</b>: Constant.
  627. BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
  628. const_reference front() const
  629. {
  630. BOOST_ASSERT(!this->empty());
  631. return *this->begin();
  632. }
  633. //////////////////////////////////////////////
  634. //
  635. // modifiers
  636. //
  637. //////////////////////////////////////////////
  638. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  639. //! <b>Effects</b>: Inserts an object of type T constructed with
  640. //! std::forward<Args>(args)... in the front of the list
  641. //!
  642. //! <b>Returns</b>: A reference to the created object.
  643. //!
  644. //! <b>Throws</b>: If memory allocation throws or
  645. //! T's copy constructor throws.
  646. //!
  647. //! <b>Complexity</b>: Amortized constant time.
  648. template <class... Args>
  649. reference emplace_front(BOOST_FWD_REF(Args)... args)
  650. { return *this->emplace_after(this->cbefore_begin(), boost::forward<Args>(args)...); }
  651. //! <b>Effects</b>: Inserts an object of type T constructed with
  652. //! std::forward<Args>(args)... after prev
  653. //!
  654. //! <b>Throws</b>: If memory allocation throws or
  655. //! T's in-place constructor throws.
  656. //!
  657. //! <b>Complexity</b>: Constant
  658. template <class... Args>
  659. iterator emplace_after(const_iterator prev, BOOST_FWD_REF(Args)... args)
  660. {
  661. NodePtr pnode(AllocHolder::create_node(boost::forward<Args>(args)...));
  662. return iterator(this->icont().insert_after(prev.get(), *pnode));
  663. }
  664. #else // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  665. #define BOOST_CONTAINER_SLIST_EMPLACE_CODE(N) \
  666. BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
  667. reference emplace_front(BOOST_MOVE_UREF##N)\
  668. { return *this->emplace_after(this->cbefore_begin() BOOST_MOVE_I##N BOOST_MOVE_FWD##N);}\
  669. \
  670. BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
  671. iterator emplace_after(const_iterator p BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
  672. {\
  673. NodePtr pnode (AllocHolder::create_node(BOOST_MOVE_FWD##N));\
  674. return iterator(this->icont().insert_after(p.get(), *pnode));\
  675. }\
  676. //
  677. BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_SLIST_EMPLACE_CODE)
  678. #undef BOOST_CONTAINER_SLIST_EMPLACE_CODE
  679. #endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  680. #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  681. //! <b>Effects</b>: Inserts a copy of x at the beginning of the list.
  682. //!
  683. //! <b>Throws</b>: If memory allocation throws or
  684. //! T's copy constructor throws.
  685. //!
  686. //! <b>Complexity</b>: Amortized constant time.
  687. void push_front(const T &x);
  688. //! <b>Effects</b>: Constructs a new element in the beginning of the list
  689. //! and moves the resources of x to this new element.
  690. //!
  691. //! <b>Throws</b>: If memory allocation throws.
  692. //!
  693. //! <b>Complexity</b>: Amortized constant time.
  694. void push_front(T &&x);
  695. #else
  696. BOOST_MOVE_CONVERSION_AWARE_CATCH(push_front, T, void, priv_push_front)
  697. #endif
  698. #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  699. //! <b>Requires</b>: p must be a valid iterator of *this.
  700. //!
  701. //! <b>Effects</b>: Inserts a copy of the value after prev_p.
  702. //!
  703. //! <b>Returns</b>: An iterator to the inserted element.
  704. //!
  705. //! <b>Throws</b>: If memory allocation throws or T's copy constructor throws.
  706. //!
  707. //! <b>Complexity</b>: Amortized constant time.
  708. //!
  709. //! <b>Note</b>: Does not affect the validity of iterators and references of
  710. //! previous values.
  711. iterator insert_after(const_iterator prev_p, const T &x);
  712. //! <b>Requires</b>: prev_p must be a valid iterator of *this.
  713. //!
  714. //! <b>Effects</b>: Inserts a move constructed copy object from the value after the
  715. //! element pointed by prev_p.
  716. //!
  717. //! <b>Returns</b>: An iterator to the inserted element.
  718. //!
  719. //! <b>Throws</b>: If memory allocation throws.
  720. //!
  721. //! <b>Complexity</b>: Amortized constant time.
  722. //!
  723. //! <b>Note</b>: Does not affect the validity of iterators and references of
  724. //! previous values.
  725. iterator insert_after(const_iterator prev_p, T &&x);
  726. #else
  727. BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(insert_after, T, iterator, priv_insert_after, const_iterator, const_iterator)
  728. #endif
  729. //! <b>Requires</b>: prev_p must be a valid iterator of *this.
  730. //!
  731. //! <b>Effects</b>: Inserts n copies of x after prev_p.
  732. //!
  733. //! <b>Returns</b>: an iterator to the last inserted element or prev_p if n is 0.
  734. //!
  735. //! <b>Throws</b>: If memory allocation throws or T's copy constructor throws.
  736. //!
  737. //!
  738. //! <b>Complexity</b>: Linear to n.
  739. //!
  740. //! <b>Note</b>: Does not affect the validity of iterators and references of
  741. //! previous values.
  742. iterator insert_after(const_iterator prev_p, size_type n, const value_type& x)
  743. {
  744. typedef constant_iterator<value_type> cvalue_iterator;
  745. return this->insert_after(prev_p, cvalue_iterator(x, n), cvalue_iterator());
  746. }
  747. //! <b>Requires</b>: prev_p must be a valid iterator of *this.
  748. //!
  749. //! <b>Effects</b>: Inserts the range pointed by [first, last) after prev_p.
  750. //!
  751. //! <b>Returns</b>: an iterator to the last inserted element or prev_p if first == last.
  752. //!
  753. //! <b>Throws</b>: If memory allocation throws, T's constructor from a
  754. //! dereferenced InpIt throws.
  755. //!
  756. //! <b>Complexity</b>: Linear to the number of elements inserted.
  757. //!
  758. //! <b>Note</b>: Does not affect the validity of iterators and references of
  759. //! previous values.
  760. template <class InpIt>
  761. iterator insert_after(const_iterator prev_p, InpIt first, InpIt last
  762. #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  763. , typename dtl::enable_if_c
  764. < !dtl::is_convertible<InpIt, size_type>::value
  765. && (dtl::is_input_iterator<InpIt>::value
  766. || dtl::is_same<alloc_version, version_1>::value
  767. )
  768. >::type * = 0
  769. #endif
  770. )
  771. {
  772. iterator ret_it(prev_p.get());
  773. for (; first != last; ++first){
  774. ret_it = iterator(this->icont().insert_after(ret_it.get(), *this->create_node_from_it(first)));
  775. }
  776. return ret_it;
  777. }
  778. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  779. //! <b>Requires</b>: prev_p must be a valid iterator of *this.
  780. //!
  781. //! <b>Effects</b>: Inserts the range pointed by [il.begin(), il.end()) after prev_p.
  782. //!
  783. //! <b>Returns</b>: an iterator to the last inserted element or prev_p if il.begin() == il.end().
  784. //!
  785. //! <b>Throws</b>: If memory allocation throws, T's constructor from a
  786. //! dereferenced std::initializer_list iterator throws.
  787. //!
  788. //! <b>Complexity</b>: Linear to the number of elements inserted.
  789. //!
  790. //! <b>Note</b>: Does not affect the validity of iterators and references of
  791. //! previous values.
  792. iterator insert_after(const_iterator prev_p, std::initializer_list<value_type> il)
  793. {
  794. return insert_after(prev_p, il.begin(), il.end());
  795. }
  796. #endif
  797. #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  798. template <class FwdIt>
  799. iterator insert_after(const_iterator prev, FwdIt first, FwdIt last
  800. , typename dtl::enable_if_c
  801. < !dtl::is_convertible<FwdIt, size_type>::value
  802. && !(dtl::is_input_iterator<FwdIt>::value
  803. || dtl::is_same<alloc_version, version_1>::value
  804. )
  805. >::type * = 0
  806. )
  807. {
  808. //Optimized allocation and construction
  809. insertion_functor func(this->icont(), prev.get());
  810. this->allocate_many_and_construct(first, boost::container::iterator_udistance(first, last), func);
  811. return iterator(func.inserted_first());
  812. }
  813. #endif
  814. //! <b>Effects</b>: Removes the first element from the list.
  815. //!
  816. //! <b>Throws</b>: Nothing.
  817. //!
  818. //! <b>Complexity</b>: Amortized constant time.
  819. void pop_front()
  820. {
  821. BOOST_ASSERT(!this->empty());
  822. this->icont().pop_front_and_dispose(Destroyer(this->node_alloc()));
  823. }
  824. //! <b>Effects</b>: Erases the element after the element pointed by prev_p
  825. //! of the list.
  826. //!
  827. //! <b>Returns</b>: the first element remaining beyond the removed elements,
  828. //! or end() if no such element exists.
  829. //!
  830. //! <b>Throws</b>: Nothing.
  831. //!
  832. //! <b>Complexity</b>: Constant.
  833. //!
  834. //! <b>Note</b>: Does not invalidate iterators or references to non erased elements.
  835. iterator erase_after(const_iterator prev_p)
  836. {
  837. return iterator(this->icont().erase_after_and_dispose(prev_p.get(), Destroyer(this->node_alloc())));
  838. }
  839. //! <b>Effects</b>: Erases the range (before_first, last) from
  840. //! the list.
  841. //!
  842. //! <b>Returns</b>: the first element remaining beyond the removed elements,
  843. //! or end() if no such element exists.
  844. //!
  845. //! <b>Throws</b>: Nothing.
  846. //!
  847. //! <b>Complexity</b>: Linear to the number of erased elements.
  848. //!
  849. //! <b>Note</b>: Does not invalidate iterators or references to non erased elements.
  850. iterator erase_after(const_iterator before_first, const_iterator last)
  851. {
  852. return iterator(this->icont().erase_after_and_dispose(before_first.get(), last.get(), Destroyer(this->node_alloc())));
  853. }
  854. //! <b>Effects</b>: Swaps the contents of *this and x.
  855. //!
  856. //! <b>Throws</b>: Nothing.
  857. //!
  858. //! <b>Complexity</b>: Linear to the number of elements on *this and x.
  859. void swap(slist& x)
  860. BOOST_NOEXCEPT_IF( allocator_traits_type::propagate_on_container_swap::value
  861. || allocator_traits_type::is_always_equal::value)
  862. {
  863. BOOST_ASSERT(allocator_traits_type::propagate_on_container_swap::value ||
  864. allocator_traits_type::is_always_equal::value ||
  865. this->get_stored_allocator() == x.get_stored_allocator());
  866. AllocHolder::swap(x);
  867. }
  868. //! <b>Effects</b>: Erases all the elements of the list.
  869. //!
  870. //! <b>Throws</b>: Nothing.
  871. //!
  872. //! <b>Complexity</b>: Linear to the number of elements in the list.
  873. void clear()
  874. { this->icont().clear_and_dispose(Destroyer(this->node_alloc())); }
  875. //////////////////////////////////////////////
  876. //
  877. // slist operations
  878. //
  879. //////////////////////////////////////////////
  880. //! <b>Requires</b>: p must point to an element contained
  881. //! by the list. x != *this
  882. //!
  883. //! <b>Effects</b>: Transfers all the elements of list x to this list, after the
  884. //! the element pointed by p. No destructors or copy constructors are called.
  885. //!
  886. //! <b>Throws</b>: runtime_error if this' allocator and x's allocator
  887. //! are not equal.
  888. //!
  889. //! <b>Complexity</b>: Linear to the elements in x.
  890. //!
  891. //! <b>Note</b>: Iterators of values obtained from list x now point to elements of
  892. //! this list. Iterators of this list and all the references are not invalidated.
  893. void splice_after(const_iterator prev_p, slist& x) BOOST_NOEXCEPT_OR_NOTHROW
  894. {
  895. BOOST_ASSERT(this != &x);
  896. BOOST_ASSERT(this->node_alloc() == x.node_alloc());
  897. this->icont().splice_after(prev_p.get(), x.icont());
  898. }
  899. //! <b>Requires</b>: p must point to an element contained
  900. //! by the list. x != *this
  901. //!
  902. //! <b>Effects</b>: Transfers all the elements of list x to this list, after the
  903. //! the element pointed by p. No destructors or copy constructors are called.
  904. //!
  905. //! <b>Throws</b>: runtime_error if this' allocator and x's allocator
  906. //! are not equal.
  907. //!
  908. //! <b>Complexity</b>: Linear to the elements in x.
  909. //!
  910. //! <b>Note</b>: Iterators of values obtained from list x now point to elements of
  911. //! this list. Iterators of this list and all the references are not invalidated.
  912. void splice_after(const_iterator prev_p, BOOST_RV_REF(slist) x) BOOST_NOEXCEPT_OR_NOTHROW
  913. { this->splice_after(prev_p, BOOST_MOVE_TO_LV(x)); }
  914. //! <b>Requires</b>: prev_p must be a valid iterator of this.
  915. //! i must point to an element contained in list x.
  916. //! this' allocator and x's allocator shall compare equal.
  917. //!
  918. //! <b>Effects</b>: Transfers the value pointed by i, from list x to this list,
  919. //! after the element pointed by prev_p.
  920. //! If prev_p == prev or prev_p == ++prev, this function is a null operation.
  921. //!
  922. //! <b>Throws</b>: Nothing
  923. //!
  924. //! <b>Complexity</b>: Constant.
  925. //!
  926. //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
  927. //! list. Iterators of this list and all the references are not invalidated.
  928. void splice_after(const_iterator prev_p, slist& x, const_iterator prev) BOOST_NOEXCEPT_OR_NOTHROW
  929. {
  930. BOOST_ASSERT(this->node_alloc() == x.node_alloc());
  931. this->icont().splice_after(prev_p.get(), x.icont(), prev.get());
  932. }
  933. //! <b>Requires</b>: prev_p must be a valid iterator of this.
  934. //! i must point to an element contained in list x.
  935. //! this' allocator and x's allocator shall compare equal.
  936. //!
  937. //! <b>Effects</b>: Transfers the value pointed by i, from list x to this list,
  938. //! after the element pointed by prev_p.
  939. //! If prev_p == prev or prev_p == ++prev, this function is a null operation.
  940. //!
  941. //! <b>Throws</b>: Nothing
  942. //!
  943. //! <b>Complexity</b>: Constant.
  944. //!
  945. //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
  946. //! list. Iterators of this list and all the references are not invalidated.
  947. void splice_after(const_iterator prev_p, BOOST_RV_REF(slist) x, const_iterator prev) BOOST_NOEXCEPT_OR_NOTHROW
  948. { this->splice_after(prev_p, BOOST_MOVE_TO_LV(x), prev); }
  949. //! <b>Requires</b>: prev_p must be a valid iterator of this.
  950. //! before_first and before_last must be valid iterators of x.
  951. //! prev_p must not be contained in [before_first, before_last) range.
  952. //! this' allocator and x's allocator shall compare equal.
  953. //!
  954. //! <b>Effects</b>: Transfers the range [before_first + 1, before_last + 1)
  955. //! from list x to this list, after the element pointed by prev_p.
  956. //!
  957. //! <b>Throws</b>: Nothing
  958. //!
  959. //! <b>Complexity</b>: Linear to the number of transferred elements.
  960. //!
  961. //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
  962. //! list. Iterators of this list and all the references are not invalidated.
  963. void splice_after(const_iterator prev_p, slist& x,
  964. const_iterator before_first, const_iterator before_last) BOOST_NOEXCEPT_OR_NOTHROW
  965. {
  966. BOOST_ASSERT(this->node_alloc() == x.node_alloc());
  967. this->icont().splice_after
  968. (prev_p.get(), x.icont(), before_first.get(), before_last.get());
  969. }
  970. //! <b>Requires</b>: prev_p must be a valid iterator of this.
  971. //! before_first and before_last must be valid iterators of x.
  972. //! prev_p must not be contained in [before_first, before_last) range.
  973. //! this' allocator and x's allocator shall compare equal.
  974. //!
  975. //! <b>Effects</b>: Transfers the range [before_first + 1, before_last + 1)
  976. //! from list x to this list, after the element pointed by prev_p.
  977. //!
  978. //! <b>Throws</b>: Nothing
  979. //!
  980. //! <b>Complexity</b>: Linear to the number of transferred elements.
  981. //!
  982. //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
  983. //! list. Iterators of this list and all the references are not invalidated.
  984. void splice_after(const_iterator prev_p, BOOST_RV_REF(slist) x,
  985. const_iterator before_first, const_iterator before_last) BOOST_NOEXCEPT_OR_NOTHROW
  986. { this->splice_after(prev_p, BOOST_MOVE_TO_LV(x), before_first, before_last); }
  987. //! <b>Requires</b>: prev_p must be a valid iterator of this.
  988. //! before_first and before_last must be valid iterators of x.
  989. //! prev_p must not be contained in [before_first, before_last) range.
  990. //! n == distance(before_first, before_last).
  991. //! this' allocator and x's allocator shall compare equal.
  992. //!
  993. //! <b>Effects</b>: Transfers the range [before_first + 1, before_last + 1)
  994. //! from list x to this list, after the element pointed by prev_p.
  995. //!
  996. //! <b>Throws</b>: Nothing
  997. //!
  998. //! <b>Complexity</b>: Constant.
  999. //!
  1000. //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
  1001. //! list. Iterators of this list and all the references are not invalidated.
  1002. void splice_after(const_iterator prev_p, slist& x,
  1003. const_iterator before_first, const_iterator before_last,
  1004. size_type n) BOOST_NOEXCEPT_OR_NOTHROW
  1005. {
  1006. BOOST_ASSERT(this->node_alloc() == x.node_alloc());
  1007. this->icont().splice_after
  1008. (prev_p.get(), x.icont(), before_first.get(), before_last.get(), n);
  1009. }
  1010. //! <b>Requires</b>: prev_p must be a valid iterator of this.
  1011. //! before_first and before_last must be valid iterators of x.
  1012. //! prev_p must not be contained in [before_first, before_last) range.
  1013. //! n == distance(before_first, before_last).
  1014. //! this' allocator and x's allocator shall compare equal.
  1015. //!
  1016. //! <b>Effects</b>: Transfers the range [before_first + 1, before_last + 1)
  1017. //! from list x to this list, after the element pointed by prev_p.
  1018. //!
  1019. //! <b>Throws</b>: Nothing
  1020. //!
  1021. //! <b>Complexity</b>: Constant.
  1022. //!
  1023. //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
  1024. //! list. Iterators of this list and all the references are not invalidated.
  1025. void splice_after(const_iterator prev_p, BOOST_RV_REF(slist) x,
  1026. const_iterator before_first, const_iterator before_last,
  1027. size_type n) BOOST_NOEXCEPT_OR_NOTHROW
  1028. { this->splice_after(prev_p, BOOST_MOVE_TO_LV(x), before_first, before_last, n); }
  1029. //! <b>Effects</b>: Removes all the elements that compare equal to value.
  1030. //!
  1031. //! <b>Throws</b>: Nothing.
  1032. //!
  1033. //! <b>Complexity</b>: Linear time. It performs exactly size() comparisons for equality.
  1034. //!
  1035. //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
  1036. //! and iterators to elements that are not removed remain valid.
  1037. void remove(const T& value)
  1038. { this->remove_if(equal_to_value_type(value)); }
  1039. //! <b>Effects</b>: Removes all the elements for which a specified
  1040. //! predicate is satisfied.
  1041. //!
  1042. //! <b>Throws</b>: If pred throws.
  1043. //!
  1044. //! <b>Complexity</b>: Linear time. It performs exactly size() calls to the predicate.
  1045. //!
  1046. //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
  1047. //! and iterators to elements that are not removed remain valid.
  1048. template <class Pred>
  1049. void remove_if(Pred pred)
  1050. {
  1051. typedef value_to_node_compare<Node, Pred> value_to_node_compare_type;
  1052. this->icont().remove_and_dispose_if(value_to_node_compare_type(pred), Destroyer(this->node_alloc()));
  1053. }
  1054. //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
  1055. //! elements that are equal from the list.
  1056. //!
  1057. //! <b>Throws</b>: If comparison throws.
  1058. //!
  1059. //! <b>Complexity</b>: Linear time (size()-1 comparisons equality comparisons).
  1060. //!
  1061. //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
  1062. //! and iterators to elements that are not removed remain valid.
  1063. void unique()
  1064. { this->unique(value_equal_t()); }
  1065. //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
  1066. //! elements that satisfy some binary predicate from the list.
  1067. //!
  1068. //! <b>Throws</b>: If pred throws.
  1069. //!
  1070. //! <b>Complexity</b>: Linear time (size()-1 comparisons calls to pred()).
  1071. //!
  1072. //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
  1073. //! and iterators to elements that are not removed remain valid.
  1074. template <class Pred>
  1075. void unique(Pred pred)
  1076. {
  1077. typedef value_to_node_compare<Node, Pred> value_to_node_compare_type;
  1078. this->icont().unique_and_dispose(value_to_node_compare_type(pred), Destroyer(this->node_alloc()));
  1079. }
  1080. //! <b>Requires</b>: The lists x and *this must be distinct.
  1081. //!
  1082. //! <b>Effects</b>: This function removes all of x's elements and inserts them
  1083. //! in order into *this according to std::less<value_type>. The merge is stable;
  1084. //! that is, if an element from *this is equivalent to one from x, then the element
  1085. //! from *this will precede the one from x.
  1086. //!
  1087. //! <b>Throws</b>: If comparison throws.
  1088. //!
  1089. //! <b>Complexity</b>: This function is linear time: it performs at most
  1090. //! size() + x.size() - 1 comparisons.
  1091. void merge(slist & x)
  1092. { this->merge(x, value_less_t()); }
  1093. //! <b>Requires</b>: The lists x and *this must be distinct.
  1094. //!
  1095. //! <b>Effects</b>: This function removes all of x's elements and inserts them
  1096. //! in order into *this according to std::less<value_type>. The merge is stable;
  1097. //! that is, if an element from *this is equivalent to one from x, then the element
  1098. //! from *this will precede the one from x.
  1099. //!
  1100. //! <b>Throws</b>: If comparison throws.
  1101. //!
  1102. //! <b>Complexity</b>: This function is linear time: it performs at most
  1103. //! size() + x.size() - 1 comparisons.
  1104. void merge(BOOST_RV_REF(slist) x)
  1105. { this->merge(BOOST_MOVE_TO_LV(x)); }
  1106. //! <b>Requires</b>: p must be a comparison function that induces a strict weak
  1107. //! ordering and both *this and x must be sorted according to that ordering
  1108. //! The lists x and *this must be distinct.
  1109. //!
  1110. //! <b>Effects</b>: This function removes all of x's elements and inserts them
  1111. //! in order into *this. The merge is stable; that is, if an element from *this is
  1112. //! equivalent to one from x, then the element from *this will precede the one from x.
  1113. //!
  1114. //! <b>Throws</b>: If comp throws.
  1115. //!
  1116. //! <b>Complexity</b>: This function is linear time: it performs at most
  1117. //! size() + x.size() - 1 comparisons.
  1118. //!
  1119. //! <b>Note</b>: Iterators and references to *this are not invalidated.
  1120. template <class StrictWeakOrdering>
  1121. void merge(slist& x, StrictWeakOrdering comp)
  1122. {
  1123. typedef value_to_node_compare<Node, StrictWeakOrdering> value_to_node_compare_type;
  1124. BOOST_ASSERT(this->node_alloc() == x.node_alloc());
  1125. this->icont().merge(x.icont(), value_to_node_compare_type(comp));
  1126. }
  1127. //! <b>Requires</b>: p must be a comparison function that induces a strict weak
  1128. //! ordering and both *this and x must be sorted according to that ordering
  1129. //! The lists x and *this must be distinct.
  1130. //!
  1131. //! <b>Effects</b>: This function removes all of x's elements and inserts them
  1132. //! in order into *this. The merge is stable; that is, if an element from *this is
  1133. //! equivalent to one from x, then the element from *this will precede the one from x.
  1134. //!
  1135. //! <b>Throws</b>: If comp throws.
  1136. //!
  1137. //! <b>Complexity</b>: This function is linear time: it performs at most
  1138. //! size() + x.size() - 1 comparisons.
  1139. //!
  1140. //! <b>Note</b>: Iterators and references to *this are not invalidated.
  1141. template <class StrictWeakOrdering>
  1142. void merge(BOOST_RV_REF(slist) x, StrictWeakOrdering comp)
  1143. { this->merge(BOOST_MOVE_TO_LV(x), comp); }
  1144. //! <b>Effects</b>: This function sorts the list *this according to std::less<value_type>.
  1145. //! The sort is stable, that is, the relative order of equivalent elements is preserved.
  1146. //!
  1147. //! <b>Throws</b>: If comparison throws.
  1148. //!
  1149. //! <b>Notes</b>: Iterators and references are not invalidated.
  1150. //!
  1151. //! <b>Complexity</b>: The number of comparisons is approximately N log N, where N
  1152. //! is the list's size.
  1153. void sort()
  1154. { this->sort(value_less_t()); }
  1155. //! <b>Effects</b>: This function sorts the list *this according to std::less<value_type>.
  1156. //! The sort is stable, that is, the relative order of equivalent elements is preserved.
  1157. //!
  1158. //! <b>Throws</b>: If comp throws.
  1159. //!
  1160. //! <b>Notes</b>: Iterators and references are not invalidated.
  1161. //!
  1162. //! <b>Complexity</b>: The number of comparisons is approximately N log N, where N
  1163. //! is the list's size.
  1164. template <class StrictWeakOrdering>
  1165. void sort(StrictWeakOrdering comp)
  1166. {
  1167. typedef value_to_node_compare<Node, StrictWeakOrdering> value_to_node_compare_type;
  1168. // nothing if the slist has length 0 or 1.
  1169. if (this->size() < 2)
  1170. return;
  1171. this->icont().sort(value_to_node_compare_type(comp));
  1172. }
  1173. //! <b>Effects</b>: Reverses the order of elements in the list.
  1174. //!
  1175. //! <b>Throws</b>: Nothing.
  1176. //!
  1177. //! <b>Complexity</b>: This function is linear time.
  1178. //!
  1179. //! <b>Note</b>: Iterators and references are not invalidated
  1180. void reverse() BOOST_NOEXCEPT_OR_NOTHROW
  1181. { this->icont().reverse(); }
  1182. //////////////////////////////////////////////
  1183. //
  1184. // list compatibility interface
  1185. //
  1186. //////////////////////////////////////////////
  1187. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  1188. //! <b>Effects</b>: Inserts an object of type T constructed with
  1189. //! std::forward<Args>(args)... before p
  1190. //!
  1191. //! <b>Throws</b>: If memory allocation throws or
  1192. //! T's in-place constructor throws.
  1193. //!
  1194. //! <b>Complexity</b>: Linear to the elements before p
  1195. template <class... Args>
  1196. iterator emplace(const_iterator p, BOOST_FWD_REF(Args)... args)
  1197. { return this->emplace_after(this->previous(p), boost::forward<Args>(args)...); }
  1198. #else
  1199. #define BOOST_CONTAINER_SLIST_EMPLACE_CODE(N) \
  1200. BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
  1201. iterator emplace(const_iterator p BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
  1202. {\
  1203. return this->emplace_after(this->previous(p) BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
  1204. }\
  1205. //
  1206. BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_SLIST_EMPLACE_CODE)
  1207. #undef BOOST_CONTAINER_SLIST_EMPLACE_CODE
  1208. #endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  1209. #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  1210. //! <b>Requires</b>: p must be a valid iterator of *this.
  1211. //!
  1212. //! <b>Effects</b>: Insert a copy of x before p.
  1213. //!
  1214. //! <b>Returns</b>: an iterator to the inserted element.
  1215. //!
  1216. //! <b>Throws</b>: If memory allocation throws or x's copy constructor throws.
  1217. //!
  1218. //! <b>Complexity</b>: Linear to the elements before p.
  1219. iterator insert(const_iterator p, const T &x);
  1220. //! <b>Requires</b>: p must be a valid iterator of *this.
  1221. //!
  1222. //! <b>Effects</b>: Insert a new element before p with x's resources.
  1223. //!
  1224. //! <b>Returns</b>: an iterator to the inserted element.
  1225. //!
  1226. //! <b>Throws</b>: If memory allocation throws.
  1227. //!
  1228. //! <b>Complexity</b>: Linear to the elements before p.
  1229. iterator insert(const_iterator prev_p, T &&x);
  1230. #else
  1231. BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(insert, T, iterator, priv_insert, const_iterator, const_iterator)
  1232. #endif
  1233. //! <b>Requires</b>: p must be a valid iterator of *this.
  1234. //!
  1235. //! <b>Effects</b>: Inserts n copies of x before p.
  1236. //!
  1237. //! <b>Returns</b>: an iterator to the first inserted element or p if n == 0.
  1238. //!
  1239. //! <b>Throws</b>: If memory allocation throws or T's copy constructor throws.
  1240. //!
  1241. //! <b>Complexity</b>: Linear to n plus linear to the elements before p.
  1242. iterator insert(const_iterator p, size_type n, const value_type& x)
  1243. {
  1244. const_iterator prev(this->previous(p));
  1245. this->insert_after(prev, n, x);
  1246. return ++iterator(prev.get());
  1247. }
  1248. //! <b>Requires</b>: p must be a valid iterator of *this.
  1249. //!
  1250. //! <b>Effects</b>: Insert a copy of the [first, last) range before p.
  1251. //!
  1252. //! <b>Returns</b>: an iterator to the first inserted element or p if first == last.
  1253. //!
  1254. //! <b>Throws</b>: If memory allocation throws, T's constructor from a
  1255. //! dereferenced InpIt throws.
  1256. //!
  1257. //! <b>Complexity</b>: Linear to distance [first, last) plus
  1258. //! linear to the elements before p.
  1259. template <class InIter>
  1260. iterator insert(const_iterator p, InIter first, InIter last)
  1261. {
  1262. const_iterator prev(this->previous(p));
  1263. this->insert_after(prev, first, last);
  1264. return ++iterator(prev.get());
  1265. }
  1266. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  1267. //! <b>Requires</b>: p must be a valid iterator of *this.
  1268. //!
  1269. //! <b>Effects</b>: Insert a copy of the [il.begin(), il.end()) range before p.
  1270. //!
  1271. //! <b>Returns</b>: an iterator to the first inserted element or p if il.begin() == il.end().
  1272. //!
  1273. //! <b>Throws</b>: If memory allocation throws, T's constructor from a
  1274. //! dereferenced std::initializer_list iterator throws.
  1275. //!
  1276. //! <b>Complexity</b>: Linear to the range [il.begin(), il.end()) plus
  1277. //! linear to the elements before p.
  1278. iterator insert(const_iterator p, std::initializer_list<value_type> il)
  1279. {
  1280. return insert(p, il.begin(), il.end());
  1281. }
  1282. #endif
  1283. //! <b>Requires</b>: p must be a valid iterator of *this.
  1284. //!
  1285. //! <b>Effects</b>: Erases the element at p.
  1286. //!
  1287. //! <b>Throws</b>: Nothing.
  1288. //!
  1289. //! <b>Complexity</b>: Linear to the number of elements before p.
  1290. iterator erase(const_iterator p) BOOST_NOEXCEPT_OR_NOTHROW
  1291. { return iterator(this->erase_after(previous(p))); }
  1292. //! <b>Requires</b>: first and last must be valid iterator to elements in *this.
  1293. //!
  1294. //! <b>Effects</b>: Erases the elements pointed by [first, last).
  1295. //!
  1296. //! <b>Throws</b>: Nothing.
  1297. //!
  1298. //! <b>Complexity</b>: Linear to the distance between first and last plus
  1299. //! linear to the elements before first.
  1300. iterator erase(const_iterator first, const_iterator last) BOOST_NOEXCEPT_OR_NOTHROW
  1301. { return iterator(this->erase_after(previous(first), last)); }
  1302. //! <b>Requires</b>: p must point to an element contained
  1303. //! by the list. x != *this. this' allocator and x's allocator shall compare equal
  1304. //!
  1305. //! <b>Effects</b>: Transfers all the elements of list x to this list, before the
  1306. //! the element pointed by p. No destructors or copy constructors are called.
  1307. //!
  1308. //! <b>Throws</b>: Nothing
  1309. //!
  1310. //! <b>Complexity</b>: Linear in distance(begin(), p), and linear in x.size().
  1311. //!
  1312. //! <b>Note</b>: Iterators of values obtained from list x now point to elements of
  1313. //! this list. Iterators of this list and all the references are not invalidated.
  1314. void splice(const_iterator p, slist& x) BOOST_NOEXCEPT_OR_NOTHROW
  1315. { this->splice_after(this->previous(p), x); }
  1316. //! <b>Requires</b>: p must point to an element contained
  1317. //! by the list. x != *this. this' allocator and x's allocator shall compare equal
  1318. //!
  1319. //! <b>Effects</b>: Transfers all the elements of list x to this list, before the
  1320. //! the element pointed by p. No destructors or copy constructors are called.
  1321. //!
  1322. //! <b>Throws</b>: Nothing
  1323. //!
  1324. //! <b>Complexity</b>: Linear in distance(begin(), p), and linear in x.size().
  1325. //!
  1326. //! <b>Note</b>: Iterators of values obtained from list x now point to elements of
  1327. //! this list. Iterators of this list and all the references are not invalidated.
  1328. void splice(const_iterator p, BOOST_RV_REF(slist) x) BOOST_NOEXCEPT_OR_NOTHROW
  1329. { this->splice(p, BOOST_MOVE_TO_LV(x)); }
  1330. //! <b>Requires</b>: p must point to an element contained
  1331. //! by this list. i must point to an element contained in list x.
  1332. //! this' allocator and x's allocator shall compare equal
  1333. //!
  1334. //! <b>Effects</b>: Transfers the value pointed by i, from list x to this list,
  1335. //! before the element pointed by p. No destructors or copy constructors are called.
  1336. //! If p == i or p == ++i, this function is a null operation.
  1337. //!
  1338. //! <b>Throws</b>: Nothing
  1339. //!
  1340. //! <b>Complexity</b>: Linear in distance(begin(), p), and in distance(x.begin(), i).
  1341. //!
  1342. //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
  1343. //! list. Iterators of this list and all the references are not invalidated.
  1344. void splice(const_iterator p, slist& x, const_iterator i) BOOST_NOEXCEPT_OR_NOTHROW
  1345. { this->splice_after(this->previous(p), x, x.previous(i)); }
  1346. //! <b>Requires</b>: p must point to an element contained
  1347. //! by this list. i must point to an element contained in list x.
  1348. //! this' allocator and x's allocator shall compare equal.
  1349. //!
  1350. //! <b>Effects</b>: Transfers the value pointed by i, from list x to this list,
  1351. //! before the element pointed by p. No destructors or copy constructors are called.
  1352. //! If p == i or p == ++i, this function is a null operation.
  1353. //!
  1354. //! <b>Throws</b>: Nothing
  1355. //!
  1356. //! <b>Complexity</b>: Linear in distance(begin(), p), and in distance(x.begin(), i).
  1357. //!
  1358. //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
  1359. //! list. Iterators of this list and all the references are not invalidated.
  1360. void splice(const_iterator p, BOOST_RV_REF(slist) x, const_iterator i) BOOST_NOEXCEPT_OR_NOTHROW
  1361. { this->splice(p, BOOST_MOVE_TO_LV(x), i); }
  1362. //! <b>Requires</b>: p must point to an element contained
  1363. //! by this list. first and last must point to elements contained in list x.
  1364. //!
  1365. //! <b>Effects</b>: Transfers the range pointed by first and last from list x to this list,
  1366. //! before the element pointed by p. No destructors or copy constructors are called.
  1367. //! this' allocator and x's allocator shall compare equal.
  1368. //!
  1369. //! <b>Throws</b>: Nothing
  1370. //!
  1371. //! <b>Complexity</b>: Linear in distance(begin(), p), in distance(x.begin(), first),
  1372. //! and in distance(first, last).
  1373. //!
  1374. //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
  1375. //! list. Iterators of this list and all the references are not invalidated.
  1376. void splice(const_iterator p, slist& x, const_iterator first, const_iterator last) BOOST_NOEXCEPT_OR_NOTHROW
  1377. { this->splice_after(this->previous(p), x, x.previous(first), x.previous(last)); }
  1378. //! <b>Requires</b>: p must point to an element contained
  1379. //! by this list. first and last must point to elements contained in list x.
  1380. //! this' allocator and x's allocator shall compare equal
  1381. //!
  1382. //! <b>Effects</b>: Transfers the range pointed by first and last from list x to this list,
  1383. //! before the element pointed by p. No destructors or copy constructors are called.
  1384. //!
  1385. //! <b>Throws</b>: Nothing
  1386. //!
  1387. //! <b>Complexity</b>: Linear in distance(begin(), p), in distance(x.begin(), first),
  1388. //! and in distance(first, last).
  1389. //!
  1390. //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
  1391. //! list. Iterators of this list and all the references are not invalidated.
  1392. void splice(const_iterator p, BOOST_RV_REF(slist) x, const_iterator first, const_iterator last) BOOST_NOEXCEPT_OR_NOTHROW
  1393. { this->splice(p, BOOST_MOVE_TO_LV(x), first, last); }
  1394. //! <b>Effects</b>: Returns true if x and y are equal
  1395. //!
  1396. //! <b>Complexity</b>: Linear to the number of elements in the container.
  1397. friend bool operator==(const slist& x, const slist& y)
  1398. { return x.size() == y.size() && ::boost::container::algo_equal(x.begin(), x.end(), y.begin()); }
  1399. //! <b>Effects</b>: Returns true if x and y are unequal
  1400. //!
  1401. //! <b>Complexity</b>: Linear to the number of elements in the container.
  1402. BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
  1403. friend bool operator!=(const slist& x, const slist& y)
  1404. { return !(x == y); }
  1405. //! <b>Effects</b>: Returns true if x is less than y
  1406. //!
  1407. //! <b>Complexity</b>: Linear to the number of elements in the container.
  1408. BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
  1409. friend bool operator<(const slist& x, const slist& y)
  1410. { return ::boost::container::algo_lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); }
  1411. //! <b>Effects</b>: Returns true if x is greater than y
  1412. //!
  1413. //! <b>Complexity</b>: Linear to the number of elements in the container.
  1414. BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
  1415. friend bool operator>(const slist& x, const slist& y)
  1416. { return y < x; }
  1417. //! <b>Effects</b>: Returns true if x is equal or less than y
  1418. //!
  1419. //! <b>Complexity</b>: Linear to the number of elements in the container.
  1420. BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
  1421. friend bool operator<=(const slist& x, const slist& y)
  1422. { return !(y < x); }
  1423. //! <b>Effects</b>: Returns true if x is equal or greater than y
  1424. //!
  1425. //! <b>Complexity</b>: Linear to the number of elements in the container.
  1426. BOOST_CONTAINER_ATTRIBUTE_NODISCARD inline
  1427. friend bool operator>=(const slist& x, const slist& y)
  1428. { return !(x < y); }
  1429. //! <b>Effects</b>: x.swap(y)
  1430. //!
  1431. //! <b>Complexity</b>: Constant.
  1432. friend void swap(slist& x, slist& y)
  1433. BOOST_NOEXCEPT_IF(BOOST_NOEXCEPT(x.swap(y)))
  1434. { x.swap(y); }
  1435. #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  1436. private:
  1437. void priv_move_assign(BOOST_RV_REF(slist) x, dtl::bool_<true> /*steal_resources*/)
  1438. {
  1439. //Destroy objects but retain memory in case x reuses it in the future
  1440. this->clear();
  1441. //Move allocator if needed
  1442. this->AllocHolder::move_assign_alloc(x);
  1443. //Obtain resources
  1444. this->icont() = boost::move(x.icont());
  1445. }
  1446. void priv_move_assign(BOOST_RV_REF(slist) x, dtl::bool_<false> /*steal_resources*/)
  1447. {
  1448. //We can't guarantee a compile-time equal allocator or propagation so fallback to runtime
  1449. //Resources can be transferred if both allocators are equal
  1450. if (this->node_alloc() == x.node_alloc()) {
  1451. this->priv_move_assign(boost::move(x), dtl::true_());
  1452. }
  1453. else {
  1454. this->assign(boost::make_move_iterator(x.begin()), boost::make_move_iterator(x.end()));
  1455. }
  1456. }
  1457. template<class U>
  1458. void priv_push_front(BOOST_FWD_REF(U) x)
  1459. { this->icont().push_front(*this->create_node(::boost::forward<U>(x))); }
  1460. bool priv_try_shrink(size_type new_size, const_iterator &last_pos)
  1461. {
  1462. typename Icont::iterator end_n(this->icont().end()), cur(this->icont().before_begin()), cur_next;
  1463. while (++(cur_next = cur) != end_n && new_size > 0){
  1464. --new_size;
  1465. cur = cur_next;
  1466. }
  1467. last_pos = const_iterator(cur);
  1468. if (cur_next != end_n){
  1469. this->erase_after(last_pos, const_iterator(end_n));
  1470. return true;
  1471. }
  1472. else{
  1473. return false;
  1474. }
  1475. }
  1476. template<class U>
  1477. iterator priv_insert(const_iterator p, BOOST_FWD_REF(U) x)
  1478. { return this->insert_after(previous(p), ::boost::forward<U>(x)); }
  1479. template<class U>
  1480. iterator priv_insert_after(const_iterator prev_p, BOOST_FWD_REF(U) x)
  1481. { return iterator(this->icont().insert_after(prev_p.get(), *this->create_node(::boost::forward<U>(x)))); }
  1482. class insertion_functor;
  1483. friend class insertion_functor;
  1484. class insertion_functor
  1485. {
  1486. Icont &icont_;
  1487. typedef typename Icont::iterator iiterator;
  1488. typedef typename Icont::const_iterator iconst_iterator;
  1489. const iconst_iterator prev_;
  1490. iiterator ret_;
  1491. public:
  1492. insertion_functor(Icont &icont, typename Icont::const_iterator prev)
  1493. : icont_(icont), prev_(prev), ret_(prev.unconst())
  1494. {}
  1495. void operator()(Node &n)
  1496. {
  1497. ret_ = this->icont_.insert_after(prev_, n);
  1498. }
  1499. iiterator inserted_first() const
  1500. { return ret_; }
  1501. };
  1502. //Functors for member algorithm defaults
  1503. typedef value_less<value_type> value_less_t;
  1504. typedef value_equal<value_type> value_equal_t;
  1505. #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  1506. };
  1507. #ifndef BOOST_CONTAINER_NO_CXX17_CTAD
  1508. template <typename InpIt>
  1509. slist(InpIt, InpIt) ->
  1510. slist<typename iterator_traits<InpIt>::value_type>;
  1511. template <typename InpIt, typename Allocator>
  1512. slist(InpIt, InpIt, Allocator const&) ->
  1513. slist<typename iterator_traits<InpIt>::value_type, Allocator>;
  1514. #endif
  1515. }}
  1516. #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  1517. namespace boost {
  1518. //!has_trivial_destructor_after_move<> == true_type
  1519. //!specialization for optimizations
  1520. template <class T, class Allocator>
  1521. struct has_trivial_destructor_after_move<boost::container::slist<T, Allocator> >
  1522. {
  1523. typedef typename boost::container::slist<T, Allocator>::allocator_type allocator_type;
  1524. typedef typename ::boost::container::allocator_traits<allocator_type>::pointer pointer;
  1525. BOOST_STATIC_CONSTEXPR bool value = ::boost::has_trivial_destructor_after_move<allocator_type>::value &&
  1526. ::boost::has_trivial_destructor_after_move<pointer>::value;
  1527. };
  1528. namespace container {
  1529. }} //namespace boost{ namespace container {
  1530. #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  1531. // Specialization of insert_iterator so that insertions will be constant
  1532. // time rather than linear time.
  1533. #include <boost/move/detail/std_ns_begin.hpp>
  1534. BOOST_CONTAINER_DOC1ST(namespace std {, BOOST_MOVE_STD_NS_BEG)
  1535. //! A specialization of insert_iterator
  1536. //! that works with slist
  1537. template <class T, class ValueAllocator>
  1538. class insert_iterator<boost::container::slist<T, ValueAllocator> >
  1539. {
  1540. private:
  1541. typedef boost::container::slist<T, ValueAllocator> Container;
  1542. Container* container;
  1543. typename Container::iterator iter;
  1544. public:
  1545. typedef Container container_type;
  1546. typedef output_iterator_tag iterator_category;
  1547. typedef void value_type;
  1548. typedef void difference_type;
  1549. typedef void pointer;
  1550. typedef void reference;
  1551. insert_iterator(Container& x,
  1552. typename Container::iterator i,
  1553. bool is_previous = false)
  1554. : container(&x), iter(is_previous ? i : x.previous(i)){ }
  1555. insert_iterator<Container>&
  1556. operator=(const typename Container::value_type& value)
  1557. {
  1558. iter = container->insert_after(iter, value);
  1559. return *this;
  1560. }
  1561. insert_iterator<Container>& operator*(){ return *this; }
  1562. insert_iterator<Container>& operator++(){ return *this; }
  1563. insert_iterator<Container>& operator++(int){ return *this; }
  1564. };
  1565. BOOST_CONTAINER_DOC1ST( }, BOOST_MOVE_STD_NS_END)
  1566. #include <boost/move/detail/std_ns_end.hpp>
  1567. #include <boost/container/detail/config_end.hpp>
  1568. #endif // BOOST_CONTAINER_SLIST_HPP