slist.hpp 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756
  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 dtl::aligned_storage<sizeof(T), dtl::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 (BOOST_LIKELY(this != &x)) {
  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. if (BOOST_LIKELY(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. }
  398. return *this;
  399. }
  400. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  401. //! <b>Effects</b>: Makes *this contain the same elements as in il.
  402. //!
  403. //! <b>Postcondition</b>: this->size() == il.size(). *this contains a copy
  404. //! of each of il's elements.
  405. //!
  406. //! <b>Throws</b>: If allocator_traits_type::propagate_on_container_move_assignment
  407. //! is false and (allocation throws or value_type's move constructor throws)
  408. slist& operator=(std::initializer_list<value_type> il)
  409. {
  410. assign(il.begin(), il.end());
  411. return *this;
  412. }
  413. #endif
  414. //! <b>Effects</b>: Assigns the n copies of val to *this.
  415. //!
  416. //! <b>Throws</b>: If memory allocation throws or T's copy constructor throws.
  417. //!
  418. //! <b>Complexity</b>: Linear to n.
  419. void assign(size_type n, const T& val)
  420. {
  421. typedef constant_iterator<value_type, difference_type> cvalue_iterator;
  422. return this->assign(cvalue_iterator(val, n), cvalue_iterator());
  423. }
  424. //! <b>Effects</b>: Assigns the range [first, last) to *this.
  425. //!
  426. //! <b>Throws</b>: If memory allocation throws or
  427. //! T's constructor from dereferencing InpIt throws.
  428. //!
  429. //! <b>Complexity</b>: Linear to n.
  430. template <class InpIt>
  431. void assign(InpIt first, InpIt last
  432. #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  433. , typename dtl::disable_if_convertible<InpIt, size_type>::type * = 0
  434. #endif
  435. )
  436. {
  437. iterator end_n(this->end());
  438. iterator prev(this->before_begin());
  439. iterator node(this->begin());
  440. while (node != end_n && first != last){
  441. *node = *first;
  442. prev = node;
  443. ++node;
  444. ++first;
  445. }
  446. if (first != last)
  447. this->insert_after(prev, first, last);
  448. else
  449. this->erase_after(prev, end_n);
  450. }
  451. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  452. //! <b>Effects</b>: Assigns the range [il.begin(), il.end()) to *this.
  453. //!
  454. //! <b>Throws</b>: If memory allocation throws or
  455. //! T's constructor from dereferencing std::initializer_list iterator throws.
  456. //!
  457. //! <b>Complexity</b>: Linear to range [il.begin(), il.end()).
  458. void assign(std::initializer_list<value_type> il)
  459. {
  460. assign(il.begin(), il.end());
  461. }
  462. #endif
  463. //! <b>Effects</b>: Returns a copy of the internal allocator.
  464. //!
  465. //! <b>Throws</b>: If allocator's copy constructor throws.
  466. //!
  467. //! <b>Complexity</b>: Constant.
  468. allocator_type get_allocator() const BOOST_NOEXCEPT_OR_NOTHROW
  469. { return allocator_type(this->node_alloc()); }
  470. //! <b>Effects</b>: Returns a reference to the internal allocator.
  471. //!
  472. //! <b>Throws</b>: Nothing
  473. //!
  474. //! <b>Complexity</b>: Constant.
  475. //!
  476. //! <b>Note</b>: Non-standard extension.
  477. stored_allocator_type &get_stored_allocator() BOOST_NOEXCEPT_OR_NOTHROW
  478. { return this->node_alloc(); }
  479. //! <b>Effects</b>: Returns a reference to the internal allocator.
  480. //!
  481. //! <b>Throws</b>: Nothing
  482. //!
  483. //! <b>Complexity</b>: Constant.
  484. //!
  485. //! <b>Note</b>: Non-standard extension.
  486. const stored_allocator_type &get_stored_allocator() const BOOST_NOEXCEPT_OR_NOTHROW
  487. { return this->node_alloc(); }
  488. //////////////////////////////////////////////
  489. //
  490. // iterators
  491. //
  492. //////////////////////////////////////////////
  493. //! <b>Effects</b>: Returns a non-dereferenceable iterator that,
  494. //! when incremented, yields begin(). This iterator may be used
  495. //! as the argument to insert_after, erase_after, etc.
  496. //!
  497. //! <b>Throws</b>: Nothing.
  498. //!
  499. //! <b>Complexity</b>: Constant.
  500. iterator before_begin() BOOST_NOEXCEPT_OR_NOTHROW
  501. { return iterator(end()); }
  502. //! <b>Effects</b>: Returns a non-dereferenceable const_iterator
  503. //! that, when incremented, yields begin(). This iterator may be used
  504. //! as the argument to insert_after, erase_after, etc.
  505. //!
  506. //! <b>Throws</b>: Nothing.
  507. //!
  508. //! <b>Complexity</b>: Constant.
  509. const_iterator before_begin() const BOOST_NOEXCEPT_OR_NOTHROW
  510. { return this->cbefore_begin(); }
  511. //! <b>Effects</b>: Returns an iterator to the first element contained in the list.
  512. //!
  513. //! <b>Throws</b>: Nothing.
  514. //!
  515. //! <b>Complexity</b>: Constant.
  516. iterator begin() BOOST_NOEXCEPT_OR_NOTHROW
  517. { return iterator(this->icont().begin()); }
  518. //! <b>Effects</b>: Returns a const_iterator to the first element contained in the list.
  519. //!
  520. //! <b>Throws</b>: Nothing.
  521. //!
  522. //! <b>Complexity</b>: Constant.
  523. const_iterator begin() const BOOST_NOEXCEPT_OR_NOTHROW
  524. { return this->cbegin(); }
  525. //! <b>Effects</b>: Returns an iterator to the end of the list.
  526. //!
  527. //! <b>Throws</b>: Nothing.
  528. //!
  529. //! <b>Complexity</b>: Constant.
  530. iterator end() BOOST_NOEXCEPT_OR_NOTHROW
  531. { return iterator(this->icont().end()); }
  532. //! <b>Effects</b>: Returns a const_iterator to the end of the list.
  533. //!
  534. //! <b>Throws</b>: Nothing.
  535. //!
  536. //! <b>Complexity</b>: Constant.
  537. const_iterator end() const BOOST_NOEXCEPT_OR_NOTHROW
  538. { return this->cend(); }
  539. //! <b>Effects</b>: Returns a non-dereferenceable const_iterator
  540. //! that, when incremented, yields begin(). This iterator may be used
  541. //! as the argument to insert_after, erase_after, etc.
  542. //!
  543. //! <b>Throws</b>: Nothing.
  544. //!
  545. //! <b>Complexity</b>: Constant.
  546. const_iterator cbefore_begin() const BOOST_NOEXCEPT_OR_NOTHROW
  547. { return const_iterator(end()); }
  548. //! <b>Effects</b>: Returns a const_iterator to the first element contained in the list.
  549. //!
  550. //! <b>Throws</b>: Nothing.
  551. //!
  552. //! <b>Complexity</b>: Constant.
  553. const_iterator cbegin() const BOOST_NOEXCEPT_OR_NOTHROW
  554. { return const_iterator(this->non_const_icont().begin()); }
  555. //! <b>Effects</b>: Returns a const_iterator to the end of the list.
  556. //!
  557. //! <b>Throws</b>: Nothing.
  558. //!
  559. //! <b>Complexity</b>: Constant.
  560. const_iterator cend() const BOOST_NOEXCEPT_OR_NOTHROW
  561. { return const_iterator(this->non_const_icont().end()); }
  562. //! <b>Returns</b>: The iterator to the element before i in the sequence.
  563. //! Returns the end-iterator, if either i is the begin-iterator or the
  564. //! sequence is empty.
  565. //!
  566. //! <b>Throws</b>: Nothing.
  567. //!
  568. //! <b>Complexity</b>: Linear to the number of elements before i.
  569. //!
  570. //! <b>Note</b>: Non-standard extension.
  571. iterator previous(iterator p) BOOST_NOEXCEPT_OR_NOTHROW
  572. { return iterator(this->icont().previous(p.get())); }
  573. //! <b>Returns</b>: The const_iterator to the element before i in the sequence.
  574. //! Returns the end-const_iterator, if either i is the begin-const_iterator or
  575. //! the sequence is empty.
  576. //!
  577. //! <b>Throws</b>: Nothing.
  578. //!
  579. //! <b>Complexity</b>: Linear to the number of elements before i.
  580. //!
  581. //! <b>Note</b>: Non-standard extension.
  582. const_iterator previous(const_iterator p)
  583. { return const_iterator(this->icont().previous(p.get())); }
  584. //////////////////////////////////////////////
  585. //
  586. // capacity
  587. //
  588. //////////////////////////////////////////////
  589. //! <b>Effects</b>: Returns true if the list contains no elements.
  590. //!
  591. //! <b>Throws</b>: Nothing.
  592. //!
  593. //! <b>Complexity</b>: Constant.
  594. bool empty() const
  595. { return !this->size(); }
  596. //! <b>Effects</b>: Returns the number of the elements contained in the list.
  597. //!
  598. //! <b>Throws</b>: Nothing.
  599. //!
  600. //! <b>Complexity</b>: Constant.
  601. size_type size() const
  602. { return this->icont().size(); }
  603. //! <b>Effects</b>: Returns the largest possible size of the list.
  604. //!
  605. //! <b>Throws</b>: Nothing.
  606. //!
  607. //! <b>Complexity</b>: Constant.
  608. size_type max_size() const
  609. { return AllocHolder::max_size(); }
  610. //! <b>Effects</b>: Inserts or erases elements at the end such that
  611. //! the size becomes n. New elements are value initialized.
  612. //!
  613. //! <b>Throws</b>: If memory allocation throws, or T's copy constructor throws.
  614. //!
  615. //! <b>Complexity</b>: Linear to the difference between size() and new_size.
  616. void resize(size_type new_size)
  617. {
  618. const_iterator last_pos;
  619. if(!priv_try_shrink(new_size, last_pos)){
  620. typedef value_init_construct_iterator<value_type, difference_type> value_init_iterator;
  621. this->insert_after(last_pos, value_init_iterator(new_size - this->size()), value_init_iterator());
  622. }
  623. }
  624. //! <b>Effects</b>: Inserts or erases elements at the end such that
  625. //! the size becomes n. New elements are copy constructed from x.
  626. //!
  627. //! <b>Throws</b>: If memory allocation throws, or T's copy constructor throws.
  628. //!
  629. //! <b>Complexity</b>: Linear to the difference between size() and new_size.
  630. void resize(size_type new_size, const T& x)
  631. {
  632. const_iterator last_pos;
  633. if(!priv_try_shrink(new_size, last_pos)){
  634. this->insert_after(last_pos, new_size, x);
  635. }
  636. }
  637. //////////////////////////////////////////////
  638. //
  639. // element access
  640. //
  641. //////////////////////////////////////////////
  642. //! <b>Requires</b>: !empty()
  643. //!
  644. //! <b>Effects</b>: Returns a reference to the first element
  645. //! from the beginning of the container.
  646. //!
  647. //! <b>Throws</b>: Nothing.
  648. //!
  649. //! <b>Complexity</b>: Constant.
  650. reference front()
  651. {
  652. BOOST_ASSERT(!this->empty());
  653. return *this->begin();
  654. }
  655. //! <b>Requires</b>: !empty()
  656. //!
  657. //! <b>Effects</b>: Returns a const reference to the first element
  658. //! from the beginning of the container.
  659. //!
  660. //! <b>Throws</b>: Nothing.
  661. //!
  662. //! <b>Complexity</b>: Constant.
  663. const_reference front() const
  664. {
  665. BOOST_ASSERT(!this->empty());
  666. return *this->begin();
  667. }
  668. //////////////////////////////////////////////
  669. //
  670. // modifiers
  671. //
  672. //////////////////////////////////////////////
  673. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  674. //! <b>Effects</b>: Inserts an object of type T constructed with
  675. //! std::forward<Args>(args)... in the front of the list
  676. //!
  677. //! <b>Returns</b>: A reference to the created object.
  678. //!
  679. //! <b>Throws</b>: If memory allocation throws or
  680. //! T's copy constructor throws.
  681. //!
  682. //! <b>Complexity</b>: Amortized constant time.
  683. template <class... Args>
  684. reference emplace_front(BOOST_FWD_REF(Args)... args)
  685. { return *this->emplace_after(this->cbefore_begin(), boost::forward<Args>(args)...); }
  686. //! <b>Effects</b>: Inserts an object of type T constructed with
  687. //! std::forward<Args>(args)... after prev
  688. //!
  689. //! <b>Throws</b>: If memory allocation throws or
  690. //! T's in-place constructor throws.
  691. //!
  692. //! <b>Complexity</b>: Constant
  693. template <class... Args>
  694. iterator emplace_after(const_iterator prev, BOOST_FWD_REF(Args)... args)
  695. {
  696. NodePtr pnode(AllocHolder::create_node(boost::forward<Args>(args)...));
  697. return iterator(this->icont().insert_after(prev.get(), *pnode));
  698. }
  699. #else // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  700. #define BOOST_CONTAINER_SLIST_EMPLACE_CODE(N) \
  701. BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
  702. reference emplace_front(BOOST_MOVE_UREF##N)\
  703. { return *this->emplace_after(this->cbefore_begin() BOOST_MOVE_I##N BOOST_MOVE_FWD##N);}\
  704. \
  705. BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
  706. iterator emplace_after(const_iterator p BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
  707. {\
  708. NodePtr pnode (AllocHolder::create_node(BOOST_MOVE_FWD##N));\
  709. return iterator(this->icont().insert_after(p.get(), *pnode));\
  710. }\
  711. //
  712. BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_SLIST_EMPLACE_CODE)
  713. #undef BOOST_CONTAINER_SLIST_EMPLACE_CODE
  714. #endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  715. #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  716. //! <b>Effects</b>: Inserts a copy of x at the beginning of the list.
  717. //!
  718. //! <b>Throws</b>: If memory allocation throws or
  719. //! T's copy constructor throws.
  720. //!
  721. //! <b>Complexity</b>: Amortized constant time.
  722. void push_front(const T &x);
  723. //! <b>Effects</b>: Constructs a new element in the beginning of the list
  724. //! and moves the resources of x to this new element.
  725. //!
  726. //! <b>Throws</b>: If memory allocation throws.
  727. //!
  728. //! <b>Complexity</b>: Amortized constant time.
  729. void push_front(T &&x);
  730. #else
  731. BOOST_MOVE_CONVERSION_AWARE_CATCH(push_front, T, void, priv_push_front)
  732. #endif
  733. #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  734. //! <b>Requires</b>: p must be a valid iterator of *this.
  735. //!
  736. //! <b>Effects</b>: Inserts a copy of the value after prev_p.
  737. //!
  738. //! <b>Returns</b>: An iterator to the inserted element.
  739. //!
  740. //! <b>Throws</b>: If memory allocation throws or T's copy constructor throws.
  741. //!
  742. //! <b>Complexity</b>: Amortized constant time.
  743. //!
  744. //! <b>Note</b>: Does not affect the validity of iterators and references of
  745. //! previous values.
  746. iterator insert_after(const_iterator prev_p, const T &x);
  747. //! <b>Requires</b>: prev_p must be a valid iterator of *this.
  748. //!
  749. //! <b>Effects</b>: Inserts a move constructed copy object from the value after the
  750. //! element pointed by prev_p.
  751. //!
  752. //! <b>Returns</b>: An iterator to the inserted element.
  753. //!
  754. //! <b>Throws</b>: If memory allocation throws.
  755. //!
  756. //! <b>Complexity</b>: Amortized constant time.
  757. //!
  758. //! <b>Note</b>: Does not affect the validity of iterators and references of
  759. //! previous values.
  760. iterator insert_after(const_iterator prev_p, T &&x);
  761. #else
  762. BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(insert_after, T, iterator, priv_insert_after, const_iterator, const_iterator)
  763. #endif
  764. //! <b>Requires</b>: prev_p must be a valid iterator of *this.
  765. //!
  766. //! <b>Effects</b>: Inserts n copies of x after prev_p.
  767. //!
  768. //! <b>Returns</b>: an iterator to the last inserted element or prev_p if n is 0.
  769. //!
  770. //! <b>Throws</b>: If memory allocation throws or T's copy constructor throws.
  771. //!
  772. //!
  773. //! <b>Complexity</b>: Linear to n.
  774. //!
  775. //! <b>Note</b>: Does not affect the validity of iterators and references of
  776. //! previous values.
  777. iterator insert_after(const_iterator prev_p, size_type n, const value_type& x)
  778. {
  779. typedef constant_iterator<value_type, difference_type> cvalue_iterator;
  780. return this->insert_after(prev_p, cvalue_iterator(x, n), cvalue_iterator());
  781. }
  782. //! <b>Requires</b>: prev_p must be a valid iterator of *this.
  783. //!
  784. //! <b>Effects</b>: Inserts the range pointed by [first, last) after prev_p.
  785. //!
  786. //! <b>Returns</b>: an iterator to the last inserted element or prev_p if first == last.
  787. //!
  788. //! <b>Throws</b>: If memory allocation throws, T's constructor from a
  789. //! dereferenced InpIt throws.
  790. //!
  791. //! <b>Complexity</b>: Linear to the number of elements inserted.
  792. //!
  793. //! <b>Note</b>: Does not affect the validity of iterators and references of
  794. //! previous values.
  795. template <class InpIt>
  796. iterator insert_after(const_iterator prev_p, InpIt first, InpIt last
  797. #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  798. , typename dtl::enable_if_c
  799. < !dtl::is_convertible<InpIt, size_type>::value
  800. && (dtl::is_input_iterator<InpIt>::value
  801. || dtl::is_same<alloc_version, version_1>::value
  802. )
  803. >::type * = 0
  804. #endif
  805. )
  806. {
  807. iterator ret_it(prev_p.get());
  808. for (; first != last; ++first){
  809. ret_it = iterator(this->icont().insert_after(ret_it.get(), *this->create_node_from_it(first)));
  810. }
  811. return ret_it;
  812. }
  813. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  814. //! <b>Requires</b>: prev_p must be a valid iterator of *this.
  815. //!
  816. //! <b>Effects</b>: Inserts the range pointed by [il.begin(), il.end()) after prev_p.
  817. //!
  818. //! <b>Returns</b>: an iterator to the last inserted element or prev_p if il.begin() == il.end().
  819. //!
  820. //! <b>Throws</b>: If memory allocation throws, T's constructor from a
  821. //! dereferenced std::initializer_list iterator throws.
  822. //!
  823. //! <b>Complexity</b>: Linear to the number of elements inserted.
  824. //!
  825. //! <b>Note</b>: Does not affect the validity of iterators and references of
  826. //! previous values.
  827. iterator insert_after(const_iterator prev_p, std::initializer_list<value_type> il)
  828. {
  829. return insert_after(prev_p, il.begin(), il.end());
  830. }
  831. #endif
  832. #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  833. template <class FwdIt>
  834. iterator insert_after(const_iterator prev, FwdIt first, FwdIt last
  835. , typename dtl::enable_if_c
  836. < !dtl::is_convertible<FwdIt, size_type>::value
  837. && !(dtl::is_input_iterator<FwdIt>::value
  838. || dtl::is_same<alloc_version, version_1>::value
  839. )
  840. >::type * = 0
  841. )
  842. {
  843. //Optimized allocation and construction
  844. insertion_functor func(this->icont(), prev.get());
  845. this->allocate_many_and_construct(first, boost::container::iterator_distance(first, last), func);
  846. return iterator(func.inserted_first());
  847. }
  848. #endif
  849. //! <b>Effects</b>: Removes the first element from the list.
  850. //!
  851. //! <b>Throws</b>: Nothing.
  852. //!
  853. //! <b>Complexity</b>: Amortized constant time.
  854. void pop_front()
  855. {
  856. BOOST_ASSERT(!this->empty());
  857. this->icont().pop_front_and_dispose(Destroyer(this->node_alloc()));
  858. }
  859. //! <b>Effects</b>: Erases the element after the element pointed by prev_p
  860. //! of the list.
  861. //!
  862. //! <b>Returns</b>: the first element remaining beyond the removed elements,
  863. //! or end() if no such element exists.
  864. //!
  865. //! <b>Throws</b>: Nothing.
  866. //!
  867. //! <b>Complexity</b>: Constant.
  868. //!
  869. //! <b>Note</b>: Does not invalidate iterators or references to non erased elements.
  870. iterator erase_after(const_iterator prev_p)
  871. {
  872. return iterator(this->icont().erase_after_and_dispose(prev_p.get(), Destroyer(this->node_alloc())));
  873. }
  874. //! <b>Effects</b>: Erases the range (before_first, last) from
  875. //! the list.
  876. //!
  877. //! <b>Returns</b>: the first element remaining beyond the removed elements,
  878. //! or end() if no such element exists.
  879. //!
  880. //! <b>Throws</b>: Nothing.
  881. //!
  882. //! <b>Complexity</b>: Linear to the number of erased elements.
  883. //!
  884. //! <b>Note</b>: Does not invalidate iterators or references to non erased elements.
  885. iterator erase_after(const_iterator before_first, const_iterator last)
  886. {
  887. return iterator(this->icont().erase_after_and_dispose(before_first.get(), last.get(), Destroyer(this->node_alloc())));
  888. }
  889. //! <b>Effects</b>: Swaps the contents of *this and x.
  890. //!
  891. //! <b>Throws</b>: Nothing.
  892. //!
  893. //! <b>Complexity</b>: Linear to the number of elements on *this and x.
  894. void swap(slist& x)
  895. BOOST_NOEXCEPT_IF( allocator_traits_type::propagate_on_container_swap::value
  896. || allocator_traits_type::is_always_equal::value)
  897. {
  898. BOOST_ASSERT(allocator_traits_type::propagate_on_container_swap::value ||
  899. allocator_traits_type::is_always_equal::value ||
  900. this->get_stored_allocator() == x.get_stored_allocator());
  901. AllocHolder::swap(x);
  902. }
  903. //! <b>Effects</b>: Erases all the elements of the list.
  904. //!
  905. //! <b>Throws</b>: Nothing.
  906. //!
  907. //! <b>Complexity</b>: Linear to the number of elements in the list.
  908. void clear()
  909. { this->icont().clear_and_dispose(Destroyer(this->node_alloc())); }
  910. //////////////////////////////////////////////
  911. //
  912. // slist operations
  913. //
  914. //////////////////////////////////////////////
  915. //! <b>Requires</b>: p must point to an element contained
  916. //! by the list. x != *this
  917. //!
  918. //! <b>Effects</b>: Transfers all the elements of list x to this list, after the
  919. //! the element pointed by p. No destructors or copy constructors are called.
  920. //!
  921. //! <b>Throws</b>: std::runtime_error if this' allocator and x's allocator
  922. //! are not equal.
  923. //!
  924. //! <b>Complexity</b>: Linear to the elements in x.
  925. //!
  926. //! <b>Note</b>: Iterators of values obtained from list x now point to elements of
  927. //! this list. Iterators of this list and all the references are not invalidated.
  928. void splice_after(const_iterator prev_p, slist& x) BOOST_NOEXCEPT_OR_NOTHROW
  929. {
  930. BOOST_ASSERT(this != &x);
  931. BOOST_ASSERT(this->node_alloc() == x.node_alloc());
  932. this->icont().splice_after(prev_p.get(), x.icont());
  933. }
  934. //! <b>Requires</b>: p must point to an element contained
  935. //! by the list. x != *this
  936. //!
  937. //! <b>Effects</b>: Transfers all the elements of list x to this list, after the
  938. //! the element pointed by p. No destructors or copy constructors are called.
  939. //!
  940. //! <b>Throws</b>: std::runtime_error if this' allocator and x's allocator
  941. //! are not equal.
  942. //!
  943. //! <b>Complexity</b>: Linear to the elements in x.
  944. //!
  945. //! <b>Note</b>: Iterators of values obtained from list x now point to elements of
  946. //! this 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) BOOST_NOEXCEPT_OR_NOTHROW
  948. { this->splice_after(prev_p, static_cast<slist&>(x)); }
  949. //! <b>Requires</b>: prev_p must be a valid iterator of this.
  950. //! i must point to an element contained in list x.
  951. //! this' allocator and x's allocator shall compare equal.
  952. //!
  953. //! <b>Effects</b>: Transfers the value pointed by i, from list x to this list,
  954. //! after the element pointed by prev_p.
  955. //! If prev_p == prev or prev_p == ++prev, this function is a null operation.
  956. //!
  957. //! <b>Throws</b>: Nothing
  958. //!
  959. //! <b>Complexity</b>: Constant.
  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, const_iterator prev) BOOST_NOEXCEPT_OR_NOTHROW
  964. {
  965. BOOST_ASSERT(this->node_alloc() == x.node_alloc());
  966. this->icont().splice_after(prev_p.get(), x.icont(), prev.get());
  967. }
  968. //! <b>Requires</b>: prev_p must be a valid iterator of this.
  969. //! i must point to an element contained in list x.
  970. //! this' allocator and x's allocator shall compare equal.
  971. //!
  972. //! <b>Effects</b>: Transfers the value pointed by i, from list x to this list,
  973. //! after the element pointed by prev_p.
  974. //! If prev_p == prev or prev_p == ++prev, this function is a null operation.
  975. //!
  976. //! <b>Throws</b>: Nothing
  977. //!
  978. //! <b>Complexity</b>: Constant.
  979. //!
  980. //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
  981. //! list. Iterators of this list and all the references are not invalidated.
  982. void splice_after(const_iterator prev_p, BOOST_RV_REF(slist) x, const_iterator prev) BOOST_NOEXCEPT_OR_NOTHROW
  983. { this->splice_after(prev_p, static_cast<slist&>(x), prev); }
  984. //! <b>Requires</b>: prev_p must be a valid iterator of this.
  985. //! before_first and before_last must be valid iterators of x.
  986. //! prev_p must not be contained in [before_first, before_last) range.
  987. //! this' allocator and x's allocator shall compare equal.
  988. //!
  989. //! <b>Effects</b>: Transfers the range [before_first + 1, before_last + 1)
  990. //! from list x to this list, after the element pointed by prev_p.
  991. //!
  992. //! <b>Throws</b>: Nothing
  993. //!
  994. //! <b>Complexity</b>: Linear to the number of transferred elements.
  995. //!
  996. //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
  997. //! list. Iterators of this list and all the references are not invalidated.
  998. void splice_after(const_iterator prev_p, slist& x,
  999. const_iterator before_first, const_iterator before_last) BOOST_NOEXCEPT_OR_NOTHROW
  1000. {
  1001. BOOST_ASSERT(this->node_alloc() == x.node_alloc());
  1002. this->icont().splice_after
  1003. (prev_p.get(), x.icont(), before_first.get(), before_last.get());
  1004. }
  1005. //! <b>Requires</b>: prev_p must be a valid iterator of this.
  1006. //! before_first and before_last must be valid iterators of x.
  1007. //! prev_p must not be contained in [before_first, before_last) range.
  1008. //! this' allocator and x's allocator shall compare equal.
  1009. //!
  1010. //! <b>Effects</b>: Transfers the range [before_first + 1, before_last + 1)
  1011. //! from list x to this list, after the element pointed by prev_p.
  1012. //!
  1013. //! <b>Throws</b>: Nothing
  1014. //!
  1015. //! <b>Complexity</b>: Linear to the number of transferred elements.
  1016. //!
  1017. //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
  1018. //! list. Iterators of this list and all the references are not invalidated.
  1019. void splice_after(const_iterator prev_p, BOOST_RV_REF(slist) x,
  1020. const_iterator before_first, const_iterator before_last) BOOST_NOEXCEPT_OR_NOTHROW
  1021. { this->splice_after(prev_p, static_cast<slist&>(x), before_first, before_last); }
  1022. //! <b>Requires</b>: prev_p must be a valid iterator of this.
  1023. //! before_first and before_last must be valid iterators of x.
  1024. //! prev_p must not be contained in [before_first, before_last) range.
  1025. //! n == distance(before_first, before_last).
  1026. //! this' allocator and x's allocator shall compare equal.
  1027. //!
  1028. //! <b>Effects</b>: Transfers the range [before_first + 1, before_last + 1)
  1029. //! from list x to this list, after the element pointed by prev_p.
  1030. //!
  1031. //! <b>Throws</b>: Nothing
  1032. //!
  1033. //! <b>Complexity</b>: Constant.
  1034. //!
  1035. //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
  1036. //! list. Iterators of this list and all the references are not invalidated.
  1037. void splice_after(const_iterator prev_p, slist& x,
  1038. const_iterator before_first, const_iterator before_last,
  1039. size_type n) BOOST_NOEXCEPT_OR_NOTHROW
  1040. {
  1041. BOOST_ASSERT(this->node_alloc() == x.node_alloc());
  1042. this->icont().splice_after
  1043. (prev_p.get(), x.icont(), before_first.get(), before_last.get(), n);
  1044. }
  1045. //! <b>Requires</b>: prev_p must be a valid iterator of this.
  1046. //! before_first and before_last must be valid iterators of x.
  1047. //! prev_p must not be contained in [before_first, before_last) range.
  1048. //! n == distance(before_first, before_last).
  1049. //! this' allocator and x's allocator shall compare equal.
  1050. //!
  1051. //! <b>Effects</b>: Transfers the range [before_first + 1, before_last + 1)
  1052. //! from list x to this list, after the element pointed by prev_p.
  1053. //!
  1054. //! <b>Throws</b>: Nothing
  1055. //!
  1056. //! <b>Complexity</b>: Constant.
  1057. //!
  1058. //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
  1059. //! list. Iterators of this list and all the references are not invalidated.
  1060. void splice_after(const_iterator prev_p, BOOST_RV_REF(slist) x,
  1061. const_iterator before_first, const_iterator before_last,
  1062. size_type n) BOOST_NOEXCEPT_OR_NOTHROW
  1063. { this->splice_after(prev_p, static_cast<slist&>(x), before_first, before_last, n); }
  1064. //! <b>Effects</b>: Removes all the elements that compare equal to value.
  1065. //!
  1066. //! <b>Throws</b>: Nothing.
  1067. //!
  1068. //! <b>Complexity</b>: Linear time. It performs exactly size() comparisons for equality.
  1069. //!
  1070. //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
  1071. //! and iterators to elements that are not removed remain valid.
  1072. void remove(const T& value)
  1073. { this->remove_if(equal_to_value_type(value)); }
  1074. //! <b>Effects</b>: Removes all the elements for which a specified
  1075. //! predicate is satisfied.
  1076. //!
  1077. //! <b>Throws</b>: If pred throws.
  1078. //!
  1079. //! <b>Complexity</b>: Linear time. It performs exactly size() calls to the predicate.
  1080. //!
  1081. //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
  1082. //! and iterators to elements that are not removed remain valid.
  1083. template <class Pred>
  1084. void remove_if(Pred pred)
  1085. {
  1086. typedef value_to_node_compare<Node, Pred> value_to_node_compare_type;
  1087. this->icont().remove_and_dispose_if(value_to_node_compare_type(pred), Destroyer(this->node_alloc()));
  1088. }
  1089. //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
  1090. //! elements that are equal from the list.
  1091. //!
  1092. //! <b>Throws</b>: If comparison throws.
  1093. //!
  1094. //! <b>Complexity</b>: Linear time (size()-1 comparisons equality comparisons).
  1095. //!
  1096. //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
  1097. //! and iterators to elements that are not removed remain valid.
  1098. void unique()
  1099. { this->unique(value_equal_t()); }
  1100. //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
  1101. //! elements that satisfy some binary predicate from the list.
  1102. //!
  1103. //! <b>Throws</b>: If pred throws.
  1104. //!
  1105. //! <b>Complexity</b>: Linear time (size()-1 comparisons calls to pred()).
  1106. //!
  1107. //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
  1108. //! and iterators to elements that are not removed remain valid.
  1109. template <class Pred>
  1110. void unique(Pred pred)
  1111. {
  1112. typedef value_to_node_compare<Node, Pred> value_to_node_compare_type;
  1113. this->icont().unique_and_dispose(value_to_node_compare_type(pred), Destroyer(this->node_alloc()));
  1114. }
  1115. //! <b>Requires</b>: The lists x and *this must be distinct.
  1116. //!
  1117. //! <b>Effects</b>: This function removes all of x's elements and inserts them
  1118. //! in order into *this according to std::less<value_type>. The merge is stable;
  1119. //! that is, if an element from *this is equivalent to one from x, then the element
  1120. //! from *this will precede the one from x.
  1121. //!
  1122. //! <b>Throws</b>: If comparison throws.
  1123. //!
  1124. //! <b>Complexity</b>: This function is linear time: it performs at most
  1125. //! size() + x.size() - 1 comparisons.
  1126. void merge(slist & x)
  1127. { this->merge(x, value_less_t()); }
  1128. //! <b>Requires</b>: The lists x and *this must be distinct.
  1129. //!
  1130. //! <b>Effects</b>: This function removes all of x's elements and inserts them
  1131. //! in order into *this according to std::less<value_type>. The merge is stable;
  1132. //! that is, if an element from *this is equivalent to one from x, then the element
  1133. //! from *this will precede the one from x.
  1134. //!
  1135. //! <b>Throws</b>: If comparison throws.
  1136. //!
  1137. //! <b>Complexity</b>: This function is linear time: it performs at most
  1138. //! size() + x.size() - 1 comparisons.
  1139. void merge(BOOST_RV_REF(slist) x)
  1140. { this->merge(static_cast<slist&>(x)); }
  1141. //! <b>Requires</b>: p must be a comparison function that induces a strict weak
  1142. //! ordering and both *this and x must be sorted according to that ordering
  1143. //! The lists x and *this must be distinct.
  1144. //!
  1145. //! <b>Effects</b>: This function removes all of x's elements and inserts them
  1146. //! in order into *this. The merge is stable; that is, if an element from *this is
  1147. //! equivalent to one from x, then the element from *this will precede the one from x.
  1148. //!
  1149. //! <b>Throws</b>: If comp throws.
  1150. //!
  1151. //! <b>Complexity</b>: This function is linear time: it performs at most
  1152. //! size() + x.size() - 1 comparisons.
  1153. //!
  1154. //! <b>Note</b>: Iterators and references to *this are not invalidated.
  1155. template <class StrictWeakOrdering>
  1156. void merge(slist& x, StrictWeakOrdering comp)
  1157. {
  1158. typedef value_to_node_compare<Node, StrictWeakOrdering> value_to_node_compare_type;
  1159. BOOST_ASSERT(this->node_alloc() == x.node_alloc());
  1160. this->icont().merge(x.icont(), value_to_node_compare_type(comp));
  1161. }
  1162. //! <b>Requires</b>: p must be a comparison function that induces a strict weak
  1163. //! ordering and both *this and x must be sorted according to that ordering
  1164. //! The lists x and *this must be distinct.
  1165. //!
  1166. //! <b>Effects</b>: This function removes all of x's elements and inserts them
  1167. //! in order into *this. The merge is stable; that is, if an element from *this is
  1168. //! equivalent to one from x, then the element from *this will precede the one from x.
  1169. //!
  1170. //! <b>Throws</b>: If comp throws.
  1171. //!
  1172. //! <b>Complexity</b>: This function is linear time: it performs at most
  1173. //! size() + x.size() - 1 comparisons.
  1174. //!
  1175. //! <b>Note</b>: Iterators and references to *this are not invalidated.
  1176. template <class StrictWeakOrdering>
  1177. void merge(BOOST_RV_REF(slist) x, StrictWeakOrdering comp)
  1178. { this->merge(static_cast<slist&>(x), comp); }
  1179. //! <b>Effects</b>: This function sorts the list *this according to std::less<value_type>.
  1180. //! The sort is stable, that is, the relative order of equivalent elements is preserved.
  1181. //!
  1182. //! <b>Throws</b>: If comparison throws.
  1183. //!
  1184. //! <b>Notes</b>: Iterators and references are not invalidated.
  1185. //!
  1186. //! <b>Complexity</b>: The number of comparisons is approximately N log N, where N
  1187. //! is the list's size.
  1188. void sort()
  1189. { this->sort(value_less_t()); }
  1190. //! <b>Effects</b>: This function sorts the list *this according to std::less<value_type>.
  1191. //! The sort is stable, that is, the relative order of equivalent elements is preserved.
  1192. //!
  1193. //! <b>Throws</b>: If comp throws.
  1194. //!
  1195. //! <b>Notes</b>: Iterators and references are not invalidated.
  1196. //!
  1197. //! <b>Complexity</b>: The number of comparisons is approximately N log N, where N
  1198. //! is the list's size.
  1199. template <class StrictWeakOrdering>
  1200. void sort(StrictWeakOrdering comp)
  1201. {
  1202. typedef value_to_node_compare<Node, StrictWeakOrdering> value_to_node_compare_type;
  1203. // nothing if the slist has length 0 or 1.
  1204. if (this->size() < 2)
  1205. return;
  1206. this->icont().sort(value_to_node_compare_type(comp));
  1207. }
  1208. //! <b>Effects</b>: Reverses the order of elements in the list.
  1209. //!
  1210. //! <b>Throws</b>: Nothing.
  1211. //!
  1212. //! <b>Complexity</b>: This function is linear time.
  1213. //!
  1214. //! <b>Note</b>: Iterators and references are not invalidated
  1215. void reverse() BOOST_NOEXCEPT_OR_NOTHROW
  1216. { this->icont().reverse(); }
  1217. //////////////////////////////////////////////
  1218. //
  1219. // list compatibility interface
  1220. //
  1221. //////////////////////////////////////////////
  1222. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  1223. //! <b>Effects</b>: Inserts an object of type T constructed with
  1224. //! std::forward<Args>(args)... before p
  1225. //!
  1226. //! <b>Throws</b>: If memory allocation throws or
  1227. //! T's in-place constructor throws.
  1228. //!
  1229. //! <b>Complexity</b>: Linear to the elements before p
  1230. template <class... Args>
  1231. iterator emplace(const_iterator p, BOOST_FWD_REF(Args)... args)
  1232. { return this->emplace_after(this->previous(p), boost::forward<Args>(args)...); }
  1233. #else
  1234. #define BOOST_CONTAINER_SLIST_EMPLACE_CODE(N) \
  1235. BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
  1236. iterator emplace(const_iterator p BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
  1237. {\
  1238. return this->emplace_after(this->previous(p) BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
  1239. }\
  1240. //
  1241. BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_SLIST_EMPLACE_CODE)
  1242. #undef BOOST_CONTAINER_SLIST_EMPLACE_CODE
  1243. #endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  1244. #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
  1245. //! <b>Requires</b>: p must be a valid iterator of *this.
  1246. //!
  1247. //! <b>Effects</b>: Insert a copy of x before p.
  1248. //!
  1249. //! <b>Returns</b>: an iterator to the inserted element.
  1250. //!
  1251. //! <b>Throws</b>: If memory allocation throws or x's copy constructor throws.
  1252. //!
  1253. //! <b>Complexity</b>: Linear to the elements before p.
  1254. iterator insert(const_iterator p, const T &x);
  1255. //! <b>Requires</b>: p must be a valid iterator of *this.
  1256. //!
  1257. //! <b>Effects</b>: Insert a new element before p with x's resources.
  1258. //!
  1259. //! <b>Returns</b>: an iterator to the inserted element.
  1260. //!
  1261. //! <b>Throws</b>: If memory allocation throws.
  1262. //!
  1263. //! <b>Complexity</b>: Linear to the elements before p.
  1264. iterator insert(const_iterator prev_p, T &&x);
  1265. #else
  1266. BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(insert, T, iterator, priv_insert, const_iterator, const_iterator)
  1267. #endif
  1268. //! <b>Requires</b>: p must be a valid iterator of *this.
  1269. //!
  1270. //! <b>Effects</b>: Inserts n copies of x before p.
  1271. //!
  1272. //! <b>Returns</b>: an iterator to the first inserted element or p if n == 0.
  1273. //!
  1274. //! <b>Throws</b>: If memory allocation throws or T's copy constructor throws.
  1275. //!
  1276. //! <b>Complexity</b>: Linear to n plus linear to the elements before p.
  1277. iterator insert(const_iterator p, size_type n, const value_type& x)
  1278. {
  1279. const_iterator prev(this->previous(p));
  1280. this->insert_after(prev, n, x);
  1281. return ++iterator(prev.get());
  1282. }
  1283. //! <b>Requires</b>: p must be a valid iterator of *this.
  1284. //!
  1285. //! <b>Effects</b>: Insert a copy of the [first, last) range before p.
  1286. //!
  1287. //! <b>Returns</b>: an iterator to the first inserted element or p if first == last.
  1288. //!
  1289. //! <b>Throws</b>: If memory allocation throws, T's constructor from a
  1290. //! dereferenced InpIt throws.
  1291. //!
  1292. //! <b>Complexity</b>: Linear to distance [first, last) plus
  1293. //! linear to the elements before p.
  1294. template <class InIter>
  1295. iterator insert(const_iterator p, InIter first, InIter last)
  1296. {
  1297. const_iterator prev(this->previous(p));
  1298. this->insert_after(prev, first, last);
  1299. return ++iterator(prev.get());
  1300. }
  1301. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  1302. //! <b>Requires</b>: p must be a valid iterator of *this.
  1303. //!
  1304. //! <b>Effects</b>: Insert a copy of the [il.begin(), il.end()) range before p.
  1305. //!
  1306. //! <b>Returns</b>: an iterator to the first inserted element or p if il.begin() == il.end().
  1307. //!
  1308. //! <b>Throws</b>: If memory allocation throws, T's constructor from a
  1309. //! dereferenced std::initializer_list iterator throws.
  1310. //!
  1311. //! <b>Complexity</b>: Linear to the range [il.begin(), il.end()) plus
  1312. //! linear to the elements before p.
  1313. iterator insert(const_iterator p, std::initializer_list<value_type> il)
  1314. {
  1315. return insert(p, il.begin(), il.end());
  1316. }
  1317. #endif
  1318. //! <b>Requires</b>: p must be a valid iterator of *this.
  1319. //!
  1320. //! <b>Effects</b>: Erases the element at p.
  1321. //!
  1322. //! <b>Throws</b>: Nothing.
  1323. //!
  1324. //! <b>Complexity</b>: Linear to the number of elements before p.
  1325. iterator erase(const_iterator p) BOOST_NOEXCEPT_OR_NOTHROW
  1326. { return iterator(this->erase_after(previous(p))); }
  1327. //! <b>Requires</b>: first and last must be valid iterator to elements in *this.
  1328. //!
  1329. //! <b>Effects</b>: Erases the elements pointed by [first, last).
  1330. //!
  1331. //! <b>Throws</b>: Nothing.
  1332. //!
  1333. //! <b>Complexity</b>: Linear to the distance between first and last plus
  1334. //! linear to the elements before first.
  1335. iterator erase(const_iterator first, const_iterator last) BOOST_NOEXCEPT_OR_NOTHROW
  1336. { return iterator(this->erase_after(previous(first), last)); }
  1337. //! <b>Requires</b>: p must point to an element contained
  1338. //! by the list. x != *this. this' allocator and x's allocator shall compare equal
  1339. //!
  1340. //! <b>Effects</b>: Transfers all the elements of list x to this list, before the
  1341. //! the element pointed by p. No destructors or copy constructors are called.
  1342. //!
  1343. //! <b>Throws</b>: Nothing
  1344. //!
  1345. //! <b>Complexity</b>: Linear in distance(begin(), p), and linear in x.size().
  1346. //!
  1347. //! <b>Note</b>: Iterators of values obtained from list x now point to elements of
  1348. //! this list. Iterators of this list and all the references are not invalidated.
  1349. void splice(const_iterator p, slist& x) BOOST_NOEXCEPT_OR_NOTHROW
  1350. { this->splice_after(this->previous(p), x); }
  1351. //! <b>Requires</b>: p must point to an element contained
  1352. //! by the list. x != *this. this' allocator and x's allocator shall compare equal
  1353. //!
  1354. //! <b>Effects</b>: Transfers all the elements of list x to this list, before the
  1355. //! the element pointed by p. No destructors or copy constructors are called.
  1356. //!
  1357. //! <b>Throws</b>: Nothing
  1358. //!
  1359. //! <b>Complexity</b>: Linear in distance(begin(), p), and linear in x.size().
  1360. //!
  1361. //! <b>Note</b>: Iterators of values obtained from list x now point to elements of
  1362. //! this list. Iterators of this list and all the references are not invalidated.
  1363. void splice(const_iterator p, BOOST_RV_REF(slist) x) BOOST_NOEXCEPT_OR_NOTHROW
  1364. { this->splice(p, static_cast<slist&>(x)); }
  1365. //! <b>Requires</b>: p must point to an element contained
  1366. //! by this list. i must point to an element contained in list x.
  1367. //! this' allocator and x's allocator shall compare equal
  1368. //!
  1369. //! <b>Effects</b>: Transfers the value pointed by i, from list x to this list,
  1370. //! before the element pointed by p. No destructors or copy constructors are called.
  1371. //! If p == i or p == ++i, this function is a null operation.
  1372. //!
  1373. //! <b>Throws</b>: Nothing
  1374. //!
  1375. //! <b>Complexity</b>: Linear in distance(begin(), p), and in distance(x.begin(), i).
  1376. //!
  1377. //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
  1378. //! list. Iterators of this list and all the references are not invalidated.
  1379. void splice(const_iterator p, slist& x, const_iterator i) BOOST_NOEXCEPT_OR_NOTHROW
  1380. { this->splice_after(this->previous(p), x, x.previous(i)); }
  1381. //! <b>Requires</b>: p must point to an element contained
  1382. //! by this list. i must point to an element contained in list x.
  1383. //! this' allocator and x's allocator shall compare equal.
  1384. //!
  1385. //! <b>Effects</b>: Transfers the value pointed by i, from list x to this list,
  1386. //! before the element pointed by p. No destructors or copy constructors are called.
  1387. //! If p == i or p == ++i, this function is a null operation.
  1388. //!
  1389. //! <b>Throws</b>: Nothing
  1390. //!
  1391. //! <b>Complexity</b>: Linear in distance(begin(), p), and in distance(x.begin(), i).
  1392. //!
  1393. //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
  1394. //! list. Iterators of this list and all the references are not invalidated.
  1395. void splice(const_iterator p, BOOST_RV_REF(slist) x, const_iterator i) BOOST_NOEXCEPT_OR_NOTHROW
  1396. { this->splice(p, static_cast<slist&>(x), i); }
  1397. //! <b>Requires</b>: p must point to an element contained
  1398. //! by this list. first and last must point to elements contained in list x.
  1399. //!
  1400. //! <b>Effects</b>: Transfers the range pointed by first and last from list x to this list,
  1401. //! before the element pointed by p. No destructors or copy constructors are called.
  1402. //! this' allocator and x's allocator shall compare equal.
  1403. //!
  1404. //! <b>Throws</b>: Nothing
  1405. //!
  1406. //! <b>Complexity</b>: Linear in distance(begin(), p), in distance(x.begin(), first),
  1407. //! and in distance(first, last).
  1408. //!
  1409. //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
  1410. //! list. Iterators of this list and all the references are not invalidated.
  1411. void splice(const_iterator p, slist& x, const_iterator first, const_iterator last) BOOST_NOEXCEPT_OR_NOTHROW
  1412. { this->splice_after(this->previous(p), x, x.previous(first), x.previous(last)); }
  1413. //! <b>Requires</b>: p must point to an element contained
  1414. //! by this list. first and last must point to elements contained in list x.
  1415. //! this' allocator and x's allocator shall compare equal
  1416. //!
  1417. //! <b>Effects</b>: Transfers the range pointed by first and last from list x to this list,
  1418. //! before the element pointed by p. No destructors or copy constructors are called.
  1419. //!
  1420. //! <b>Throws</b>: Nothing
  1421. //!
  1422. //! <b>Complexity</b>: Linear in distance(begin(), p), in distance(x.begin(), first),
  1423. //! and in distance(first, last).
  1424. //!
  1425. //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
  1426. //! list. Iterators of this list and all the references are not invalidated.
  1427. void splice(const_iterator p, BOOST_RV_REF(slist) x, const_iterator first, const_iterator last) BOOST_NOEXCEPT_OR_NOTHROW
  1428. { this->splice(p, static_cast<slist&>(x), first, last); }
  1429. //! <b>Effects</b>: Returns true if x and y are equal
  1430. //!
  1431. //! <b>Complexity</b>: Linear to the number of elements in the container.
  1432. friend bool operator==(const slist& x, const slist& y)
  1433. { return x.size() == y.size() && ::boost::container::algo_equal(x.begin(), x.end(), y.begin()); }
  1434. //! <b>Effects</b>: Returns true if x and y are unequal
  1435. //!
  1436. //! <b>Complexity</b>: Linear to the number of elements in the container.
  1437. friend bool operator!=(const slist& x, const slist& y)
  1438. { return !(x == y); }
  1439. //! <b>Effects</b>: Returns true if x is less than y
  1440. //!
  1441. //! <b>Complexity</b>: Linear to the number of elements in the container.
  1442. friend bool operator<(const slist& x, const slist& y)
  1443. { return ::boost::container::algo_lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); }
  1444. //! <b>Effects</b>: Returns true if x is greater than y
  1445. //!
  1446. //! <b>Complexity</b>: Linear to the number of elements in the container.
  1447. friend bool operator>(const slist& x, const slist& y)
  1448. { return y < x; }
  1449. //! <b>Effects</b>: Returns true if x is equal or less than y
  1450. //!
  1451. //! <b>Complexity</b>: Linear to the number of elements in the container.
  1452. friend bool operator<=(const slist& x, const slist& y)
  1453. { return !(y < x); }
  1454. //! <b>Effects</b>: Returns true if x is equal or greater than y
  1455. //!
  1456. //! <b>Complexity</b>: Linear to the number of elements in the container.
  1457. friend bool operator>=(const slist& x, const slist& y)
  1458. { return !(x < y); }
  1459. //! <b>Effects</b>: x.swap(y)
  1460. //!
  1461. //! <b>Complexity</b>: Constant.
  1462. friend void swap(slist& x, slist& y)
  1463. { x.swap(y); }
  1464. #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  1465. private:
  1466. void priv_push_front (const T &x)
  1467. { this->insert_after(this->cbefore_begin(), x); }
  1468. void priv_push_front (BOOST_RV_REF(T) x)
  1469. { this->insert_after(this->cbefore_begin(), ::boost::move(x)); }
  1470. bool priv_try_shrink(size_type new_size, const_iterator &last_pos)
  1471. {
  1472. typename Icont::iterator end_n(this->icont().end()), cur(this->icont().before_begin()), cur_next;
  1473. while (++(cur_next = cur) != end_n && new_size > 0){
  1474. --new_size;
  1475. cur = cur_next;
  1476. }
  1477. last_pos = const_iterator(cur);
  1478. if (cur_next != end_n){
  1479. this->erase_after(last_pos, const_iterator(end_n));
  1480. return true;
  1481. }
  1482. else{
  1483. return false;
  1484. }
  1485. }
  1486. template<class U>
  1487. iterator priv_insert(const_iterator p, BOOST_FWD_REF(U) x)
  1488. { return this->insert_after(previous(p), ::boost::forward<U>(x)); }
  1489. template<class U>
  1490. iterator priv_insert_after(const_iterator prev_p, BOOST_FWD_REF(U) x)
  1491. { return iterator(this->icont().insert_after(prev_p.get(), *this->create_node(::boost::forward<U>(x)))); }
  1492. class insertion_functor;
  1493. friend class insertion_functor;
  1494. class insertion_functor
  1495. {
  1496. Icont &icont_;
  1497. typedef typename Icont::iterator iiterator;
  1498. typedef typename Icont::const_iterator iconst_iterator;
  1499. const iconst_iterator prev_;
  1500. iiterator ret_;
  1501. public:
  1502. insertion_functor(Icont &icont, typename Icont::const_iterator prev)
  1503. : icont_(icont), prev_(prev), ret_(prev.unconst())
  1504. {}
  1505. void operator()(Node &n)
  1506. {
  1507. ret_ = this->icont_.insert_after(prev_, n);
  1508. }
  1509. iiterator inserted_first() const
  1510. { return ret_; }
  1511. };
  1512. //Functors for member algorithm defaults
  1513. typedef value_less<value_type> value_less_t;
  1514. typedef value_equal<value_type> value_equal_t;
  1515. #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  1516. };
  1517. #ifndef BOOST_CONTAINER_NO_CXX17_CTAD
  1518. template <typename InpIt>
  1519. slist(InpIt, InpIt) ->
  1520. slist<typename iterator_traits<InpIt>::value_type>;
  1521. template <typename InpIt, typename Allocator>
  1522. slist(InpIt, InpIt, Allocator const&) ->
  1523. slist<typename iterator_traits<InpIt>::value_type, Allocator>;
  1524. #endif
  1525. }}
  1526. #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  1527. namespace boost {
  1528. //!has_trivial_destructor_after_move<> == true_type
  1529. //!specialization for optimizations
  1530. template <class T, class Allocator>
  1531. struct has_trivial_destructor_after_move<boost::container::slist<T, Allocator> >
  1532. {
  1533. typedef typename boost::container::slist<T, Allocator>::allocator_type allocator_type;
  1534. typedef typename ::boost::container::allocator_traits<allocator_type>::pointer pointer;
  1535. static const bool value = ::boost::has_trivial_destructor_after_move<allocator_type>::value &&
  1536. ::boost::has_trivial_destructor_after_move<pointer>::value;
  1537. };
  1538. namespace container {
  1539. }} //namespace boost{ namespace container {
  1540. #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  1541. // Specialization of insert_iterator so that insertions will be constant
  1542. // time rather than linear time.
  1543. #include <boost/move/detail/std_ns_begin.hpp>
  1544. BOOST_CONTAINER_DOC1ST(namespace std {, BOOST_MOVE_STD_NS_BEG)
  1545. //! A specialization of insert_iterator
  1546. //! that works with slist
  1547. template <class T, class ValueAllocator>
  1548. class insert_iterator<boost::container::slist<T, ValueAllocator> >
  1549. {
  1550. private:
  1551. typedef boost::container::slist<T, ValueAllocator> Container;
  1552. Container* container;
  1553. typename Container::iterator iter;
  1554. public:
  1555. typedef Container container_type;
  1556. typedef output_iterator_tag iterator_category;
  1557. typedef void value_type;
  1558. typedef void difference_type;
  1559. typedef void pointer;
  1560. typedef void reference;
  1561. insert_iterator(Container& x,
  1562. typename Container::iterator i,
  1563. bool is_previous = false)
  1564. : container(&x), iter(is_previous ? i : x.previous(i)){ }
  1565. insert_iterator<Container>&
  1566. operator=(const typename Container::value_type& value)
  1567. {
  1568. iter = container->insert_after(iter, value);
  1569. return *this;
  1570. }
  1571. insert_iterator<Container>& operator*(){ return *this; }
  1572. insert_iterator<Container>& operator++(){ return *this; }
  1573. insert_iterator<Container>& operator++(int){ return *this; }
  1574. };
  1575. BOOST_CONTAINER_DOC1ST( }, BOOST_MOVE_STD_NS_END)
  1576. #include <boost/move/detail/std_ns_end.hpp>
  1577. #include <boost/container/detail/config_end.hpp>
  1578. #endif // BOOST_CONTAINER_SLIST_HPP