Inherits std::_List_base< _Tp, _Alloc >.
typedef _Alloc allocator_type
typedef _List_const_iterator< _Tp > const_iterator
typedef _Tp_alloc_traits::const_pointer const_pointer
typedef _Tp_alloc_traits::const_reference const_reference
typedef std::reverse_iterator< const_iterator > const_reverse_iterator
typedef ptrdiff_t difference_type
typedef _List_iterator< _Tp > iterator
typedef _Tp_alloc_traits::pointer pointer
typedef _Tp_alloc_traits::reference reference
typedef std::reverse_iterator< iterator > reverse_iterator
typedef size_t size_type
typedef _Tp value_type
list ()=default
Creates a list with no elements.
list (const allocator_type &__a) noexcept
Creates a list with no elements.
list (size_type __n, const allocator_type &__a=allocator_type())
Creates a list with default constructed elements.
list (size_type __n, const value_type &__value, const allocator_type &__a=allocator_type())
Creates a list with copies of an exemplar element.
list (const list &__x)
List copy constructor.
list (list &&)=default
List move constructor.
list (initializer_list< value_type > __l, const allocator_type &__a=allocator_type())
Builds a list from an initializer_list.
list (const list &__x, const allocator_type &__a)
list (list &&__x, const allocator_type &__a) noexcept(_Node_alloc_traits::_S_always_equal())
template<typename _InputIterator , typename = std::_RequireInputIter<_InputIterator>> list (_InputIterator __first, _InputIterator __last, const allocator_type &__a=allocator_type())
Builds a list from a range.
~list ()=default
void assign (size_type __n, const value_type &__val)
Assigns a given value to a list.
template<typename _InputIterator , typename = std::_RequireInputIter<_InputIterator>> void assign (_InputIterator __first, _InputIterator __last)
Assigns a range to a list.
void assign (initializer_list< value_type > __l)
Assigns an initializer_list to a list.
reference back () noexcept
const_reference back () const noexcept
iterator begin () noexcept
const_iterator begin () const noexcept
const_iterator cbegin () const noexcept
const_iterator cend () const noexcept
void clear () noexcept
const_reverse_iterator crbegin () const noexcept
const_reverse_iterator crend () const noexcept
template<typename... _Args> iterator emplace (const_iterator __position, _Args &&... __args)
Constructs object in list before specified iterator.
template<typename... _Args> void emplace_back (_Args &&... __args)
template<typename... _Args> void emplace_front (_Args &&... __args)
bool empty () const noexcept
iterator end () noexcept
const_iterator end () const noexcept
iterator erase (const_iterator __position) noexcept
Remove element at given position.
iterator erase (const_iterator __first, const_iterator __last) noexcept
Remove a range of elements.
reference front () noexcept
const_reference front () const noexcept
allocator_type get_allocator () const noexcept
Get a copy of the memory allocation object.
iterator insert (const_iterator __position, const value_type &__x)
Inserts given value into list before specified iterator.
iterator insert (const_iterator __position, value_type &&__x)
Inserts given rvalue into list before specified iterator.
iterator insert (const_iterator __p, initializer_list< value_type > __l)
Inserts the contents of an initializer_list into list before specified const_iterator.
iterator insert (const_iterator __position, size_type __n, const value_type &__x)
Inserts a number of copies of given data into the list.
template<typename _InputIterator , typename = std::_RequireInputIter<_InputIterator>> iterator insert (const_iterator __position, _InputIterator __first, _InputIterator __last)
Inserts a range into the list.
size_type max_size () const noexcept
void merge (list &&__x)
Merge sorted lists.
void merge (list &__x)
template<typename _StrictWeakOrdering > void merge (list &&__x, _StrictWeakOrdering __comp)
Merge sorted lists according to comparison function.
template<typename _StrictWeakOrdering > void merge (list &__x, _StrictWeakOrdering __comp)
list & operator= (const list &__x)
List assignment operator.
list & operator= (list &&__x) noexcept(_Node_alloc_traits::_S_nothrow_move())
List move assignment operator.
list & operator= (initializer_list< value_type > __l)
List initializer list assignment operator.
void pop_back () noexcept
Removes last element.
void pop_front () noexcept
Removes first element.
void push_back (const value_type &__x)
Add data to the end of the list.
void push_back (value_type &&__x)
void push_front (const value_type &__x)
Add data to the front of the list.
void push_front (value_type &&__x)
reverse_iterator rbegin () noexcept
const_reverse_iterator rbegin () const noexcept
void remove (const _Tp &__value)
Remove all elements equal to value.
template<typename _Predicate > void remove_if (_Predicate)
Remove all elements satisfying a predicate.
reverse_iterator rend () noexcept
const_reverse_iterator rend () const noexcept
void resize (size_type __new_size)
Resizes the list to the specified number of elements.
void resize (size_type __new_size, const value_type &__x)
Resizes the list to the specified number of elements.
void reverse () noexcept
Reverse the elements in list.
size_type size () const noexcept
void sort ()
Sort the elements.
template<typename _StrictWeakOrdering > void sort (_StrictWeakOrdering)
Sort the elements according to comparison function.
void splice (const_iterator __position, list &&__x) noexcept
Insert contents of another list.
void splice (const_iterator __position, list &__x) noexcept
void splice (const_iterator __position, list &&__x, const_iterator __i) noexcept
Insert element from another list.
void splice (const_iterator __position, list &__x, const_iterator __i) noexcept
Insert element from another list.
void splice (const_iterator __position, list &&__x, const_iterator __first, const_iterator __last) noexcept
Insert range from another list.
void splice (const_iterator __position, list &__x, const_iterator __first, const_iterator __last) noexcept
Insert range from another list.
void swap (list &__x) noexcept
Swaps data with another list.
void unique ()
Remove consecutive duplicate elements.
template<typename _BinaryPredicate > void unique (_BinaryPredicate)
Remove consecutive elements satisfying a predicate.
typedef _List_node< _Tp > _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_check_equal_allocators (list &__x) noexcept
void _M_clear () noexcept
template<typename... _Args> _Node * _M_create_node (_Args &&... __args)
void _M_dec_size (size_t)
void _M_default_append (size_type __n)
void _M_default_initialize (size_type __n)
size_t _M_distance (const void *, const void *) const
void _M_erase (iterator __position) noexcept
void _M_fill_assign (size_type __n, const value_type &__val)
void _M_fill_initialize (size_type __n, const value_type &__x)
_Node_alloc_traits::pointer _M_get_node ()
_Node_alloc_traits::pointer _M_get_node ()
_Node_alloc_type & _M_get_Node_allocator () noexcept
const _Node_alloc_type & _M_get_Node_allocator () const noexcept
_Node_alloc_type & _M_get_Node_allocator () noexcept
const _Node_alloc_type & _M_get_Node_allocator () const noexcept
size_t _M_get_size () const
void _M_inc_size (size_t)
void _M_init () noexcept
template<typename _Integer > void _M_initialize_dispatch (_Integer __n, _Integer __x, __true_type)
template<typename _InputIterator > void _M_initialize_dispatch (_InputIterator __first, _InputIterator __last, __false_type)
template<typename... _Args> void _M_insert (iterator __position, _Args &&... __args)
void _M_move_assign (list &&__x, true_type) noexcept
void _M_move_assign (list &&__x, false_type)
void _M_move_nodes (_List_base &&__x)
size_t _M_node_count () const
void _M_put_node (typename _Node_alloc_traits::pointer __p) noexcept
void _M_put_node (typename _Node_alloc_traits::pointer __p) noexcept
const_iterator _M_resize_pos (size_type &__new_size) const
void _M_set_size (size_t)
void _M_transfer (iterator __position, iterator __first, iterator __last)
static size_t _S_distance (const __detail::_List_node_base *__first, const __detail::_List_node_base *__last)
static size_t _S_distance (const_iterator, const_iterator)
Template Parameters:
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
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.
Definition at line 564 of file stl_list.h.
Creates a list with no elements.
Creates a list with no elements.
Parameters:
Definition at line 691 of file stl_list.h.
Creates a list with default constructed elements.
Parameters:
This constructor fills the list with __n default constructed elements.
Definition at line 704 of file stl_list.h.
Creates a list with copies of an exemplar element.
Parameters:
This constructor fills the list with __n copies of __value.
Definition at line 716 of file stl_list.h.
List copy constructor.
Parameters:
The newly-created list uses a copy of the allocation object used by __x (unless the allocator traits dictate a different object).
Definition at line 743 of file stl_list.h.
List move constructor. The newly-created list contains the exact contents of the moved instance. The contents of the moved instance are a valid, but unspecified list.
Builds a list from an initializer_list.
Parameters:
Create a list consisting of copies of the elements in the initializer_list __l. This is linear in __l.size().
Definition at line 766 of file stl_list.h.
Builds a list from a range.
Parameters:
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 811 of file stl_list.h.
Parameters:
Allocates space for a new node and constructs a copy of __args in it.
Definition at line 640 of file stl_list.h.
Assigns a given value to a list.
Parameters:
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.
Definition at line 897 of file stl_list.h.
Referenced by std::list< __inp, __rebind_inp >::operator=().
Assigns a range to a list.
Parameters:
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.
Definition at line 916 of file stl_list.h.
Assigns an initializer_list to a list.
Parameters:
Replace the contents of the list with copies of the elements in the initializer_list __l. This is linear in __l.size().
Definition at line 938 of file stl_list.h.
Definition at line 1138 of file stl_list.h.
Definition at line 1150 of file stl_list.h.
Definition at line 953 of file stl_list.h.
Referenced by std::list< __inp, __rebind_inp >::crend(), std::list< __inp, __rebind_inp >::front(), std::list< __inp, __rebind_inp >::insert(), std::list< __inp, __rebind_inp >::list(), std::list< __inp, __rebind_inp >::merge(), std::operator<(), std::list< __inp, __rebind_inp >::operator=(), std::operator==(), std::list< __inp, __rebind_inp >::pop_front(), std::list< __inp, __rebind_inp >::push_front(), std::list< __inp, __rebind_inp >::rend(), and std::list< __inp, __rebind_inp >::splice().
Definition at line 962 of file stl_list.h.
Definition at line 1026 of file stl_list.h.
Definition at line 1035 of file stl_list.h.
Definition at line 1506 of file stl_list.h.
Definition at line 1044 of file stl_list.h.
Definition at line 1053 of file stl_list.h.
Constructs object in list before specified iterator.
Parameters:
Returns:
This function will insert an object of type T constructed with T(std::forward<Args>(args)...) 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.
Definition at line 90 of file list.tcc.
Referenced by std::list< __inp, __rebind_inp >::insert().
Definition at line 1063 of file stl_list.h.
Referenced by std::list< __inp, __rebind_inp >::insert(), and std::list< __inp, __rebind_inp >::splice().
Definition at line 971 of file stl_list.h.
Referenced by std::list< __inp, __rebind_inp >::back(), std::list< __inp, __rebind_inp >::crbegin(), std::list< __inp, __rebind_inp >::list(), std::list< __inp, __rebind_inp >::merge(), std::operator<(), std::list< __inp, __rebind_inp >::operator=(), std::operator==(), std::list< __inp, __rebind_inp >::push_back(), std::list< __inp, __rebind_inp >::rbegin(), and std::list< __inp, __rebind_inp >::splice().
Definition at line 980 of file stl_list.h.
Remove element at given position.
Parameters:
Returns:
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.
Definition at line 152 of file list.tcc.
Referenced by std::list< __inp, __rebind_inp >::erase().
Remove a range of elements.
Parameters:
Returns:
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.
Definition at line 1464 of file stl_list.h.
Definition at line 1122 of file stl_list.h.
Definition at line 1130 of file stl_list.h.
Get a copy of the memory allocation object.
Definition at line 944 of file stl_list.h.
Inserts given value into list before specified iterator.
Parameters:
Returns:
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.
Definition at line 103 of file list.tcc.
Referenced by std::list< __inp, __rebind_inp >::insert().
Inserts given rvalue into list before specified iterator.
Parameters:
Returns:
This function will insert a copy of the given rvalue 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.
Definition at line 1316 of file stl_list.h.
Inserts the contents of an initializer_list into list before specified const_iterator.
Parameters:
Returns:
This function will insert copies of the data in the initializer_list l into the list before the location specified by p.
This operation is linear in the number of elements inserted and does not invalidate iterators and references.
Definition at line 1335 of file stl_list.h.
Inserts a number of copies of given data into the list.
Parameters:
Returns:
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.
Definition at line 118 of file list.tcc.
Inserts a range into the list.
Parameters:
Returns:
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.
Definition at line 134 of file list.tcc.
Definition at line 1073 of file stl_list.h.
Merge sorted lists.
Parameters:
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.
Definition at line 375 of file list.tcc.
Merge sorted lists according to comparison function.
Template Parameters:
Parameters:
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().
Definition at line 422 of file list.tcc.
List assignment operator.
Parameters:
All the elements of __x are copied.
Whether the allocator is copied depends on the allocator traits.
Definition at line 268 of file list.tcc.
List move assignment operator.
Parameters:
The contents of __x are moved into this list (without copying).
Afterwards __x is a valid, but unspecified list
Whether the allocator is moved depends on the allocator traits.
Definition at line 861 of file stl_list.h.
List initializer list assignment operator.
Parameters:
Replace the contents of the list with copies of the elements in the initializer_list __l. This is linear in l.size().
Definition at line 879 of file stl_list.h.
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 1254 of file stl_list.h.
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 1205 of file stl_list.h.
Add data to the end of the list.
Parameters:
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.
Definition at line 1219 of file stl_list.h.
Add data to the front of the list.
Parameters:
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.
Definition at line 1169 of file stl_list.h.
Definition at line 989 of file stl_list.h.
Definition at line 998 of file stl_list.h.
Remove all elements equal to value.
Parameters:
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.
Definition at line 326 of file list.tcc.
Remove all elements satisfying a predicate.
Template Parameters:
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 515 of file list.tcc.
Definition at line 1007 of file stl_list.h.
Definition at line 1016 of file stl_list.h.
Resizes the list to the specified number of elements.
Parameters:
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 default constructed elements are appended.
Definition at line 231 of file list.tcc.
Resizes the list to the specified number of elements.
Parameters:
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.
Definition at line 243 of file list.tcc.
Reverse the elements in list. Reverse the order of elements in the list in linear time.
Definition at line 1790 of file stl_list.h.
Definition at line 1068 of file stl_list.h.
Referenced by std::list< __inp, __rebind_inp >::merge(), and std::operator==().
Sort the elements. Sorts the elements of this list in NlogN time. Equivalent elements remain in list order.
Definition at line 468 of file list.tcc.
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 554 of file list.tcc.
Insert contents of another list.
Parameters:
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.
Definition at line 1526 of file stl_list.h.
Referenced by std::list< __inp, __rebind_inp >::splice().
Insert element from another list.
Parameters:
Removes the element in list __x referenced by __i and inserts it into the current list before __position.
Definition at line 1561 of file stl_list.h.
Insert element from another list.
Parameters:
Removes the element in list __x referenced by __i and inserts it into the current list before __position.
Definition at line 1603 of file stl_list.h.
Insert range from another list.
Parameters:
Removes elements in the range [__first,__last) and inserts them before __position in constant time.
Undefined if __position is in [__first,__last).
Definition at line 1622 of file stl_list.h.
Insert range from another list.
Parameters:
Removes elements in the range [__first,__last) and inserts them before __position in constant time.
Undefined if __position is in [__first,__last).
Definition at line 1672 of file stl_list.h.
Swaps data with another list.
Parameters:
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.
Whether the allocators are swapped depends on the allocator traits.
Definition at line 1486 of file stl_list.h.
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 354 of file list.tcc.
Remove consecutive elements satisfying a predicate.
Template Parameters:
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 533 of file list.tcc.
Generated automatically by Doxygen for libstdc++ from the source code.