slist.hpp 67 KB

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