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

deque

Library:  Containers


Does not inherit

Local Index

Members

Non-Members

Summary

A sequence that supports random access iterators and efficient insertion/deletion at both beginning and end

Synopsis

#include <deque>

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

Description

deque is a type of sequence that supports random access iterators. It supports constant time insert and erase operations at the beginning or the end of the container. Insertion and erase in the middle take linear time. Storage management is handled by the Allocator template parameter.

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 
deque(const Allocator& alloc = Allocator());
explicit 
deque(size_type n);
deque(size_type n, const T& value, 
       const Allocator& alloc = Allocator());
deque(const deque<T, Allocator>& x);
template <class InputIterator>
deque(InputIterator start, InputIterator finish, 
       const Allocator& alloc = Allocator());

Destructors

~deque();

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;

Assignment Operators

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

Reference Operators

reference operator[](size_type n);
const_reference operator[](size_type n) const;

Member Functions

template <class InputIterator>
void
assign(InputIterator start, InputIterator finish);
void
assign(size_type n, const T& t);
reference 
at(size_type n);
const_reference 
at(size_type) const;
reference 
back();
const_reference 
back() const;
void
clear();
bool 
empty() const;
reference 
front();
const_reference 
front() const;
iterator
erase(iterator start, iterator finish);
iterator
erase(iterator position);
iterator
insert(iterator position, const_reference x);
void
insert(iterator position, size_type n, const_reference x);
template <class InputIterator>
void
insert(iterator position, InputIterator start, InputIterator finish);
size_type 
max_size() const;
void 
pop_back();
void 
pop_front();
void
push_back(const T& x);
void 
push_front(const T& x);
void 
resize(size_type sz, T c);
size_type 
size() const;
void 
swap(deque<T,Allocator>& x);

Nonmember Functions

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

Specialized Algorithms

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

Example

Warnings

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

deque 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 deque in the following two ways:

You cannot construct a deque this way:

since the long_deque and first_deque are not the same type.

Standards Conformance

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



Previous fileTop of DocumentContentsIndex pageNext file