libstdc++
|
Public Types | |
typedef _Alloc | allocator_type |
typedef _Fwd_list_const_iterator< _Tp > | const_iterator |
typedef _Tp_alloc_type::const_pointer | const_pointer |
typedef _Tp_alloc_type::const_reference | const_reference |
typedef std::ptrdiff_t | difference_type |
typedef _Fwd_list_iterator< _Tp > | iterator |
typedef _Tp_alloc_type::pointer | pointer |
typedef _Tp_alloc_type::reference | reference |
typedef std::size_t | size_type |
typedef _Tp | value_type |
Public Member Functions | |
forward_list (const _Alloc &__al=_Alloc()) | |
forward_list (const forward_list &__list, const _Alloc &__al) | |
forward_list (forward_list &&__list, const _Alloc &__al) | |
forward_list (size_type __n) | |
forward_list (size_type __n, const _Tp &__value, const _Alloc &__al=_Alloc()) | |
template<typename _InputIterator > | |
forward_list (_InputIterator __first, _InputIterator __last, const _Alloc &__al=_Alloc()) | |
forward_list (const forward_list &__list) | |
forward_list (forward_list &&__list) noexcept | |
forward_list (std::initializer_list< _Tp > __il, const _Alloc &__al=_Alloc()) | |
~forward_list () noexcept | |
template<typename _InputIterator > | |
void | assign (_InputIterator __first, _InputIterator __last) |
void | assign (size_type __n, const _Tp &__val) |
void | assign (std::initializer_list< _Tp > __il) |
iterator | before_begin () noexcept |
const_iterator | before_begin () const noexcept |
iterator | begin () noexcept |
const_iterator | begin () const noexcept |
const_iterator | cbefore_begin () const noexcept |
const_iterator | cbegin () const noexcept |
const_iterator | cend () const noexcept |
void | clear () noexcept |
template<typename... _Args> | |
iterator | emplace_after (const_iterator __pos, _Args &&...__args) |
template<typename... _Args> | |
void | emplace_front (_Args &&...__args) |
bool | empty () const noexcept |
iterator | end () noexcept |
const_iterator | end () const noexcept |
iterator | erase_after (const_iterator __pos) |
iterator | erase_after (const_iterator __pos, const_iterator __last) |
reference | front () |
const_reference | front () const |
allocator_type | get_allocator () const noexcept |
template<typename _InputIterator > | |
forward_list< _Tp, _Alloc > ::iterator | insert_after (const_iterator __pos, _InputIterator __first, _InputIterator __last) |
iterator | insert_after (const_iterator __pos, const _Tp &__val) |
iterator | insert_after (const_iterator __pos, _Tp &&__val) |
iterator | insert_after (const_iterator __pos, size_type __n, const _Tp &__val) |
template<typename _InputIterator > | |
iterator | insert_after (const_iterator __pos, _InputIterator __first, _InputIterator __last) |
iterator | insert_after (const_iterator __pos, std::initializer_list< _Tp > __il) |
size_type | max_size () const noexcept |
void | merge (forward_list &&__list) |
void | merge (forward_list &__list) |
template<typename _Comp > | |
void | merge (forward_list &&__list, _Comp __comp) |
template<typename _Comp > | |
void | merge (forward_list &__list, _Comp __comp) |
forward_list & | operator= (const forward_list &__list) |
forward_list & | operator= (forward_list &&__list) |
forward_list & | operator= (std::initializer_list< _Tp > __il) |
void | pop_front () |
void | push_front (const _Tp &__val) |
void | push_front (_Tp &&__val) |
void | remove (const _Tp &__val) |
template<typename _Pred > | |
void | remove_if (_Pred __pred) |
void | resize (size_type __sz) |
void | resize (size_type __sz, const value_type &__val) |
void | reverse () noexcept |
void | sort () |
template<typename _Comp > | |
void | sort (_Comp __comp) |
void | splice_after (const_iterator __pos, forward_list &&__list) |
void | splice_after (const_iterator __pos, forward_list &__list) |
void | splice_after (const_iterator __pos, forward_list &&__list, const_iterator __i) |
void | splice_after (const_iterator __pos, forward_list &__list, const_iterator __i) |
void | splice_after (const_iterator __pos, forward_list &&, const_iterator __before, const_iterator __last) |
void | splice_after (const_iterator __pos, forward_list &, const_iterator __before, const_iterator __last) |
void | swap (forward_list &__list) |
void | unique () |
template<typename _BinPred > | |
void | unique (_BinPred __binary_pred) |
Private Member Functions | |
template<typename... _Args> | |
_Node * | _M_create_node (_Args &&...__args) |
_Fwd_list_node_base * | _M_erase_after (_Fwd_list_node_base *__pos) |
_Fwd_list_node_base * | _M_erase_after (_Fwd_list_node_base *__pos, _Fwd_list_node_base *__last) |
_Node * | _M_get_node () |
_Node_alloc_type & | _M_get_Node_allocator () noexcept |
const _Node_alloc_type & | _M_get_Node_allocator () const noexcept |
template<typename... _Args> | |
_Fwd_list_node_base * | _M_insert_after (const_iterator __pos, _Args &&...__args) |
void | _M_put_node (_Node *__p) |
Private Attributes | |
_Fwd_list_impl | _M_impl |
A standard container with linear time access to elements, and fixed time insertion/deletion at any point in the sequence.
Meets the requirements of a container, a sequence, including the optional sequence requirements with the exception of at
and operator
[].
This is a singly linked list. Traversal up 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::forward_list provides specialized algorithms unique to linked lists, such as splicing, sorting, and in-place reversal.
A couple points on memory allocation for forward_list<Tp>:
First, we never actually allocate a Tp, we allocate Fwd_list_node<Tp>'s and trust [20.1.5]/4 to DTRT. This is to ensure that after elements from forward_list<X,Alloc1> are spliced into forward_list<X,Alloc2>, destroying the memory of the second list is a valid operation, i.e., Alloc1 giveth and Alloc2 taketh away.
Definition at line 405 of file forward_list.h.
|
inlineexplicit |
Creates a forward_list with no elements.
__al | An allocator object. |
Definition at line 435 of file forward_list.h.
|
inline |
Copy constructor with allocator argument.
__list | Input list to copy. |
__al | An allocator object. |
Definition at line 444 of file forward_list.h.
|
inline |
Move constructor with allocator argument.
__list | Input list to move. |
__al | An allocator object. |
Definition at line 453 of file forward_list.h.
|
inlineexplicit |
Creates a forward_list with default constructed elements.
__n | The number of elements to initially create. |
This constructor creates the forward_list with __n default constructed elements.
Definition at line 465 of file forward_list.h.
|
inline |
Creates a forward_list with copies of an exemplar element.
__n | The number of elements to initially create. |
__value | An element to copy. |
__al | An allocator object. |
This constructor fills the forward_list with __n copies of __value.
Definition at line 478 of file forward_list.h.
|
inline |
Builds a forward_list from a range.
__first | An input iterator. |
__last | An input iterator. |
__al | An allocator object. |
Create a forward_list consisting of copies of the elements from [__first,__last). This is linear in N (where N is distance(__first,__last)).
Definition at line 494 of file forward_list.h.
|
inline |
The forward_list copy constructor.
__list | A forward_list of identical element and allocator types. |
The newly-created forward_list uses a copy of the allocation object used by __list.
Definition at line 511 of file forward_list.h.
References std::forward_list< _Tp, _Alloc >::begin(), and std::forward_list< _Tp, _Alloc >::end().
|
inlinenoexcept |
The forward_list move constructor.
__list | A forward_list of identical element and allocator types. |
The newly-created forward_list contains the exact contents of forward_list. The contents of __list are a valid, but unspecified forward_list.
Definition at line 524 of file forward_list.h.
|
inline |
Builds a forward_list from an initializer_list.
__il | An initializer_list of value_type. |
__al | An allocator object. |
Create a forward_list consisting of copies of the elements in the initializer_list __il. This is linear in __il.size().
Definition at line 535 of file forward_list.h.
|
inlinenoexcept |
The forward_list dtor.
Definition at line 543 of file forward_list.h.
|
inline |
Assigns a range to a forward_list.
__first | An input iterator. |
__last | An input iterator. |
This function fills a forward_list with copies of the elements in the range [__first,__last).
Note that the assignment completely changes the forward_list and that the number of elements of the resulting forward_list's is the same as the number of elements assigned. Old data is lost.
Definition at line 605 of file forward_list.h.
References std::forward_list< _Tp, _Alloc >::cbefore_begin(), std::forward_list< _Tp, _Alloc >::clear(), and std::forward_list< _Tp, _Alloc >::insert_after().
Referenced by std::forward_list< _Tp, _Alloc >::operator=().
|
inline |
Assigns a given value to a forward_list.
__n | Number of elements to be assigned. |
__val | Value to be assigned. |
This function fills a forward_list with __n copies of the given value. Note that the assignment completely changes the forward_list, and that the resulting forward_list has __n elements. Old data is lost.
Definition at line 622 of file forward_list.h.
References std::forward_list< _Tp, _Alloc >::cbefore_begin(), std::forward_list< _Tp, _Alloc >::clear(), and std::forward_list< _Tp, _Alloc >::insert_after().
|
inline |
Assigns an initializer_list to a forward_list.
__il | An initializer_list of value_type. |
Replace the contents of the forward_list with copies of the elements in the initializer_list __il. This is linear in il.size().
Definition at line 637 of file forward_list.h.
References std::forward_list< _Tp, _Alloc >::cbefore_begin(), std::forward_list< _Tp, _Alloc >::clear(), and std::forward_list< _Tp, _Alloc >::insert_after().
|
inlinenoexcept |
Returns a read/write iterator that points before the first element in the forward_list. Iteration is done in ordinary element order.
Definition at line 655 of file forward_list.h.
Referenced by std::forward_list< _Tp, _Alloc >::insert_after().
|
inlinenoexcept |
Returns a read-only (constant) iterator that points before the first element in the forward_list. Iteration is done in ordinary element order.
Definition at line 664 of file forward_list.h.
|
inlinenoexcept |
Returns a read/write iterator that points to the first element in the forward_list. Iteration is done in ordinary element order.
Definition at line 672 of file forward_list.h.
Referenced by std::forward_list< _Tp, _Alloc >::forward_list().
|
inlinenoexcept |
Returns a read-only (constant) iterator that points to the first element in the forward_list. Iteration is done in ordinary element order.
Definition at line 681 of file forward_list.h.
|
inlinenoexcept |
Returns a read-only (constant) iterator that points before the first element in the forward_list. Iteration is done in ordinary element order.
Definition at line 717 of file forward_list.h.
Referenced by std::forward_list< _Tp, _Alloc >::assign(), std::forward_list< _Tp, _Alloc >::emplace_front(), and std::forward_list< _Tp, _Alloc >::push_front().
|
inlinenoexcept |
Returns a read-only (constant) iterator that points to the first element in the forward_list. Iteration is done in ordinary element order.
Definition at line 708 of file forward_list.h.
Referenced by std::forward_list< _Tp, _Alloc >::operator=(), and std::operator==().
|
inlinenoexcept |
Returns a read-only (constant) iterator that points one past the last element in the forward_list. Iteration is done in ordinary element order.
Definition at line 726 of file forward_list.h.
Referenced by std::forward_list< _Tp, _Alloc >::operator=(), and std::operator==().
|
inlinenoexcept |
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.
Definition at line 1023 of file forward_list.h.
Referenced by std::forward_list< _Tp, _Alloc >::assign(), and std::forward_list< _Tp, _Alloc >::operator=().
|
inline |
Constructs object in forward_list after the specified iterator.
__pos | A const_iterator into the forward_list. |
__args | Arguments. |
This function will insert an object of type T constructed with T(std::forward<Args>(args)...) after the specified location. Due to the nature of a forward_list this operation can be done in constant time, and does not invalidate iterators and references.
Definition at line 839 of file forward_list.h.
|
inline |
Constructs object in forward_list at the front of the list.
__args | Arguments. |
This function will insert an object of type Tp constructed with Tp(std::forward<Args>(args)...) at the front of the list Due to the nature of a forward_list this operation can be done in constant time, and does not invalidate iterators and references.
Definition at line 783 of file forward_list.h.
References std::forward_list< _Tp, _Alloc >::cbefore_begin().
|
inlinenoexcept |
Returns true if the forward_list is empty. (Thus begin() would equal end().)
Definition at line 734 of file forward_list.h.
|
inlinenoexcept |
Returns a read/write iterator that points one past the last element in the forward_list. Iteration is done in ordinary element order.
Definition at line 690 of file forward_list.h.
Referenced by std::forward_list< _Tp, _Alloc >::forward_list(), and std::forward_list< _Tp, _Alloc >::insert_after().
|
inlinenoexcept |
Returns a read-only iterator that points one past the last element in the forward_list. Iteration is done in ordinary element order.
Definition at line 699 of file forward_list.h.
|
inline |
Removes the element pointed to by the iterator following pos
.
__pos | Iterator pointing before element to be erased. |
This function will erase the element at the given position and thus shorten the forward_list by one.
Due to the nature of a forward_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.
Definition at line 941 of file forward_list.h.
|
inline |
Remove a range of elements.
__pos | Iterator pointing before the first element to be erased. |
__last | Iterator pointing to one past the last element to be erased. |
This function will erase the elements in the range (__pos,__last) and shorten the forward_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.
Definition at line 964 of file forward_list.h.
|
inline |
Returns a read/write reference to the data at the first element of the forward_list.
Definition at line 751 of file forward_list.h.
|
inline |
Returns a read-only (constant) reference to the data at the first element of the forward_list.
Definition at line 762 of file forward_list.h.
|
inlinenoexcept |
Get a copy of the memory allocation object.
Definition at line 645 of file forward_list.h.
|
inline |
Inserts given value into forward_list after specified iterator.
__pos | An iterator into the forward_list. |
__val | Data to be inserted. |
This function will insert a copy of the given value after the specified location. Due to the nature of a forward_list this operation can be done in constant time, and does not invalidate iterators and references.
Definition at line 856 of file forward_list.h.
Referenced by std::forward_list< _Tp, _Alloc >::assign(), and std::forward_list< _Tp, _Alloc >::insert_after().
forward_list< _Tp, _Alloc >::iterator forward_list::insert_after | ( | const_iterator | __pos, |
size_type | __n, | ||
const _Tp & | __val | ||
) |
Inserts a number of copies of given data into the forward_list.
__pos | An iterator into the forward_list. |
__n | Number of elements to be inserted. |
__val | Data to be inserted. |
This function will insert a specified number of copies of the given data after the location specified by pos.
This operation is linear in the number of elements inserted and does not invalidate iterators and references.
Definition at line 264 of file forward_list.tcc.
References std::forward_list< _Tp, _Alloc >::before_begin(), and std::forward_list< _Tp, _Alloc >::end().
iterator std::forward_list< _Tp, _Alloc >::insert_after | ( | const_iterator | __pos, |
_InputIterator | __first, | ||
_InputIterator | __last | ||
) |
Inserts a range into the forward_list.
__pos | An iterator into the forward_list. |
__first | An input iterator. |
__last | An input iterator. |
This function will insert copies of the data in the range [__first,__last) into the forward_list after the location specified by __pos.
This operation is linear in the number of elements inserted and does not invalidate iterators and references.
|
inline |
Inserts the contents of an initializer_list into forward_list after the specified iterator.
__pos | An iterator into the forward_list. |
__il | An initializer_list of value_type. |
This function will insert copies of the data in the initializer_list __il into the forward_list before the location specified by __pos.
This operation is linear in the number of elements inserted and does not invalidate iterators and references.
Definition at line 920 of file forward_list.h.
References std::forward_list< _Tp, _Alloc >::insert_after().
|
inlinenoexcept |
Returns the largest possible number of elements of forward_list.
Definition at line 741 of file forward_list.h.
|
inline |
Merge sorted lists.
__list | Sorted list to merge. |
Assumes that both list and this list are sorted according to operator<(). Merges elements of __list into this list in sorted order, leaving __list empty when complete. Elements in this list precede elements in __list that are equal.
Definition at line 1161 of file forward_list.h.
void forward_list::merge | ( | forward_list< _Tp, _Alloc > && | __list, |
_Comp | __comp | ||
) |
Merge sorted lists according to comparison function.
__list | Sorted list to merge. |
__comp | Comparison function defining sort order. |
Assumes that both __list and this list are sorted according to comp. Merges elements of __list into this list in sorted order, leaving __list empty when complete. Elements in this list precede elements in __list that are equivalent according to comp().
Definition at line 358 of file forward_list.tcc.
forward_list< _Tp, _Alloc > & forward_list::operator= | ( | const forward_list< _Tp, _Alloc > & | __list | ) |
The forward_list assignment operator.
__list | A forward_list of identical element and allocator types. |
All the elements of __list are copied, but unlike the copy constructor, the allocator object is not copied.
Definition at line 145 of file forward_list.tcc.
References std::begin(), std::forward_list< _Tp, _Alloc >::cbegin(), std::forward_list< _Tp, _Alloc >::cend(), and std::end().
|
inline |
The forward_list move assignment operator.
__list | A forward_list of identical element and allocator types. |
The contents of __list are moved into this forward_list (without copying). __list is a valid, but unspecified forward_list
Definition at line 567 of file forward_list.h.
References std::forward_list< _Tp, _Alloc >::clear(), and std::forward_list< _Tp, _Alloc >::swap().
|
inline |
The forward_list initializer list assignment operator.
__il | An initializer_list of value_type. |
Replace the contents of the forward_list with copies of the elements in the initializer_list __il. This is linear in __il.size().
Definition at line 585 of file forward_list.h.
References std::forward_list< _Tp, _Alloc >::assign().
|
inline |
Removes first element.
This is a typical stack operation. It shrinks the forward_list by one. Due to the nature of a forward_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 821 of file forward_list.h.
|
inline |
Add data to the front of the forward_list.
__val | Data to be added. |
This is a typical stack operation. The function creates an element at the front of the forward_list and assigns the given data to it. Due to the nature of a forward_list this operation can be done in constant time, and does not invalidate iterators and references.
Definition at line 798 of file forward_list.h.
References std::forward_list< _Tp, _Alloc >::cbefore_begin().
void forward_list::remove | ( | const _Tp & | __val | ) |
Remove all elements equal to value.
__val | The value to remove. |
Removes every element in the list equal to __val. 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.
Definition at line 292 of file forward_list.tcc.
References std::__addressof().
void forward_list::remove_if | ( | _Pred | __pred | ) |
Remove all elements satisfying a predicate.
__pred | 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 responsibility.
Definition at line 321 of file forward_list.tcc.
void forward_list::resize | ( | size_type | __sz | ) |
Resizes the forward_list to the specified number of elements.
__sz | Number of elements the forward_list should contain. |
This function will resize the forward_list to the specified number of elements. If the number is smaller than the forward_list's current number of elements the forward_list is truncated, otherwise the forward_list is extended and the new elements are default constructed.
Definition at line 190 of file forward_list.tcc.
References std::end().
void forward_list::resize | ( | size_type | __sz, |
const value_type & | __val | ||
) |
Resizes the forward_list to the specified number of elements.
__sz | Number of elements the forward_list should contain. |
__val | Data with which new elements should be populated. |
This function will resize the forward_list to the specified number of elements. If the number is smaller than the forward_list's current number of elements the forward_list is truncated, otherwise the forward_list is extended and new elements are populated with given data.
Definition at line 209 of file forward_list.tcc.
References std::end().
|
inlinenoexcept |
Reverse the elements in list.
Reverse the order of elements in the list in linear time.
Definition at line 1214 of file forward_list.h.
|
inline |
Sort the elements of the list.
Sorts the elements of this list in NlogN time. Equivalent elements remain in list order.
Definition at line 1195 of file forward_list.h.
void forward_list::sort | ( | _Comp | __comp | ) |
Sort the forward_list using a comparison function.
Sorts the elements of this list in NlogN time. Equivalent elements remain in list order.
Definition at line 404 of file forward_list.tcc.
|
inline |
Insert contents of another forward_list.
__pos | Iterator referencing the element to insert after. |
__list | Source list. |
The elements of list are inserted in constant time after the element referenced by pos. list becomes an empty list.
Requires this != x.
Definition at line 1040 of file forward_list.h.
void forward_list::splice_after | ( | const_iterator | __pos, |
forward_list< _Tp, _Alloc > && | __list, | ||
const_iterator | __i | ||
) |
Insert element from another forward_list.
__pos | Iterator referencing the element to insert after. |
__list | Source list. |
__i | Iterator referencing the element before the element to move. |
Removes the element in list list referenced by i and inserts it into the current list after pos.
Definition at line 247 of file forward_list.tcc.
|
inline |
Insert range from another forward_list.
__pos | Iterator referencing the element to insert after. |
__list | Source list. |
__before | Iterator referencing before the start of range in list. |
__last | Iterator referencing the end of range in list. |
Removes elements in the range (__before,__last) and inserts them after __pos in constant time.
Undefined if __pos is in (__before,__last).
Definition at line 1083 of file forward_list.h.
|
inline |
Swaps data with another forward_list.
__list | A forward_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 981 of file forward_list.h.
Referenced by std::forward_list< _Tp, _Alloc >::operator=(), and std::swap().
|
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 responsibility.
Definition at line 1132 of file forward_list.h.
void forward_list::unique | ( | _BinPred | __binary_pred | ) |
Remove consecutive elements satisfying a predicate.
__binary_pred | 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 responsibility.
Definition at line 337 of file forward_list.tcc.
References std::begin(), and std::end().