Previous fileTop of DocumentContentsIndex pageNext file
Apache C++ Standard Library Reference Guide

list

Library:  Containers


Does not inherit

Local Index

Members

Non-Members

Summary

A sequence that supports bidirectional iterators

Synopsis

#include <list>

namespace std {
  template <class T, class Allocator = allocator<T> >
  class list;
}

Description

list is a type of sequence that supports bidirectional iterators. A list allows constant time insert and erase operations anywhere within the sequence, with storage management handled automatically. Constant time random access is not supported.

Any type used for the template parameter T must include the following members. Here T is the type, t is a value of T and u is a const value of T.

Copy constructors

T(t) and T(u)

Destructor

t.~T()

Address of

&t and &u yielding T* and const T* respectively

Assignment

t = a where a is a (possibly const) value of T

Interface

Constructors

explicit list(const Allocator& alloc = Allocator());
explicit list(size_type n);
list(size_type n, const T& value, 
      const Allocator& alloc = Allocator());
template <class InputIterator>
list(InputIterator start, InputIterator finish,
      const Allocator& alloc = Allocator()); 
list(const list<T, Allocator>& x);

Destructors

~list();

Assignment Operators

list<T, Allocator>& 
operator=(const list<T, Allocator>& x)

Allocators

allocator_type 
get_allocator() const;

Iterators

iterator 
begin();
const_iterator 
begin() const;
iterator 
end();
const_iterator 
end() const;
reverse_iterator 
rbegin();
const_reverse_iterator
rbegin() const;
reverse_iterator 
rend();
const_reverse_iterator 
rend() const;

Member Functions

template <class InputIterator>
void
assign(InputIterator start, InputIterator finish);
void
assign(size_type n, const T& t);
reference 
back();
const_reference 
back() const;
void
clear();
bool 
empty() const;
iterator
erase(iterator position);
iterator
erase(iterator start, iterator finish);
reference 
front();
const_reference 
front() const;
iterator 
insert(iterator position, const T& x);
void 
insert(iterator position, size_type n, const T& x);
template <class InputIterator>
void 
insert(iterator position, InputIterator start,
        InputIterator finish);
size_type
max_size() const;
void 
merge(list<T, Allocator>& x);
template <class Compare>
void 
merge(list<T, Allocator>& x, Compare comp);
void 
pop_back();
void 
pop_front();
void 
push_back(const T& x);
void
push_front(const T& x);
void 
remove(const T& value);
template <class Predicate>
void 
remove_if(Predicate pred);
void 
resize(size_type sz, T c);
void 
reverse();
size_type 
size() const;
void 
sort();
template <class Compare>
void 
sort(Compare comp);
void 
splice(iterator position, list<T, Allocator>& x);
void 
splice(iterator position, list<T, Allocator>& x, 
        iterator i);
void 
splice(iterator position, list<T, Allocator >& x,
        iterator start, iterator finish);
void
swap(list <T, Allocator>& x);
void 
unique();
template <class BinaryPredicate>
void 
unique(BinaryPredicate binary_pred);

Nonmember Operators

template <class T, class Allocator>
bool operator==(const list<T, Allocator>& x,
                 const list<T, Allocator>& y);
template <class T, class Allocator>
bool operator!=(const list<T, Allocator>& x,
                 const list<T, Allocator>& y);
template <class T, class Allocator>
bool operator<(const list<T, Allocator>& x,
                const list<T,Allocator>& y);
template <class T, class Allocator>
bool operator>(const list<T, Allocator>& x,
                const list<T,Allocator>& y);
template <class T, class Allocator>
bool operator<=(const list<T, Allocator>& x,
                const list<T,Allocator>& y);
template <class T, class Allocator>
bool operator>=(const list<T, Allocator>& x,
                const list<T,Allocator>& y);

Specialized Algorithms

template <class T, class Allocator>
void swap(list<T, Allocator>& a, list<T, Allocator>& b);

Example

Warnings

Member function templates are used in all of the containers included in the Standard Template Library. For example, the constructor for list takes two templatized iterators:

list also has an insert() function of this type. These functions, when not restricted by compiler limitations, allow you to use any type of input iterator as arguments. For compilers that do not support this feature, substitute functions allow you to use an iterator obtained from the same type of container as the one you are constructing (or calling a member function on), or you can use a pointer to the type of element you have in the container.

For example, if your compiler does not support member function templates, you can construct a list in the following two ways:

You cannot construct a list this way:

since the long_list and first_list are not the same type.

Additionally, list includes a merge() function of this type.

This function allows you to specify a compare function object to be used in merging two lists. In this case, a substitute function is not included with the merge that uses the operator< as the default. Thus, if your compiler does not support member function templates, all list merges use operator<.

See Also

allocator, Containers, Iterators

Standards Conformance

ISO/IEC 14882:1998 -- International Standard for Information Systems -- Programming Language C++, Section 23.2.2



Previous fileTop of DocumentContentsIndex pageNext file