GNU g++  v5.2.1
GNU Standard C++
stl_list.h File Reference

This is an internal header file, included by other library headers. More...

Include dependency graph for stl_list.h:

Functions

namespace std _GLIBCXX_VISIBILITY (default)
 

Detailed Description

This is an internal header file, included by other library headers.

Do not attempt to use it directly. {list}

Function Documentation

namespace std _GLIBCXX_VISIBILITY ( default  )

Common part of a node in the list.

An actual node in the list.

< User's data.

A list::iterator.

All the functions are op overloads.

A list::const_iterator.

All the functions are op overloads.

See bits/stl_deque.h's _Deque_base for an explanation.

A standard container with linear time access to elements, and fixed time insertion/deletion at any point in the sequence.

Template Parameters
_TpType of element.
_AllocAllocator type, defaults to allocator<_Tp>.

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.

A couple points on memory allocation for list<Tp>:

First, we never actually allocate a Tp, we allocate List_node<Tp>'s and trust [20.1.5]/4 to DTRT. This is to ensure that after elements from list<X,Alloc1> are spliced into list<X,Alloc2>, destroying the memory of the second list is a valid operation, i.e., Alloc1 giveth and Alloc2 taketh away.

Second, a list conceptually represented as

1 A <---> B <---> C <---> D

is actually circular; a link exists between A and D. The list class holds (as its only data member) a private list::iterator pointing to D, not to A! To get to the head of the list, we start at the tail and move forward by one. When this member iterator's next/previous pointers refer to itself, the list is empty.

Parameters
__argsAn instance of user data.

Allocates space for a new node and constructs a copy of __args in it.

Creates a list with no elements.

Creates a list with no elements.

Parameters
__aAn allocator object.

Creates a list with copies of an exemplar element.

Parameters
__nThe number of elements to initially create.
__valueAn element to copy.
__aAn allocator object.

This constructor fills the list with __n copies of __value.

List copy constructor.

Parameters
__xA list of identical element and allocator types.

The newly-created list uses a copy of the allocation object used by __x.

Builds a list from a range.

Parameters
__firstAn input iterator.
__lastAn input iterator.
__aAn allocator object.

Create a list consisting of copies of the elements from [__first,__last). This is linear in N (where N is distance(__first,__last)).

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 responsibility.

List assignment operator.

Parameters
__xA list of identical element and allocator types.

All the elements of __x are copied, but unlike the copy constructor, the allocator object is not copied.

Assigns a given value to a list.

Parameters
__nNumber of elements to be assigned.
__valValue 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.

Assigns a range to a list.

Parameters
__firstAn input iterator.
__lastAn 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.

Get a copy of the memory allocation object.

Returns a read/write iterator that points to the first element in the list. Iteration is done in ordinary element order.

Returns a read-only (constant) iterator that points to the first element in the list. Iteration is done in ordinary element order.

Returns a read/write iterator that points one past the last element in the list. Iteration is done in ordinary element order.

Returns a read-only (constant) iterator that points one past the last element in the list. Iteration is done in ordinary element order.

Returns a read/write reverse iterator that points to the last element in the list. Iteration is done in reverse element order.

Returns a read-only (constant) reverse iterator that points to the last element in the list. Iteration is done in reverse element order.

Returns a read/write reverse iterator that points to one before the first element in the list. Iteration is done in reverse element order.

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.

Returns true if the list is empty. (Thus begin() would equal end().)

Returns the number of elements in the list.

Returns the size() of the largest possible list.

Resizes the list to the specified number of elements.

Parameters
__new_sizeNumber of elements the list should contain.
__xData 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.

Returns a read/write reference to the data at the first element of the list.

Returns a read-only (constant) reference to the data at the first element of the list.

Returns a read/write reference to the data at the last element of the list.

Returns a read-only (constant) reference to the data at the last element of the list.

Add data to the front of the list.

Parameters
__xData to be added.

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.

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.

Add data to the end of the list.

Parameters
__xData to be added.

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.

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.

Inserts given value into list before specified iterator.

Parameters
__positionAn iterator into the list.
__xData 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.

Inserts a number of copies of given data into the list.

Parameters
__positionAn iterator into the list.
__nNumber of elements to be inserted.
__xData to be inserted.

This function will insert a specified number of copies of the given data before the location specified by position.

This operation is linear in the number of elements inserted and does not invalidate iterators and references.

Inserts a range into the list.

Parameters
__positionAn iterator into the list.
__firstAn input iterator.
__lastAn input iterator.

This function will insert copies of the data in the range [first,last) into the list before the location specified by position.

This operation is linear in the number of elements inserted and does not invalidate iterators and references.

Remove element at given position.

Parameters
__positionIterator 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 responsibility.

Remove a range of elements.

Parameters
__firstIterator pointing to the first element to be erased.
__lastIterator 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.

This operation is linear time in the size of the range 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 responsibility.

Swaps data with another list.

Parameters
__xA 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.

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 responsibility.

Insert contents of another list.

Parameters
__positionIterator referencing the element to insert before.
__xSource list.

The elements of __x are inserted in constant time in front of the element referenced by __position. __x becomes an empty list.

Requires this != __x.

Insert element from another list.

Parameters
__positionIterator referencing the element to insert before.
__xSource list.
__iIterator referencing the element to move.

Removes the element in list __x referenced by __i and inserts it into the current list before __position.

Insert range from another list.

Parameters
__positionIterator referencing the element to insert before.
__xSource list.
__firstIterator referencing the start of range in x.
__lastIterator 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).

Remove all elements equal to value.

Parameters
__valueThe 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 responsibility.

Remove all elements satisfying a predicate.

Template Parameters
_PredicateUnary 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 responsibility.

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 responsibility.

Remove consecutive elements satisfying a predicate.

Template Parameters
_BinaryPredicateBinary 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 responsibility.

Merge sorted lists.

Parameters
__xSorted list to merge.

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.

Merge sorted lists according to comparison function.

Template Parameters
_StrictWeakOrderingComparison function defining sort order.
Parameters
__xSorted list to merge.
__compComparison functor.

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().

Reverse the elements in list.

Reverse the order of elements in the list in linear time.

Sort the elements.

Sorts the elements of this list in NlogN time. Equivalent elements remain in list order.

Sort the elements according to comparison function.

Sorts the elements of this list in NlogN time. Equivalent elements remain in list order.

List equality comparison.

Parameters
__xA list.
__yA list of the same type as __x.
Returns
True iff the size and elements of the lists are equal.

This is an equivalence relation. It is linear in the size of the lists. Lists are considered equivalent if their sizes are equal, and if corresponding elements compare equal.

List ordering relation.

Parameters
__xA list.
__yA list of the same type as __x.
Returns
True iff __x is lexicographically less than __y.

This is a total ordering relation. It is linear in the size of the lists. The elements must be comparable with <.

See std::lexicographical_compare() for how the determination is made.

Based on operator==

Based on operator<

Based on operator<

Based on operator<

See std::list::swap().

References __catch, __glibcxx_class_requires, __glibcxx_class_requires2, __throw_exception_again, __try, std::__exception_ptr::operator!=(), std::__exception_ptr::operator==(), __gnu_debug::operator>(), __gnu_debug::operator>=(), and std::__exception_ptr::swap().

Here is the call graph for this function: