summaryrefslogtreecommitdiff
path: root/boost/container/slist.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/container/slist.hpp')
-rw-r--r--boost/container/slist.hpp530
1 files changed, 269 insertions, 261 deletions
diff --git a/boost/container/slist.hpp b/boost/container/slist.hpp
index 1cdcdf1046..57719357fc 100644
--- a/boost/container/slist.hpp
+++ b/boost/container/slist.hpp
@@ -1,6 +1,6 @@
//////////////////////////////////////////////////////////////////////////////
//
-// (C) Copyright Ion Gaztanaga 2004-2011. Distributed under the Boost
+// (C) Copyright Ion Gaztanaga 2004-2012. 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)
//
@@ -32,7 +32,7 @@
#if defined(BOOST_CONTAINER_PERFECT_FORWARDING) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
//Preprocessor library to emulate perfect forwarding
#else
-#include <boost/container/detail/preprocessor.hpp>
+#include <boost/container/detail/preprocessor.hpp>
#endif
#include <stdexcept>
@@ -65,31 +65,11 @@ template <class T, class VoidPointer>
struct slist_node
: public slist_hook<VoidPointer>::type
{
+ private:
+ slist_node();
- slist_node()
- : m_data()
- {}
-
- #if defined(BOOST_CONTAINER_PERFECT_FORWARDING) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
-
- template<class ...Args>
- slist_node(Args &&...args)
- : m_data(boost::forward<Args>(args)...)
- {}
-
- #else //#ifdef BOOST_CONTAINER_PERFECT_FORWARDING
-
- #define BOOST_PP_LOCAL_MACRO(n) \
- template<BOOST_PP_ENUM_PARAMS(n, class P)> \
- slist_node(BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_LIST, _)) \
- : m_data(BOOST_PP_ENUM(n, BOOST_CONTAINER_PP_PARAM_FORWARD, _)) \
- {} \
- //!
- #define BOOST_PP_LOCAL_LIMITS (1, BOOST_CONTAINER_MAX_CONSTRUCTOR_PARAMETERS)
- #include BOOST_PP_LOCAL_ITERATE()
-
- #endif//#ifdef BOOST_CONTAINER_PERFECT_FORWARDING
-
+ public:
+ typedef typename slist_hook<VoidPointer>::type hook_type;
T m_data;
};
@@ -119,51 +99,51 @@ struct intrusive_slist_type
/// @endcond
-//! 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<T>::iterator might have a different predecessor or successor after a list
-//! operation than it did before), but the iterators themselves will not be invalidated
+//! 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<T>::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:
+//! 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,
+//!
+//! 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.
#ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
template <class T, class A = std::allocator<T> >
#else
template <class T, class A>
#endif
-class slist
+class slist
: protected container_detail::node_alloc_holder
<A, typename container_detail::intrusive_slist_type<A>::type>
{
/// @cond
typedef typename container_detail::
move_const_ref_type<T>::type insert_const_ref_type;
- typedef typename
+ typedef typename
container_detail::intrusive_slist_type<A>::type Icont;
typedef container_detail::node_alloc_holder<A, Icont> AllocHolder;
typedef typename AllocHolder::NodePtr NodePtr;
@@ -238,11 +218,11 @@ class slist
public:
- //! Const iterator used to iterate through a list.
+ //! Const iterator used to iterate through a list.
class const_iterator
/// @cond
- : public std::iterator<std::forward_iterator_tag,
- value_type, list_difference_type,
+ : public std::iterator<std::forward_iterator_tag,
+ value_type, list_difference_type,
list_const_pointer, list_const_reference>
{
@@ -265,17 +245,17 @@ class slist
{}
//Pointer like operators
- const_reference operator*() const
+ const_reference operator*() const
{ return m_it->m_data; }
- const_pointer operator->() const
+ const_pointer operator->() const
{ return const_pointer(&m_it->m_data); }
//Increment / Decrement
- const_iterator& operator++()
+ const_iterator& operator++()
{ prot_incr(); return *this; }
- const_iterator operator++(int)
+ const_iterator operator++(int)
{ typename Icont::iterator tmp = m_it; ++*this; return const_iterator(tmp); }
//Comparison operators
@@ -298,7 +278,7 @@ class slist
explicit iterator(typename Icont::iterator it)
: const_iterator(it)
{}
-
+
typename Icont::iterator get()
{ return this->m_it; }
@@ -315,7 +295,7 @@ class slist
pointer operator->() const { return pointer(&this->m_it->m_data); }
//Increment / Decrement
- iterator& operator++()
+ iterator& operator++()
{ this->prot_incr(); return *this; }
iterator operator++(int)
@@ -326,18 +306,18 @@ class slist
public:
//! <b>Effects</b>: Constructs a list taking the allocator as parameter.
- //!
+ //!
//! <b>Throws</b>: If allocator_type's copy constructor throws.
- //!
+ //!
//! <b>Complexity</b>: Constant.
slist()
: AllocHolder()
{}
//! <b>Effects</b>: Constructs a list taking the allocator as parameter.
- //!
+ //!
//! <b>Throws</b>: If allocator_type's copy constructor throws.
- //!
+ //!
//! <b>Complexity</b>: Constant.
explicit slist(const allocator_type& a)
: AllocHolder(a)
@@ -352,7 +332,7 @@ class slist
//!
//! <b>Throws</b>: If allocator_type's default constructor or copy constructor
//! throws or T's default or copy constructor throws.
- //!
+ //!
//! <b>Complexity</b>: Linear to n.
explicit slist(size_type n, const value_type& x, const allocator_type& a = allocator_type())
: AllocHolder(a)
@@ -367,34 +347,62 @@ class slist
//! <b>Complexity</b>: Linear to the range [first, last).
template <class InpIt>
slist(InpIt first, InpIt last,
- const allocator_type& a = allocator_type())
+ const allocator_type& a = allocator_type())
: AllocHolder(a)
{ this->insert_after(this->before_begin(), first, last); }
//! <b>Effects</b>: Copy constructs a list.
//!
//! <b>Postcondition</b>: x == *this.
- //!
+ //!
//! <b>Throws</b>: If allocator_type's default constructor or copy constructor throws.
- //!
+ //!
//! <b>Complexity</b>: Linear to the elements x contains.
- slist(const slist& x)
+ slist(const slist& x)
: AllocHolder(x)
{ this->insert_after(this->before_begin(), x.begin(), x.end()); }
//! <b>Effects</b>: Move constructor. Moves mx's resources to *this.
//!
//! <b>Throws</b>: If allocator_type's copy constructor throws.
- //!
+ //!
//! <b>Complexity</b>: Constant.
slist(BOOST_RV_REF(slist) x)
: AllocHolder(boost::move(static_cast<AllocHolder&>(x)))
{}
+ //! <b>Effects</b>: Copy constructs a list using the specified allocator.
+ //!
+ //! <b>Postcondition</b>: x == *this.
+ //!
+ //! <b>Throws</b>: If allocator_type's default constructor or copy constructor throws.
+ //!
+ //! <b>Complexity</b>: Linear to the elements x contains.
+ slist(const slist& x, const allocator_type &a)
+ : AllocHolder(a)
+ { this->insert_after(this->before_begin(), x.begin(), x.end()); }
+
+ //! <b>Effects</b>: Move constructor using the specified allocator.
+ //! Moves x's resources to *this.
+ //!
+ //! <b>Throws</b>: If allocation or value_type's copy constructor throws.
+ //!
+ //! <b>Complexity</b>: 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(this->cbegin(), x.begin(), x.end());
+ }
+ }
+
//! <b>Effects</b>: Makes *this contain the same elements as x.
//!
- //! <b>Postcondition</b>: this->size() == x.size(). *this contains a copy
- //! of each of x's elements.
+ //! <b>Postcondition</b>: this->size() == x.size(). *this contains a copy
+ //! of each of x's elements.
//!
//! <b>Throws</b>: If memory allocation throws or T's copy constructor throws.
//!
@@ -417,8 +425,8 @@ class slist
//! <b>Effects</b>: Makes *this contain the same elements as x.
//!
- //! <b>Postcondition</b>: this->size() == x.size(). *this contains a copy
- //! of each of x's elements.
+ //! <b>Postcondition</b>: this->size() == x.size(). *this contains a copy
+ //! of each of x's elements.
//!
//! <b>Throws</b>: If memory allocation throws or T's copy constructor throws.
//!
@@ -452,18 +460,18 @@ class slist
//! <b>Throws</b>: Nothing.
//!
//! <b>Complexity</b>: Linear to the number of elements.
- ~slist()
+ ~slist()
{} //AllocHolder clears the slist
//! <b>Effects</b>: Returns a copy of the internal allocator.
- //!
+ //!
//! <b>Throws</b>: If allocator's copy constructor throws.
- //!
+ //!
//! <b>Complexity</b>: Constant.
allocator_type get_allocator() const
{ return allocator_type(this->node_alloc()); }
- const stored_allocator_type &get_stored_allocator() const
+ const stored_allocator_type &get_stored_allocator() const
{ return this->node_alloc(); }
stored_allocator_type &get_stored_allocator()
@@ -486,7 +494,7 @@ class slist
//!
//! <b>Complexity</b>: Linear to n.
template <class InpIt>
- void assign(InpIt first, InpIt last)
+ void assign(InpIt first, InpIt last)
{
const bool aux_boolean = container_detail::is_convertible<InpIt, size_type>::value;
typedef container_detail::bool_<aux_boolean> Result;
@@ -494,33 +502,33 @@ class slist
}
//! <b>Effects</b>: Returns an iterator to the first element contained in the list.
- //!
+ //!
//! <b>Throws</b>: Nothing.
- //!
+ //!
//! <b>Complexity</b>: Constant.
- iterator begin()
+ iterator begin()
{ return iterator(this->icont().begin()); }
//! <b>Effects</b>: Returns a const_iterator to the first element contained in the list.
- //!
+ //!
//! <b>Throws</b>: Nothing.
- //!
+ //!
//! <b>Complexity</b>: Constant.
- const_iterator begin() const
+ const_iterator begin() const
{ return this->cbegin(); }
//! <b>Effects</b>: Returns an iterator to the end of the list.
- //!
+ //!
//! <b>Throws</b>: Nothing.
- //!
+ //!
//! <b>Complexity</b>: Constant.
iterator end()
{ return iterator(this->icont().end()); }
//! <b>Effects</b>: Returns a const_iterator to the end of the list.
- //!
+ //!
//! <b>Throws</b>: Nothing.
- //!
+ //!
//! <b>Complexity</b>: Constant.
const_iterator end() const
{ return this->cend(); }
@@ -528,71 +536,71 @@ class slist
//! <b>Effects</b>: Returns a non-dereferenceable iterator that,
//! when incremented, yields begin(). This iterator may be used
//! as the argument toinsert_after, erase_after, etc.
- //!
+ //!
//! <b>Throws</b>: Nothing.
- //!
+ //!
//! <b>Complexity</b>: Constant.
- iterator before_begin()
+ iterator before_begin()
{ return iterator(end()); }
- //! <b>Effects</b>: Returns a non-dereferenceable const_iterator
+ //! <b>Effects</b>: Returns a non-dereferenceable const_iterator
//! that, when incremented, yields begin(). This iterator may be used
//! as the argument toinsert_after, erase_after, etc.
- //!
+ //!
//! <b>Throws</b>: Nothing.
- //!
+ //!
//! <b>Complexity</b>: Constant.
const_iterator before_begin() const
{ return this->cbefore_begin(); }
//! <b>Effects</b>: Returns a const_iterator to the first element contained in the list.
- //!
+ //!
//! <b>Throws</b>: Nothing.
- //!
+ //!
//! <b>Complexity</b>: Constant.
- const_iterator cbegin() const
+ const_iterator cbegin() const
{ return const_iterator(this->non_const_icont().begin()); }
//! <b>Effects</b>: Returns a const_iterator to the end of the list.
- //!
+ //!
//! <b>Throws</b>: Nothing.
- //!
+ //!
//! <b>Complexity</b>: Constant.
const_iterator cend() const
{ return const_iterator(this->non_const_icont().end()); }
- //! <b>Effects</b>: Returns a non-dereferenceable const_iterator
+ //! <b>Effects</b>: Returns a non-dereferenceable const_iterator
//! that, when incremented, yields begin(). This iterator may be used
//! as the argument toinsert_after, erase_after, etc.
- //!
+ //!
//! <b>Throws</b>: Nothing.
- //!
+ //!
//! <b>Complexity</b>: Constant.
const_iterator cbefore_begin() const
{ return const_iterator(end()); }
//! <b>Effects</b>: Returns the number of the elements contained in the list.
- //!
+ //!
//! <b>Throws</b>: Nothing.
- //!
+ //!
//! <b>Complexity</b>: Constant.
- size_type size() const
+ size_type size() const
{ return this->icont().size(); }
//! <b>Effects</b>: Returns the largest possible size of the list.
- //!
+ //!
//! <b>Throws</b>: Nothing.
- //!
+ //!
//! <b>Complexity</b>: Constant.
- size_type max_size() const
+ size_type max_size() const
{ return AllocHolder::max_size(); }
//! <b>Effects</b>: Returns true if the list contains no elements.
- //!
+ //!
//! <b>Throws</b>: Nothing.
- //!
+ //!
//! <b>Complexity</b>: Constant.
- bool empty() const
+ bool empty() const
{ return !this->size(); }
//! <b>Effects</b>: Swaps the contents of *this and x.
@@ -605,24 +613,24 @@ class slist
//! <b>Requires</b>: !empty()
//!
- //! <b>Effects</b>: Returns a reference to the first element
+ //! <b>Effects</b>: Returns a reference to the first element
//! from the beginning of the container.
- //!
+ //!
//! <b>Throws</b>: Nothing.
- //!
+ //!
//! <b>Complexity</b>: Constant.
- reference front()
+ reference front()
{ return *this->begin(); }
//! <b>Requires</b>: !empty()
//!
- //! <b>Effects</b>: Returns a const reference to the first element
+ //! <b>Effects</b>: Returns a const reference to the first element
//! from the beginning of the container.
- //!
+ //!
//! <b>Throws</b>: Nothing.
- //!
+ //!
//! <b>Complexity</b>: Constant.
- const_reference front() const
+ const_reference front() const
{ return *this->begin(); }
//! <b>Effects</b>: Inserts a copy of t in the beginning of the list.
@@ -660,24 +668,24 @@ class slist
void pop_front()
{ this->icont().pop_front_and_dispose(Destroyer(this->node_alloc())); }
- //! <b>Returns</b>: 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.
- //!
+ //! <b>Returns</b>: 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.
+ //!
//! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Linear to the number of elements before i.
- iterator previous(iterator p)
+ //!
+ //! <b>Complexity</b>: Linear to the number of elements before i.
+ iterator previous(iterator p)
{ return iterator(this->icont().previous(p.get())); }
- //! <b>Returns</b>: 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.
- //!
+ //! <b>Returns</b>: 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.
+ //!
//! <b>Throws</b>: Nothing.
- //!
- //! <b>Complexity</b>: Linear to the number of elements before i.
- const_iterator previous(const_iterator p)
+ //!
+ //! <b>Complexity</b>: Linear to the number of elements before i.
+ const_iterator previous(const_iterator p)
{ return const_iterator(this->icont().previous(p.get())); }
//! <b>Requires</b>: p must be a valid iterator of *this.
@@ -686,14 +694,14 @@ class slist
//! by prev_p.
//!
//! <b>Returns</b>: An iterator to the inserted element.
- //!
+ //!
//! <b>Throws</b>: If memory allocation throws or T's copy constructor throws.
- //!
+ //!
//! <b>Complexity</b>: Amortized constant time.
//!
//! <b>Note</b>: Does not affect the validity of iterators and references of
//! previous values.
- iterator insert_after(const_iterator prev_pos, insert_const_ref_type x)
+ iterator insert_after(const_iterator prev_pos, insert_const_ref_type x)
{ return this->priv_insert_after(prev_pos, x); }
#if defined(BOOST_NO_RVALUE_REFERENCES) && !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
@@ -712,14 +720,14 @@ class slist
//! p pointed by prev_pos.
//!
//! <b>Returns</b>: An iterator to the inserted element.
- //!
+ //!
//! <b>Throws</b>: If memory allocation throws.
- //!
+ //!
//! <b>Complexity</b>: Amortized constant time.
//!
//! <b>Note</b>: Does not affect the validity of iterators and references of
//! previous values.
- iterator insert_after(const_iterator prev_pos, BOOST_RV_REF(value_type) x)
+ iterator insert_after(const_iterator prev_pos, BOOST_RV_REF(value_type) x)
{ return iterator(this->icont().insert_after(prev_pos.get(), *this->create_node(boost::move(x)))); }
//! <b>Requires</b>: prev_pos must be a valid iterator of *this.
@@ -736,19 +744,19 @@ class slist
{ this->priv_create_and_insert_nodes(prev_pos, n, x); }
//! <b>Requires</b>: prev_pos must be a valid iterator of *this.
- //!
- //! <b>Effects</b>: Inserts the range pointed by [first, last)
+ //!
+ //! <b>Effects</b>: Inserts the range pointed by [first, last)
//! after the p prev_pos.
- //!
+ //!
//! <b>Throws</b>: If memory allocation throws, T's constructor from a
//! dereferenced InpIt throws.
- //!
+ //!
//! <b>Complexity</b>: Linear to the number of elements inserted.
- //!
+ //!
//! <b>Note</b>: Does not affect the validity of iterators and references of
//! previous values.
template <class InIter>
- void insert_after(const_iterator prev_pos, InIter first, InIter last)
+ void insert_after(const_iterator prev_pos, InIter first, InIter last)
{
const bool aux_boolean = container_detail::is_convertible<InIter, size_type>::value;
typedef container_detail::bool_<aux_boolean> Result;
@@ -762,7 +770,7 @@ class slist
//! <b>Throws</b>: If memory allocation throws or x's copy constructor throws.
//!
//! <b>Complexity</b>: Linear to the elements before p.
- iterator insert(const_iterator position, insert_const_ref_type x)
+ iterator insert(const_iterator position, insert_const_ref_type x)
{ return this->priv_insert(position, x); }
#if defined(BOOST_NO_RVALUE_REFERENCES) && !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
@@ -782,7 +790,7 @@ class slist
//! <b>Throws</b>: If memory allocation throws.
//!
//! <b>Complexity</b>: Linear to the elements before p.
- iterator insert(const_iterator p, BOOST_RV_REF(value_type) x)
+ iterator insert(const_iterator p, BOOST_RV_REF(value_type) x)
{ return this->insert_after(previous(p), boost::move(x)); }
//! <b>Requires</b>: p must be a valid iterator of *this.
@@ -792,9 +800,9 @@ class slist
//! <b>Throws</b>: If memory allocation throws or T's copy constructor throws.
//!
//! <b>Complexity</b>: Linear to n plus linear to the elements before p.
- void insert(const_iterator p, size_type n, const value_type& x)
+ void insert(const_iterator p, size_type n, const value_type& x)
{ return this->insert_after(previous(p), n, x); }
-
+
//! <b>Requires</b>: p must be a valid iterator of *this.
//!
//! <b>Effects</b>: Insert a copy of the [first, last) range before p.
@@ -805,7 +813,7 @@ class slist
//! <b>Complexity</b>: Linear to std::distance [first, last) plus
//! linear to the elements before p.
template <class InIter>
- void insert(const_iterator p, InIter first, InIter last)
+ void insert(const_iterator p, InIter first, InIter last)
{ return this->insert_after(previous(p), first, last); }
#if defined(BOOST_CONTAINER_PERFECT_FORWARDING) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
@@ -884,11 +892,11 @@ class slist
//!
//! <b>Returns</b>: the first element remaining beyond the removed elements,
//! or end() if no such element exists.
- //!
+ //!
//! <b>Throws</b>: Nothing.
- //!
+ //!
//! <b>Complexity</b>: Constant.
- //!
+ //!
//! <b>Note</b>: Does not invalidate iterators or references to non erased elements.
iterator erase_after(const_iterator prev_pos)
{
@@ -896,17 +904,17 @@ class slist
}
//! <b>Effects</b>: Erases the range (before_first, last) from
- //! the list.
+ //! the list.
//!
//! <b>Returns</b>: the first element remaining beyond the removed elements,
//! or end() if no such element exists.
- //!
+ //!
//! <b>Throws</b>: Nothing.
- //!
+ //!
//! <b>Complexity</b>: Linear to the number of erased elements.
- //!
+ //!
//! <b>Note</b>: Does not invalidate iterators or references to non erased elements.
- iterator erase_after(const_iterator before_first, const_iterator last)
+ 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())));
}
@@ -918,7 +926,7 @@ class slist
//! <b>Throws</b>: Nothing.
//!
//! <b>Complexity</b>: Linear to the number of elements before p.
- iterator erase(const_iterator p)
+ iterator erase(const_iterator p)
{ return iterator(this->erase_after(previous(p))); }
//! <b>Requires</b>: first and last must be valid iterator to elements in *this.
@@ -945,7 +953,7 @@ class slist
--new_size;
cur = cur_next;
}
- if (cur_next != end_n)
+ if (cur_next != end_n)
this->erase_after(const_iterator(cur), const_iterator(end_n));
else
this->insert_after(const_iterator(cur), new_size, x);
@@ -962,7 +970,7 @@ class slist
typename Icont::iterator end_n(this->icont().end()), cur(this->icont().before_begin()), cur_next;
size_type len = this->size();
size_type left = new_size;
-
+
while (++(cur_next = cur) != end_n && left > 0){
--left;
cur = cur_next;
@@ -980,7 +988,7 @@ class slist
//! <b>Throws</b>: Nothing.
//!
//! <b>Complexity</b>: Linear to the number of elements in the list.
- void clear()
+ void clear()
{ this->icont().clear_and_dispose(Destroyer(this->node_alloc())); }
//! <b>Requires</b>: p must point to an element contained
@@ -993,7 +1001,7 @@ class slist
//! are not equal.
//!
//! <b>Complexity</b>: Linear to the elements in x.
- //!
+ //!
//! <b>Note</b>: 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_pos, slist& x)
@@ -1008,16 +1016,16 @@ class slist
//! <b>Requires</b>: prev_pos must be a valid iterator of this.
//! i must point to an element contained in list x.
- //!
- //! <b>Effects</b>: Transfers the value pointed by i, from list x to this list,
+ //!
+ //! <b>Effects</b>: Transfers the value pointed by i, from list x to this list,
//! after the element pointed by prev_pos.
- //! If prev_pos == prev or prev_pos == ++prev, this function is a null operation.
- //!
+ //! If prev_pos == prev or prev_pos == ++prev, this function is a null operation.
+ //!
//! <b>Throws</b>: std::runtime_error if this' allocator and x's allocator
//! are not equal.
- //!
+ //!
//! <b>Complexity</b>: Constant.
- //!
+ //!
//! <b>Note</b>: 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_pos, slist& x, const_iterator prev)
@@ -1033,18 +1041,18 @@ class slist
//! <b>Requires</b>: prev_pos must be a valid iterator of this.
//! before_first and before_last must be valid iterators of x.
//! prev_pos must not be contained in [before_first, before_last) range.
- //!
+ //!
//! <b>Effects</b>: Transfers the range [before_first + 1, before_last + 1)
//! from list x to this list, after the element pointed by prev_pos.
- //!
+ //!
//! <b>Throws</b>: std::runtime_error if this' allocator and x's allocator
//! are not equal.
- //!
+ //!
//! <b>Complexity</b>: Linear to the number of transferred elements.
- //!
+ //!
//! <b>Note</b>: 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_pos, slist& x,
+ void splice_after(const_iterator prev_pos, slist& x,
const_iterator before_first, const_iterator before_last)
{
if((NodeAlloc&)*this == (NodeAlloc&)x){
@@ -1060,18 +1068,18 @@ class slist
//! before_first and before_last must be valid iterators of x.
//! prev_pos must not be contained in [before_first, before_last) range.
//! n == std::distance(before_first, before_last)
- //!
+ //!
//! <b>Effects</b>: Transfers the range [before_first + 1, before_last + 1)
//! from list x to this list, after the element pointed by prev_pos.
- //!
+ //!
//! <b>Throws</b>: std::runtime_error if this' allocator and x's allocator
//! are not equal.
- //!
+ //!
//! <b>Complexity</b>: Constant.
- //!
+ //!
//! <b>Note</b>: 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_pos, slist& x,
+ void splice_after(const_iterator prev_pos, slist& x,
const_iterator before_first, const_iterator before_last,
size_type n)
{
@@ -1094,24 +1102,24 @@ class slist
//! are not equal.
//!
//! <b>Complexity</b>: Linear in distance(begin(), p), and linear in x.size().
- //!
+ //!
//! <b>Note</b>: 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, ThisType& x)
+ void splice(const_iterator p, ThisType& x)
{ this->splice_after(this->previous(p), x); }
//! <b>Requires</b>: p must point to an element contained
//! by this list. i must point to an element contained in list x.
- //!
- //! <b>Effects</b>: Transfers the value pointed by i, from list x to this list,
+ //!
+ //! <b>Effects</b>: 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.
- //!
+ //! If p == i or p == ++i, this function is a null operation.
+ //!
//! <b>Throws</b>: std::runtime_error if this' allocator and x's allocator
//! are not equal.
- //!
+ //!
//! <b>Complexity</b>: Linear in distance(begin(), p), and in distance(x.begin(), i).
- //!
+ //!
//! <b>Note</b>: 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)
@@ -1119,37 +1127,37 @@ class slist
//! <b>Requires</b>: p must point to an element contained
//! by this list. first and last must point to elements contained in list x.
- //!
- //! <b>Effects</b>: Transfers the range pointed by first and last from list x to this list,
+ //!
+ //! <b>Effects</b>: 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.
- //!
+ //!
//! <b>Throws</b>: std::runtime_error if this' allocator and x's allocator
//! are not equal.
- //!
+ //!
//! <b>Complexity</b>: Linear in distance(begin(), p), in distance(x.begin(), first),
//! and in distance(first, last).
- //!
+ //!
//! <b>Note</b>: 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)
{ this->splice_after(previous(p), x, previous(first), previous(last)); }
- //! <b>Effects</b>: Reverses the order of elements in the list.
- //!
+ //! <b>Effects</b>: Reverses the order of elements in the list.
+ //!
//! <b>Throws</b>: Nothing.
- //!
+ //!
//! <b>Complexity</b>: This function is linear time.
- //!
+ //!
//! <b>Note</b>: Iterators and references are not invalidated
- void reverse()
+ void reverse()
{ this->icont().reverse(); }
//! <b>Effects</b>: Removes all the elements that compare equal to value.
- //!
+ //!
//! <b>Throws</b>: Nothing.
- //!
+ //!
//! <b>Complexity</b>: Linear time. It performs exactly size() comparisons for equality.
- //!
+ //!
//! <b>Note</b>: 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)
@@ -1157,57 +1165,57 @@ class slist
//! <b>Effects</b>: Removes all the elements for which a specified
//! predicate is satisfied.
- //!
+ //!
//! <b>Throws</b>: If pred throws.
- //!
+ //!
//! <b>Complexity</b>: Linear time. It performs exactly size() calls to the predicate.
- //!
+ //!
//! <b>Note</b>: The relative order of elements that are not removed is unchanged,
//! and iterators to elements that are not removed remain valid.
- template <class Pred>
+ template <class Pred>
void remove_if(Pred pred)
{
typedef ValueCompareToNodeCompare<Pred> Predicate;
this->icont().remove_and_dispose_if(Predicate(pred), Destroyer(this->node_alloc()));
}
- //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
+ //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
//! elements that are equal from the list.
- //!
+ //!
//! <b>Throws</b>: Nothing.
- //!
+ //!
//! <b>Complexity</b>: Linear time (size()-1 comparisons calls to pred()).
- //!
+ //!
//! <b>Note</b>: 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()); }
- //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
+ //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
//! elements that satisfy some binary predicate from the list.
- //!
+ //!
//! <b>Throws</b>: If pred throws.
- //!
+ //!
//! <b>Complexity</b>: Linear time (size()-1 comparisons equality comparisons).
- //!
+ //!
//! <b>Note</b>: The relative order of elements that are not removed is unchanged,
//! and iterators to elements that are not removed remain valid.
- template <class Pred>
+ template <class Pred>
void unique(Pred pred)
{
typedef ValueCompareToNodeCompare<Pred> Predicate;
this->icont().unique_and_dispose(Predicate(pred), Destroyer(this->node_alloc()));
}
- //! <b>Requires</b>: The lists x and *this must be distinct.
+ //! <b>Requires</b>: The lists x and *this must be distinct.
//!
//! <b>Effects</b>: This function removes all of x's elements and inserts them
- //! in order into *this according to std::less<value_type>. 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.
- //!
+ //! in order into *this according to std::less<value_type>. 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.
+ //!
//! <b>Throws</b>: Nothing.
- //!
+ //!
//! <b>Complexity</b>: This function is linear time: it performs at most
//! size() + x.size() - 1 comparisons.
void merge(slist & x)
@@ -1215,17 +1223,17 @@ class slist
//! <b>Requires</b>: 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.
- //!
+ //! The lists x and *this must be distinct.
+ //!
//! <b>Effects</b>: 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.
- //!
+ //! 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.
+ //!
//! <b>Throws</b>: Nothing.
- //!
+ //!
//! <b>Complexity</b>: This function is linear time: it performs at most
//! size() + x.size() - 1 comparisons.
- //!
+ //!
//! <b>Note</b>: Iterators and references to *this are not invalidated.
template <class StrictWeakOrdering>
void merge(slist& x, StrictWeakOrdering comp)
@@ -1239,28 +1247,28 @@ class slist
}
}
- //! <b>Effects</b>: This function sorts the list *this according to std::less<value_type>.
+ //! <b>Effects</b>: This function sorts the list *this according to std::less<value_type>.
//! The sort is stable, that is, the relative order of equivalent elements is preserved.
- //!
+ //!
//! <b>Throws</b>: Nothing.
//!
//! <b>Notes</b>: Iterators and references are not invalidated.
- //!
+ //!
//! <b>Complexity</b>: The number of comparisons is approximately N log N, where N
//! is the list's size.
void sort()
{ this->sort(value_less()); }
- //! <b>Effects</b>: This function sorts the list *this according to std::less<value_type>.
+ //! <b>Effects</b>: This function sorts the list *this according to std::less<value_type>.
//! The sort is stable, that is, the relative order of equivalent elements is preserved.
- //!
+ //!
//! <b>Throws</b>: Nothing.
//!
//! <b>Notes</b>: Iterators and references are not invalidated.
- //!
+ //!
//! <b>Complexity</b>: The number of comparisons is approximately N log N, where N
//! is the list's size.
- template <class StrictWeakOrdering>
+ template <class StrictWeakOrdering>
void sort(StrictWeakOrdering comp)
{
// nothing if the slist has length 0 or 1.
@@ -1271,10 +1279,10 @@ class slist
/// @cond
private:
- iterator priv_insert(const_iterator p, const value_type& x)
+ iterator priv_insert(const_iterator p, const value_type& x)
{ return this->insert_after(previous(p), x); }
- iterator priv_insert_after(const_iterator prev_pos, const value_type& x)
+ iterator priv_insert_after(const_iterator prev_pos, const value_type& x)
{ return iterator(this->icont().insert_after(prev_pos.get(), *this->create_node(x))); }
void priv_push_front(const value_type &x)
@@ -1354,10 +1362,10 @@ class slist
{ this->priv_create_and_insert_nodes(prev, first, last); }
template<class Integer>
- void priv_insert_dispatch(const_iterator prev, Integer n, Integer x, container_detail::true_)
+ void priv_insert_dispatch(const_iterator prev, Integer n, Integer x, container_detail::true_)
{ this->priv_create_and_insert_nodes(prev, (size_type)n, x); }
- void priv_fill_assign(size_type n, const T& val)
+ void priv_fill_assign(size_type n, const T& val)
{
iterator end_n(this->end());
iterator prev(this->before_begin());
@@ -1396,11 +1404,11 @@ class slist
}
template <class Int>
- void priv_insert_after_range_dispatch(const_iterator prev_pos, Int n, Int x, container_detail::true_)
+ void priv_insert_after_range_dispatch(const_iterator prev_pos, Int n, Int x, container_detail::true_)
{ this->priv_create_and_insert_nodes(prev_pos, (size_type)n, x); }
template <class InIter>
- void priv_insert_after_range_dispatch(const_iterator prev_pos, InIter first, InIter last, container_detail::false_)
+ void priv_insert_after_range_dispatch(const_iterator prev_pos, InIter first, InIter last, container_detail::false_)
{ this->priv_create_and_insert_nodes(prev_pos, first, last); }
//Functors for member algorithm defaults
@@ -1430,7 +1438,7 @@ class slist
};
template <class T, class A>
-inline bool
+inline bool
operator==(const slist<T,A>& x, const slist<T,A>& y)
{
if(x.size() != y.size()){
@@ -1457,27 +1465,27 @@ operator<(const slist<T,A>& sL1, const slist<T,A>& sL2)
}
template <class T, class A>
-inline bool
-operator!=(const slist<T,A>& sL1, const slist<T,A>& sL2)
+inline bool
+operator!=(const slist<T,A>& sL1, const slist<T,A>& sL2)
{ return !(sL1 == sL2); }
template <class T, class A>
-inline bool
-operator>(const slist<T,A>& sL1, const slist<T,A>& sL2)
+inline bool
+operator>(const slist<T,A>& sL1, const slist<T,A>& sL2)
{ return sL2 < sL1; }
template <class T, class A>
-inline bool
+inline bool
operator<=(const slist<T,A>& sL1, const slist<T,A>& sL2)
{ return !(sL2 < sL1); }
template <class T, class A>
-inline bool
+inline bool
operator>=(const slist<T,A>& sL1, const slist<T,A>& sL2)
{ return !(sL1 < sL2); }
template <class T, class A>
-inline void swap(slist<T,A>& x, slist<T,A>& y)
+inline void swap(slist<T,A>& x, slist<T,A>& y)
{ x.swap(y); }
}}
@@ -1505,12 +1513,12 @@ namespace container {
///@cond
-//Ummm, I don't like to define things in namespace std, but
+//Ummm, I don't like to define things in namespace std, but
//there is no other way
namespace std {
template <class T, class A>
-class insert_iterator<boost::container::slist<T, A> >
+class insert_iterator<boost::container::slist<T, A> >
{
protected:
typedef boost::container::slist<T, A> Container;
@@ -1524,14 +1532,14 @@ class insert_iterator<boost::container::slist<T, A> >
typedef void pointer;
typedef void reference;
- insert_iterator(Container& x,
- typename Container::iterator i,
- bool is_previous = false)
+ insert_iterator(Container& x,
+ typename Container::iterator i,
+ bool is_previous = false)
: container(&x), iter(is_previous ? i : x.previous(i)){ }
- insert_iterator<Container>&
- operator=(const typename Container::value_type& value)
- {
+ insert_iterator<Container>&
+ operator=(const typename Container::value_type& value)
+ {
iter = container->insert_after(iter, value);
return *this;
}