C++ Library - <list>

List is a popularly used sequence container. Container is an object that holds data of same type. List container is implemented as doubly linked-list, hence it provides bidirectional sequential access to it's data.
List doesn't provide fast random access, it only supports sequential access in both directions. List allows insertion and deletion operation anywhere within a sequence in constant time.
Elements of list can be scattered in different chunks of memory. Container stores necessary information to allow sequential access to it's data. Lists can shrink or expand as needed from both ends at run time. The storage requirement is fulfilled automatically by internal allocator.
Zero sized lists are also valid. In that case list.begin() and list.end() points to same location. But behavior of calling front() or back() is undefined.
Below is definition of std::list from <list> header file
template < class T, class Alloc = allocator<T> > class list;

T − Type of the element contained.
T may be substituted by any other data type including user-defined type.
T − Type of the element contained.
T may be substituted by any other data type including user-defined type.
Alloc − Type of allocator object.
By default, the allocator class template is used, which defines the simplest memory allocation model and is value-independent.
Alloc − Type of allocator object.
By default, the allocator class template is used, which defines the simplest memory allocation model and is value-independent.
Following member types can be used as parameters or return type by member functions.
Below is list of all methods from <list> header.
Constructs an empty list with zero elements.
Constructs a new list with n elements and assigns val to each element of list.
Constructs a new list with n elements and assign zero value to each element of list.
Constructs a list with as many elements as in range of first to last.
Constructs a list with copy of each elements present in existing list.
Constructs a list with the contents of other using move semantics.
Constructs a list with the contents of other using move semantics.
Destroys list object by deallocating it's memory.
Assigns new value to list by replacing old ones.
Assigns new values to list by replacing old ones.
Assigns new values to list by replacing old ones.
Returns a reference to the last element of the list.
Returns a random access iterator which points to the first element of the list.
Returns a constant random access iterator which points to the beginning of the list.
Returns a constant random access iterator which points to the end of the list.
Destroys the list by removing all elements from the list and sets size of list to zero.
Returns a constant reverse iterator which points to the last element of the list.
Returns a constant reverse iterator which points to the theoretical element preceding the first element in the list.
Extends list by inserting new element at a given position.
Inserts new element at the end of list and increases size of list by one.
Inserts new element at the beginning of the list and increases size of list by one.
Tests whether list is empty or not.
Returns a random access iterator which points to the last element of the list.
Removes single element from the the list.
Removes range of element from the the list.
Returns a reference to the first element of the list.
Returns an allocator associated with list
Extends iterator by inserting new element at position in list.
Extends list by inserting new elements in the container.
Extends list by inserting new elements in the container.
Extends list by inserting new element in the container.
Extends list by inserting new elements in the container
Returns the maximum number of elements can be held by list.
Merges two sorted lists into one.
Merges two sorted lists into one.
Merges two sorted lists into one by using move semantics.
Merges two sorted lists into one by using move semantics.
Assigns new contents to the list by replacing old ones.
Assign new contents to the list by replacing old ones.
Assign new contents to the list by replacing old ones.
Removes last element from list.
Removes first element from list.
Inserts new element at the end of list.
Inserts new element at the end of list.
Inserts new element at the beginning of list.
Inserts new element at the beginning of list.
Returns a reverse iterator which points to the last element of the list.
removes element(s) from the list that matches the value.
removes elements from the list that fulfills the condition.
Returns a reverse iterator which points to the reverse end of the list.
Changes the size of list.
Changes the size of list.
Reverses the order of the elements present in the list.
Returns the number of elements present in the list.
Sorts the elements of the list.
Sorts the elements of the list.
Transfers all elements from list to *this.
Transfers a element pointed to by iterator i from list x into *this.
Transfers all elements from list x to *this by using move semantics.
Transfers the elements in the range of first to last from x to *this.
Transfers the element pointed to by iterator i from list x into *this by using move semantics.
Transfers the elements in the range of first to last from x to *this by using move semantics.
Exchanges the content of list with contents of another list x.
Removes all consecutive duplicate elements from the list.
Removes all consecutive duplicate elements from the list.
Tests whether two lists are equal or not.
Tests whether two lists are equal or not.
Tests whether first list is less than other or not.
Tests whether first list is less than or equal to other or not.
Tests whether first list is greater than other or not.
Tests whether first list is greater than or equal to other or not.
Exchanges the contents of two list.
 Print
 Add Notes
 Bookmark this page