Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
STL Containers
bitset
deque
list
map
multimap
multiset
priority_queue
queue
set
stack
vector
list
comparison operators
list::list
list::~list
member functions:
list::assign
list::back
list::begin
list::clear
list::empty
list::end
list::erase
list::front
list::get_allocator
list::insert
list::max_size
list::merge
list::operator=
list::pop_back
list::pop_front
list::push_back
list::push_front
list::rbegin
list::remove
list::remove_if
list::rend
list::resize
list::reverse
list::size
list::sort
list::splice
list::swap
list::unique


list::list

public member function
explicit list ( const Allocator& = Allocator() );
explicit list ( size_type n, const T& value = T(), const Allocator& = Allocator() );
template < class InputIterator >
         list ( InputIterator first, InputIterator last, const Allocator& = Allocator() );
list ( const list<T,Allocator>& x );

Construct list

Constructs a list container object, initializing its contents depending on the constructor version used:

explicit list ( const Allocator& = Allocator() );
Default constructor: constructs an empty list object, with no content and a size of zero.
explicit list ( size_type n, const T& value= T(), const Allocator& = Allocator() );
Repetitive sequence constructor: Initializes the container object with its content set to a repetition, n times, of copies of value.
template <class InputIterator> list ( InputIterator first, InputIterator last, const Allocator& = Allocator() );
Iteration constructor: Iterates between first and last, setting a copy of each of the sequence of elements as the content of the container object.
list ( const list<T,Allocator>& x );
Copy constructor: The object is initialized to have the same contents and properties as the x list object.

Parameters

n
Times that value is repeated to form the content of the object.
Member type size_type is an unsigned integral type.
value
Value to be repeated n times as the content of the object.
T is the first class template parameter (the type of the elements stored in the list).
first, last
Input iterators to the initial and final positions in a sequence. The range used is [first,last), which includes all the elements between first and last, including the element pointed by first but not the element pointed by last.
The function template type can be any type of input iterator.
x
Another list object with the same class template parameters (T and Allocator).
unnamed Allocator parameter
Allocator object to be used instead of constructing a new one.
For class instantiations using their version of the default allocator class template, this parameter is not relevant.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// constructing lists
#include <iostream>
#include <list>
using namespace std;
int main ()
{
  // constructors used in the same order as described above:
  list<int> first;                                // empty list of ints
  list<int> second (4,100);                       // four ints with value 100
  list<int> third (second.begin(),second.end());  // iterating through second
  list<int> fourth (third);                       // a copy of third
  // the iterator constructor can also be used to construct from arrays:
  int myints[] = {16,2,77,29};
  list<int> fifth (myints, myints + sizeof(myints) / sizeof(int) );
  cout << "The contents of fifth are: ";
  for (list<int>::iterator it = fifth.begin(); it != fifth.end(); it++)
    cout << *it << " ";
  cout << endl;
  return 0;
}

Output:
The contents of fifth are: 16 2 77 29 

Complexity

For the default constructor, constant.
For the repetitive sequence constructor, linear in n (copy constructions).
For the iterator constructor, linear in the distance between the iterators (copy constructions).
For the copy constructor, linear on x's size (copy constructions).

See also