////////////////////////////////////////////////////////////////////////////// // // (C) Copyright Ion Gaztanaga 2004-2013. Distributed under the Boost // Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // // See http://www.boost.org/libs/container for documentation. // ////////////////////////////////////////////////////////////////////////////// #ifndef BOOST_CONTAINER_SLIST_HPP #define BOOST_CONTAINER_SLIST_HPP #ifndef BOOST_CONFIG_HPP # include #endif #if defined(BOOST_HAS_PRAGMA_ONCE) # pragma once #endif #include #include // container #include #include //new_allocator #include // container/detail #include //algo_equal(), algo_lexicographical_compare #include #include #include #include #include #include // intrusive #include #include // move #include #include #include // move/detail #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) #include #endif #include // other #include // std #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) #include #endif namespace boost { namespace container { #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED template class slist; namespace container_detail { template struct slist_hook { typedef typename container_detail::bi::make_slist_base_hook , container_detail::bi::link_mode >::type type; }; template struct slist_node : public slist_hook::type { private: slist_node(); public: typedef T value_type; typedef typename slist_hook::type hook_type; T m_data; T &get_data() { return this->m_data; } const T &get_data() const { return this->m_data; } }; template struct iiterator_node_value_type< slist_node > { typedef T type; }; template struct intrusive_slist_type { typedef boost::container::allocator_traits allocator_traits_type; typedef typename allocator_traits_type::value_type value_type; typedef typename boost::intrusive::pointer_traits ::template rebind_pointer::type void_pointer; typedef typename container_detail::slist_node node_type; typedef typename container_detail::bi::make_slist ::type> ,container_detail::bi::constant_time_size , container_detail::bi::size_type >::type container_type; typedef container_type type ; }; } //namespace container_detail { #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED //! An slist is a singly linked list: a list where each element is linked to the next //! element, but not to the previous element. That is, it is a Sequence that //! supports forward but not backward traversal, and (amortized) constant time //! insertion and removal of elements. Slists, like lists, have the important //! property that insertion and splicing do not invalidate iterators to list elements, //! and that even removal invalidates only the iterators that point to the elements //! that are removed. The ordering of iterators may be changed (that is, //! slist::iterator might have a different predecessor or successor after a list //! operation than it did before), but the iterators themselves will not be invalidated //! or made to point to different elements unless that invalidation or mutation is explicit. //! //! The main difference between slist and list is that list's iterators are bidirectional //! iterators, while slist's iterators are forward iterators. This means that slist is //! less versatile than list; frequently, however, bidirectional iterators are //! unnecessary. You should usually use slist unless you actually need the extra //! functionality of list, because singly linked lists are smaller and faster than double //! linked lists. //! //! Important performance note: like every other Sequence, slist defines the member //! functions insert and erase. Using these member functions carelessly, however, can //! result in disastrously slow programs. The problem is that insert's first argument is //! an iterator p, and that it inserts the new element(s) before p. This means that //! insert must find the iterator just before p; this is a constant-time operation //! for list, since list has bidirectional iterators, but for slist it must find that //! iterator by traversing the list from the beginning up to p. In other words: //! insert and erase are slow operations anywhere but near the beginning of the slist. //! //! Slist provides the member functions insert_after and erase_after, which are constant //! time operations: you should always use insert_after and erase_after whenever //! possible. If you find that insert_after and erase_after aren't adequate for your //! needs, and that you often need to use insert and erase in the middle of the list, //! then you should probably use list instead of slist. //! //! \tparam T The type of object that is stored in the list //! \tparam Allocator The allocator used for all internal memory management #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED template > #else template #endif class slist : protected container_detail::node_alloc_holder ::type> { #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED typedef typename container_detail::intrusive_slist_type::type Icont; typedef container_detail::node_alloc_holder AllocHolder; typedef typename AllocHolder::NodePtr NodePtr; typedef typename AllocHolder::NodeAlloc NodeAlloc; typedef typename AllocHolder::ValAlloc ValAlloc; typedef typename AllocHolder::Node Node; typedef container_detail::allocator_destroyer Destroyer; typedef typename AllocHolder::alloc_version alloc_version; typedef boost::container:: allocator_traits allocator_traits_type; typedef boost::container::equal_to_value equal_to_value_type; BOOST_COPYABLE_AND_MOVABLE(slist) typedef container_detail::iterator_from_iiterator iterator_impl; typedef container_detail::iterator_from_iiterator const_iterator_impl; #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED public: ////////////////////////////////////////////// // // types // ////////////////////////////////////////////// typedef T value_type; typedef typename ::boost::container::allocator_traits::pointer pointer; typedef typename ::boost::container::allocator_traits::const_pointer const_pointer; typedef typename ::boost::container::allocator_traits::reference reference; typedef typename ::boost::container::allocator_traits::const_reference const_reference; typedef typename ::boost::container::allocator_traits::size_type size_type; typedef typename ::boost::container::allocator_traits::difference_type difference_type; typedef Allocator allocator_type; typedef BOOST_CONTAINER_IMPDEF(NodeAlloc) stored_allocator_type; typedef BOOST_CONTAINER_IMPDEF(iterator_impl) iterator; typedef BOOST_CONTAINER_IMPDEF(const_iterator_impl) const_iterator; public: ////////////////////////////////////////////// // // construct/copy/destroy // ////////////////////////////////////////////// //! Effects: Constructs a list taking the allocator as parameter. //! //! Throws: If allocator_type's copy constructor throws. //! //! Complexity: Constant. slist() : AllocHolder() {} //! Effects: Constructs a list taking the allocator as parameter. //! //! Throws: Nothing //! //! Complexity: Constant. explicit slist(const allocator_type& a) BOOST_NOEXCEPT_OR_NOTHROW : AllocHolder(a) {} //! Effects: Constructs a list //! and inserts n value-initialized value_types. //! //! Throws: If allocator_type's default constructor //! throws or T's default or copy constructor throws. //! //! Complexity: Linear to n. explicit slist(size_type n) : AllocHolder(allocator_type()) { this->resize(n); } //! Effects: Constructs a list that will use a copy of allocator a //! and inserts n copies of value. //! //! Throws: If allocator_type's default constructor //! throws or T's default or copy constructor throws. //! //! Complexity: Linear to n. slist(size_type n, const allocator_type &a) : AllocHolder(a) { this->resize(n); } //! Effects: Constructs a list that will use a copy of allocator a //! and inserts n copies of value. //! //! Throws: If allocator_type's default constructor //! throws or T's default or copy constructor throws. //! //! Complexity: Linear to n. explicit slist(size_type n, const value_type& x, const allocator_type& a = allocator_type()) : AllocHolder(a) { this->insert_after(this->cbefore_begin(), n, x); } //! Effects: Constructs a list that will use a copy of allocator a //! and inserts a copy of the range [first, last) in the list. //! //! Throws: If allocator_type's default constructor //! throws or T's constructor taking a dereferenced InIt throws. //! //! Complexity: Linear to the range [first, last). template slist(InpIt first, InpIt last, const allocator_type& a = allocator_type()) : AllocHolder(a) { this->insert_after(this->cbefore_begin(), first, last); } #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) //! Effects: Constructs a list that will use a copy of allocator a //! and inserts a copy of the range [il.begin(), il.end()) in the list. //! //! Throws: If allocator_type's default constructor //! throws or T's constructor taking a dereferenced std::initializer_list iterator throws. //! //! Complexity: Linear to the range [il.begin(), il.end()). slist(std::initializer_list il, const allocator_type& a = allocator_type()) : AllocHolder(a) { this->insert_after(this->cbefore_begin(), il.begin(), il.end()); } #endif //! Effects: Copy constructs a list. //! //! Postcondition: x == *this. //! //! Throws: If allocator_type's default constructor //! //! Complexity: Linear to the elements x contains. slist(const slist& x) : AllocHolder(x) { this->insert_after(this->cbefore_begin(), x.begin(), x.end()); } //! Effects: Move constructor. Moves x's resources to *this. //! //! Throws: If allocator_type's copy constructor throws. //! //! Complexity: Constant. slist(BOOST_RV_REF(slist) x) : AllocHolder(BOOST_MOVE_BASE(AllocHolder, x)) {} //! Effects: Copy constructs a list using the specified allocator. //! //! Postcondition: x == *this. //! //! Throws: If allocator_type's default constructor //! //! Complexity: Linear to the elements x contains. slist(const slist& x, const allocator_type &a) : AllocHolder(a) { this->insert_after(this->cbefore_begin(), x.begin(), x.end()); } //! Effects: Move constructor using the specified allocator. //! Moves x's resources to *this. //! //! Throws: If allocation or value_type's copy constructor throws. //! //! Complexity: Constant if a == x.get_allocator(), linear otherwise. slist(BOOST_RV_REF(slist) x, const allocator_type &a) : AllocHolder(a) { if(this->node_alloc() == x.node_alloc()){ this->icont().swap(x.icont()); } else{ this->insert_after(this->cbefore_begin(), boost::make_move_iterator(x.begin()), boost::make_move_iterator(x.end())); } } //! Effects: Destroys the list. All stored values are destroyed //! and used memory is deallocated. //! //! Throws: Nothing. //! //! Complexity: Linear to the number of elements. ~slist() BOOST_NOEXCEPT_OR_NOTHROW {} //AllocHolder clears the slist //! Effects: Makes *this contain the same elements as x. //! //! Postcondition: this->size() == x.size(). *this contains a copy //! of each of x's elements. //! //! Throws: If memory allocation throws or T's copy constructor throws. //! //! Complexity: Linear to the number of elements in x. slist& operator= (BOOST_COPY_ASSIGN_REF(slist) x) { if (&x != this){ NodeAlloc &this_alloc = this->node_alloc(); const NodeAlloc &x_alloc = x.node_alloc(); container_detail::bool_ flag; if(flag && this_alloc != x_alloc){ this->clear(); } this->AllocHolder::copy_assign_alloc(x); this->assign(x.begin(), x.end()); } return *this; } //! Effects: Makes *this contain the same elements as x. //! //! Postcondition: this->size() == x.size(). *this contains a copy //! of each of x's elements. //! //! Throws: If allocator_traits_type::propagate_on_container_move_assignment //! is false and (allocation throws or value_type's move constructor throws) //! //! Complexity: Constant if allocator_traits_type:: //! propagate_on_container_move_assignment is true or //! this->get>allocator() == x.get_allocator(). Linear otherwise. slist& operator= (BOOST_RV_REF(slist) x) BOOST_NOEXCEPT_IF(allocator_traits_type::propagate_on_container_move_assignment::value || allocator_traits_type::is_always_equal::value) { BOOST_ASSERT(this != &x); NodeAlloc &this_alloc = this->node_alloc(); NodeAlloc &x_alloc = x.node_alloc(); const bool propagate_alloc = allocator_traits_type:: propagate_on_container_move_assignment::value; const bool allocators_equal = this_alloc == x_alloc; (void)allocators_equal; //Resources can be transferred if both allocators are //going to be equal after this function (either propagated or already equal) if(propagate_alloc || allocators_equal){ //Destroy this->clear(); //Move allocator if needed this->AllocHolder::move_assign_alloc(x); //Obtain resources this->icont() = boost::move(x.icont()); } //Else do a one by one move else{ this->assign( boost::make_move_iterator(x.begin()) , boost::make_move_iterator(x.end())); } return *this; } #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) //! Effects: Makes *this contain the same elements as in il. //! //! Postcondition: this->size() == il.size(). *this contains a copy //! of each of il's elements. //! //! Throws: If allocator_traits_type::propagate_on_container_move_assignment //! is false and (allocation throws or value_type's move constructor throws) slist& operator=(std::initializer_list il) { assign(il.begin(), il.end()); return *this; } #endif //! Effects: Assigns the n copies of val to *this. //! //! Throws: If memory allocation throws or T's copy constructor throws. //! //! Complexity: Linear to n. void assign(size_type n, const T& val) { typedef constant_iterator cvalue_iterator; return this->assign(cvalue_iterator(val, n), cvalue_iterator()); } //! Effects: Assigns the range [first, last) to *this. //! //! Throws: If memory allocation throws or //! T's constructor from dereferencing InpIt throws. //! //! Complexity: Linear to n. template void assign(InpIt first, InpIt last #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED) , typename container_detail::enable_if_c < !container_detail::is_convertible::value >::type * = 0 #endif ) { iterator end_n(this->end()); iterator prev(this->before_begin()); iterator node(this->begin()); while (node != end_n && first != last){ *node = *first; prev = node; ++node; ++first; } if (first != last) this->insert_after(prev, first, last); else this->erase_after(prev, end_n); } #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) //! Effects: Assigns the range [il.begin(), il.end()) to *this. //! //! Throws: If memory allocation throws or //! T's constructor from dereferencing std::initializer_list iterator throws. //! //! Complexity: Linear to range [il.begin(), il.end()). void assign(std::initializer_list il) { assign(il.begin(), il.end()); } #endif //! Effects: Returns a copy of the internal allocator. //! //! Throws: If allocator's copy constructor throws. //! //! Complexity: Constant. allocator_type get_allocator() const BOOST_NOEXCEPT_OR_NOTHROW { return allocator_type(this->node_alloc()); } //! Effects: Returns a reference to the internal allocator. //! //! Throws: Nothing //! //! Complexity: Constant. //! //! Note: Non-standard extension. stored_allocator_type &get_stored_allocator() BOOST_NOEXCEPT_OR_NOTHROW { return this->node_alloc(); } //! Effects: Returns a reference to the internal allocator. //! //! Throws: Nothing //! //! Complexity: Constant. //! //! Note: Non-standard extension. const stored_allocator_type &get_stored_allocator() const BOOST_NOEXCEPT_OR_NOTHROW { return this->node_alloc(); } ////////////////////////////////////////////// // // iterators // ////////////////////////////////////////////// //! Effects: Returns a non-dereferenceable iterator that, //! when incremented, yields begin(). This iterator may be used //! as the argument to insert_after, erase_after, etc. //! //! Throws: Nothing. //! //! Complexity: Constant. iterator before_begin() BOOST_NOEXCEPT_OR_NOTHROW { return iterator(end()); } //! Effects: Returns a non-dereferenceable const_iterator //! that, when incremented, yields begin(). This iterator may be used //! as the argument to insert_after, erase_after, etc. //! //! Throws: Nothing. //! //! Complexity: Constant. const_iterator before_begin() const BOOST_NOEXCEPT_OR_NOTHROW { return this->cbefore_begin(); } //! Effects: Returns an iterator to the first element contained in the list. //! //! Throws: Nothing. //! //! Complexity: Constant. iterator begin() BOOST_NOEXCEPT_OR_NOTHROW { return iterator(this->icont().begin()); } //! Effects: Returns a const_iterator to the first element contained in the list. //! //! Throws: Nothing. //! //! Complexity: Constant. const_iterator begin() const BOOST_NOEXCEPT_OR_NOTHROW { return this->cbegin(); } //! Effects: Returns an iterator to the end of the list. //! //! Throws: Nothing. //! //! Complexity: Constant. iterator end() BOOST_NOEXCEPT_OR_NOTHROW { return iterator(this->icont().end()); } //! Effects: Returns a const_iterator to the end of the list. //! //! Throws: Nothing. //! //! Complexity: Constant. const_iterator end() const BOOST_NOEXCEPT_OR_NOTHROW { return this->cend(); } //! Effects: Returns a non-dereferenceable const_iterator //! that, when incremented, yields begin(). This iterator may be used //! as the argument to insert_after, erase_after, etc. //! //! Throws: Nothing. //! //! Complexity: Constant. const_iterator cbefore_begin() const BOOST_NOEXCEPT_OR_NOTHROW { return const_iterator(end()); } //! Effects: Returns a const_iterator to the first element contained in the list. //! //! Throws: Nothing. //! //! Complexity: Constant. const_iterator cbegin() const BOOST_NOEXCEPT_OR_NOTHROW { return const_iterator(this->non_const_icont().begin()); } //! Effects: Returns a const_iterator to the end of the list. //! //! Throws: Nothing. //! //! Complexity: Constant. const_iterator cend() const BOOST_NOEXCEPT_OR_NOTHROW { return const_iterator(this->non_const_icont().end()); } //! Returns: The iterator to the element before i in the sequence. //! Returns the end-iterator, if either i is the begin-iterator or the //! sequence is empty. //! //! Throws: Nothing. //! //! Complexity: Linear to the number of elements before i. //! //! Note: Non-standard extension. iterator previous(iterator p) BOOST_NOEXCEPT_OR_NOTHROW { return iterator(this->icont().previous(p.get())); } //! Returns: The const_iterator to the element before i in the sequence. //! Returns the end-const_iterator, if either i is the begin-const_iterator or //! the sequence is empty. //! //! Throws: Nothing. //! //! Complexity: Linear to the number of elements before i. //! //! Note: Non-standard extension. const_iterator previous(const_iterator p) { return const_iterator(this->icont().previous(p.get())); } ////////////////////////////////////////////// // // capacity // ////////////////////////////////////////////// //! Effects: Returns true if the list contains no elements. //! //! Throws: Nothing. //! //! Complexity: Constant. bool empty() const { return !this->size(); } //! Effects: Returns the number of the elements contained in the list. //! //! Throws: Nothing. //! //! Complexity: Constant. size_type size() const { return this->icont().size(); } //! Effects: Returns the largest possible size of the list. //! //! Throws: Nothing. //! //! Complexity: Constant. size_type max_size() const { return AllocHolder::max_size(); } //! Effects: Inserts or erases elements at the end such that //! the size becomes n. New elements are value initialized. //! //! Throws: If memory allocation throws, or T's copy constructor throws. //! //! Complexity: Linear to the difference between size() and new_size. void resize(size_type new_size) { const_iterator last_pos; if(!priv_try_shrink(new_size, last_pos)){ typedef value_init_construct_iterator value_init_iterator; this->insert_after(last_pos, value_init_iterator(new_size - this->size()), value_init_iterator()); } } //! Effects: Inserts or erases elements at the end such that //! the size becomes n. New elements are copy constructed from x. //! //! Throws: If memory allocation throws, or T's copy constructor throws. //! //! Complexity: Linear to the difference between size() and new_size. void resize(size_type new_size, const T& x) { const_iterator last_pos; if(!priv_try_shrink(new_size, last_pos)){ this->insert_after(last_pos, new_size, x); } } ////////////////////////////////////////////// // // element access // ////////////////////////////////////////////// //! Requires: !empty() //! //! Effects: Returns a reference to the first element //! from the beginning of the container. //! //! Throws: Nothing. //! //! Complexity: Constant. reference front() { return *this->begin(); } //! Requires: !empty() //! //! Effects: Returns a const reference to the first element //! from the beginning of the container. //! //! Throws: Nothing. //! //! Complexity: Constant. const_reference front() const { return *this->begin(); } ////////////////////////////////////////////// // // modifiers // ////////////////////////////////////////////// #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED) //! Effects: Inserts an object of type T constructed with //! std::forward(args)... in the front of the list //! //! Throws: If memory allocation throws or //! T's copy constructor throws. //! //! Complexity: Amortized constant time. template void emplace_front(BOOST_FWD_REF(Args)... args) { this->emplace_after(this->cbefore_begin(), boost::forward(args)...); } //! Effects: Inserts an object of type T constructed with //! std::forward(args)... after prev //! //! Throws: If memory allocation throws or //! T's in-place constructor throws. //! //! Complexity: Constant template iterator emplace_after(const_iterator prev, BOOST_FWD_REF(Args)... args) { NodePtr pnode(AllocHolder::create_node(boost::forward(args)...)); return iterator(this->icont().insert_after(prev.get(), *pnode)); } #else // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) #define BOOST_CONTAINER_SLIST_EMPLACE_CODE(N) \ BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \ void emplace_front(BOOST_MOVE_UREF##N)\ { this->emplace_after(this->cbefore_begin() BOOST_MOVE_I##N BOOST_MOVE_FWD##N);}\ \ BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \ iterator emplace_after(const_iterator p BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\ {\ NodePtr pnode (AllocHolder::create_node(BOOST_MOVE_FWD##N));\ return iterator(this->icont().insert_after(p.get(), *pnode));\ }\ // BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_SLIST_EMPLACE_CODE) #undef BOOST_CONTAINER_SLIST_EMPLACE_CODE #endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED) //! Effects: Inserts a copy of x at the beginning of the list. //! //! Throws: If memory allocation throws or //! T's copy constructor throws. //! //! Complexity: Amortized constant time. void push_front(const T &x); //! Effects: Constructs a new element in the beginning of the list //! and moves the resources of x to this new element. //! //! Throws: If memory allocation throws. //! //! Complexity: Amortized constant time. void push_front(T &&x); #else BOOST_MOVE_CONVERSION_AWARE_CATCH(push_front, T, void, priv_push_front) #endif #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED) //! Requires: p must be a valid iterator of *this. //! //! Effects: Inserts a copy of the value after prev_p. //! //! Returns: An iterator to the inserted element. //! //! Throws: If memory allocation throws or T's copy constructor throws. //! //! Complexity: Amortized constant time. //! //! Note: Does not affect the validity of iterators and references of //! previous values. iterator insert_after(const_iterator prev_p, const T &x); //! Requires: prev_p must be a valid iterator of *this. //! //! Effects: Inserts a move constructed copy object from the value after the //! p pointed by prev_p. //! //! Returns: An iterator to the inserted element. //! //! Throws: If memory allocation throws. //! //! Complexity: Amortized constant time. //! //! Note: Does not affect the validity of iterators and references of //! previous values. iterator insert_after(const_iterator prev_p, T &&x); #else BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(insert_after, T, iterator, priv_insert_after, const_iterator, const_iterator) #endif //! Requires: prev_p must be a valid iterator of *this. //! //! Effects: Inserts n copies of x after prev_p. //! //! Returns: an iterator to the last inserted element or prev_p if n is 0. //! //! Throws: If memory allocation throws or T's copy constructor throws. //! //! //! Complexity: Linear to n. //! //! Note: Does not affect the validity of iterators and references of //! previous values. iterator insert_after(const_iterator prev_p, size_type n, const value_type& x) { typedef constant_iterator cvalue_iterator; return this->insert_after(prev_p, cvalue_iterator(x, n), cvalue_iterator()); } //! Requires: prev_p must be a valid iterator of *this. //! //! Effects: Inserts the range pointed by [first, last) after prev_p. //! //! Returns: an iterator to the last inserted element or prev_p if first == last. //! //! Throws: If memory allocation throws, T's constructor from a //! dereferenced InpIt throws. //! //! Complexity: Linear to the number of elements inserted. //! //! Note: Does not affect the validity of iterators and references of //! previous values. template iterator insert_after(const_iterator prev_p, InpIt first, InpIt last #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED) , typename container_detail::enable_if_c < !container_detail::is_convertible::value && (container_detail::is_input_iterator::value || container_detail::is_same::value ) >::type * = 0 #endif ) { iterator ret_it(prev_p.get()); for (; first != last; ++first){ ret_it = iterator(this->icont().insert_after(ret_it.get(), *this->create_node_from_it(first))); } return ret_it; } #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) //! Requires: prev_p must be a valid iterator of *this. //! //! Effects: Inserts the range pointed by [il.begin(), il.end()) after prev_p. //! //! Returns: an iterator to the last inserted element or prev_p if il.begin() == il.end(). //! //! Throws: If memory allocation throws, T's constructor from a //! dereferenced std::initializer_list iterator throws. //! //! Complexity: Linear to the number of elements inserted. //! //! Note: Does not affect the validity of iterators and references of //! previous values. iterator insert_after(const_iterator prev_p, std::initializer_list il) { return insert_after(prev_p, il.begin(), il.end()); } #endif #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED) template iterator insert_after(const_iterator prev, FwdIt first, FwdIt last , typename container_detail::enable_if_c < !container_detail::is_convertible::value && !(container_detail::is_input_iterator::value || container_detail::is_same::value ) >::type * = 0 ) { //Optimized allocation and construction insertion_functor func(this->icont(), prev.get()); this->allocate_many_and_construct(first, boost::container::iterator_distance(first, last), func); return iterator(func.inserted_first()); } #endif //! Effects: Removes the first element from the list. //! //! Throws: Nothing. //! //! Complexity: Amortized constant time. void pop_front() { this->icont().pop_front_and_dispose(Destroyer(this->node_alloc())); } //! Effects: Erases the element after the element pointed by prev_p //! of the list. //! //! Returns: the first element remaining beyond the removed elements, //! or end() if no such element exists. //! //! Throws: Nothing. //! //! Complexity: Constant. //! //! Note: Does not invalidate iterators or references to non erased elements. iterator erase_after(const_iterator prev_p) { return iterator(this->icont().erase_after_and_dispose(prev_p.get(), Destroyer(this->node_alloc()))); } //! Effects: Erases the range (before_first, last) from //! the list. //! //! Returns: the first element remaining beyond the removed elements, //! or end() if no such element exists. //! //! Throws: Nothing. //! //! Complexity: Linear to the number of erased elements. //! //! Note: Does not invalidate iterators or references to non erased elements. iterator erase_after(const_iterator before_first, const_iterator last) { return iterator(this->icont().erase_after_and_dispose(before_first.get(), last.get(), Destroyer(this->node_alloc()))); } //! Effects: Swaps the contents of *this and x. //! //! Throws: Nothing. //! //! Complexity: Linear to the number of elements on *this and x. void swap(slist& x) BOOST_NOEXCEPT_IF( allocator_traits_type::propagate_on_container_swap::value || allocator_traits_type::is_always_equal::value) { AllocHolder::swap(x); } //! Effects: Erases all the elements of the list. //! //! Throws: Nothing. //! //! Complexity: Linear to the number of elements in the list. void clear() { this->icont().clear_and_dispose(Destroyer(this->node_alloc())); } ////////////////////////////////////////////// // // slist operations // ////////////////////////////////////////////// //! Requires: p must point to an element contained //! by the list. x != *this //! //! Effects: Transfers all the elements of list x to this list, after the //! the element pointed by p. No destructors or copy constructors are called. //! //! Throws: std::runtime_error if this' allocator and x's allocator //! are not equal. //! //! Complexity: Linear to the elements in x. //! //! Note: Iterators of values obtained from list x now point to elements of //! this list. Iterators of this list and all the references are not invalidated. void splice_after(const_iterator prev_p, slist& x) BOOST_NOEXCEPT_OR_NOTHROW { BOOST_ASSERT(this != &x); BOOST_ASSERT(this->node_alloc() == x.node_alloc()); this->icont().splice_after(prev_p.get(), x.icont()); } //! Requires: p must point to an element contained //! by the list. x != *this //! //! Effects: Transfers all the elements of list x to this list, after the //! the element pointed by p. No destructors or copy constructors are called. //! //! Throws: std::runtime_error if this' allocator and x's allocator //! are not equal. //! //! Complexity: Linear to the elements in x. //! //! Note: Iterators of values obtained from list x now point to elements of //! this list. Iterators of this list and all the references are not invalidated. void splice_after(const_iterator prev_p, BOOST_RV_REF(slist) x) BOOST_NOEXCEPT_OR_NOTHROW { this->splice_after(prev_p, static_cast(x)); } //! Requires: prev_p must be a valid iterator of this. //! i must point to an element contained in list x. //! this' allocator and x's allocator shall compare equal. //! //! Effects: Transfers the value pointed by i, from list x to this list, //! after the element pointed by prev_p. //! If prev_p == prev or prev_p == ++prev, this function is a null operation. //! //! Throws: Nothing //! //! Complexity: Constant. //! //! Note: Iterators of values obtained from list x now point to elements of this //! list. Iterators of this list and all the references are not invalidated. void splice_after(const_iterator prev_p, slist& x, const_iterator prev) BOOST_NOEXCEPT_OR_NOTHROW { BOOST_ASSERT(this->node_alloc() == x.node_alloc()); this->icont().splice_after(prev_p.get(), x.icont(), prev.get()); } //! Requires: prev_p must be a valid iterator of this. //! i must point to an element contained in list x. //! this' allocator and x's allocator shall compare equal. //! //! Effects: Transfers the value pointed by i, from list x to this list, //! after the element pointed by prev_p. //! If prev_p == prev or prev_p == ++prev, this function is a null operation. //! //! Throws: Nothing //! //! Complexity: Constant. //! //! Note: Iterators of values obtained from list x now point to elements of this //! list. Iterators of this list and all the references are not invalidated. void splice_after(const_iterator prev_p, BOOST_RV_REF(slist) x, const_iterator prev) BOOST_NOEXCEPT_OR_NOTHROW { this->splice_after(prev_p, static_cast(x), prev); } //! Requires: prev_p must be a valid iterator of this. //! before_first and before_last must be valid iterators of x. //! prev_p must not be contained in [before_first, before_last) range. //! this' allocator and x's allocator shall compare equal. //! //! Effects: Transfers the range [before_first + 1, before_last + 1) //! from list x to this list, after the element pointed by prev_p. //! //! Throws: Nothing //! //! Complexity: Linear to the number of transferred elements. //! //! Note: Iterators of values obtained from list x now point to elements of this //! list. Iterators of this list and all the references are not invalidated. void splice_after(const_iterator prev_p, slist& x, const_iterator before_first, const_iterator before_last) BOOST_NOEXCEPT_OR_NOTHROW { BOOST_ASSERT(this->node_alloc() == x.node_alloc()); this->icont().splice_after (prev_p.get(), x.icont(), before_first.get(), before_last.get()); } //! Requires: prev_p must be a valid iterator of this. //! before_first and before_last must be valid iterators of x. //! prev_p must not be contained in [before_first, before_last) range. //! this' allocator and x's allocator shall compare equal. //! //! Effects: Transfers the range [before_first + 1, before_last + 1) //! from list x to this list, after the element pointed by prev_p. //! //! Throws: Nothing //! //! Complexity: Linear to the number of transferred elements. //! //! Note: Iterators of values obtained from list x now point to elements of this //! list. Iterators of this list and all the references are not invalidated. void splice_after(const_iterator prev_p, BOOST_RV_REF(slist) x, const_iterator before_first, const_iterator before_last) BOOST_NOEXCEPT_OR_NOTHROW { this->splice_after(prev_p, static_cast(x), before_first, before_last); } //! Requires: prev_p must be a valid iterator of this. //! before_first and before_last must be valid iterators of x. //! prev_p must not be contained in [before_first, before_last) range. //! n == distance(before_first, before_last). //! this' allocator and x's allocator shall compare equal. //! //! Effects: Transfers the range [before_first + 1, before_last + 1) //! from list x to this list, after the element pointed by prev_p. //! //! Throws: Nothing //! //! Complexity: Constant. //! //! Note: Iterators of values obtained from list x now point to elements of this //! list. Iterators of this list and all the references are not invalidated. void splice_after(const_iterator prev_p, slist& x, const_iterator before_first, const_iterator before_last, size_type n) BOOST_NOEXCEPT_OR_NOTHROW { BOOST_ASSERT(this->node_alloc() == x.node_alloc()); this->icont().splice_after (prev_p.get(), x.icont(), before_first.get(), before_last.get(), n); } //! Requires: prev_p must be a valid iterator of this. //! before_first and before_last must be valid iterators of x. //! prev_p must not be contained in [before_first, before_last) range. //! n == distance(before_first, before_last). //! this' allocator and x's allocator shall compare equal. //! //! Effects: Transfers the range [before_first + 1, before_last + 1) //! from list x to this list, after the element pointed by prev_p. //! //! Throws: Nothing //! //! Complexity: Constant. //! //! Note: Iterators of values obtained from list x now point to elements of this //! list. Iterators of this list and all the references are not invalidated. void splice_after(const_iterator prev_p, BOOST_RV_REF(slist) x, const_iterator before_first, const_iterator before_last, size_type n) BOOST_NOEXCEPT_OR_NOTHROW { this->splice_after(prev_p, static_cast(x), before_first, before_last, n); } //! Effects: Removes all the elements that compare equal to value. //! //! Throws: Nothing. //! //! Complexity: Linear time. It performs exactly size() comparisons for equality. //! //! Note: The relative order of elements that are not removed is unchanged, //! and iterators to elements that are not removed remain valid. void remove(const T& value) { this->remove_if(equal_to_value_type(value)); } //! Effects: Removes all the elements for which a specified //! predicate is satisfied. //! //! Throws: If pred throws. //! //! Complexity: Linear time. It performs exactly size() calls to the predicate. //! //! Note: The relative order of elements that are not removed is unchanged, //! and iterators to elements that are not removed remain valid. template void remove_if(Pred pred) { typedef value_to_node_compare value_to_node_compare_type; this->icont().remove_and_dispose_if(value_to_node_compare_type(pred), Destroyer(this->node_alloc())); } //! Effects: Removes adjacent duplicate elements or adjacent //! elements that are equal from the list. //! //! Throws: If comparison throws. //! //! Complexity: Linear time (size()-1 comparisons equality comparisons). //! //! Note: The relative order of elements that are not removed is unchanged, //! and iterators to elements that are not removed remain valid. void unique() { this->unique(value_equal()); } //! Effects: Removes adjacent duplicate elements or adjacent //! elements that satisfy some binary predicate from the list. //! //! Throws: If pred throws. //! //! Complexity: Linear time (size()-1 comparisons calls to pred()). //! //! Note: The relative order of elements that are not removed is unchanged, //! and iterators to elements that are not removed remain valid. template void unique(Pred pred) { typedef value_to_node_compare value_to_node_compare_type; this->icont().unique_and_dispose(value_to_node_compare_type(pred), Destroyer(this->node_alloc())); } //! Requires: The lists x and *this must be distinct. //! //! Effects: This function removes all of x's elements and inserts them //! in order into *this according to std::less. The merge is stable; //! that is, if an element from *this is equivalent to one from x, then the element //! from *this will precede the one from x. //! //! Throws: If comparison throws. //! //! Complexity: This function is linear time: it performs at most //! size() + x.size() - 1 comparisons. void merge(slist & x) { this->merge(x, value_less()); } //! Requires: The lists x and *this must be distinct. //! //! Effects: This function removes all of x's elements and inserts them //! in order into *this according to std::less. The merge is stable; //! that is, if an element from *this is equivalent to one from x, then the element //! from *this will precede the one from x. //! //! Throws: If comparison throws. //! //! Complexity: This function is linear time: it performs at most //! size() + x.size() - 1 comparisons. void merge(BOOST_RV_REF(slist) x) { this->merge(static_cast(x)); } //! Requires: p must be a comparison function that induces a strict weak //! ordering and both *this and x must be sorted according to that ordering //! The lists x and *this must be distinct. //! //! Effects: This function removes all of x's elements and inserts them //! in order into *this. The merge is stable; that is, if an element from *this is //! equivalent to one from x, then the element from *this will precede the one from x. //! //! Throws: If comp throws. //! //! Complexity: This function is linear time: it performs at most //! size() + x.size() - 1 comparisons. //! //! Note: Iterators and references to *this are not invalidated. template void merge(slist& x, StrictWeakOrdering comp) { typedef value_to_node_compare value_to_node_compare_type; BOOST_ASSERT(this->node_alloc() == x.node_alloc()); this->icont().merge(x.icont(), value_to_node_compare_type(comp)); } //! Requires: p must be a comparison function that induces a strict weak //! ordering and both *this and x must be sorted according to that ordering //! The lists x and *this must be distinct. //! //! Effects: This function removes all of x's elements and inserts them //! in order into *this. The merge is stable; that is, if an element from *this is //! equivalent to one from x, then the element from *this will precede the one from x. //! //! Throws: If comp throws. //! //! Complexity: This function is linear time: it performs at most //! size() + x.size() - 1 comparisons. //! //! Note: Iterators and references to *this are not invalidated. template void merge(BOOST_RV_REF(slist) x, StrictWeakOrdering comp) { this->merge(static_cast(x), comp); } //! Effects: This function sorts the list *this according to std::less. //! The sort is stable, that is, the relative order of equivalent elements is preserved. //! //! Throws: If comparison throws. //! //! Notes: Iterators and references are not invalidated. //! //! Complexity: The number of comparisons is approximately N log N, where N //! is the list's size. void sort() { this->sort(value_less()); } //! Effects: This function sorts the list *this according to std::less. //! The sort is stable, that is, the relative order of equivalent elements is preserved. //! //! Throws: If comp throws. //! //! Notes: Iterators and references are not invalidated. //! //! Complexity: The number of comparisons is approximately N log N, where N //! is the list's size. template void sort(StrictWeakOrdering comp) { typedef value_to_node_compare value_to_node_compare_type; // nothing if the slist has length 0 or 1. if (this->size() < 2) return; this->icont().sort(value_to_node_compare_type(comp)); } //! Effects: Reverses the order of elements in the list. //! //! Throws: Nothing. //! //! Complexity: This function is linear time. //! //! Note: Iterators and references are not invalidated void reverse() BOOST_NOEXCEPT_OR_NOTHROW { this->icont().reverse(); } ////////////////////////////////////////////// // // list compatibility interface // ////////////////////////////////////////////// #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED) //! Effects: Inserts an object of type T constructed with //! std::forward(args)... before p //! //! Throws: If memory allocation throws or //! T's in-place constructor throws. //! //! Complexity: Linear to the elements before p template iterator emplace(const_iterator p, BOOST_FWD_REF(Args)... args) { return this->emplace_after(this->previous(p), boost::forward(args)...); } #else #define BOOST_CONTAINER_SLIST_EMPLACE_CODE(N) \ BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \ iterator emplace(const_iterator p BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\ {\ return this->emplace_after(this->previous(p) BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\ }\ // BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_SLIST_EMPLACE_CODE) #undef BOOST_CONTAINER_SLIST_EMPLACE_CODE #endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) #if defined(BOOST_CONTAINER_DOXYGEN_INVOKED) //! Requires: p must be a valid iterator of *this. //! //! Effects: Insert a copy of x before p. //! //! Returns: an iterator to the inserted element. //! //! Throws: If memory allocation throws or x's copy constructor throws. //! //! Complexity: Linear to the elements before p. iterator insert(const_iterator p, const T &x); //! Requires: p must be a valid iterator of *this. //! //! Effects: Insert a new element before p with x's resources. //! //! Returns: an iterator to the inserted element. //! //! Throws: If memory allocation throws. //! //! Complexity: Linear to the elements before p. iterator insert(const_iterator prev_p, T &&x); #else BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(insert, T, iterator, priv_insert, const_iterator, const_iterator) #endif //! Requires: p must be a valid iterator of *this. //! //! Effects: Inserts n copies of x before p. //! //! Returns: an iterator to the first inserted element or p if n == 0. //! //! Throws: If memory allocation throws or T's copy constructor throws. //! //! Complexity: Linear to n plus linear to the elements before p. iterator insert(const_iterator p, size_type n, const value_type& x) { const_iterator prev(this->previous(p)); this->insert_after(prev, n, x); return ++iterator(prev.get()); } //! Requires: p must be a valid iterator of *this. //! //! Effects: Insert a copy of the [first, last) range before p. //! //! Returns: an iterator to the first inserted element or p if first == last. //! //! Throws: If memory allocation throws, T's constructor from a //! dereferenced InpIt throws. //! //! Complexity: Linear to distance [first, last) plus //! linear to the elements before p. template iterator insert(const_iterator p, InIter first, InIter last) { const_iterator prev(this->previous(p)); this->insert_after(prev, first, last); return ++iterator(prev.get()); } #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) //! Requires: p must be a valid iterator of *this. //! //! Effects: Insert a copy of the [il.begin(), il.end()) range before p. //! //! Returns: an iterator to the first inserted element or p if il.begin() == il.end(). //! //! Throws: If memory allocation throws, T's constructor from a //! dereferenced std::initializer_list iterator throws. //! //! Complexity: Linear to the range [il.begin(), il.end()) plus //! linear to the elements before p. iterator insert(const_iterator p, std::initializer_list il) { return insert(p, il.begin(), il.end()); } #endif //! Requires: p must be a valid iterator of *this. //! //! Effects: Erases the element at p p. //! //! Throws: Nothing. //! //! Complexity: Linear to the number of elements before p. iterator erase(const_iterator p) BOOST_NOEXCEPT_OR_NOTHROW { return iterator(this->erase_after(previous(p))); } //! Requires: first and last must be valid iterator to elements in *this. //! //! Effects: Erases the elements pointed by [first, last). //! //! Throws: Nothing. //! //! Complexity: Linear to the distance between first and last plus //! linear to the elements before first. iterator erase(const_iterator first, const_iterator last) BOOST_NOEXCEPT_OR_NOTHROW { return iterator(this->erase_after(previous(first), last)); } //! Requires: p must point to an element contained //! by the list. x != *this. this' allocator and x's allocator shall compare equal //! //! Effects: Transfers all the elements of list x to this list, before the //! the element pointed by p. No destructors or copy constructors are called. //! //! Throws: Nothing //! //! Complexity: Linear in distance(begin(), p), and linear in x.size(). //! //! Note: Iterators of values obtained from list x now point to elements of //! this list. Iterators of this list and all the references are not invalidated. void splice(const_iterator p, slist& x) BOOST_NOEXCEPT_OR_NOTHROW { this->splice_after(this->previous(p), x); } //! Requires: p must point to an element contained //! by the list. x != *this. this' allocator and x's allocator shall compare equal //! //! Effects: Transfers all the elements of list x to this list, before the //! the element pointed by p. No destructors or copy constructors are called. //! //! Throws: Nothing //! //! Complexity: Linear in distance(begin(), p), and linear in x.size(). //! //! Note: Iterators of values obtained from list x now point to elements of //! this list. Iterators of this list and all the references are not invalidated. void splice(const_iterator p, BOOST_RV_REF(slist) x) BOOST_NOEXCEPT_OR_NOTHROW { this->splice(p, static_cast(x)); } //! Requires: p must point to an element contained //! by this list. i must point to an element contained in list x. //! this' allocator and x's allocator shall compare equal //! //! Effects: Transfers the value pointed by i, from list x to this list, //! before the the element pointed by p. No destructors or copy constructors are called. //! If p == i or p == ++i, this function is a null operation. //! //! Throws: Nothing //! //! Complexity: Linear in distance(begin(), p), and in distance(x.begin(), i). //! //! Note: Iterators of values obtained from list x now point to elements of this //! list. Iterators of this list and all the references are not invalidated. void splice(const_iterator p, slist& x, const_iterator i) BOOST_NOEXCEPT_OR_NOTHROW { this->splice_after(this->previous(p), x, this->previous(i)); } //! Requires: p must point to an element contained //! by this list. i must point to an element contained in list x. //! this' allocator and x's allocator shall compare equal. //! //! Effects: Transfers the value pointed by i, from list x to this list, //! before the the element pointed by p. No destructors or copy constructors are called. //! If p == i or p == ++i, this function is a null operation. //! //! Throws: Nothing //! //! Complexity: Linear in distance(begin(), p), and in distance(x.begin(), i). //! //! Note: Iterators of values obtained from list x now point to elements of this //! list. Iterators of this list and all the references are not invalidated. void splice(const_iterator p, BOOST_RV_REF(slist) x, const_iterator i) BOOST_NOEXCEPT_OR_NOTHROW { this->splice(p, static_cast(x), i); } //! Requires: p must point to an element contained //! by this list. first and last must point to elements contained in list x. //! //! Effects: Transfers the range pointed by first and last from list x to this list, //! before the the element pointed by p. No destructors or copy constructors are called. //! this' allocator and x's allocator shall compare equal. //! //! Throws: Nothing //! //! Complexity: Linear in distance(begin(), p), in distance(x.begin(), first), //! and in distance(first, last). //! //! Note: Iterators of values obtained from list x now point to elements of this //! list. Iterators of this list and all the references are not invalidated. void splice(const_iterator p, slist& x, const_iterator first, const_iterator last) BOOST_NOEXCEPT_OR_NOTHROW { this->splice_after(this->previous(p), x, this->previous(first), this->previous(last)); } //! Requires: p must point to an element contained //! by this list. first and last must point to elements contained in list x. //! this' allocator and x's allocator shall compare equal //! //! Effects: Transfers the range pointed by first and last from list x to this list, //! before the the element pointed by p. No destructors or copy constructors are called. //! //! Throws: Nothing //! //! Complexity: Linear in distance(begin(), p), in distance(x.begin(), first), //! and in distance(first, last). //! //! Note: Iterators of values obtained from list x now point to elements of this //! list. Iterators of this list and all the references are not invalidated. void splice(const_iterator p, BOOST_RV_REF(slist) x, const_iterator first, const_iterator last) BOOST_NOEXCEPT_OR_NOTHROW { this->splice(p, static_cast(x), first, last); } //! Effects: Returns true if x and y are equal //! //! Complexity: Linear to the number of elements in the container. friend bool operator==(const slist& x, const slist& y) { return x.size() == y.size() && ::boost::container::algo_equal(x.begin(), x.end(), y.begin()); } //! Effects: Returns true if x and y are unequal //! //! Complexity: Linear to the number of elements in the container. friend bool operator!=(const slist& x, const slist& y) { return !(x == y); } //! Effects: Returns true if x is less than y //! //! Complexity: Linear to the number of elements in the container. friend bool operator<(const slist& x, const slist& y) { return ::boost::container::algo_lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); } //! Effects: Returns true if x is greater than y //! //! Complexity: Linear to the number of elements in the container. friend bool operator>(const slist& x, const slist& y) { return y < x; } //! Effects: Returns true if x is equal or less than y //! //! Complexity: Linear to the number of elements in the container. friend bool operator<=(const slist& x, const slist& y) { return !(y < x); } //! Effects: Returns true if x is equal or greater than y //! //! Complexity: Linear to the number of elements in the container. friend bool operator>=(const slist& x, const slist& y) { return !(x < y); } //! Effects: x.swap(y) //! //! Complexity: Constant. friend void swap(slist& x, slist& y) { x.swap(y); } #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED private: void priv_push_front (const T &x) { this->insert_after(this->cbefore_begin(), x); } void priv_push_front (BOOST_RV_REF(T) x) { this->insert_after(this->cbefore_begin(), ::boost::move(x)); } bool priv_try_shrink(size_type new_size, const_iterator &last_pos) { typename Icont::iterator end_n(this->icont().end()), cur(this->icont().before_begin()), cur_next; while (++(cur_next = cur) != end_n && new_size > 0){ --new_size; cur = cur_next; } last_pos = const_iterator(cur); if (cur_next != end_n){ this->erase_after(last_pos, const_iterator(end_n)); return true; } else{ return false; } } template iterator priv_insert(const_iterator p, BOOST_FWD_REF(U) x) { return this->insert_after(previous(p), ::boost::forward(x)); } template iterator priv_insert_after(const_iterator prev_p, BOOST_FWD_REF(U) x) { return iterator(this->icont().insert_after(prev_p.get(), *this->create_node(::boost::forward(x)))); } class insertion_functor; friend class insertion_functor; class insertion_functor { Icont &icont_; typedef typename Icont::iterator iiterator; typedef typename Icont::const_iterator iconst_iterator; const iconst_iterator prev_; iiterator ret_; public: insertion_functor(Icont &icont, typename Icont::const_iterator prev) : icont_(icont), prev_(prev), ret_(prev.unconst()) {} void operator()(Node &n) { ret_ = this->icont_.insert_after(prev_, n); } iiterator inserted_first() const { return ret_; } }; //Functors for member algorithm defaults struct value_less { bool operator()(const value_type &a, const value_type &b) const { return a < b; } }; struct value_equal { bool operator()(const value_type &a, const value_type &b) const { return a == b; } }; struct value_equal_to_this { explicit value_equal_to_this(const value_type &ref) : m_ref(ref){} bool operator()(const value_type &val) const { return m_ref == val; } const value_type &m_ref; }; #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED }; }} #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED namespace boost { //!has_trivial_destructor_after_move<> == true_type //!specialization for optimizations template struct has_trivial_destructor_after_move > { typedef typename ::boost::container::allocator_traits::pointer pointer; static const bool value = ::boost::has_trivial_destructor_after_move::value && ::boost::has_trivial_destructor_after_move::value; }; namespace container { #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED }} //namespace boost{ namespace container { // Specialization of insert_iterator so that insertions will be constant // time rather than linear time. #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED #if defined(__clang__) && defined(_LIBCPP_VERSION) #define BOOST_CONTAINER_CLANG_INLINE_STD_NS #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wc++11-extensions" #endif BOOST_CONTAINER_STD_NS_BEG template class insert_iterator > { protected: typedef boost::container::slist Container; Container* container; typename Container::iterator iter; public: typedef Container container_type; typedef output_iterator_tag iterator_category; typedef void value_type; typedef void difference_type; typedef void pointer; typedef void reference; insert_iterator(Container& x, typename Container::iterator i, bool is_previous = false) : container(&x), iter(is_previous ? i : x.previous(i)){ } insert_iterator& operator=(const typename Container::value_type& value) { iter = container->insert_after(iter, value); return *this; } insert_iterator& operator*(){ return *this; } insert_iterator& operator++(){ return *this; } insert_iterator& operator++(int){ return *this; } }; BOOST_CONTAINER_STD_NS_END #ifdef BOOST_CONTAINER_CLANG_INLINE_STD_NS #pragma GCC diagnostic pop #undef BOOST_CONTAINER_CLANG_INLINE_STD_NS #endif //BOOST_CONTAINER_CLANG_INLINE_STD_NS #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED #include #endif // BOOST_CONTAINER_SLIST_HPP