#include <stl_list.h>
List of all members.
Detailed Description
template<typename Type, typename Alloc = allocator<Type>>
class std::list< Type, Alloc >
Meets the requirements of a container, a reversible container, and a sequence, including the optional sequence requirements with the exception of at
and operator
[].
This is a doubly linked list. Traversal up and down the list requires linear time, but adding and removing elements (or nodes) is done in constant time, regardless of where the change takes place. Unlike std::vector and std::deque, random-access iterators are not provided, so subscripting (
[] ) access is not allowed. For algorithms which only need sequential access, this lack makes no difference.
Also unlike the other standard containers, std::list provides specialized algorithms unique to linked lists, such as splicing, sorting, and in-place reversal.
Definition at line 389 of file stl_list.h.
Public Types
-
typedef Base::allocator_type allocator_type
-
typedef List_const_iterator<
Type > const_iterator
-
typedef Alloc::const_pointer const_pointer
-
typedef Alloc::const_reference const_reference
-
typedef std::reverse_iterator<
const_iterator > const_reverse_iterator
-
typedef ptrdiff_t difference_type
-
typedef List_iterator< Type > iterator
-
typedef Alloc::pointer pointer
-
typedef Alloc::reference reference
-
typedef std::reverse_iterator<
iterator > reverse_iterator
-
typedef size_t size_type
-
typedef Type value_type
Public Member Functions
- template<typename InputIterator> void assign (InputIterator first, InputIterator last)
- void assign (size_type n, const value_type &__val)
- const_reference back () const
- reference back ()
- const_iterator begin () const
- iterator begin ()
- void clear ()
- bool empty () const
- const_iterator end () const
- iterator end ()
- iterator erase (iterator first, iterator last)
- iterator erase (iterator position)
- const_reference front () const
- reference front ()
- allocator_type get_allocator () const
- template<typename InputIterator> void insert (iterator position, InputIterator first, InputIterator last)
- void insert (iterator position, size_type n, const value_type &x)
- iterator insert (iterator position, const value_type &x)
- template<typename InputIterator> list (InputIterator first, InputIterator last, const allocator_type &a=allocator_type())
- list (const list &x)
- list (size_type n)
- list (size_type n, const value_type &value, const allocator_type &a=allocator_type())
- list (const allocator_type &a=allocator_type())
- size_type max_size () const
- template<typename StrictWeakOrdering> void merge (list &, StrictWeakOrdering)
- void merge (list &x)
- list & operator= (const list &x)
- void pop_back ()
- void pop_front ()
- void push_back (const value_type &x)
- void push_front (const value_type &x)
- const_reverse_iterator rbegin () const
- reverse_iterator rbegin ()
- void remove (const Type &value)
- template<typename Predicate> void remove_if (Predicate)
- const_reverse_iterator rend () const
- reverse_iterator rend ()
- void resize (size_type new_size)
- void resize (size_type new_size, const value_type &x)
- void reverse ()
- size_type size () const
- template<typename StrictWeakOrdering> void sort (StrictWeakOrdering)
- void sort ()
- void splice (iterator position, list &, iterator first, iterator last)
- void splice (iterator position, list &, iterator __i)
- void splice (iterator position, list &x)
- void swap (list &x)
- template<typename BinaryPredicate> void unique (BinaryPredicate)
- void unique ()
Protected Types
-
typedef List_node< Type > Node
Protected Member Functions
-
template<typename InputIterator> void M_assign_dispatch (InputIterator first, InputIterator last, __false_type)
-
template<typename Integer> void M_assign_dispatch (Integer n, Integer __val, __true_type)
-
Node * M_create_node (const value_type &x)
-
void M_erase (iterator position)
-
void M_fill_assign (size_type n, const value_type &__val)
-
void M_fill_insert (iterator position, size_type n, const value_type &x)
-
void M_insert (iterator position, const value_type &x)
-
template<typename InputIterator> void M_insert_dispatch (iterator position, InputIterator first, InputIterator last, __false_type)
-
template<typename Integer> void M_insert_dispatch (iterator position, Integer n, Integer x, __true_type)
-
void M_transfer (iterator position, iterator first, iterator last)
Constructor & Destructor Documentation
list |
( |
const allocator_type & |
a = allocator_type() |
) |
[inline, explicit] |
|
|
Default constructor creates no elements.
Definition at line 455 of file stl_list.h. |
list |
( |
size_type |
n, |
|
|
const value_type & |
value, |
|
|
const allocator_type & |
a = allocator_type() |
|
) |
[inline] |
|
|
Create a list with copies of an exemplar element.
- Parameters:
-
| n | The number of elements to initially create. |
| value | An element to copy. |
This constructor fills the list with n copies of value. Definition at line 465 of file stl_list.h. |
list |
( |
size_type |
n |
) |
[inline, explicit] |
|
|
Create a list with default elements.
- Parameters:
-
| n | The number of elements to initially create. |
This constructor fills the list with n copies of a default-constructed element. Definition at line 478 of file stl_list.h. |
list |
( |
const list< Type, Alloc > & |
x |
) |
[inline] |
|
|
List copy constructor.
- Parameters:
-
| x | A list of identical element and allocator types. |
The newly-created list uses a copy of the allocation object used by x. Definition at line 489 of file stl_list.h.
References list::begin(), and list::end(). |
list |
( |
InputIterator |
first, |
|
|
InputIterator |
last, |
|
|
const allocator_type & |
a = allocator_type() |
|
) |
[inline] |
|
|
Builds a list from a range.
- Parameters:
-
| first | An input iterator. |
| last | An input iterator. |
Create a list consisting of copies of the elements from [first,last). This is linear in N (where N is distance(first,last)). Definition at line 508 of file stl_list.h. |
Member Function Documentation
void assign |
( |
InputIterator |
first, |
|
|
InputIterator |
last |
|
) |
[inline] |
|
|
Assigns a range to a list.
- Parameters:
-
| first | An input iterator. |
| last | An input iterator. |
This function fills a list with copies of the elements in the range [first,last).
Note that the assignment completely changes the list and that the resulting list's size is the same as the number of elements assigned. Old data may be lost. Definition at line 559 of file stl_list.h. |
void assign |
( |
size_type |
n, |
|
|
const value_type & |
__val |
|
) |
[inline] |
|
|
Assigns a given value to a list.
- Parameters:
-
| n | Number of elements to be assigned. |
| val | Value to be assigned. |
This function fills a list with n copies of the given value. Note that the assignment completely changes the list and that the resulting list's size is the same as the number of elements assigned. Old data may be lost. Definition at line 542 of file stl_list.h. |
const_reference back |
( |
|
) |
const [inline] |
|
|
Returns a read-only (constant) reference to the data at the last element of the list. Definition at line 717 of file stl_list.h. |
reference back |
( |
|
) |
[inline] |
|
|
Returns a read/write reference to the data at the last element of the list. Definition at line 709 of file stl_list.h. |
|
Returns a read-only (constant) iterator that points to the first element in the list. Iteration is done in ordinary element order. Definition at line 586 of file stl_list.h. |
|
Erases all the elements. Note that this function only erases the elements, and that if the elements themselves are pointers, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibilty. Definition at line 900 of file stl_list.h. |
bool empty |
( |
|
) |
const [inline] |
|
|
Returns a read-only (constant) iterator that points one past the last element in the list. Iteration is done in ordinary element order. Definition at line 603 of file stl_list.h. |
|
Remove a range of elements.
- Parameters:
-
| first | Iterator pointing to the first element to be erased. |
| last | Iterator pointing to one past the last element to be erased. |
- Returns:
- An iterator pointing to the element pointed to by last prior to erasing (or end()).
This function will erase the elements in the range [first,last) and shorten the list accordingly.
Due to the nature of a list this operation can be done in constant time, and only invalidates iterators/references to the element being removed. The user is also cautioned that this function only erases the elements, and that if the elements themselves are pointers, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibilty. Definition at line 873 of file stl_list.h. |
|
Remove element at given position.
- Parameters:
-
| position | Iterator pointing to element to be erased. |
- Returns:
- An iterator pointing to the next element (or end()).
This function will erase the element at the given position and thus shorten the list by one.
Due to the nature of a list this operation can be done in constant time, and only invalidates iterators/references to the element being removed. The user is also cautioned that this function only erases the element, and that if the element is itself a pointer, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibilty. Definition at line 95 of file list.tcc.
Referenced by list::operator=(), and list::resize(). |
const_reference front |
( |
|
) |
const [inline] |
|
|
Returns a read-only (constant) reference to the data at the first element of the list. Definition at line 701 of file stl_list.h. |
reference front |
( |
|
) |
[inline] |
|
|
Returns a read/write reference to the data at the first element of the list. Definition at line 693 of file stl_list.h. |
allocator_type get_allocator |
( |
|
) |
const [inline] |
|
|
Get a copy of the memory allocation object.
Definition at line 568 of file stl_list.h. |
void insert |
( |
iterator |
position, |
|
|
InputIterator |
first, |
|
|
InputIterator |
last |
|
) |
[inline] |
|
|
Inserts a range into the list.
- Parameters:
-
| position | An iterator into the list. |
| first | An input iterator. |
| last | An input iterator. |
This function will insert copies of the data in the range [first,last) into the list before the location specified by position.
Due to the nature of a list this operation can be done in constant time, and does not invalidate iterators and references. Definition at line 827 of file stl_list.h. |
void insert |
( |
iterator |
position, |
|
|
size_type |
n, |
|
|
const value_type & |
x |
|
) |
[inline] |
|
|
Inserts a number of copies of given data into the list.
- Parameters:
-
| position | An iterator into the list. |
| n | Number of elements to be inserted. |
| x | Data to be inserted. |
This function will insert a specified number of copies of the given data before the location specified by position.
Due to the nature of a list this operation can be done in constant time, and does not invalidate iterators and references. Definition at line 808 of file stl_list.h. |
|
Inserts given value into list before specified iterator.
- Parameters:
-
| position | An iterator into the list. |
| x | Data to be inserted. |
- Returns:
- An iterator that points to the inserted data.
This function will insert a copy of the given value before the specified location. Due to the nature of a list this operation can be done in constant time, and does not invalidate iterators and references. Definition at line 85 of file list.tcc.
Referenced by list::operator=(), and list::resize(). |
size_type max_size |
( |
|
) |
const [inline] |
|
void merge |
( |
list< Type, Alloc > & |
, |
|
|
StrictWeakOrdering |
|
|
) |
|
|
|
Merge sorted lists according to comparison function.
- Parameters:
-
| x | Sorted list to merge. |
| StrictWeakOrdering | Comparison function definining sort order. |
Assumes that both x and this list are sorted according to StrictWeakOrdering. Merges elements of x into this list in sorted order, leaving x empty when complete. Elements in this list precede elements in x that are equivalent according to StrictWeakOrdering(). Definition at line 314 of file list.tcc.
References list::begin(), and list::end(). |
void merge |
( |
list< Type, Alloc > & |
x |
) |
|
|
|
Merge sorted lists.
- Parameters:
-
Assumes that both x and this list are sorted according to operator<(). Merges elements of x into this list in sorted order, leaving x empty when complete. Elements in this list precede elements in x that are equal. Definition at line 210 of file list.tcc.
References list::begin(), and list::end().
Referenced by list::sort(). |
list< Type, Alloc > & operator= |
( |
const list< Type, Alloc > & |
x |
) |
|
|
void pop_back |
( |
|
) |
[inline] |
|
|
Removes last element.
This is a typical stack operation. It shrinks the list by one. Due to the nature of a list this operation can be done in constant time, and only invalidates iterators/references to the element being removed.
Note that no data is returned, and if the last element's data is needed, it should be retrieved before pop_back() is called. Definition at line 777 of file stl_list.h. |
void pop_front |
( |
|
) |
[inline] |
|
|
Removes first element.
This is a typical stack operation. It shrinks the list by one. Due to the nature of a list this operation can be done in constant time, and only invalidates iterators/references to the element being removed.
Note that no data is returned, and if the first element's data is needed, it should be retrieved before pop_front() is called. Definition at line 748 of file stl_list.h. |
void push_back |
( |
const value_type & |
x |
) |
[inline] |
|
|
Add data to the end of the list.
- Parameters:
-
This is a typical stack operation. The function creates an element at the end of the list and assigns the given data to it. Due to the nature of a list this operation can be done in constant time, and does not invalidate iterators and references. Definition at line 762 of file stl_list.h. |
void push_front |
( |
const value_type & |
x |
) |
[inline] |
|
|
Add data to the front of the list.
- Parameters:
-
This is a typical stack operation. The function creates an element at the front of the list and assigns the given data to it. Due to the nature of a list this operation can be done in constant time, and does not invalidate iterators and references. Definition at line 732 of file stl_list.h. |
|
Returns a read-only (constant) reverse iterator that points to the last element in the list. Iteration is done in reverse element order. Definition at line 621 of file stl_list.h. |
|
Returns a read/write reverse iterator that points to the last element in the list. Iteration is done in reverse element order. Definition at line 612 of file stl_list.h. |
void remove |
( |
const Type & |
value |
) |
|
|
|
Remove all elements equal to value.
- Parameters:
-
| value | The value to remove. |
Removes every element in the list equal to value. Remaining elements stay in list order. Note that this function only erases the elements, and that if the elements themselves are pointers, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibilty. |
void remove_if |
( |
Predicate |
|
) |
|
|
|
Remove all elements satisfying a predicate.
- Parameters:
-
| Predicate | Unary predicate function or object. |
Removes every element in the list for which the predicate returns true. Remaining elements stay in list order. Note that this function only erases the elements, and that if the elements themselves are pointers, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibilty. Definition at line 275 of file list.tcc.
References list::begin(), and list::end(). |
|
Returns a read-only (constant) reverse iterator that points to one before the first element in the list. Iteration is done in reverse element order. Definition at line 639 of file stl_list.h. |
|
Returns a read/write reverse iterator that points to one before the first element in the list. Iteration is done in reverse element order. Definition at line 630 of file stl_list.h. |
void resize |
( |
size_type |
new_size |
) |
[inline] |
|
|
Resizes the list to the specified number of elements.
- Parameters:
-
| new_size | Number of elements the list should contain. |
This function will resize the list to the specified number of elements. If the number is smaller than the list's current size the list is truncated, otherwise the list is extended and new elements are default-constructed. Definition at line 684 of file stl_list.h. |
void resize |
( |
size_type |
new_size, |
|
|
const value_type & |
x |
|
) |
|
|
|
Resizes the list to the specified number of elements.
- Parameters:
-
| new_size | Number of elements the list should contain. |
| x | Data with which new elements should be populated. |
This function will resize the list to the specified number of elements. If the number is smaller than the list's current size the list is truncated, otherwise the list is extended and new elements are populated with given data. Definition at line 105 of file list.tcc.
References list::begin(), list::end(), list::erase(), and list::insert(). |
void reverse |
( |
|
) |
[inline] |
|
|
Reverse the elements in list.
Reverse the order of elements in the list in linear time. Definition at line 1053 of file stl_list.h. |
size_type size |
( |
|
) |
const [inline] |
|
void sort |
( |
StrictWeakOrdering |
|
) |
|
|
|
Insert range from another list.
- Parameters:
-
| position | Iterator referencing the element to insert before. |
| x | Source list. |
| first | Iterator referencing the start of range in x. |
| last | Iterator referencing the end of range in x. |
Removes elements in the range [first,last) and inserts them before position in constant time.
Undefined if position is in [first,last). Definition at line 955 of file stl_list.h. |
|
Insert element from another list.
- Parameters:
-
| position | Iterator referencing the element to insert before. |
| x | Source list. |
| i | Iterator referencing the element to move. |
Removes the element in list x referenced by i and inserts it into the current list before position. Definition at line 933 of file stl_list.h. |
void splice |
( |
iterator |
position, |
|
|
list< Type, Alloc > & |
x |
|
) |
[inline] |
|
|
Insert contents of another list.
- Parameters:
-
| position | Iterator referencing the element to insert before. |
| x | Source list. |
The elements of x are inserted in constant time in front of the element referenced by position. x becomes an empty list. Definition at line 917 of file stl_list.h.
References list::begin(), list::empty(), and list::end().
Referenced by list::sort(). |
void swap |
( |
list< Type, Alloc > & |
x |
) |
[inline] |
|
|
Swaps data with another list.
- Parameters:
-
| x | A list of the same element and allocator types. |
This exchanges the elements between two lists in constant time. Note that the global std::swap() function is specialized such that std::swap(l1,l2) will feed to this function. Definition at line 890 of file stl_list.h.
References std::swap().
Referenced by list::sort(), and std::swap(). |
void unique |
( |
BinaryPredicate |
|
) |
|
|
|
Remove consecutive elements satisfying a predicate.
- Parameters:
-
| BinaryPredicate | Binary predicate function or object. |
For each consecutive set of elements [first,last) that satisfy predicate(first,i) where i is an iterator in [first,last), remove all but the first one. Remaining elements stay in list order. Note that this function only erases the elements, and that if the elements themselves are pointers, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibilty. Definition at line 293 of file list.tcc.
References list::begin(), and list::end(). |
|
Remove consecutive duplicate elements.
For each consecutive set of elements with the same value, remove all but the first one. Remaining elements stay in list order. Note that this function only erases the elements, and that if the elements themselves are pointers, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibilty. Definition at line 190 of file list.tcc.
References list::begin(), and list::end(). |
The documentation for this class was generated from the following files:
Generated on Sun Sep 12 15:50:19 2004 for libstdc++ source by
1.3.8