#include <stl_list.h>
Public Types | |
typedef Type | value_type |
typedef Alloc::pointer | pointer |
typedef Alloc::const_pointer | const_pointer |
typedef Alloc::reference | reference |
typedef Alloc::const_reference | const_reference |
typedef List_iterator< Type > | iterator |
typedef List_const_iterator < Type > | const_iterator |
typedef std::reverse_iterator < const_iterator > | const_reverse_iterator |
typedef std::reverse_iterator < iterator > | reverse_iterator |
typedef size_t | size_type |
typedef ptrdiff_t | difference_type |
typedef Base::allocator_type | allocator_type |
Public Member Functions | |
list (const allocator_type &a=allocator_type()) | |
Default constructor creates no elements. | |
list (size_type n, const value_type &value, const allocator_type &a=allocator_type()) | |
Create a list with copies of an exemplar element. | |
list (size_type n) | |
Create a list with default elements. | |
list (const list &x) | |
List copy constructor. | |
template<typename InputIterator> | |
list (InputIterator first, InputIterator last, const allocator_type &a=allocator_type()) | |
Builds a list from a range. | |
list & | operator= (const list &x) |
List assignment operator. | |
void | assign (size_type n, const value_type &__val) |
Assigns a given value to a list. | |
template<typename InputIterator> | |
void | assign (InputIterator first, InputIterator last) |
Assigns a range to a list. | |
allocator_type | get_allocator () const |
Get a copy of the memory allocation object. | |
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 | resize (size_type new_size, const value_type &x) |
Resizes the list to the specified number of elements. | |
void | resize (size_type new_size) |
Resizes the list to the specified number of elements. | |
reference | front () |
const_reference | front () const |
reference | back () |
const_reference | back () const |
void | push_front (const value_type &x) |
Add data to the front of the list. | |
void | pop_front () |
Removes first element. | |
void | push_back (const value_type &x) |
Add data to the end of the list. | |
void | pop_back () |
Removes last element. | |
iterator | insert (iterator position, const value_type &x) |
Inserts given value into list before specified iterator. | |
void | insert (iterator position, size_type n, const value_type &x) |
Inserts a number of copies of given data into the list. | |
template<typename InputIterator> | |
void | insert (iterator position, InputIterator first, InputIterator last) |
Inserts a range into the list. | |
iterator | erase (iterator position) |
Remove element at given position. | |
iterator | erase (iterator first, iterator last) |
Remove a range of elements. | |
void | swap (list &x) |
Swaps data with another list. | |
void | clear () |
void | splice (iterator position, list &x) |
Insert contents of another list. | |
void | splice (iterator position, list &, iterator __i) |
Insert element from another list. | |
void | splice (iterator position, list &, iterator first, iterator last) |
Insert range from another list. | |
void | remove (const Type &value) |
Remove all elements equal to value. | |
template<typename Predicate> | |
void | remove_if (Predicate) |
Remove all elements satisfying a predicate. | |
void | unique () |
Remove consecutive duplicate elements. | |
template<typename BinaryPredicate> | |
void | unique (BinaryPredicate) |
Remove consecutive elements satisfying a predicate. | |
void | merge (list &x) |
Merge sorted lists. | |
template<typename StrictWeakOrdering> | |
void | merge (list &, StrictWeakOrdering) |
Merge sorted lists according to comparison function. | |
void | reverse () |
Reverse the elements in list. | |
void | sort () |
Sort the elements. | |
template<typename StrictWeakOrdering> | |
void | sort (StrictWeakOrdering) |
Sort the elements according to comparison function. | |
Protected Types | |
typedef List_node< Type > | Node |
typedef Alloc::template rebind< List_node < Type > >::other | NodeAlloc_type |
Protected Member Functions | |
Node * | M_create_node (const value_type &x) |
Node * | M_create_node () |
template<typename Integer> | |
void | M_assign_dispatch (Integer n, Integer __val, __true_type) |
template<typename InputIterator> | |
void | M_assign_dispatch (InputIterator first, InputIterator last, __false_type) |
void | M_fill_assign (size_type n, const value_type &__val) |
template<typename Integer> | |
void | M_insert_dispatch (iterator position, Integer n, Integer x, __true_type) |
template<typename InputIterator> | |
void | M_insert_dispatch (iterator position, InputIterator first, InputIterator last, __false_type) |
void | M_fill_insert (iterator position, size_type n, const value_type &x) |
void | M_transfer (iterator position, iterator first, iterator last) |
void | M_insert (iterator position, const value_type &x) |
void | M_erase (iterator position) |
List_node< Type > * | M_get_node () |
void | M_put_node (List_node< Type > *__p) |
void | M_clear () |
void | M_init () |
Protected Attributes | |
List_impl | M_impl |
Private Types | |
typedef List_base < Type, Alloc > | Base |
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.
std::list< Type, Alloc >::list | ( | const allocator_type & | a = allocator_type() |
) | [inline, explicit] |
std::list< Type, Alloc >::list | ( | size_type | n, | |
const value_type & | value, | |||
const allocator_type & | a = allocator_type() | |||
) | [inline] |
Create a list with copies of an exemplar element.
n | The number of elements to initially create. | |
value | An element to copy. |
Definition at line 487 of file stl_list.h.
std::list< Type, Alloc >::list | ( | size_type | n | ) | [inline, explicit] |
Create a list with default elements.
n | The number of elements to initially create. |
Definition at line 500 of file stl_list.h.
std::list< Type, Alloc >::list | ( | const list< Type, Alloc > & | x | ) | [inline] |
List copy constructor.
x | A list of identical element and allocator types. |
Definition at line 511 of file stl_list.h.
std::list< Type, Alloc >::list | ( | InputIterator | first, | |
InputIterator | last, | |||
const allocator_type & | a = allocator_type() | |||
) | [inline] |
Builds a list from a range.
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 530 of file stl_list.h.
list< Type, Alloc > & std::list< Type, Alloc >::operator= | ( | const list< Type, Alloc > & | x | ) | [inline] |
List assignment operator.
No explicit dtor needed as the Base dtor takes care of things. The Base dtor only erases the elements, and note 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.
x | A list of identical element and allocator types. |
Definition at line 120 of file list.tcc.
References std::list< Type, Alloc >::begin(), std::list< Type, Alloc >::end(), std::list< Type, Alloc >::erase(), and std::list< Type, Alloc >::insert().
void std::list< Type, Alloc >::assign | ( | size_type | n, | |
const value_type & | __val | |||
) | [inline] |
Assigns a given value to a list.
n | Number of elements to be assigned. | |
val | Value to be assigned. |
Reimplemented in __gnu_debug_def::list< Type, Allocator >.
Definition at line 564 of file stl_list.h.
void std::list< Type, Alloc >::assign | ( | InputIterator | first, | |
InputIterator | last | |||
) | [inline] |
Assigns a range to a list.
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.
Reimplemented in __gnu_debug_def::list< Type, Allocator >.
Definition at line 581 of file stl_list.h.
allocator_type std::list< Type, Alloc >::get_allocator | ( | ) | const [inline] |
Get a copy of the memory allocation object.
Reimplemented from std::List_base< Type, Alloc >.
Definition at line 590 of file stl_list.h.
Referenced by __gnu_debug_def::list< Type, Allocator >::splice().
iterator std::list< Type, Alloc >::begin | ( | ) | [inline] |
Returns a read/write iterator that points to the first element in the list. Iteration is done in ordinary element order.
Reimplemented in __gnu_debug_def::list< Type, Allocator >.
Definition at line 599 of file stl_list.h.
Referenced by std::list< Type, Allocator >::list(), std::list< Type, Alloc >::M_assign_dispatch(), std::list< Type, Alloc >::M_fill_assign(), std::list< Type, Alloc >::merge(), std::list< Type, Alloc >::operator=(), std::operator==(), std::list< Type, Alloc >::remove(), std::list< Type, Alloc >::remove_if(), std::list< Type, Alloc >::resize(), std::list< Type, Alloc >::sort(), std::list< Type, Allocator >::splice(), and std::list< Type, Alloc >::unique().
const_iterator std::list< Type, Alloc >::begin | ( | ) | const [inline] |
Returns a read-only (constant) iterator that points to the first element in the list. Iteration is done in ordinary element order.
Reimplemented in __gnu_debug_def::list< Type, Allocator >.
Definition at line 608 of file stl_list.h.
iterator std::list< Type, Alloc >::end | ( | ) | [inline] |
Returns a read/write iterator that points one past the last element in the list. Iteration is done in ordinary element order.
Reimplemented in __gnu_debug_def::list< Type, Allocator >.
Definition at line 617 of file stl_list.h.
Referenced by std::list< Type, Allocator >::list(), std::list< Type, Alloc >::M_assign_dispatch(), std::list< Type, Alloc >::M_fill_assign(), std::list< Type, Alloc >::merge(), std::list< Type, Alloc >::operator=(), std::operator==(), std::list< Type, Alloc >::remove(), std::list< Type, Alloc >::remove_if(), std::list< Type, Alloc >::resize(), std::list< Type, Allocator >::splice(), and std::list< Type, Alloc >::unique().
const_iterator std::list< Type, Alloc >::end | ( | ) | 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.
Reimplemented in __gnu_debug_def::list< Type, Allocator >.
Definition at line 625 of file stl_list.h.
reverse_iterator std::list< Type, Alloc >::rbegin | ( | ) | [inline] |
Returns a read/write reverse iterator that points to the last element in the list. Iteration is done in reverse element order.
Reimplemented in __gnu_debug_def::list< Type, Allocator >.
Definition at line 634 of file stl_list.h.
const_reverse_iterator std::list< Type, Alloc >::rbegin | ( | ) | const [inline] |
Returns a read-only (constant) reverse iterator that points to the last element in the list. Iteration is done in reverse element order.
Reimplemented in __gnu_debug_def::list< Type, Allocator >.
Definition at line 643 of file stl_list.h.
reverse_iterator std::list< Type, Alloc >::rend | ( | ) | [inline] |
Returns a read/write reverse iterator that points to one before the first element in the list. Iteration is done in reverse element order.
Reimplemented in __gnu_debug_def::list< Type, Allocator >.
Definition at line 652 of file stl_list.h.
const_reverse_iterator std::list< Type, Alloc >::rend | ( | ) | const [inline] |
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.
Reimplemented in __gnu_debug_def::list< Type, Allocator >.
Definition at line 661 of file stl_list.h.
bool std::list< Type, Alloc >::empty | ( | ) | const [inline] |
Returns true if the list is empty. (Thus begin() would equal end().)
Definition at line 670 of file stl_list.h.
Referenced by std::list< Type, Alloc >::sort(), and std::list< Type, Allocator >::splice().
size_type std::list< Type, Alloc >::size | ( | ) | const [inline] |
Returns the number of elements in the list.
Definition at line 675 of file stl_list.h.
size_type std::list< Type, Alloc >::max_size | ( | ) | const [inline] |
Returns the size() of the largest possible list.
Definition at line 680 of file stl_list.h.
void std::list< Type, Alloc >::resize | ( | size_type | new_size, | |
const value_type & | x | |||
) | [inline] |
Resizes the list to the specified number of elements.
new_size | Number of elements the list should contain. | |
x | Data with which new elements should be populated. |
Definition at line 105 of file list.tcc.
References std::list< Type, Alloc >::begin(), std::list< Type, Alloc >::end(), std::list< Type, Alloc >::erase(), and std::list< Type, Alloc >::insert().
void std::list< Type, Alloc >::resize | ( | size_type | new_size | ) | [inline] |
Resizes the list to the specified number of elements.
new_size | Number of elements the list should contain. |
Definition at line 706 of file stl_list.h.
reference std::list< Type, Alloc >::front | ( | ) | [inline] |
Returns a read/write reference to the data at the first element of the list.
Reimplemented in __gnu_debug_def::list< Type, Allocator >.
Definition at line 715 of file stl_list.h.
const_reference std::list< Type, Alloc >::front | ( | ) | const [inline] |
Returns a read-only (constant) reference to the data at the first element of the list.
Reimplemented in __gnu_debug_def::list< Type, Allocator >.
Definition at line 723 of file stl_list.h.
reference std::list< Type, Alloc >::back | ( | ) | [inline] |
Returns a read/write reference to the data at the last element of the list.
Reimplemented in __gnu_debug_def::list< Type, Allocator >.
Definition at line 731 of file stl_list.h.
const_reference std::list< Type, Alloc >::back | ( | ) | const [inline] |
Returns a read-only (constant) reference to the data at the last element of the list.
Reimplemented in __gnu_debug_def::list< Type, Allocator >.
Definition at line 739 of file stl_list.h.
void std::list< Type, Alloc >::push_front | ( | const value_type & | x | ) | [inline] |
Add data to the front of the list.
x | Data to be added. |
Definition at line 754 of file stl_list.h.
void std::list< Type, Alloc >::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.
Reimplemented in __gnu_debug_def::list< Type, Allocator >.
Definition at line 770 of file stl_list.h.
void std::list< Type, Alloc >::push_back | ( | const value_type & | x | ) | [inline] |
Add data to the end of the list.
x | Data to be added. |
Definition at line 784 of file stl_list.h.
void std::list< Type, Alloc >::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.
Reimplemented in __gnu_debug_def::list< Type, Allocator >.
Definition at line 799 of file stl_list.h.
list< Type, Alloc >::iterator std::list< Type, Alloc >::insert | ( | iterator | position, | |
const value_type & | x | |||
) | [inline] |
Inserts given value into list before specified iterator.
position | An iterator into the list. | |
x | Data to be inserted. |
Definition at line 85 of file list.tcc.
Referenced by std::list< Type, Alloc >::M_assign_dispatch(), std::list< Type, Alloc >::M_fill_assign(), std::list< Type, Alloc >::operator=(), and std::list< Type, Alloc >::resize().
void std::list< Type, Alloc >::insert | ( | iterator | position, | |
size_type | n, | |||
const value_type & | x | |||
) | [inline] |
Inserts a number of copies of given data into the list.
position | An iterator into the list. | |
n | Number of elements to be inserted. | |
x | Data to be inserted. |
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 830 of file stl_list.h.
void std::list< Type, Alloc >::insert | ( | iterator | position, | |
InputIterator | first, | |||
InputIterator | last | |||
) | [inline] |
Inserts a range into the list.
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 849 of file stl_list.h.
list< Type, Alloc >::iterator std::list< Type, Alloc >::erase | ( | iterator | position | ) | [inline] |
Remove element at given position.
position | Iterator pointing to element to be erased. |
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 std::list< Type, Alloc >::M_assign_dispatch(), std::list< Type, Alloc >::M_fill_assign(), std::list< Type, Alloc >::operator=(), and std::list< Type, Alloc >::resize().
iterator std::list< Type, Alloc >::erase | ( | iterator | first, | |
iterator | last | |||
) | [inline] |
Remove a range of elements.
first | Iterator pointing to the first element to be erased. | |
last | Iterator pointing to one past the last element to be erased. |
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 895 of file stl_list.h.
void std::list< Type, Alloc >::swap | ( | list< Type, Alloc > & | x | ) | [inline] |
Swaps data with another list.
x | A list of the same element and allocator types. |
Definition at line 912 of file stl_list.h.
Referenced by std::list< Type, Alloc >::sort(), and std::swap().
void std::list< Type, Alloc >::clear | ( | ) | [inline] |
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.
Reimplemented in __gnu_debug_def::list< Type, Allocator >.
Definition at line 922 of file stl_list.h.
void std::list< Type, Alloc >::splice | ( | iterator | position, | |
list< Type, Alloc > & | x | |||
) | [inline] |
Insert contents of another list.
position | Iterator referencing the element to insert before. | |
x | Source list. |
Definition at line 939 of file stl_list.h.
Referenced by std::list< Type, Alloc >::sort().
void std::list< Type, Alloc >::splice | ( | iterator | position, | |
list< Type, Alloc > & | , | |||
iterator | __i | |||
) | [inline] |
Insert element from another list.
position | Iterator referencing the element to insert before. | |
x | Source list. | |
i | Iterator referencing the element to move. |
Definition at line 955 of file stl_list.h.
void std::list< Type, Alloc >::splice | ( | iterator | position, | |
list< Type, Alloc > & | , | |||
iterator | first, | |||
iterator | last | |||
) | [inline] |
Insert range from another list.
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. |
Undefined if position is in [first,last).
Definition at line 977 of file stl_list.h.
void std::list< Type, Alloc >::remove | ( | const Type & | value | ) | [inline] |
Remove all elements equal to value.
value | The value to remove. |
Reimplemented in __gnu_debug_def::list< Type, Allocator >.
Definition at line 173 of file list.tcc.
References std::list< Type, Alloc >::begin(), and std::list< Type, Alloc >::end().
void std::list< Type, Alloc >::remove_if | ( | Predicate | pred | ) | [inline] |
Remove all elements satisfying a predicate.
Predicate | Unary predicate function or object. |
Reimplemented in __gnu_debug_def::list< Type, Allocator >.
Definition at line 275 of file list.tcc.
References std::list< Type, Alloc >::begin(), and std::list< Type, Alloc >::end().
void std::list< Type, Alloc >::unique | ( | ) | [inline] |
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.
Reimplemented in __gnu_debug_def::list< Type, Allocator >.
Definition at line 190 of file list.tcc.
References std::list< Type, Alloc >::begin(), and std::list< Type, Alloc >::end().
void std::list< Type, Alloc >::unique | ( | BinaryPredicate | __binary_pred | ) | [inline] |
Remove consecutive elements satisfying a predicate.
BinaryPredicate | Binary predicate function or object. |
Reimplemented in __gnu_debug_def::list< Type, Allocator >.
Definition at line 293 of file list.tcc.
References std::list< Type, Alloc >::begin(), and std::list< Type, Alloc >::end().
void std::list< Type, Alloc >::merge | ( | list< Type, Alloc > & | x | ) | [inline] |
Merge sorted lists.
x | Sorted list to merge. |
Definition at line 210 of file list.tcc.
References std::list< Type, Alloc >::begin(), and std::list< Type, Alloc >::end().
Referenced by std::list< Type, Alloc >::sort().
void std::list< Type, Alloc >::merge | ( | list< Type, Alloc > & | x, | |
StrictWeakOrdering | comp | |||
) | [inline] |
Merge sorted lists according to comparison function.
x | Sorted list to merge. | |
StrictWeakOrdering | Comparison function definining sort order. |
Definition at line 313 of file list.tcc.
References std::list< Type, Alloc >::begin(), and std::list< Type, Alloc >::end().
void std::list< Type, Alloc >::reverse | ( | ) | [inline] |
Reverse the elements in list.
Reverse the order of elements in the list in linear time.
Definition at line 1075 of file stl_list.h.
void std::list< Type, Alloc >::sort | ( | ) | [inline] |
Sort the elements.
Sorts the elements of this list in NlogN time. Equivalent elements remain in list order.
Reimplemented in __gnu_debug_def::list< Type, Allocator >.
Definition at line 237 of file list.tcc.
References std::list< Type, Alloc >::begin(), std::list< Type, Alloc >::empty(), std::list< Type, Alloc >::merge(), std::list< Type, Alloc >::splice(), and std::list< Type, Alloc >::swap().
void std::list< Type, Alloc >::sort | ( | StrictWeakOrdering | comp | ) | [inline] |
Sort the elements according to comparison function.
Sorts the elements of this list in NlogN time. Equivalent elements remain in list order.
Reimplemented in __gnu_debug_def::list< Type, Allocator >.
Definition at line 341 of file list.tcc.
References std::list< Type, Alloc >::begin(), std::list< Type, Alloc >::empty(), std::list< Type, Alloc >::merge(), std::list< Type, Alloc >::splice(), and std::list< Type, Alloc >::swap().