Category: containers
Component type: type
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. [1]
Note that singly linked lists, which only support forward traversal, are also sometimes useful. If you do not need backward traversal, then slist may be more efficient than list. Definition Defined in the standard header list, and in the nonstandard backward- compatibility header list.h.
Example list<int> L;
L.push_back(0);
L.push_front(1);
L.insert(++L.begin(), 2);
copy(L.begin(), L.end(), ostream_iterator<int>(cout, ' '));
// The values that are printed are 1 2 0
Template parameters Parameter | Description | Default |
T | The list 's value type: the type of object that is stored in the list. | |
Alloc | The list 's allocator, used for all internal memory management. | alloc |
Model of Reversible Container, Front Insertion Sequence, Back Insertion Sequence.
Type requirements None, except for those imposed by the requirements of Reversible Container, Front Insertion Sequence, and Back Insertion Sequence.
Public base classes None.
Members Member | Where defined | Description |
value_type | Container | The type of object, T, stored in the list. |
pointer | Container | Pointer to T. |
reference | Container | Reference to T |
const_reference | Container | Const reference to T |
size_type | Container | An unsigned integral type. |
difference_type | Container | A signed integral type. |
iterator | Container | Iterator used to iterate through a list. |
const_iterator | Container |