Rogue Wave banner
Previous fileTop of documentContentsIndexNext file

list


Container

Summary

A sequence that supports bidirectional iterators.

Data Type and Member Function Indexes
(exclusive of constructors and destructors)

Synopsis

#include <list>
template <class T, class Allocator = allocator<T> >
class list;

Description

list<T,Allocator> is a type of sequence that supports bidirectional iterators. A list<T,Allocator> 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 (where 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

   typedef typename std::reverse_iterator<iterator>
                         reverse_iterator;
   typedef typename std::reverse_iterator<const_iterator>
                         const_reverse_iterator;

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 first, InputIterator last,
      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 first, InputIterator last);
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 first, iterator last);
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 first,
        InputIterator last);
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);
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 first, iterator last);
void
swap(list <T, Allocator>& x);
void 
unique();
template <class BinaryPredicate>
void 
unique(BinaryPredicate binary_pred);

Non-member 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

Program Output

Warnings

Member function templates are used in all containers included in the Standard Template Library. An example of this feature is the constructor for list<T, Allocator> that 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:

But not 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<.

Also, many compilers do not support default template arguments. If your compiler is one of these, you always need to supply the Allocator template argument. For instance, you have to write:

list<int, allocator<int> >

instead of:

list<int>

If your compiler does not support namespaces, then you do not need the using declaration for std.

See Also

allocator, Containers, Iterators



Previous fileTop of documentContentsIndexNext file
©Copyright 1998, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.
OEM Release, June 1998