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