We recommend using Visual Studio 2017
This documentation is archived and is not being maintained.

list Class

The STL list class is a template class of sequence containers that maintain their elements in a linear arrangement and allow efficient insertions and deletions at any location within the sequence. The sequence is stored as a bidirectional linked list of elements, each containing a member of some type Type.

For a list of all members of this type, see list Class Members.

template < 
    class Type,
    class Allocator=allocator<Type> 
class list;


The element data type to be stored in the list.


The type that represents the stored allocator object that encapsulates details about the list's allocation and deallocation of memory. This argument is optional, and the default value is allocator<Type>.

The choice of container type should be based generally on the type of searching and inserting required by the application. Vectors should be the preferred container for managing a sequence when random access to any element is at a premium and insertions or deletions of elements are only required at the end of a sequence. The performance of the class deque container is superior when random access is needed and insertions and deletions at both the start and the end of a sequence are at a premium.

The list member functions merge, reverse, unique, remove, and remove_if have been optimized for operation on list objects and offer a high-performance alternative to their generic counterparts.

List reallocation occurs when a member function must insert or delete elements of the list. In all such cases, only iterators or references that point at erased parts of the controlled sequence become invalid.

Include the STL standard header <list> to define the container template class list and several supporting templates.

Header: <list>