Inherits std::_List_base< _Tp, _Alloc >.
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 398 of file stl_list.h.
list | ( | const allocator_type & | __a = allocator_type() |
) | [inline, explicit] |
list | ( | size_type | __n, | |
const value_type & | __value = value_type() , |
|||
const allocator_type & | __a = allocator_type() | |||
) | [inline, explicit] |
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 479 of file stl_list.h.
List copy constructor.
x | A list of identical element and allocator types. |
Definition at line 491 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.
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 510 of file stl_list.h.
void 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.
Definition at line 561 of file stl_list.h.
void 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. |
Definition at line 544 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 711 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 699 of file stl_list.h.
const_iterator 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.
Definition at line 588 of file stl_list.h.
iterator begin | ( | ) | [inline] |
Returns a read/write iterator that points to the first element in the list. Iteration is done in ordinary element order.
Definition at line 579 of file stl_list.h.
Referenced by list::list(), list::merge(), list::operator=(), std::operator==(), list::remove(), list::remove_if(), list::resize(), list::sort(), list::splice(), and list::unique().
void 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.
Definition at line 898 of file stl_list.h.
bool empty | ( | ) | const [inline] |
Returns true if the list is empty. (Thus begin() would equal end().)
Definition at line 651 of file stl_list.h.
Referenced by list::sort(), and list::splice().
const_iterator 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.
Definition at line 606 of file stl_list.h.
iterator end | ( | ) | [inline] |
Returns a read/write iterator that points one past the last element in the list. Iteration is done in ordinary element order.
Definition at line 597 of file stl_list.h.
Referenced by list::list(), list::merge(), list::operator=(), std::operator==(), list::remove(), list::remove_if(), list::resize(), list::splice(), and list::unique().
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 871 of file stl_list.h.
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.
References _List_iterator::_M_node.
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 691 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 683 of file stl_list.h.
allocator_type get_allocator | ( | ) | const [inline] |
void 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 825 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.
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 806 of file stl_list.h.
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.
References _List_iterator::_M_node.
Referenced by list::operator=(), and list::resize().
size_type max_size | ( | ) | const [inline] |
Returns the size() of the largest possible list.
Definition at line 661 of file stl_list.h.
void merge | ( | list< _Tp, _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 315 of file list.tcc.
References list::begin(), and list::end().
void merge | ( | list< _Tp, _Alloc > & | __x | ) | [inline] |
Merge sorted lists.
x | Sorted list to merge. |
Definition at line 211 of file list.tcc.
References list::begin(), and list::end().
Referenced by list::sort().
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 list::begin(), list::end(), list::erase(), and list::insert().
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 775 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 746 of file stl_list.h.
void push_back | ( | const value_type & | __x | ) | [inline] |
Add data to the end of the list.
x | Data to be added. |
Definition at line 760 of file stl_list.h.
void push_front | ( | const value_type & | __x | ) | [inline] |
Add data to the front of the list.
x | Data to be added. |
Definition at line 730 of file stl_list.h.
const_reverse_iterator 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.
Definition at line 624 of file stl_list.h.
reverse_iterator rbegin | ( | ) | [inline] |
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 615 of file stl_list.h.
void remove | ( | const _Tp & | __value | ) | [inline] |
Remove all elements equal to value.
value | The value to remove. |
Definition at line 174 of file list.tcc.
References list::begin(), and list::end().
void remove_if | ( | _Predicate | __pred | ) | [inline] |
Remove all elements satisfying a predicate.
Predicate | Unary predicate function or object. |
Definition at line 276 of file list.tcc.
References list::begin(), and list::end().
const_reverse_iterator 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.
Definition at line 642 of file stl_list.h.
reverse_iterator 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.
Definition at line 633 of file stl_list.h.
void resize | ( | size_type | __new_size, | |
value_type | __x = value_type() | |||
) | [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 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 1051 of file stl_list.h.
size_type size | ( | ) | const [inline] |
Returns the number of elements in the list.
Definition at line 656 of file stl_list.h.
References std::distance().
void 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.
Definition at line 343 of file list.tcc.
References list::begin(), list::empty(), list::merge(), list::splice(), and list::swap().
void sort | ( | ) | [inline] |
Sort the elements.
Sorts the elements of this list in NlogN time. Equivalent elements remain in list order.
Definition at line 238 of file list.tcc.
References list::begin(), list::empty(), list::merge(), list::splice(), and list::swap().
void splice | ( | iterator | __position, | |
list< _Tp, _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 953 of file stl_list.h.
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 931 of file stl_list.h.
Insert contents of another list.
position | Iterator referencing the element to insert before. | |
x | Source list. |
Definition at line 915 of file stl_list.h.
References list::begin(), list::empty(), and list::end().
Referenced by list::sort().
void swap | ( | list< _Tp, _Alloc > & | __x | ) | [inline] |
Swaps data with another list.
x | A list of the same element and allocator types. |
Definition at line 888 of file stl_list.h.
References std::swap().
Referenced by list::sort(), and std::swap().
void unique | ( | _BinaryPredicate | __binary_pred | ) | [inline] |
Remove consecutive elements satisfying a predicate.
BinaryPredicate | Binary predicate function or object. |
Definition at line 294 of file list.tcc.
References list::begin(), and list::end().
void 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.
Definition at line 191 of file list.tcc.
References list::begin(), and list::end().