slist.hpp 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757
  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