slist.hpp 69 KB

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