list


A sequential container that is optimized for insertion and erasure at arbitrary points in its structure at the expense of losing indexed-based access.

Library

Standards<ToolKit>

Declaration


#include <list>

template< class T, class Allocator >
class list

Interface

Constructor
list()
Constructs an empty list.
Constructor
explicit list( Allocator& alloc )
Constructs an empty list. Uses alloc to manage storage.
Constructor
list( size_type n , const T& value , const Allocator& alloc )
Constructs a list that contains n elements set to value (default T() ), using alloc (default allocator< T > ) to manage storage.
Constructor
list( const T* first , const T* last , const Allocator& alloc )
Constructs a list that contains copies of all elements in the range [ first , last ) , using alloc to manage storage.
Constructor
list( const_iterator first , const_iterator last , const Allocator& alloc )
Constructs a list that contains copies of all elements in the range [ first , last ) , using alloc to manage storage.
Destructor
~list()
Destroys the list and erases all of its items.
=
list< T, Allocator >& operator=( const list< T, Allocator >& x )
Replaces the list's contents with a copy of x.
assign
void assign( const T* first , const T* last )
Removes all list elements, then inserts the elements in the range [ first ... last ) .
assign
void assign( const_iterator first , const_iterator last )
Removes all list elements, then inserts the elements in the range [ first ... last ) .
assign
void assign( size_type n , const T& value )
Removes all list elements, then inserts n elements of value (default T() ).
back
T& back()
Returns a reference to the list's last element.
back
const T& back() const
Returns a reference to the list's last element.
begin
iterator begin()
Returns an iterator positioned at the list's first item.
begin
const_iterator begin() const
Returns an iterator positioned at the list's first item.
clear
void clear()
Erases all the list elements.
empty
bool empty() const
Returns true if the list contains no entries.
end
iterator end()
Returns an iterator positioned immediately after the list's last item.
end
const_iterator end() const
Returns an iterator positioned immediately after the list's last item.
erase
void erase( iterator pos )
Erases the element at pos .
erase
void erase( iterator first , iterator last )
Erases the elements in range [ first , last ) .
front
T& front()
Returns a reference to the list's first element.
front
const T& front() const
Returns a reference to the list's first element.
get_allocator
Allocator get_allocator() const
Returns a copy of the allocator the list is using.
insert
iterator insert( iterator pos , const T& value )
Inserts a copy of value (default T() ) at pos and returns an iterator pointing to the new element's position.
insert
void insert( iterator pos , size_type n , const T& value )
Inserts n copies of value at pos .
insert
void insert( iterator pos , const T* first , const T* last )
Inserts copies of the elements in the range [ first , last ) at pos .
insert
void insert( iterator pos , const_iterator first , const_iterator last )
Inserts copies of the elements in the range [ first , last ) at pos .
max_size
size_type max_size() const
Returns the maximum number of entries the list can contain.
merge
void merge( const list< T, Allocator >& x )
Moves the elements of x into the list and places them so that all of the list's elements are sorted using the operator< . This operation assumes that both the list and x were already sorted using operator< .
merge
void merge( const list< T, Allocator >& x, bool (* compare )( const T&, const T&) )
Moves the elements of x into the list and places them so that all of the list's elements are sorted using compare . This operation assumes that both the list and x were already sorted using compare .
pop_back
void pop_back()
Erases the last list element.
pop_front
void pop_front()
Erases the first list element.
push_back
void push_back( const T& value )
Adds value at the end of list.
push_front
void push_front( const T& value )
Inserts a copy of value in front of list's first element.
rbegin
reverse_iterator rbegin()
Returns a reverse iterator positioned at list's last item.
rbegin
const_reverse_iterator rbegin() const
Returns a reverse iterator positioned at list's last item.
remove
void remove( const T& value )
Erases all elements that match value , using operator== to perform the comparison.
remove_if
void remove_if( const unary_function< T, bool >& pred )
Erases all elements for which pred evaluates to true .
rend
reverse_iterator rend()
Returns a reverse iterator positioned immediately before list's first item.
rend
const_reverse_iterator rend() const
Returns a reverse iterator positioned immediately before list's first item.
resize
void resize( size_type n , T value )
Adjusts list to hold n elements, using elements of value (default T() ) to expand the list if necessary.
reverse
void reverse()
Reverses the order of the list elements. The time complexity is O(N).
size
size_type size() const
Returns the number of entries list contains.
sort
void sort()
Sorts the list elements using operator< . The time complexity is O(NlogN).
sort
void sort( bool (*compare)( const T&, const T& ) )
Sorts the list elements using the comparator compare .
splice
void splice( iterator pos , list< T, Allocator >& x )
Removes all elements in x and inserts them at position pos .
splice
void splice( iterator to , list< T, Allocator >& x , iterator from )
Removes the element in x at position from and inserts it at position to .
splice
void splice( iterator pos , list< T, Allocator >& x , iterator first , iterator last )
Removes the elements from x in the range [ first , last ) and inserts them at position pos .
swap
void swap( list< T, Allocator >& x )
Exchanges the contents of list and x .
unique
void unique()
Replaces all repeating sequences of a single element by a single occurrence of that element.

Non-Member Functions

==
bool operator==( const list< T, Allocator >& x , const list< T, Allocator >& y ) const
Returns true if x contains the same items in the same order as y .
<
bool operator<( const list< T, Allocator >& x , const list< T, Allocator >& y ) const
Returns true if x is lexicographically less than y .
swap
void swap( const list< T, Allocator >& x , const list< T, Allocator >& y ) const
Exchanges the contents of x and y .

Copyright©1994-2026 Recursion Software LLC
All Rights Reserved - For use by licensed users only.