📄 deq_4164.htm
字号:
<HTML><TITLE>deque </TITLE><BODY>
<A HREF="ref.htm"><IMG SRC="images/banner.gif"></A>
<P><STRONG>Click on the banner to return to the Class Reference home page.</STRONG></P>
<P>©Copyright 1996 Rogue Wave Software</P>
<H2>deque </H2>
<HR><PRE> Container</PRE><HR>
<A NAME="Summary"><H3>Summary</H3></A>
<P>A sequence that supports random access iterators and efficient insertion/deletion at both beginning and end.</P>
<H3>Contents</H3>
<UL>
<A HREF="#Synopsis"><LI>Synopsis</LI></A>
<A HREF="#Description"><LI>Description</LI></A>
<A HREF="#Interface"><LI>Interface</LI></A>
<A HREF="#Constructors and Destructor"><LI>Constructors and Destructor</LI></A>
<A HREF="#Allocator"><LI>Allocator</LI></A>
<A HREF="#Iterators"><LI>Iterators</LI></A>
<A HREF="#Assignment Operator"><LI>Assignment Operator</LI></A>
<A HREF="#Reference Operators"><LI>Reference Operators</LI></A>
<A HREF="#Member Functions"><LI>Member Functions</LI></A>
<A HREF="#Non-member Functions"><LI>Non-member Functions</LI></A>
<A HREF="#Example"><LI>Example</LI></A>
<A HREF="#Warnings"><LI>Warnings</LI></A>
</UL>
<A NAME="Synopsis"><H3>Synopsis</H3></A>
<PRE>#include <deque></PRE>
<PRE>
template <class T, class Allocator = allocator>
class deque;</PRE>
<A NAME="Description"><H3>Description</H3></A>
<P><B><I>deque<T, Allocator></B></I> 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 <SAMP>Allocator</SAMP> template parameter. </P>
<P>Any type used for the template parameter <SAMP>T</SAMP> must provide the following (where <SAMP>T</SAMP> is the <SAMP>type</SAMP>, <SAMP>t</SAMP> is a <SAMP>value</SAMP> of <SAMP>T</SAMP> and<SAMP> u</SAMP> is a <SAMP>const</SAMP> <SAMP>value</SAMP> of <SAMP>T</SAMP>): </P>
<CENTER><TABLE CELLSPACING=3 CELLPADDING=3>
<TR VALIGN=top>
<TD>Default constructor</TD>
<TD><SAMP>T()</SAMP></TD></TR>
<TR VALIGN=top>
<TD>Copy constructors </TD>
<TD><SAMP>T(t)</SAMP> and <SAMP>T(u)</SAMP></TD></TR>
<TR VALIGN=top>
<TD>Destructor</TD>
<TD><SAMP>t.~T()</SAMP></TD></TR>
<TR VALIGN=top>
<TD>Address of</TD>
<TD><SAMP>&t</SAMP> and <SAMP>&u</SAMP> yielding <SAMP>T*</SAMP> and <SAMP>const T*</SAMP> respectively</TD></TR>
<TR VALIGN=top>
<TD>Assignment</TD>
<TD><SAMP>t = a</SAMP> where <SAMP>a</SAMP> is a (possibly <SAMP>const</SAMP>) value of <SAMP>T</SAMP></TD></TR>
</TABLE></CENTER>
<A NAME="Interface"><H3>Interface</H3></A>
<PRE>template <class T, class Allocator = allocator></PRE>
<PRE> class deque {
public:
// Types
class iterator;
class const_iterator;
typedef T value_type;
typedef Allocator allocator_type;
typename reference;
typename const_reference;
typename size_type;
typename difference_type;
typename reverse_iterator;
typename const_reverse_iterator;
// Construct/Copy/Destroy
explicit deque (const Allocator& = Allocator());
explicit deque (size_type, const Allocator& = Allocator ());
deque (size_type, const T& value,
const Allocator& = Allocator ());
deque (const deque<T,Allocator>&);
template <class InputIterator>
deque (InputIterator, InputIterator,
const Allocator& = Allocator ());
~deque ();
deque<T,Allocator>& operator= (const deque<T,Allocator>&);
template <class InputIterator>
void assign (InputIterator, InputIterator);
template <class Size, class T>
void assign (Size);
template <class Size, class T>
void assign (Size, const T&);
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;
// Capacity
size_type size () const;
size_type max_size () const;
void resize (size_type);
void resize (size_type, T);
bool empty () const;
// Element access
reference operator[] (size_type);
const_reference operator[] (size_type) const;
reference at (size_type);
const_reference at (size_type) const;
reference front ();
const_reference front () const;
reference back ();
const_reference back () const;
// Modifiers
void push_front (const T&);
void push_back (const T&);
iterator insert (iterator);
iterator insert (iterator, const T&);
void insert (iterator, size_type, const T&);
template <class InputIterator>
void insert (iterator, InputIterator, InputIterator);
void pop_front ();
void pop_back ();
iterator erase (iterator);
iterator erase (iterator, iterator);
void swap (deque<T, Allocator>&);
void clear();
};
// Non-member Operators
template <class T, class Allocator>
bool operator== (const deque<T, Allocator>&,
const deque<T, Allocator>&);
template <class T, class Allocator>
bool operator<<B> </B>(const deque<T, Allocator>&,
const deque<T, Allocator>&);
// Specialized Algorithms
template <class T, class Allocator>
voice swap (deque<T, Allocator>&, deque<T, Allocator>&);</PRE>
<A NAME="Constructors and Destructor"><H3>Constructors and Destructor</H3></A>
<PRE>explicit
<B>deque</B> (const Allocator& alloc = Allocator());</PRE>
<UL><P>The default constructor. Creates a deque of zero elements. The deque will use the allocator <SAMP>alloc</SAMP> for all storage management.</P>
</UL>
<PRE>explicit
<B>deque</B> (size_type n, const Allocator& alloc = Allocator());</PRE>
<UL><P>Creates a list of length <SAMP>n</SAMP>, containing <SAMP>n</SAMP> copies of the default value for type <SAMP>T</SAMP>. Requires that <SAMP>T</SAMP> have a default constructor. The deque will use the allocator <SAMP>alloc</SAMP> for all storage management. </P>
</UL>
<PRE><B>deque</B> (size_type n, const T& value,
const Allocator& alloc = Allocator());</PRE>
<UL><P>Creates a list of length <SAMP>n</SAMP>, containing <SAMP>n</SAMP> copies of <SAMP>value</SAMP>. The deque will use the allocator <SAMP>alloc</SAMP> for all storage management. </P>
</UL>
<PRE><B>deque</B> (const deque<T, Allocator>& x);</PRE>
<UL><P>Copy constructor. Creates a copy of <SAMP>x</SAMP>.</P>
</UL>
<PRE>template <class InputIterator>
<B>deque</B> (InputIterator first, InputIterator last,
const Allocator& alloc = Allocator());</PRE>
<UL><P>Creates a deque of length <SAMP>last - first</SAMP>, filled with all values obtained by dereferencing the <SAMP>InputIterators</SAMP> on the range <SAMP>[first, last)</SAMP>. The deque will use the allocator <SAMP>alloc</SAMP> for all storage management. </P>
</UL>
<PRE><B>~deque</B> ();</PRE>
<UL><P>The destructor. Releases any allocated memory for self.</P>
</UL>
<A NAME="Allocator"><H3>Allocator</H3></A>
<PRE><B>allocator</B>
allocator_type <B>get_allocator</B> () const;</PRE>
<UL><P>Returns a copy of the allocator used by self for storage management.</P>
</UL>
<A NAME="Iterators"><H3>Iterators</H3></A>
<PRE>iterator <B>begin</B> ();</PRE>
<UL><P>Returns a random access <SAMP>iterator</SAMP> that points to the first element.</P>
</UL>
<PRE>const_iterator <B>begin</B> () const;</PRE>
<UL><P>Returns a constant random access iterator that points to the first element.</P>
</UL>
<PRE>iterator <B>end</B> ();</PRE>
<UL><P>Returns a random access <SAMP>iterator</SAMP> that points to the past-the-end value.</P>
</UL>
<PRE>const_iterator <B>end</B> () const;</PRE>
<UL><P>Returns a constant random access iterator that points to the past-the-end value.</P>
</UL>
<PRE>reverse_iterator <B>rbegin</B> ();</PRE>
<UL><P>Returns a random access <SAMP>reverse_iterator</SAMP> that points to the past-the-end value.</P>
</UL>
<PRE>const_reverse_iterator <B>rbegin</B> () const;</PRE>
<UL><P>Returns a constant random access reverse iterator that points to the past-the-end value.</P>
</UL>
<PRE>reverse_iterator <B>rend</B> ();</PRE>
<UL><P>Returns a random access <SAMP>reverse_iterator</SAMP> that points to the first element.</P>
</UL>
<PRE>const_reverse_iterator <B>rend</B> () const;</PRE>
<UL><P>Returns a constant random access reverse iterator that points to the first element.</P>
</UL>
<A NAME="Assignment Operator"><H3>Assignment Operator</H3></A>
<PRE>deque<T, Allocator>&
<B>operator=</B> (const deque<T, Allocator>& x);</PRE>
<UL><P>Erases all elements in self then inserts into self a copy of each element in <SAMP>x</SAMP>. Returns a reference to self.</P>
</UL>
<A NAME="Reference Operators"><H3>Reference Operators</H3></A>
<PRE>reference <B>operator</B>[] (size_type n);</PRE>
<UL><P>Returns a <SAMP>reference</SAMP> to element <SAMP>n</SAMP> of self. The result can be used as an lvalue. The index <SAMP>n</SAMP> must be between 0 and the size less one.</P>
</UL>
<PRE>const_reference <B>operator</B>[] (size_type n) const;</PRE>
<UL><P>Returns a constant reference to element <SAMP>n</SAMP> of self. The index <SAMP>n</SAMP> must be between 0 and the <SAMP>size() - 1</SAMP>.</P>
</UL>
<A NAME="Member Functions"><H3>Member Functions</H3></A>
<PRE>template <class InputIterator>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -