Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of boost. Click here for the latest Boost documentation.
PrevUpHomeNext

Class template list

boost::interprocess::list

Synopsis

template<typename T, typename A> 
class list {
public:
  // types
  typedef T value_type;
  typedef A::pointer                              pointer;                 // Pointer to T. 
  typedef A::const_pointer                        const_pointer;           // Const pointer to T. 
  typedef A::reference                            reference;               // Reference to T. 
  typedef A::const_reference                      const_reference;         // Const reference to T. 
  typedef A::size_type                            size_type;               // An unsigned integral type. 
  typedef A::difference_type                      difference_type;         // A signed integral type. 
  typedef A                                       allocator_type;          // The allocator type. 
  typedef NodeAlloc                               stored_allocator_type;   // The stored allocator type. 
  typedef std::reverse_iterator< iterator >       reverse_iterator;        // Iterator used to iterate backwards through a list. 
  typedef std::reverse_iterator< const_iterator > const_reverse_iterator;  // Const iterator used to iterate backwards through a list. 

  // construct/copy/destruct
  list(const allocator_type & = A());
  list(size_type, const T & = T(), const A & = A());
  list(const list &);
  list(unspecified);
  template<typename InpIt> list(InpIt, InpIt, const A & = A());
  list& operator=(const ThisType &);
  list& operator=(unspecified);
  ~list();

  // public member functions
  allocator_type get_allocator() const;
  const stored_allocator_type & get_stored_allocator() const;
  stored_allocator_type & get_stored_allocator() ;
  void clear() ;
  iterator begin() ;
  const_iterator begin() const;
  iterator end() ;
  const_iterator end() const;
  reverse_iterator rbegin() ;
  const_reverse_iterator rbegin() const;
  reverse_iterator rend() ;
  const_reverse_iterator rend() const;
  bool empty() const;
  size_type size() const;
  size_type max_size() const;
  void push_front(const T &) ;
  void push_front(unspecified) ;
  void push_back(const T &) ;
  void push_back(unspecified) ;
  void pop_front() ;
  void pop_back() ;
  reference front() ;
  const_reference front() const;
  reference back() ;
  const_reference back() const;
  void resize(size_type, const T &) ;
  void resize(size_type) ;
  void swap(ThisType &) ;
  void insert(iterator, size_type, const T &) ;
  template<typename InpIt> void insert(iterator, InpIt, InpIt) ;
  iterator insert(iterator, const T &) ;
  iterator insert(iterator, unspecified) ;
  iterator erase(iterator) ;
  iterator erase(iterator, iterator) ;
  void assign(size_type, const T &) ;
  template<typename InpIt> void assign(InpIt, InpIt) ;
  void splice(iterator, ThisType &) ;
  void splice(iterator, ThisType &, iterator) ;
  void splice(iterator, ThisType &, iterator, iterator) ;
  void splice(iterator, ThisType &, iterator, iterator, size_type) ;
  void reverse() ;
  void remove(const T &) ;
  template<typename Pred> void remove_if(Pred) ;
  void unique() ;
  template<typename BinaryPredicate> void unique(BinaryPredicate) ;
  void merge(list< T, A > &) ;
  template<typename StrictWeakOrdering> 
    void merge(list< T, A > &, StrictWeakOrdering) ;
  void sort() ;
  template<typename StrictWeakOrdering> void sort(StrictWeakOrdering) ;
};

Description

A list is a doubly linked list. That is, it is a Sequence that supports both forward and backward traversal, and (amortized) constant time insertion and removal of elements at the beginning or the end, or in the middle. 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, list<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.

list public types

  1. typedef T value_type;

    The type of object, T, stored in the list

list public construct/copy/destruct

  1. list(const allocator_type & a = A());

    Effects: Constructs a list taking the allocator as parameter.

    Throws: If allocator_type's copy constructor throws.

    Complexity: Constant.

  2. list(size_type n, const T & value = T(), const A & a = A());

    Effects: Constructs a list that will use a copy of allocator a and inserts n copies of value.

    Throws: If allocator_type's default constructor or copy constructor throws or T's default or copy constructor throws.

    Complexity: Linear to n.

  3. list(const list & x);

    Effects: Copy constructs a list.

    Postcondition: x == *this.

    Throws: If allocator_type's default constructor or copy constructor throws.

    Complexity: Linear to the elements x contains.

  4. list(unspecified x);

    Effects: Move constructor. Moves mx's resources to *this.

    Throws: If allocator_type's default constructor throws.

    Complexity: Constant.

  5. template<typename InpIt> list(InpIt first, InpIt last, const A & a = A());

    Effects: Constructs a list that will use a copy of allocator a and inserts a copy of the range [first, last) in the list.

    Throws: If allocator_type's default constructor or copy constructor throws or T's constructor taking an dereferenced InIt throws.

    Complexity: Linear to the range [first, last).

  6. list& operator=(const ThisType & x);

    Effects: Swaps the contents of *this and x. If this->allocator_type() != x.allocator_type() allocators are also swapped.

    Throws: Nothing.

    Complexity: Constant. Effects: Makes *this contain the same elements as x.

    Postcondition: this->size() == x.size(). *this contains a copy of each of x's elements.

    Throws: If memory allocation throws or T's copy constructor throws.

    Complexity: Linear to the number of elements in x.

  7. list& operator=(unspecified mx);

    Effects: Move assignment. All mx's values are transferred to *this.

    Postcondition: x.empty(). *this contains a the elements x had before the function.

    Throws: If allocator_type's copy constructor throws.

    Complexity: Constant.

  8. ~list();

    Effects: Destroys the list. All stored values are destroyed and used memory is deallocated.

    Throws: Nothing.

    Complexity: Linear to the number of elements.

list public member functions

  1. allocator_type get_allocator() const;

    Effects: Returns a copy of the internal allocator.

    Throws: If allocator's copy constructor throws.

    Complexity: Constant.

  2. const stored_allocator_type & get_stored_allocator() const;
  3. stored_allocator_type & get_stored_allocator() ;
  4. void clear() ;

    Effects: Erases all the elements of the list.

    Throws: Nothing.

    Complexity: Linear to the number of elements in the list.

  5. iterator begin() ;

    Effects: Returns an iterator to the first element contained in the list.

    Throws: Nothing.

    Complexity: Constant.

  6. const_iterator begin() const;

    Effects: Returns a const_iterator to the first element contained in the list.

    Throws: Nothing.

    Complexity: Constant.

  7. iterator end() ;

    Effects: Returns an iterator to the end of the list.

    Throws: Nothing.

    Complexity: Constant.

  8. const_iterator end() const;

    Effects: Returns a const_iterator to the end of the list.

    Throws: Nothing.

    Complexity: Constant.

  9. reverse_iterator rbegin() ;

    Effects: Returns a reverse_iterator pointing to the beginning of the reversed list.

    Throws: Nothing.

    Complexity: Constant.

  10. const_reverse_iterator rbegin() const;

    Effects: Returns a const_reverse_iterator pointing to the beginning of the reversed list.

    Throws: Nothing.

    Complexity: Constant.

  11. reverse_iterator rend() ;

    Effects: Returns a reverse_iterator pointing to the end of the reversed list.

    Throws: Nothing.

    Complexity: Constant.

  12. const_reverse_iterator rend() const;

    Effects: Returns a const_reverse_iterator pointing to the end of the reversed list.

    Throws: Nothing.

    Complexity: Constant.

  13. bool empty() const;

    Effects: Returns true if the list contains no elements.

    Throws: Nothing.

    Complexity: Constant.

  14. size_type size() const;

    Effects: Returns the number of the elements contained in the list.

    Throws: Nothing.

    Complexity: Constant.

  15. size_type max_size() const;

    Effects: Returns the largest possible size of the list.

    Throws: Nothing.

    Complexity: Constant.

  16. void push_front(const T & x) ;

    Effects: Inserts a copy of t in the beginning of the list.

    Throws: If memory allocation throws or T's copy constructor throws.

    Complexity: Amortized constant time.

  17. void push_front(unspecified x) ;

    Effects: Constructs a new element in the beginning of the list and moves the resources of t to this new element.

    Throws: If memory allocation throws.

    Complexity: Amortized constant time.

  18. void push_back(const T & x) ;

    Effects: Removes the last element from the list.

    Throws: Nothing.

    Complexity: Amortized constant time.

  19. void push_back(unspecified x) ;

    Effects: Removes the first element from the list.

    Throws: Nothing.

    Complexity: Amortized constant time.

  20. void pop_front() ;

    Effects: Removes the first element from the list.

    Throws: Nothing.

    Complexity: Amortized constant time.

  21. void pop_back() ;

    Effects: Removes the last element from the list.

    Throws: Nothing.

    Complexity: Amortized constant time.

  22. reference front() ;

    Requires: !empty()

    Effects: Returns a reference to the first element from the beginning of the container.

    Throws: Nothing.

    Complexity: Constant.

  23. const_reference front() const;

    Requires: !empty()

    Effects: Returns a const reference to the first element from the beginning of the container.

    Throws: Nothing.

    Complexity: Constant.

  24. reference back() ;

    Requires: !empty()

    Effects: Returns a reference to the first element from the beginning of the container.

    Throws: Nothing.

    Complexity: Constant.

  25. const_reference back() const;

    Requires: !empty()

    Effects: Returns a const reference to the first element from the beginning of the container.

    Throws: Nothing.

    Complexity: Constant.

  26. void resize(size_type new_size, const T & x) ;

    Effects: Inserts or erases elements at the end such that the size becomes n. New elements are copy constructed from x.

    Throws: If memory allocation throws, or T's copy constructor throws.

    Complexity: Linear to the difference between size() and new_size.

  27. void resize(size_type new_size) ;

    Effects: Inserts or erases elements at the end such that the size becomes n. New elements are default constructed.

    Throws: If memory allocation throws, or T's copy constructor throws.

    Complexity: Linear to the difference between size() and new_size.

  28. void swap(ThisType & x) ;

    Effects: Swaps the contents of *this and x. If this->allocator_type() != x.allocator_type() allocators are also swapped.

    Throws: Nothing.

    Complexity: Constant.

  29. void insert(iterator p, size_type n, const T & x) ;

    Requires: p must be a valid iterator of *this.

    Effects: Inserts n copies of x before p.

    Throws: If memory allocation throws or T's copy constructor throws.

    Complexity: Linear to n.

  30. template<typename InpIt> void insert(iterator p, InpIt first, InpIt last) ;

    Requires: p must be a valid iterator of *this.

    Effects: Insert a copy of the [first, last) range before p.

    Throws: If memory allocation throws, T's constructor from a dereferenced InpIt throws.

    Complexity: Linear to std::distance [first, last).

  31. iterator insert(iterator p, const T & x) ;

    Requires: p must be a valid iterator of *this.

    Effects: Insert a copy of x before p.

    Throws: If memory allocation throws or x's copy constructor throws.

    Complexity: Amortized constant time.

  32. iterator insert(iterator p, unspecified x) ;

    Requires: p must be a valid iterator of *this.

    Effects: Insert a new element before p with mx's resources.

    Throws: If memory allocation throws.

    Complexity: Amortized constant time.

  33. iterator erase(iterator p) ;

    Requires: p must be a valid iterator of *this.

    Effects: Erases the element at p p.

    Throws: Nothing.

    Complexity: Amortized constant time.

  34. iterator erase(iterator first, iterator last) ;

    Requires: first and last must be valid iterator to elements in *this.

    Effects: Erases the elements pointed by [first, last).

    Throws: Nothing.

    Complexity: Linear to the distance between first and last.

  35. void assign(size_type n, const T & val) ;

    Effects: Assigns the n copies of val to *this.

    Throws: If memory allocation throws or T's copy constructor throws.

    Complexity: Linear to n.

  36. template<typename InpIt> void assign(InpIt first, InpIt last) ;

    Effects: Assigns the the range [first, last) to *this.

    Throws: If memory allocation throws or T's constructor from dereferencing InpIt throws.

    Complexity: Linear to n.

  37. void splice(iterator p, ThisType & x) ;

    Requires: p must point to an element contained by the list. x != *this

    Effects: Transfers all the elements of list x to this list, before the the element pointed by p. No destructors or copy constructors are called.

    Throws: std::runtime_error if this' allocator and x's allocator are not equal.

    Complexity: Constant.

    Note: Iterators of values obtained from list x now point to elements of this list. Iterators of this list and all the references are not invalidated.

  38. void splice(iterator p, ThisType & x, iterator i) ;

    Requires: p must point to an element contained by this list. i must point to an element contained in list x.

    Effects: Transfers the value pointed by i, from list x to this list, before the the element pointed by p. No destructors or copy constructors are called. If p == i or p == ++i, this function is a null operation.

    Throws: std::runtime_error if this' allocator and x's allocator are not equal.

    Complexity: Constant.

    Note: Iterators of values obtained from list x now point to elements of this list. Iterators of this list and all the references are not invalidated.

  39. void splice(iterator p, ThisType & x, iterator first, iterator last) ;

    Requires: p must point to an element contained by this list. first and last must point to elements contained in list x.

    Effects: Transfers the range pointed by first and last from list x to this list, before the the element pointed by p. No destructors or copy constructors are called.

    Throws: std::runtime_error if this' allocator and x's allocator are not equal.

    Complexity: Linear to the number of elements transferred.

    Note: Iterators of values obtained from list x now point to elements of this list. Iterators of this list and all the references are not invalidated.

  40. void splice(iterator p, ThisType & x, iterator first, iterator last, 
                size_type n) ;

    Requires: p must point to an element contained by this list. first and last must point to elements contained in list x. n == std::distance(first, last)

    Effects: Transfers the range pointed by first and last from list x to this list, before the the element pointed by p. No destructors or copy constructors are called.

    Throws: std::runtime_error if this' allocator and x's allocator are not equal.

    Complexity: Constant.

    Note: Iterators of values obtained from list x now point to elements of this list. Iterators of this list and all the references are not invalidated.

  41. void reverse() ;

    Effects: Reverses the order of elements in the list.

    Throws: Nothing.

    Complexity: This function is linear time.

    Note: Iterators and references are not invalidated

  42. void remove(const T & value) ;

    Effects: Removes all the elements that compare equal to value.

    Throws: Nothing.

    Complexity: Linear time. It performs exactly size() comparisons for equality.

    Note: The relative order of elements that are not removed is unchanged, and iterators to elements that are not removed remain valid.

  43. template<typename Pred> void remove_if(Pred pred) ;

    Effects: Removes all the elements for which a specified predicate is satisfied.

    Throws: If pred throws.

    Complexity: Linear time. It performs exactly size() calls to the predicate.

    Note: The relative order of elements that are not removed is unchanged, and iterators to elements that are not removed remain valid.

  44. void unique() ;

    Effects: Removes adjacent duplicate elements or adjacent elements that are equal from the list.

    Throws: Nothing.

    Complexity: Linear time (size()-1 comparisons calls to pred()).

    Note: The relative order of elements that are not removed is unchanged, and iterators to elements that are not removed remain valid.

  45. template<typename BinaryPredicate> void unique(BinaryPredicate binary_pred) ;

    Effects: Removes adjacent duplicate elements or adjacent elements that satisfy some binary predicate from the list.

    Throws: If pred throws.

    Complexity: Linear time (size()-1 comparisons equality comparisons).

    Note: The relative order of elements that are not removed is unchanged, and iterators to elements that are not removed remain valid.

  46. void merge(list< T, A > & x) ;

    Requires: The lists x and *this must be distinct.

    Effects: This function removes all of x's elements and inserts them in order into *this according to std::less<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.

    Throws: Nothing.

    Complexity: This function is linear time: it performs at most size() + x.size() - 1 comparisons.

  47. template<typename StrictWeakOrdering> 
      void merge(list< T, A > & x, StrictWeakOrdering comp) ;

    Effects: This function removes all of moved mx'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.

    Throws: Nothing.

    Complexity: This function is linear time: it performs at most size() + x.size() - 1 comparisons.

    Note: Iterators and references to *this are not invalidated. Requires: p must be a comparison function that induces a strict weak ordering and both *this and x must be sorted according to that ordering The lists x and *this must be distinct.

    Effects: This function removes all of x's elements and inserts them in order into *this. The merge is stable; that is, if an element from *this is equivalent to one from x, then the element from *this will precede the one from x.

    Throws: Nothing.

    Complexity: This function is linear time: it performs at most size() + x.size() - 1 comparisons.

    Note: Iterators and references to *this are not invalidated.

  48. void sort() ;

    Requires: p must be a comparison function that induces a strict weak ordering and both *this and x must be sorted according to that ordering The lists x and *this must be distinct.

    Effects: This function removes all of moved mx's elements and inserts them in order into *this. The merge is stable; that is, if an element from *this is equivalent to one from x, then the element from *this will precede the one from x.

    Throws: Nothing.

    Complexity: This function is linear time: it performs at most size() + x.size() - 1 comparisons.

    Note: Iterators and references to *this are not invalidated. Effects: 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.

    Throws: Nothing.

    Notes: Iterators and references are not invalidated.

    Complexity: The number of comparisons is approximately N log N, where N is the list's size.

  49. template<typename StrictWeakOrdering> void sort(StrictWeakOrdering comp) ;

    Effects: 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.

    Throws: Nothing.

    Notes: Iterators and references are not invalidated.

    Complexity: The number of comparisons is approximately N log N, where N is the list's size.


PrevUpHomeNext