1 //////////////////////////////////////////////////////////////////////////////
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)
7 // See http://www.boost.org/libs/container for documentation.
9 //////////////////////////////////////////////////////////////////////////////
11 #ifndef BOOST_CONTAINER_SLIST_HPP
12 #define BOOST_CONTAINER_SLIST_HPP
14 #ifndef BOOST_CONFIG_HPP
15 # include <boost/config.hpp>
18 #if defined(BOOST_HAS_PRAGMA_ONCE)
22 #include <boost/container/detail/config_begin.hpp>
23 #include <boost/container/detail/workaround.hpp>
26 #include <boost/container/container_fwd.hpp>
27 #include <boost/container/new_allocator.hpp> //new_allocator
28 #include <boost/container/throw_exception.hpp>
30 #include <boost/container/detail/algorithm.hpp> //algo_equal(), algo_lexicographical_compare
31 #include <boost/container/detail/compare_functors.hpp>
32 #include <boost/container/detail/iterator.hpp>
33 #include <boost/container/detail/iterators.hpp>
34 #include <boost/container/detail/mpl.hpp>
35 #include <boost/container/detail/node_alloc_holder.hpp>
36 #include <boost/container/detail/type_traits.hpp>
38 #include <boost/intrusive/pointer_traits.hpp>
39 #include <boost/intrusive/slist.hpp>
41 #include <boost/move/iterator.hpp>
42 #include <boost/move/traits.hpp>
43 #include <boost/move/utility_core.hpp>
45 #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
46 #include <boost/move/detail/fwd_macros.hpp>
48 #include <boost/move/detail/move_helpers.hpp>
50 #include <boost/core/no_exceptions_support.hpp>
52 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
53 #include <initializer_list>
59 #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
61 template <class T, class Allocator>
64 namespace container_detail {
66 template<class VoidPointer>
69 typedef typename container_detail::bi::make_slist_base_hook
70 <container_detail::bi::void_pointer<VoidPointer>, container_detail::bi::link_mode<container_detail::bi::normal_link> >::type type;
73 template <class T, class VoidPointer>
75 : public slist_hook<VoidPointer>::type
82 typedef typename slist_hook<VoidPointer>::type hook_type;
87 { return this->m_data; }
89 const T &get_data() const
90 { return this->m_data; }
93 template <class T, class VoidPointer>
94 struct iiterator_node_value_type< slist_node<T,VoidPointer> > {
98 template<class Allocator>
99 struct intrusive_slist_type
101 typedef boost::container::allocator_traits<Allocator> allocator_traits_type;
102 typedef typename allocator_traits_type::value_type value_type;
103 typedef typename boost::intrusive::pointer_traits
104 <typename allocator_traits_type::pointer>::template
105 rebind_pointer<void>::type
107 typedef typename container_detail::slist_node
108 <value_type, void_pointer> node_type;
110 typedef typename container_detail::bi::make_slist
112 ,container_detail::bi::base_hook<typename slist_hook<void_pointer>::type>
113 ,container_detail::bi::constant_time_size<true>
114 , container_detail::bi::size_type
115 <typename allocator_traits_type::size_type>
116 >::type container_type;
117 typedef container_type type ;
120 } //namespace container_detail {
122 #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
124 //! An slist is a singly linked list: a list where each element is linked to the next
125 //! element, but not to the previous element. That is, it is a Sequence that
126 //! supports forward but not backward traversal, and (amortized) constant time
127 //! insertion and removal of elements. Slists, like lists, have the important
128 //! property that insertion and splicing do not invalidate iterators to list elements,
129 //! and that even removal invalidates only the iterators that point to the elements
130 //! that are removed. The ordering of iterators may be changed (that is,
131 //! slist<T>::iterator might have a different predecessor or successor after a list
132 //! operation than it did before), but the iterators themselves will not be invalidated
133 //! or made to point to different elements unless that invalidation or mutation is explicit.
135 //! The main difference between slist and list is that list's iterators are bidirectional
136 //! iterators, while slist's iterators are forward iterators. This means that slist is
137 //! less versatile than list; frequently, however, bidirectional iterators are
138 //! unnecessary. You should usually use slist unless you actually need the extra
139 //! functionality of list, because singly linked lists are smaller and faster than double
142 //! Important performance note: like every other Sequence, slist defines the member
143 //! functions insert and erase. Using these member functions carelessly, however, can
144 //! result in disastrously slow programs. The problem is that insert's first argument is
145 //! an iterator p, and that it inserts the new element(s) before p. This means that
146 //! insert must find the iterator just before p; this is a constant-time operation
147 //! for list, since list has bidirectional iterators, but for slist it must find that
148 //! iterator by traversing the list from the beginning up to p. In other words:
149 //! insert and erase are slow operations anywhere but near the beginning of the slist.
151 //! Slist provides the member functions insert_after and erase_after, which are constant
152 //! time operations: you should always use insert_after and erase_after whenever
153 //! possible. If you find that insert_after and erase_after aren't adequate for your
154 //! needs, and that you often need to use insert and erase in the middle of the list,
155 //! then you should probably use list instead of slist.
157 //! \tparam T The type of object that is stored in the list
158 //! \tparam Allocator The allocator used for all internal memory management
159 #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
160 template <class T, class Allocator = new_allocator<T> >
162 template <class T, class Allocator>
165 : protected container_detail::node_alloc_holder
166 <Allocator, typename container_detail::intrusive_slist_type<Allocator>::type>
168 #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
170 container_detail::intrusive_slist_type<Allocator>::type Icont;
171 typedef container_detail::node_alloc_holder<Allocator, Icont> AllocHolder;
172 typedef typename AllocHolder::NodePtr NodePtr;
173 typedef typename AllocHolder::NodeAlloc NodeAlloc;
174 typedef typename AllocHolder::ValAlloc ValAlloc;
175 typedef typename AllocHolder::Node Node;
176 typedef container_detail::allocator_destroyer<NodeAlloc> Destroyer;
177 typedef typename AllocHolder::alloc_version alloc_version;
178 typedef boost::container::
179 allocator_traits<Allocator> allocator_traits_type;
180 typedef boost::container::equal_to_value<Allocator> equal_to_value_type;
182 BOOST_COPYABLE_AND_MOVABLE(slist)
183 typedef container_detail::iterator_from_iiterator<typename Icont::iterator, false> iterator_impl;
184 typedef container_detail::iterator_from_iiterator<typename Icont::iterator, true > const_iterator_impl;
185 #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
188 //////////////////////////////////////////////
192 //////////////////////////////////////////////
194 typedef T value_type;
195 typedef typename ::boost::container::allocator_traits<Allocator>::pointer pointer;
196 typedef typename ::boost::container::allocator_traits<Allocator>::const_pointer const_pointer;
197 typedef typename ::boost::container::allocator_traits<Allocator>::reference reference;
198 typedef typename ::boost::container::allocator_traits<Allocator>::const_reference const_reference;
199 typedef typename ::boost::container::allocator_traits<Allocator>::size_type size_type;
200 typedef typename ::boost::container::allocator_traits<Allocator>::difference_type difference_type;
201 typedef Allocator allocator_type;
202 typedef BOOST_CONTAINER_IMPDEF(NodeAlloc) stored_allocator_type;
203 typedef BOOST_CONTAINER_IMPDEF(iterator_impl) iterator;
204 typedef BOOST_CONTAINER_IMPDEF(const_iterator_impl) const_iterator;
208 //////////////////////////////////////////////
210 // construct/copy/destroy
212 //////////////////////////////////////////////
214 //! <b>Effects</b>: Constructs a list taking the allocator as parameter.
216 //! <b>Throws</b>: If allocator_type's copy constructor throws.
218 //! <b>Complexity</b>: Constant.
219 slist() BOOST_NOEXCEPT_IF(container_detail::is_nothrow_default_constructible<Allocator>::value)
223 //! <b>Effects</b>: Constructs a list taking the allocator as parameter.
225 //! <b>Throws</b>: Nothing
227 //! <b>Complexity</b>: Constant.
228 explicit slist(const allocator_type& a) BOOST_NOEXCEPT_OR_NOTHROW
232 //! <b>Effects</b>: Constructs a list
233 //! and inserts n value-initialized value_types.
235 //! <b>Throws</b>: If allocator_type's default constructor
236 //! throws or T's default or copy constructor throws.
238 //! <b>Complexity</b>: Linear to n.
239 explicit slist(size_type n)
240 : AllocHolder(allocator_type())
243 //! <b>Effects</b>: Constructs a list that will use a copy of allocator a
244 //! and inserts n copies of value.
246 //! <b>Throws</b>: If allocator_type's default constructor
247 //! throws or T's default or copy constructor throws.
249 //! <b>Complexity</b>: Linear to n.
250 slist(size_type n, const allocator_type &a)
254 //! <b>Effects</b>: Constructs a list that will use a copy of allocator a
255 //! and inserts n copies of value.
257 //! <b>Throws</b>: If allocator_type's default constructor
258 //! throws or T's default or copy constructor throws.
260 //! <b>Complexity</b>: Linear to n.
261 explicit slist(size_type n, const value_type& x, const allocator_type& a = allocator_type())
263 { this->insert_after(this->cbefore_begin(), n, x); }
265 //! <b>Effects</b>: Constructs a list that will use a copy of allocator a
266 //! and inserts a copy of the range [first, last) in the list.
268 //! <b>Throws</b>: If allocator_type's default constructor
269 //! throws or T's constructor taking a dereferenced InIt throws.
271 //! <b>Complexity</b>: Linear to the range [first, last).
272 template <class InpIt>
273 slist(InpIt first, InpIt last, const allocator_type& a = allocator_type())
275 { this->insert_after(this->cbefore_begin(), first, last); }
277 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
278 //! <b>Effects</b>: Constructs a list that will use a copy of allocator a
279 //! and inserts a copy of the range [il.begin(), il.end()) in the list.
281 //! <b>Throws</b>: If allocator_type's default constructor
282 //! throws or T's constructor taking a dereferenced std::initializer_list iterator throws.
284 //! <b>Complexity</b>: Linear to the range [il.begin(), il.end()).
285 slist(std::initializer_list<value_type> il, const allocator_type& a = allocator_type())
287 { this->insert_after(this->cbefore_begin(), il.begin(), il.end()); }
290 //! <b>Effects</b>: Copy constructs a list.
292 //! <b>Postcondition</b>: x == *this.
294 //! <b>Throws</b>: If allocator_type's default constructor
296 //! <b>Complexity</b>: Linear to the elements x contains.
297 slist(const slist& x)
299 { this->insert_after(this->cbefore_begin(), x.begin(), x.end()); }
301 //! <b>Effects</b>: Move constructor. Moves x's resources to *this.
303 //! <b>Throws</b>: If allocator_type's copy constructor throws.
305 //! <b>Complexity</b>: Constant.
306 slist(BOOST_RV_REF(slist) x) BOOST_NOEXCEPT_OR_NOTHROW
307 : AllocHolder(BOOST_MOVE_BASE(AllocHolder, x))
310 //! <b>Effects</b>: Copy constructs a list using the specified allocator.
312 //! <b>Postcondition</b>: x == *this.
314 //! <b>Throws</b>: If allocator_type's default constructor
316 //! <b>Complexity</b>: Linear to the elements x contains.
317 slist(const slist& x, const allocator_type &a)
319 { this->insert_after(this->cbefore_begin(), x.begin(), x.end()); }
321 //! <b>Effects</b>: Move constructor using the specified allocator.
322 //! Moves x's resources to *this.
324 //! <b>Throws</b>: If allocation or value_type's copy constructor throws.
326 //! <b>Complexity</b>: Constant if a == x.get_allocator(), linear otherwise.
327 slist(BOOST_RV_REF(slist) x, const allocator_type &a)
330 if(this->node_alloc() == x.node_alloc()){
331 this->icont().swap(x.icont());
334 this->insert_after(this->cbefore_begin(), boost::make_move_iterator(x.begin()), boost::make_move_iterator(x.end()));
338 //! <b>Effects</b>: Destroys the list. All stored values are destroyed
339 //! and used memory is deallocated.
341 //! <b>Throws</b>: Nothing.
343 //! <b>Complexity</b>: Linear to the number of elements.
344 ~slist() BOOST_NOEXCEPT_OR_NOTHROW
345 {} //AllocHolder clears the slist
347 //! <b>Effects</b>: Makes *this contain the same elements as x.
349 //! <b>Postcondition</b>: this->size() == x.size(). *this contains a copy
350 //! of each of x's elements.
352 //! <b>Throws</b>: If memory allocation throws or T's copy constructor throws.
354 //! <b>Complexity</b>: Linear to the number of elements in x.
355 slist& operator= (BOOST_COPY_ASSIGN_REF(slist) x)
358 NodeAlloc &this_alloc = this->node_alloc();
359 const NodeAlloc &x_alloc = x.node_alloc();
360 container_detail::bool_<allocator_traits_type::
361 propagate_on_container_copy_assignment::value> flag;
362 if(flag && this_alloc != x_alloc){
365 this->AllocHolder::copy_assign_alloc(x);
366 this->assign(x.begin(), x.end());
371 //! <b>Effects</b>: Makes *this contain the same elements as x.
373 //! <b>Postcondition</b>: this->size() == x.size(). *this contains a copy
374 //! of each of x's elements.
376 //! <b>Throws</b>: If allocator_traits_type::propagate_on_container_move_assignment
377 //! is false and (allocation throws or value_type's move constructor throws)
379 //! <b>Complexity</b>: Constant if allocator_traits_type::
380 //! propagate_on_container_move_assignment is true or
381 //! this->get>allocator() == x.get_allocator(). Linear otherwise.
382 slist& operator=(BOOST_RV_REF(slist) x)
383 BOOST_NOEXCEPT_IF(allocator_traits_type::propagate_on_container_move_assignment::value
384 || allocator_traits_type::is_always_equal::value)
386 BOOST_ASSERT(this != &x);
387 NodeAlloc &this_alloc = this->node_alloc();
388 NodeAlloc &x_alloc = x.node_alloc();
389 const bool propagate_alloc = allocator_traits_type::
390 propagate_on_container_move_assignment::value;
391 const bool allocators_equal = this_alloc == x_alloc; (void)allocators_equal;
392 //Resources can be transferred if both allocators are
393 //going to be equal after this function (either propagated or already equal)
394 if(propagate_alloc || allocators_equal){
397 //Move allocator if needed
398 this->AllocHolder::move_assign_alloc(x);
400 this->icont() = boost::move(x.icont());
402 //Else do a one by one move
404 this->assign( boost::make_move_iterator(x.begin())
405 , boost::make_move_iterator(x.end()));
410 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
411 //! <b>Effects</b>: Makes *this contain the same elements as in il.
413 //! <b>Postcondition</b>: this->size() == il.size(). *this contains a copy
414 //! of each of il's elements.
416 //! <b>Throws</b>: If allocator_traits_type::propagate_on_container_move_assignment
417 //! is false and (allocation throws or value_type's move constructor throws)
418 slist& operator=(std::initializer_list<value_type> il)
420 assign(il.begin(), il.end());
425 //! <b>Effects</b>: Assigns the n copies of val to *this.
427 //! <b>Throws</b>: If memory allocation throws or T's copy constructor throws.
429 //! <b>Complexity</b>: Linear to n.
430 void assign(size_type n, const T& val)
432 typedef constant_iterator<value_type, difference_type> cvalue_iterator;
433 return this->assign(cvalue_iterator(val, n), cvalue_iterator());
436 //! <b>Effects</b>: Assigns the range [first, last) to *this.
438 //! <b>Throws</b>: If memory allocation throws or
439 //! T's constructor from dereferencing InpIt throws.
441 //! <b>Complexity</b>: Linear to n.
442 template <class InpIt>
443 void assign(InpIt first, InpIt last
444 #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
445 , typename container_detail::disable_if_convertible<InpIt, size_type>::type * = 0
449 iterator end_n(this->end());
450 iterator prev(this->before_begin());
451 iterator node(this->begin());
452 while (node != end_n && first != last){
459 this->insert_after(prev, first, last);
461 this->erase_after(prev, end_n);
464 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
465 //! <b>Effects</b>: Assigns the range [il.begin(), il.end()) to *this.
467 //! <b>Throws</b>: If memory allocation throws or
468 //! T's constructor from dereferencing std::initializer_list iterator throws.
470 //! <b>Complexity</b>: Linear to range [il.begin(), il.end()).
472 void assign(std::initializer_list<value_type> il)
474 assign(il.begin(), il.end());
477 //! <b>Effects</b>: Returns a copy of the internal allocator.
479 //! <b>Throws</b>: If allocator's copy constructor throws.
481 //! <b>Complexity</b>: Constant.
482 allocator_type get_allocator() const BOOST_NOEXCEPT_OR_NOTHROW
483 { return allocator_type(this->node_alloc()); }
485 //! <b>Effects</b>: Returns a reference to the internal allocator.
487 //! <b>Throws</b>: Nothing
489 //! <b>Complexity</b>: Constant.
491 //! <b>Note</b>: Non-standard extension.
492 stored_allocator_type &get_stored_allocator() BOOST_NOEXCEPT_OR_NOTHROW
493 { return this->node_alloc(); }
495 //! <b>Effects</b>: Returns a reference to the internal allocator.
497 //! <b>Throws</b>: Nothing
499 //! <b>Complexity</b>: Constant.
501 //! <b>Note</b>: Non-standard extension.
502 const stored_allocator_type &get_stored_allocator() const BOOST_NOEXCEPT_OR_NOTHROW
503 { return this->node_alloc(); }
505 //////////////////////////////////////////////
509 //////////////////////////////////////////////
511 //! <b>Effects</b>: Returns a non-dereferenceable iterator that,
512 //! when incremented, yields begin(). This iterator may be used
513 //! as the argument to insert_after, erase_after, etc.
515 //! <b>Throws</b>: Nothing.
517 //! <b>Complexity</b>: Constant.
518 iterator before_begin() BOOST_NOEXCEPT_OR_NOTHROW
519 { return iterator(end()); }
521 //! <b>Effects</b>: Returns a non-dereferenceable const_iterator
522 //! that, when incremented, yields begin(). This iterator may be used
523 //! as the argument to insert_after, erase_after, etc.
525 //! <b>Throws</b>: Nothing.
527 //! <b>Complexity</b>: Constant.
528 const_iterator before_begin() const BOOST_NOEXCEPT_OR_NOTHROW
529 { return this->cbefore_begin(); }
531 //! <b>Effects</b>: Returns an iterator to the first element contained in the list.
533 //! <b>Throws</b>: Nothing.
535 //! <b>Complexity</b>: Constant.
536 iterator begin() BOOST_NOEXCEPT_OR_NOTHROW
537 { return iterator(this->icont().begin()); }
539 //! <b>Effects</b>: Returns a const_iterator to the first element contained in the list.
541 //! <b>Throws</b>: Nothing.
543 //! <b>Complexity</b>: Constant.
544 const_iterator begin() const BOOST_NOEXCEPT_OR_NOTHROW
545 { return this->cbegin(); }
547 //! <b>Effects</b>: Returns an iterator to the end of the list.
549 //! <b>Throws</b>: Nothing.
551 //! <b>Complexity</b>: Constant.
552 iterator end() BOOST_NOEXCEPT_OR_NOTHROW
553 { return iterator(this->icont().end()); }
555 //! <b>Effects</b>: Returns a const_iterator to the end of the list.
557 //! <b>Throws</b>: Nothing.
559 //! <b>Complexity</b>: Constant.
560 const_iterator end() const BOOST_NOEXCEPT_OR_NOTHROW
561 { return this->cend(); }
563 //! <b>Effects</b>: Returns a non-dereferenceable const_iterator
564 //! that, when incremented, yields begin(). This iterator may be used
565 //! as the argument to insert_after, erase_after, etc.
567 //! <b>Throws</b>: Nothing.
569 //! <b>Complexity</b>: Constant.
570 const_iterator cbefore_begin() const BOOST_NOEXCEPT_OR_NOTHROW
571 { return const_iterator(end()); }
573 //! <b>Effects</b>: Returns a const_iterator to the first element contained in the list.
575 //! <b>Throws</b>: Nothing.
577 //! <b>Complexity</b>: Constant.
578 const_iterator cbegin() const BOOST_NOEXCEPT_OR_NOTHROW
579 { return const_iterator(this->non_const_icont().begin()); }
581 //! <b>Effects</b>: Returns a const_iterator to the end of the list.
583 //! <b>Throws</b>: Nothing.
585 //! <b>Complexity</b>: Constant.
586 const_iterator cend() const BOOST_NOEXCEPT_OR_NOTHROW
587 { return const_iterator(this->non_const_icont().end()); }
589 //! <b>Returns</b>: The iterator to the element before i in the sequence.
590 //! Returns the end-iterator, if either i is the begin-iterator or the
591 //! sequence is empty.
593 //! <b>Throws</b>: Nothing.
595 //! <b>Complexity</b>: Linear to the number of elements before i.
597 //! <b>Note</b>: Non-standard extension.
598 iterator previous(iterator p) BOOST_NOEXCEPT_OR_NOTHROW
599 { return iterator(this->icont().previous(p.get())); }
601 //! <b>Returns</b>: The const_iterator to the element before i in the sequence.
602 //! Returns the end-const_iterator, if either i is the begin-const_iterator or
603 //! the sequence is empty.
605 //! <b>Throws</b>: Nothing.
607 //! <b>Complexity</b>: Linear to the number of elements before i.
609 //! <b>Note</b>: Non-standard extension.
610 const_iterator previous(const_iterator p)
611 { return const_iterator(this->icont().previous(p.get())); }
613 //////////////////////////////////////////////
617 //////////////////////////////////////////////
619 //! <b>Effects</b>: Returns true if the list contains no elements.
621 //! <b>Throws</b>: Nothing.
623 //! <b>Complexity</b>: Constant.
625 { return !this->size(); }
627 //! <b>Effects</b>: Returns the number of the elements contained in the list.
629 //! <b>Throws</b>: Nothing.
631 //! <b>Complexity</b>: Constant.
632 size_type size() const
633 { return this->icont().size(); }
635 //! <b>Effects</b>: Returns the largest possible size of the list.
637 //! <b>Throws</b>: Nothing.
639 //! <b>Complexity</b>: Constant.
640 size_type max_size() const
641 { return AllocHolder::max_size(); }
643 //! <b>Effects</b>: Inserts or erases elements at the end such that
644 //! the size becomes n. New elements are value initialized.
646 //! <b>Throws</b>: If memory allocation throws, or T's copy constructor throws.
648 //! <b>Complexity</b>: Linear to the difference between size() and new_size.
649 void resize(size_type new_size)
651 const_iterator last_pos;
652 if(!priv_try_shrink(new_size, last_pos)){
653 typedef value_init_construct_iterator<value_type, difference_type> value_init_iterator;
654 this->insert_after(last_pos, value_init_iterator(new_size - this->size()), value_init_iterator());
658 //! <b>Effects</b>: Inserts or erases elements at the end such that
659 //! the size becomes n. New elements are copy constructed from x.
661 //! <b>Throws</b>: If memory allocation throws, or T's copy constructor throws.
663 //! <b>Complexity</b>: Linear to the difference between size() and new_size.
664 void resize(size_type new_size, const T& x)
666 const_iterator last_pos;
667 if(!priv_try_shrink(new_size, last_pos)){
668 this->insert_after(last_pos, new_size, x);
672 //////////////////////////////////////////////
676 //////////////////////////////////////////////
678 //! <b>Requires</b>: !empty()
680 //! <b>Effects</b>: Returns a reference to the first element
681 //! from the beginning of the container.
683 //! <b>Throws</b>: Nothing.
685 //! <b>Complexity</b>: Constant.
688 BOOST_ASSERT(!this->empty());
689 return *this->begin();
692 //! <b>Requires</b>: !empty()
694 //! <b>Effects</b>: Returns a const reference to the first element
695 //! from the beginning of the container.
697 //! <b>Throws</b>: Nothing.
699 //! <b>Complexity</b>: Constant.
700 const_reference front() const
702 BOOST_ASSERT(!this->empty());
703 return *this->begin();
706 //////////////////////////////////////////////
710 //////////////////////////////////////////////
712 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
714 //! <b>Effects</b>: Inserts an object of type T constructed with
715 //! std::forward<Args>(args)... in the front of the list
717 //! <b>Returns</b>: A reference to the created object.
719 //! <b>Throws</b>: If memory allocation throws or
720 //! T's copy constructor throws.
722 //! <b>Complexity</b>: Amortized constant time.
723 template <class... Args>
724 reference emplace_front(BOOST_FWD_REF(Args)... args)
725 { return *this->emplace_after(this->cbefore_begin(), boost::forward<Args>(args)...); }
727 //! <b>Effects</b>: Inserts an object of type T constructed with
728 //! std::forward<Args>(args)... after prev
730 //! <b>Throws</b>: If memory allocation throws or
731 //! T's in-place constructor throws.
733 //! <b>Complexity</b>: Constant
734 template <class... Args>
735 iterator emplace_after(const_iterator prev, BOOST_FWD_REF(Args)... args)
737 NodePtr pnode(AllocHolder::create_node(boost::forward<Args>(args)...));
738 return iterator(this->icont().insert_after(prev.get(), *pnode));
741 #else // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
743 #define BOOST_CONTAINER_SLIST_EMPLACE_CODE(N) \
744 BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
745 reference emplace_front(BOOST_MOVE_UREF##N)\
746 { return *this->emplace_after(this->cbefore_begin() BOOST_MOVE_I##N BOOST_MOVE_FWD##N);}\
748 BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
749 iterator emplace_after(const_iterator p BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
751 NodePtr pnode (AllocHolder::create_node(BOOST_MOVE_FWD##N));\
752 return iterator(this->icont().insert_after(p.get(), *pnode));\
755 BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_SLIST_EMPLACE_CODE)
756 #undef BOOST_CONTAINER_SLIST_EMPLACE_CODE
758 #endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
760 #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
761 //! <b>Effects</b>: Inserts a copy of x at the beginning of the list.
763 //! <b>Throws</b>: If memory allocation throws or
764 //! T's copy constructor throws.
766 //! <b>Complexity</b>: Amortized constant time.
767 void push_front(const T &x);
769 //! <b>Effects</b>: Constructs a new element in the beginning of the list
770 //! and moves the resources of x to this new element.
772 //! <b>Throws</b>: If memory allocation throws.
774 //! <b>Complexity</b>: Amortized constant time.
775 void push_front(T &&x);
777 BOOST_MOVE_CONVERSION_AWARE_CATCH(push_front, T, void, priv_push_front)
781 #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
782 //! <b>Requires</b>: p must be a valid iterator of *this.
784 //! <b>Effects</b>: Inserts a copy of the value after prev_p.
786 //! <b>Returns</b>: An iterator to the inserted element.
788 //! <b>Throws</b>: If memory allocation throws or T's copy constructor throws.
790 //! <b>Complexity</b>: Amortized constant time.
792 //! <b>Note</b>: Does not affect the validity of iterators and references of
794 iterator insert_after(const_iterator prev_p, const T &x);
796 //! <b>Requires</b>: prev_p must be a valid iterator of *this.
798 //! <b>Effects</b>: Inserts a move constructed copy object from the value after the
799 //! element pointed by prev_p.
801 //! <b>Returns</b>: An iterator to the inserted element.
803 //! <b>Throws</b>: If memory allocation throws.
805 //! <b>Complexity</b>: Amortized constant time.
807 //! <b>Note</b>: Does not affect the validity of iterators and references of
809 iterator insert_after(const_iterator prev_p, T &&x);
811 BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(insert_after, T, iterator, priv_insert_after, const_iterator, const_iterator)
814 //! <b>Requires</b>: prev_p must be a valid iterator of *this.
816 //! <b>Effects</b>: Inserts n copies of x after prev_p.
818 //! <b>Returns</b>: an iterator to the last inserted element or prev_p if n is 0.
820 //! <b>Throws</b>: If memory allocation throws or T's copy constructor throws.
823 //! <b>Complexity</b>: Linear to n.
825 //! <b>Note</b>: Does not affect the validity of iterators and references of
827 iterator insert_after(const_iterator prev_p, size_type n, const value_type& x)
829 typedef constant_iterator<value_type, difference_type> cvalue_iterator;
830 return this->insert_after(prev_p, cvalue_iterator(x, n), cvalue_iterator());
833 //! <b>Requires</b>: prev_p must be a valid iterator of *this.
835 //! <b>Effects</b>: Inserts the range pointed by [first, last) after prev_p.
837 //! <b>Returns</b>: an iterator to the last inserted element or prev_p if first == last.
839 //! <b>Throws</b>: If memory allocation throws, T's constructor from a
840 //! dereferenced InpIt throws.
842 //! <b>Complexity</b>: Linear to the number of elements inserted.
844 //! <b>Note</b>: Does not affect the validity of iterators and references of
846 template <class InpIt>
847 iterator insert_after(const_iterator prev_p, InpIt first, InpIt last
848 #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
849 , typename container_detail::enable_if_c
850 < !container_detail::is_convertible<InpIt, size_type>::value
851 && (container_detail::is_input_iterator<InpIt>::value
852 || container_detail::is_same<alloc_version, version_1>::value
858 iterator ret_it(prev_p.get());
859 for (; first != last; ++first){
860 ret_it = iterator(this->icont().insert_after(ret_it.get(), *this->create_node_from_it(first)));
865 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
866 //! <b>Requires</b>: prev_p must be a valid iterator of *this.
868 //! <b>Effects</b>: Inserts the range pointed by [il.begin(), il.end()) after prev_p.
870 //! <b>Returns</b>: an iterator to the last inserted element or prev_p if il.begin() == il.end().
872 //! <b>Throws</b>: If memory allocation throws, T's constructor from a
873 //! dereferenced std::initializer_list iterator throws.
875 //! <b>Complexity</b>: Linear to the number of elements inserted.
877 //! <b>Note</b>: Does not affect the validity of iterators and references of
879 iterator insert_after(const_iterator prev_p, std::initializer_list<value_type> il)
881 return insert_after(prev_p, il.begin(), il.end());
884 #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
885 template <class FwdIt>
886 iterator insert_after(const_iterator prev, FwdIt first, FwdIt last
887 , typename container_detail::enable_if_c
888 < !container_detail::is_convertible<FwdIt, size_type>::value
889 && !(container_detail::is_input_iterator<FwdIt>::value
890 || container_detail::is_same<alloc_version, version_1>::value
895 //Optimized allocation and construction
896 insertion_functor func(this->icont(), prev.get());
897 this->allocate_many_and_construct(first, boost::container::iterator_distance(first, last), func);
898 return iterator(func.inserted_first());
902 //! <b>Effects</b>: Removes the first element from the list.
904 //! <b>Throws</b>: Nothing.
906 //! <b>Complexity</b>: Amortized constant time.
909 BOOST_ASSERT(!this->empty());
910 this->icont().pop_front_and_dispose(Destroyer(this->node_alloc()));
913 //! <b>Effects</b>: Erases the element after the element pointed by prev_p
916 //! <b>Returns</b>: the first element remaining beyond the removed elements,
917 //! or end() if no such element exists.
919 //! <b>Throws</b>: Nothing.
921 //! <b>Complexity</b>: Constant.
923 //! <b>Note</b>: Does not invalidate iterators or references to non erased elements.
924 iterator erase_after(const_iterator prev_p)
926 return iterator(this->icont().erase_after_and_dispose(prev_p.get(), Destroyer(this->node_alloc())));
929 //! <b>Effects</b>: Erases the range (before_first, last) from
932 //! <b>Returns</b>: the first element remaining beyond the removed elements,
933 //! or end() if no such element exists.
935 //! <b>Throws</b>: Nothing.
937 //! <b>Complexity</b>: Linear to the number of erased elements.
939 //! <b>Note</b>: Does not invalidate iterators or references to non erased elements.
940 iterator erase_after(const_iterator before_first, const_iterator last)
942 return iterator(this->icont().erase_after_and_dispose(before_first.get(), last.get(), Destroyer(this->node_alloc())));
945 //! <b>Effects</b>: Swaps the contents of *this and x.
947 //! <b>Throws</b>: Nothing.
949 //! <b>Complexity</b>: Linear to the number of elements on *this and x.
951 BOOST_NOEXCEPT_IF( allocator_traits_type::propagate_on_container_swap::value
952 || allocator_traits_type::is_always_equal::value)
954 BOOST_ASSERT(allocator_traits_type::propagate_on_container_swap::value ||
955 allocator_traits_type::is_always_equal::value ||
956 this->get_stored_allocator() == x.get_stored_allocator());
957 AllocHolder::swap(x);
960 //! <b>Effects</b>: Erases all the elements of the list.
962 //! <b>Throws</b>: Nothing.
964 //! <b>Complexity</b>: Linear to the number of elements in the list.
966 { this->icont().clear_and_dispose(Destroyer(this->node_alloc())); }
968 //////////////////////////////////////////////
972 //////////////////////////////////////////////
974 //! <b>Requires</b>: p must point to an element contained
975 //! by the list. x != *this
977 //! <b>Effects</b>: Transfers all the elements of list x to this list, after the
978 //! the element pointed by p. No destructors or copy constructors are called.
980 //! <b>Throws</b>: std::runtime_error if this' allocator and x's allocator
983 //! <b>Complexity</b>: Linear to the elements in x.
985 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of
986 //! this list. Iterators of this list and all the references are not invalidated.
987 void splice_after(const_iterator prev_p, slist& x) BOOST_NOEXCEPT_OR_NOTHROW
989 BOOST_ASSERT(this != &x);
990 BOOST_ASSERT(this->node_alloc() == x.node_alloc());
991 this->icont().splice_after(prev_p.get(), x.icont());
994 //! <b>Requires</b>: p must point to an element contained
995 //! by the list. x != *this
997 //! <b>Effects</b>: Transfers all the elements of list x to this list, after the
998 //! the element pointed by p. No destructors or copy constructors are called.
1000 //! <b>Throws</b>: std::runtime_error if this' allocator and x's allocator
1003 //! <b>Complexity</b>: Linear to the elements in x.
1005 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of
1006 //! this list. Iterators of this list and all the references are not invalidated.
1007 void splice_after(const_iterator prev_p, BOOST_RV_REF(slist) x) BOOST_NOEXCEPT_OR_NOTHROW
1008 { this->splice_after(prev_p, static_cast<slist&>(x)); }
1010 //! <b>Requires</b>: prev_p must be a valid iterator of this.
1011 //! i must point to an element contained in list x.
1012 //! this' allocator and x's allocator shall compare equal.
1014 //! <b>Effects</b>: Transfers the value pointed by i, from list x to this list,
1015 //! after the element pointed by prev_p.
1016 //! If prev_p == prev or prev_p == ++prev, this function is a null operation.
1018 //! <b>Throws</b>: Nothing
1020 //! <b>Complexity</b>: Constant.
1022 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
1023 //! list. Iterators of this list and all the references are not invalidated.
1024 void splice_after(const_iterator prev_p, slist& x, const_iterator prev) BOOST_NOEXCEPT_OR_NOTHROW
1026 BOOST_ASSERT(this->node_alloc() == x.node_alloc());
1027 this->icont().splice_after(prev_p.get(), x.icont(), prev.get());
1030 //! <b>Requires</b>: prev_p must be a valid iterator of this.
1031 //! i must point to an element contained in list x.
1032 //! this' allocator and x's allocator shall compare equal.
1034 //! <b>Effects</b>: Transfers the value pointed by i, from list x to this list,
1035 //! after the element pointed by prev_p.
1036 //! If prev_p == prev or prev_p == ++prev, this function is a null operation.
1038 //! <b>Throws</b>: Nothing
1040 //! <b>Complexity</b>: Constant.
1042 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
1043 //! list. Iterators of this list and all the references are not invalidated.
1044 void splice_after(const_iterator prev_p, BOOST_RV_REF(slist) x, const_iterator prev) BOOST_NOEXCEPT_OR_NOTHROW
1045 { this->splice_after(prev_p, static_cast<slist&>(x), prev); }
1047 //! <b>Requires</b>: prev_p must be a valid iterator of this.
1048 //! before_first and before_last must be valid iterators of x.
1049 //! prev_p must not be contained in [before_first, before_last) range.
1050 //! this' allocator and x's allocator shall compare equal.
1052 //! <b>Effects</b>: Transfers the range [before_first + 1, before_last + 1)
1053 //! from list x to this list, after the element pointed by prev_p.
1055 //! <b>Throws</b>: Nothing
1057 //! <b>Complexity</b>: Linear to the number of transferred elements.
1059 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
1060 //! list. Iterators of this list and all the references are not invalidated.
1061 void splice_after(const_iterator prev_p, slist& x,
1062 const_iterator before_first, const_iterator before_last) BOOST_NOEXCEPT_OR_NOTHROW
1064 BOOST_ASSERT(this->node_alloc() == x.node_alloc());
1065 this->icont().splice_after
1066 (prev_p.get(), x.icont(), before_first.get(), before_last.get());
1069 //! <b>Requires</b>: prev_p must be a valid iterator of this.
1070 //! before_first and before_last must be valid iterators of x.
1071 //! prev_p must not be contained in [before_first, before_last) range.
1072 //! this' allocator and x's allocator shall compare equal.
1074 //! <b>Effects</b>: Transfers the range [before_first + 1, before_last + 1)
1075 //! from list x to this list, after the element pointed by prev_p.
1077 //! <b>Throws</b>: Nothing
1079 //! <b>Complexity</b>: Linear to the number of transferred elements.
1081 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
1082 //! list. Iterators of this list and all the references are not invalidated.
1083 void splice_after(const_iterator prev_p, BOOST_RV_REF(slist) x,
1084 const_iterator before_first, const_iterator before_last) BOOST_NOEXCEPT_OR_NOTHROW
1085 { this->splice_after(prev_p, static_cast<slist&>(x), before_first, before_last); }
1087 //! <b>Requires</b>: prev_p must be a valid iterator of this.
1088 //! before_first and before_last must be valid iterators of x.
1089 //! prev_p must not be contained in [before_first, before_last) range.
1090 //! n == distance(before_first, before_last).
1091 //! this' allocator and x's allocator shall compare equal.
1093 //! <b>Effects</b>: Transfers the range [before_first + 1, before_last + 1)
1094 //! from list x to this list, after the element pointed by prev_p.
1096 //! <b>Throws</b>: Nothing
1098 //! <b>Complexity</b>: Constant.
1100 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
1101 //! list. Iterators of this list and all the references are not invalidated.
1102 void splice_after(const_iterator prev_p, slist& x,
1103 const_iterator before_first, const_iterator before_last,
1104 size_type n) BOOST_NOEXCEPT_OR_NOTHROW
1106 BOOST_ASSERT(this->node_alloc() == x.node_alloc());
1107 this->icont().splice_after
1108 (prev_p.get(), x.icont(), before_first.get(), before_last.get(), n);
1111 //! <b>Requires</b>: prev_p must be a valid iterator of this.
1112 //! before_first and before_last must be valid iterators of x.
1113 //! prev_p must not be contained in [before_first, before_last) range.
1114 //! n == distance(before_first, before_last).
1115 //! this' allocator and x's allocator shall compare equal.
1117 //! <b>Effects</b>: Transfers the range [before_first + 1, before_last + 1)
1118 //! from list x to this list, after the element pointed by prev_p.
1120 //! <b>Throws</b>: Nothing
1122 //! <b>Complexity</b>: Constant.
1124 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
1125 //! list. Iterators of this list and all the references are not invalidated.
1126 void splice_after(const_iterator prev_p, BOOST_RV_REF(slist) x,
1127 const_iterator before_first, const_iterator before_last,
1128 size_type n) BOOST_NOEXCEPT_OR_NOTHROW
1129 { this->splice_after(prev_p, static_cast<slist&>(x), before_first, before_last, n); }
1131 //! <b>Effects</b>: Removes all the elements that compare equal to value.
1133 //! <b>Throws</b>: Nothing.
1135 //! <b>Complexity</b>: Linear time. It performs exactly size() comparisons for equality.
1137 //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1138 //! and iterators to elements that are not removed remain valid.
1139 void remove(const T& value)
1140 { this->remove_if(equal_to_value_type(value)); }
1142 //! <b>Effects</b>: Removes all the elements for which a specified
1143 //! predicate is satisfied.
1145 //! <b>Throws</b>: If pred throws.
1147 //! <b>Complexity</b>: Linear time. It performs exactly size() calls to the predicate.
1149 //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1150 //! and iterators to elements that are not removed remain valid.
1151 template <class Pred>
1152 void remove_if(Pred pred)
1154 typedef value_to_node_compare<Node, Pred> value_to_node_compare_type;
1155 this->icont().remove_and_dispose_if(value_to_node_compare_type(pred), Destroyer(this->node_alloc()));
1158 //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
1159 //! elements that are equal from the list.
1161 //! <b>Throws</b>: If comparison throws.
1163 //! <b>Complexity</b>: Linear time (size()-1 comparisons equality comparisons).
1165 //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1166 //! and iterators to elements that are not removed remain valid.
1168 { this->unique(value_equal()); }
1170 //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
1171 //! elements that satisfy some binary predicate from the list.
1173 //! <b>Throws</b>: If pred throws.
1175 //! <b>Complexity</b>: Linear time (size()-1 comparisons calls to pred()).
1177 //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
1178 //! and iterators to elements that are not removed remain valid.
1179 template <class Pred>
1180 void unique(Pred pred)
1182 typedef value_to_node_compare<Node, Pred> value_to_node_compare_type;
1183 this->icont().unique_and_dispose(value_to_node_compare_type(pred), Destroyer(this->node_alloc()));
1186 //! <b>Requires</b>: The lists x and *this must be distinct.
1188 //! <b>Effects</b>: This function removes all of x's elements and inserts them
1189 //! in order into *this according to std::less<value_type>. The merge is stable;
1190 //! that is, if an element from *this is equivalent to one from x, then the element
1191 //! from *this will precede the one from x.
1193 //! <b>Throws</b>: If comparison throws.
1195 //! <b>Complexity</b>: This function is linear time: it performs at most
1196 //! size() + x.size() - 1 comparisons.
1197 void merge(slist & x)
1198 { this->merge(x, value_less()); }
1200 //! <b>Requires</b>: The lists x and *this must be distinct.
1202 //! <b>Effects</b>: This function removes all of x's elements and inserts them
1203 //! in order into *this according to std::less<value_type>. The merge is stable;
1204 //! that is, if an element from *this is equivalent to one from x, then the element
1205 //! from *this will precede the one from x.
1207 //! <b>Throws</b>: If comparison throws.
1209 //! <b>Complexity</b>: This function is linear time: it performs at most
1210 //! size() + x.size() - 1 comparisons.
1211 void merge(BOOST_RV_REF(slist) x)
1212 { this->merge(static_cast<slist&>(x)); }
1214 //! <b>Requires</b>: p must be a comparison function that induces a strict weak
1215 //! ordering and both *this and x must be sorted according to that ordering
1216 //! The lists x and *this must be distinct.
1218 //! <b>Effects</b>: This function removes all of x's elements and inserts them
1219 //! in order into *this. The merge is stable; that is, if an element from *this is
1220 //! equivalent to one from x, then the element from *this will precede the one from x.
1222 //! <b>Throws</b>: If comp throws.
1224 //! <b>Complexity</b>: This function is linear time: it performs at most
1225 //! size() + x.size() - 1 comparisons.
1227 //! <b>Note</b>: Iterators and references to *this are not invalidated.
1228 template <class StrictWeakOrdering>
1229 void merge(slist& x, StrictWeakOrdering comp)
1231 typedef value_to_node_compare<Node, StrictWeakOrdering> value_to_node_compare_type;
1232 BOOST_ASSERT(this->node_alloc() == x.node_alloc());
1233 this->icont().merge(x.icont(), value_to_node_compare_type(comp));
1236 //! <b>Requires</b>: p must be a comparison function that induces a strict weak
1237 //! ordering and both *this and x must be sorted according to that ordering
1238 //! The lists x and *this must be distinct.
1240 //! <b>Effects</b>: This function removes all of x's elements and inserts them
1241 //! in order into *this. The merge is stable; that is, if an element from *this is
1242 //! equivalent to one from x, then the element from *this will precede the one from x.
1244 //! <b>Throws</b>: If comp throws.
1246 //! <b>Complexity</b>: This function is linear time: it performs at most
1247 //! size() + x.size() - 1 comparisons.
1249 //! <b>Note</b>: Iterators and references to *this are not invalidated.
1250 template <class StrictWeakOrdering>
1251 void merge(BOOST_RV_REF(slist) x, StrictWeakOrdering comp)
1252 { this->merge(static_cast<slist&>(x), comp); }
1254 //! <b>Effects</b>: This function sorts the list *this according to std::less<value_type>.
1255 //! The sort is stable, that is, the relative order of equivalent elements is preserved.
1257 //! <b>Throws</b>: If comparison throws.
1259 //! <b>Notes</b>: Iterators and references are not invalidated.
1261 //! <b>Complexity</b>: The number of comparisons is approximately N log N, where N
1262 //! is the list's size.
1264 { this->sort(value_less()); }
1266 //! <b>Effects</b>: This function sorts the list *this according to std::less<value_type>.
1267 //! The sort is stable, that is, the relative order of equivalent elements is preserved.
1269 //! <b>Throws</b>: If comp throws.
1271 //! <b>Notes</b>: Iterators and references are not invalidated.
1273 //! <b>Complexity</b>: The number of comparisons is approximately N log N, where N
1274 //! is the list's size.
1275 template <class StrictWeakOrdering>
1276 void sort(StrictWeakOrdering comp)
1278 typedef value_to_node_compare<Node, StrictWeakOrdering> value_to_node_compare_type;
1279 // nothing if the slist has length 0 or 1.
1280 if (this->size() < 2)
1282 this->icont().sort(value_to_node_compare_type(comp));
1285 //! <b>Effects</b>: Reverses the order of elements in the list.
1287 //! <b>Throws</b>: Nothing.
1289 //! <b>Complexity</b>: This function is linear time.
1291 //! <b>Note</b>: Iterators and references are not invalidated
1292 void reverse() BOOST_NOEXCEPT_OR_NOTHROW
1293 { this->icont().reverse(); }
1295 //////////////////////////////////////////////
1297 // list compatibility interface
1299 //////////////////////////////////////////////
1301 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
1303 //! <b>Effects</b>: Inserts an object of type T constructed with
1304 //! std::forward<Args>(args)... before p
1306 //! <b>Throws</b>: If memory allocation throws or
1307 //! T's in-place constructor throws.
1309 //! <b>Complexity</b>: Linear to the elements before p
1310 template <class... Args>
1311 iterator emplace(const_iterator p, BOOST_FWD_REF(Args)... args)
1312 { return this->emplace_after(this->previous(p), boost::forward<Args>(args)...); }
1316 #define BOOST_CONTAINER_SLIST_EMPLACE_CODE(N) \
1317 BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
1318 iterator emplace(const_iterator p BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
1320 return this->emplace_after(this->previous(p) BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
1323 BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_SLIST_EMPLACE_CODE)
1324 #undef BOOST_CONTAINER_SLIST_EMPLACE_CODE
1326 #endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
1328 #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
1329 //! <b>Requires</b>: p must be a valid iterator of *this.
1331 //! <b>Effects</b>: Insert a copy of x before p.
1333 //! <b>Returns</b>: an iterator to the inserted element.
1335 //! <b>Throws</b>: If memory allocation throws or x's copy constructor throws.
1337 //! <b>Complexity</b>: Linear to the elements before p.
1338 iterator insert(const_iterator p, const T &x);
1340 //! <b>Requires</b>: p must be a valid iterator of *this.
1342 //! <b>Effects</b>: Insert a new element before p with x's resources.
1344 //! <b>Returns</b>: an iterator to the inserted element.
1346 //! <b>Throws</b>: If memory allocation throws.
1348 //! <b>Complexity</b>: Linear to the elements before p.
1349 iterator insert(const_iterator prev_p, T &&x);
1351 BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(insert, T, iterator, priv_insert, const_iterator, const_iterator)
1354 //! <b>Requires</b>: p must be a valid iterator of *this.
1356 //! <b>Effects</b>: Inserts n copies of x before p.
1358 //! <b>Returns</b>: an iterator to the first inserted element or p if n == 0.
1360 //! <b>Throws</b>: If memory allocation throws or T's copy constructor throws.
1362 //! <b>Complexity</b>: Linear to n plus linear to the elements before p.
1363 iterator insert(const_iterator p, size_type n, const value_type& x)
1365 const_iterator prev(this->previous(p));
1366 this->insert_after(prev, n, x);
1367 return ++iterator(prev.get());
1370 //! <b>Requires</b>: p must be a valid iterator of *this.
1372 //! <b>Effects</b>: Insert a copy of the [first, last) range before p.
1374 //! <b>Returns</b>: an iterator to the first inserted element or p if first == last.
1376 //! <b>Throws</b>: If memory allocation throws, T's constructor from a
1377 //! dereferenced InpIt throws.
1379 //! <b>Complexity</b>: Linear to distance [first, last) plus
1380 //! linear to the elements before p.
1381 template <class InIter>
1382 iterator insert(const_iterator p, InIter first, InIter last)
1384 const_iterator prev(this->previous(p));
1385 this->insert_after(prev, first, last);
1386 return ++iterator(prev.get());
1389 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
1390 //! <b>Requires</b>: p must be a valid iterator of *this.
1392 //! <b>Effects</b>: Insert a copy of the [il.begin(), il.end()) range before p.
1394 //! <b>Returns</b>: an iterator to the first inserted element or p if il.begin() == il.end().
1396 //! <b>Throws</b>: If memory allocation throws, T's constructor from a
1397 //! dereferenced std::initializer_list iterator throws.
1399 //! <b>Complexity</b>: Linear to the range [il.begin(), il.end()) plus
1400 //! linear to the elements before p.
1401 iterator insert(const_iterator p, std::initializer_list<value_type> il)
1403 return insert(p, il.begin(), il.end());
1407 //! <b>Requires</b>: p must be a valid iterator of *this.
1409 //! <b>Effects</b>: Erases the element at p.
1411 //! <b>Throws</b>: Nothing.
1413 //! <b>Complexity</b>: Linear to the number of elements before p.
1414 iterator erase(const_iterator p) BOOST_NOEXCEPT_OR_NOTHROW
1415 { return iterator(this->erase_after(previous(p))); }
1417 //! <b>Requires</b>: first and last must be valid iterator to elements in *this.
1419 //! <b>Effects</b>: Erases the elements pointed by [first, last).
1421 //! <b>Throws</b>: Nothing.
1423 //! <b>Complexity</b>: Linear to the distance between first and last plus
1424 //! linear to the elements before first.
1425 iterator erase(const_iterator first, const_iterator last) BOOST_NOEXCEPT_OR_NOTHROW
1426 { return iterator(this->erase_after(previous(first), last)); }
1428 //! <b>Requires</b>: p must point to an element contained
1429 //! by the list. x != *this. this' allocator and x's allocator shall compare equal
1431 //! <b>Effects</b>: Transfers all the elements of list x to this list, before the
1432 //! the element pointed by p. No destructors or copy constructors are called.
1434 //! <b>Throws</b>: Nothing
1436 //! <b>Complexity</b>: Linear in distance(begin(), p), and linear in x.size().
1438 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of
1439 //! this list. Iterators of this list and all the references are not invalidated.
1440 void splice(const_iterator p, slist& x) BOOST_NOEXCEPT_OR_NOTHROW
1441 { this->splice_after(this->previous(p), x); }
1443 //! <b>Requires</b>: p must point to an element contained
1444 //! by the list. x != *this. this' allocator and x's allocator shall compare equal
1446 //! <b>Effects</b>: Transfers all the elements of list x to this list, before the
1447 //! the element pointed by p. No destructors or copy constructors are called.
1449 //! <b>Throws</b>: Nothing
1451 //! <b>Complexity</b>: Linear in distance(begin(), p), and linear in x.size().
1453 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of
1454 //! this list. Iterators of this list and all the references are not invalidated.
1455 void splice(const_iterator p, BOOST_RV_REF(slist) x) BOOST_NOEXCEPT_OR_NOTHROW
1456 { this->splice(p, static_cast<slist&>(x)); }
1458 //! <b>Requires</b>: p must point to an element contained
1459 //! by this list. i must point to an element contained in list x.
1460 //! this' allocator and x's allocator shall compare equal
1462 //! <b>Effects</b>: Transfers the value pointed by i, from list x to this list,
1463 //! before the element pointed by p. No destructors or copy constructors are called.
1464 //! If p == i or p == ++i, this function is a null operation.
1466 //! <b>Throws</b>: Nothing
1468 //! <b>Complexity</b>: Linear in distance(begin(), p), and in distance(x.begin(), i).
1470 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
1471 //! list. Iterators of this list and all the references are not invalidated.
1472 void splice(const_iterator p, slist& x, const_iterator i) BOOST_NOEXCEPT_OR_NOTHROW
1473 { this->splice_after(this->previous(p), x, this->previous(i)); }
1475 //! <b>Requires</b>: p must point to an element contained
1476 //! by this list. i must point to an element contained in list x.
1477 //! this' allocator and x's allocator shall compare equal.
1479 //! <b>Effects</b>: Transfers the value pointed by i, from list x to this list,
1480 //! before the element pointed by p. No destructors or copy constructors are called.
1481 //! If p == i or p == ++i, this function is a null operation.
1483 //! <b>Throws</b>: Nothing
1485 //! <b>Complexity</b>: Linear in distance(begin(), p), and in distance(x.begin(), i).
1487 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
1488 //! list. Iterators of this list and all the references are not invalidated.
1489 void splice(const_iterator p, BOOST_RV_REF(slist) x, const_iterator i) BOOST_NOEXCEPT_OR_NOTHROW
1490 { this->splice(p, static_cast<slist&>(x), i); }
1492 //! <b>Requires</b>: p must point to an element contained
1493 //! by this list. first and last must point to elements contained in list x.
1495 //! <b>Effects</b>: Transfers the range pointed by first and last from list x to this list,
1496 //! before the element pointed by p. No destructors or copy constructors are called.
1497 //! this' allocator and x's allocator shall compare equal.
1499 //! <b>Throws</b>: Nothing
1501 //! <b>Complexity</b>: Linear in distance(begin(), p), in distance(x.begin(), first),
1502 //! and in distance(first, last).
1504 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
1505 //! list. Iterators of this list and all the references are not invalidated.
1506 void splice(const_iterator p, slist& x, const_iterator first, const_iterator last) BOOST_NOEXCEPT_OR_NOTHROW
1507 { this->splice_after(this->previous(p), x, this->previous(first), this->previous(last)); }
1509 //! <b>Requires</b>: p must point to an element contained
1510 //! by this list. first and last must point to elements contained in list x.
1511 //! this' allocator and x's allocator shall compare equal
1513 //! <b>Effects</b>: Transfers the range pointed by first and last from list x to this list,
1514 //! before the element pointed by p. No destructors or copy constructors are called.
1516 //! <b>Throws</b>: Nothing
1518 //! <b>Complexity</b>: Linear in distance(begin(), p), in distance(x.begin(), first),
1519 //! and in distance(first, last).
1521 //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
1522 //! list. Iterators of this list and all the references are not invalidated.
1523 void splice(const_iterator p, BOOST_RV_REF(slist) x, const_iterator first, const_iterator last) BOOST_NOEXCEPT_OR_NOTHROW
1524 { this->splice(p, static_cast<slist&>(x), first, last); }
1526 //! <b>Effects</b>: Returns true if x and y are equal
1528 //! <b>Complexity</b>: Linear to the number of elements in the container.
1529 friend bool operator==(const slist& x, const slist& y)
1530 { return x.size() == y.size() && ::boost::container::algo_equal(x.begin(), x.end(), y.begin()); }
1532 //! <b>Effects</b>: Returns true if x and y are unequal
1534 //! <b>Complexity</b>: Linear to the number of elements in the container.
1535 friend bool operator!=(const slist& x, const slist& y)
1536 { return !(x == y); }
1538 //! <b>Effects</b>: Returns true if x is less than y
1540 //! <b>Complexity</b>: Linear to the number of elements in the container.
1541 friend bool operator<(const slist& x, const slist& y)
1542 { return ::boost::container::algo_lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); }
1544 //! <b>Effects</b>: Returns true if x is greater than y
1546 //! <b>Complexity</b>: Linear to the number of elements in the container.
1547 friend bool operator>(const slist& x, const slist& y)
1550 //! <b>Effects</b>: Returns true if x is equal or less than y
1552 //! <b>Complexity</b>: Linear to the number of elements in the container.
1553 friend bool operator<=(const slist& x, const slist& y)
1554 { return !(y < x); }
1556 //! <b>Effects</b>: Returns true if x is equal or greater than y
1558 //! <b>Complexity</b>: Linear to the number of elements in the container.
1559 friend bool operator>=(const slist& x, const slist& y)
1560 { return !(x < y); }
1562 //! <b>Effects</b>: x.swap(y)
1564 //! <b>Complexity</b>: Constant.
1565 friend void swap(slist& x, slist& y)
1568 #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
1571 void priv_push_front (const T &x)
1572 { this->insert_after(this->cbefore_begin(), x); }
1574 void priv_push_front (BOOST_RV_REF(T) x)
1575 { this->insert_after(this->cbefore_begin(), ::boost::move(x)); }
1577 bool priv_try_shrink(size_type new_size, const_iterator &last_pos)
1579 typename Icont::iterator end_n(this->icont().end()), cur(this->icont().before_begin()), cur_next;
1580 while (++(cur_next = cur) != end_n && new_size > 0){
1584 last_pos = const_iterator(cur);
1585 if (cur_next != end_n){
1586 this->erase_after(last_pos, const_iterator(end_n));
1595 iterator priv_insert(const_iterator p, BOOST_FWD_REF(U) x)
1596 { return this->insert_after(previous(p), ::boost::forward<U>(x)); }
1599 iterator priv_insert_after(const_iterator prev_p, BOOST_FWD_REF(U) x)
1600 { return iterator(this->icont().insert_after(prev_p.get(), *this->create_node(::boost::forward<U>(x)))); }
1602 class insertion_functor;
1603 friend class insertion_functor;
1605 class insertion_functor
1608 typedef typename Icont::iterator iiterator;
1609 typedef typename Icont::const_iterator iconst_iterator;
1610 const iconst_iterator prev_;
1614 insertion_functor(Icont &icont, typename Icont::const_iterator prev)
1615 : icont_(icont), prev_(prev), ret_(prev.unconst())
1618 void operator()(Node &n)
1620 ret_ = this->icont_.insert_after(prev_, n);
1623 iiterator inserted_first() const
1627 //Functors for member algorithm defaults
1630 bool operator()(const value_type &a, const value_type &b) const
1636 bool operator()(const value_type &a, const value_type &b) const
1640 struct value_equal_to_this
1642 explicit value_equal_to_this(const value_type &ref)
1645 bool operator()(const value_type &val) const
1646 { return m_ref == val; }
1648 const value_type &m_ref;
1650 #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
1655 #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
1659 //!has_trivial_destructor_after_move<> == true_type
1660 //!specialization for optimizations
1661 template <class T, class Allocator>
1662 struct has_trivial_destructor_after_move<boost::container::slist<T, Allocator> >
1664 typedef typename ::boost::container::allocator_traits<Allocator>::pointer pointer;
1665 static const bool value = ::boost::has_trivial_destructor_after_move<Allocator>::value &&
1666 ::boost::has_trivial_destructor_after_move<pointer>::value;
1669 namespace container {
1671 }} //namespace boost{ namespace container {
1673 #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
1675 // Specialization of insert_iterator so that insertions will be constant
1676 // time rather than linear time.
1678 #include <boost/move/detail/std_ns_begin.hpp>
1679 BOOST_CONTAINER_DOC1ST(namespace std {, BOOST_MOVE_STD_NS_BEG)
1681 //! A specialization of insert_iterator
1682 //! that works with slist
1683 template <class T, class Allocator>
1684 class insert_iterator<boost::container::slist<T, Allocator> >
1687 typedef boost::container::slist<T, Allocator> Container;
1688 Container* container;
1689 typename Container::iterator iter;
1692 typedef Container container_type;
1693 typedef output_iterator_tag iterator_category;
1694 typedef void value_type;
1695 typedef void difference_type;
1696 typedef void pointer;
1697 typedef void reference;
1699 insert_iterator(Container& x,
1700 typename Container::iterator i,
1701 bool is_previous = false)
1702 : container(&x), iter(is_previous ? i : x.previous(i)){ }
1704 insert_iterator<Container>&
1705 operator=(const typename Container::value_type& value)
1707 iter = container->insert_after(iter, value);
1710 insert_iterator<Container>& operator*(){ return *this; }
1711 insert_iterator<Container>& operator++(){ return *this; }
1712 insert_iterator<Container>& operator++(int){ return *this; }
1715 BOOST_CONTAINER_DOC1ST( }, BOOST_MOVE_STD_NS_END)
1716 #include <boost/move/detail/std_ns_end.hpp>
1718 #include <boost/container/detail/config_end.hpp>
1720 #endif // BOOST_CONTAINER_SLIST_HPP