|
|
The list class supports a list. Its template specification is
template <class T, class Allocator = allocator<T> > class list
Here, T is the type of data stored in the list. It has the following constructors:
explicit list(const Allocator &a = Allocator( ) );
explicit list(size_type num, const T &val = T ( ),
const Allocator &a = Allocator( ));
list(const list<T, Allocator> &ob);
template <class InIter>list(InIter start, InIter end,
const Allocator &a = Allocator( ));
The first form constructs an empty list. The second form constructs a list that has num elements with the value val. The third form constructs a list that contains the same elements as ob. The fourth form constructs a list that contains the elements in the range specified by start and end.
The following comparison operators are defined for list:
==, <, <=, !=, >, >=
list contains the following member functions:
Member | Description |
---|---|
template <class InIter> | Assigns the list the sequence defined by start and end. |
void assign(size_type num, const T &val); | Assigns the list num elements of value val. |
reference back( ); | Returns a reference to the last element in the list. |
iterator begin( ); | Returns an iterator to the first element in the list. |
void clear( ); | Removes all elements from the list. |
bool empty( ) const; | Returns true if the invoking list is empty and false otherwise. |
iterator end( ); | Returns an iterator to the end of the list. |
iterator erase(iterator i); | Removes the element pointed to by i. Returns an iterator to the element after the one removed. |
iterator erase(iterator start, iterator end); | Removes the elements in the range start to end. Returns an iterator to the element after the last element removed. |
reference front( ); | Returns a reference to the first element in the list. |
allocator_type get_allocator( ) const; | Returns list’s allocator. |
iterator insert(iterator i, | Inserts val immediately before the element specified by i. An iterator to the element is returned. |
void insert(iterator i, size_type num, | Inserts num copies of val immediately before the element specified by i. |
template <class InIter> | Inserts the sequence defined by start and end immediately before the element specified by i. |
size_type max_size( ) const; | Returns the maximum number of elements that the list can hold. |
void merge(list<T, Allocator> &ob); | Merges the ordered list contained in ob with the ordered invoking list. The result is ordered. After the merge, the list contained in ob is empty. In the second form, a comparison function can be specified that determines when one element is less than another. |
void pop_back( ); | Removes the last element in the list. |
void pop_front( ); | Removes the first element in the list. |
void push_back(const T &val); | Adds an element with the value specified by val to the end of the list. |
void push_front(const T &val); | Adds an element with the value specified by val to the front of the list. |
reverse_iterator rbegin( ); | Returns a reverse iterator to the end of the list. |
void remove(const T &val); | Removes elements with the value val from the list. |
template <class UnPred> | Removes elements for which the unary predicate pr is true. |
reverse_iterator rend( ); | Returns a reverse iterator to the start of the list. |
void resize(size_type num, T val = T ( )); | Changes the size of the list to that specified by num. If the list must be lengthened, those elements with the value specified by val are added to the end. |
void reverse( ); | Reverses the invoking list. |
size_type size( ) const; | Returns the number of elements currently in the list. |
void sort( ); | Sorts the list. The second form sorts the list using the comparison function cmpfn to determine when one element is less than another. |
void splice(iterator i, | The contents of ob are inserted into the invoking list at the location pointed to by i. After the operation, ob is empty. |
void splice(iterator i, | The element pointed to by el is removed from the list ob and stored in the invoking list at the location pointed to by i. |
void splice(iterator i, | The range defined by start and end is removed from ob and stored in the invoking list beginning at the location pointed to by i. |
void swap(list<T, Allocator> &ob); | Exchanges the elements stored in the invoking list with those in ob. |
void unique( ); | Removes duplicate elements from the invoking list. The second form uses pr to determine uniqueness. |
|
|