📄 deque.html
字号:
<HTML><HEAD><TITLE><deque></TITLE></HEAD><BODY><H1><A NAME="<deque>"><CODE><deque></CODE></A></H1><HR><P>Include the <A HREF="index.html#STL">STL</A>standard header <B><CODE><deque></CODE></B> to define the<A HREF="lib_cont.html#Containers">container</A>template class <CODE>deque</CODE> and several supportingtemplates.</P><PRE>namespace std {template<class Ty, class Alloc> class <B><A HREF="#deque">deque</A></B>; // TEMPLATE FUNCTIONStemplate<class Ty, class Alloc> bool <B><A HREF="#operator==">operator==</A></B>( const deque<Ty, Alloc>& left, const deque<Ty, Alloc>& right);template<class Ty, class Alloc> bool <B><A HREF="#operator!=">operator!=</A></B>( const deque<Ty, Alloc>& left, const deque<Ty, Alloc>& right);template<class Ty, class Alloc> bool <B><A HREF="#operator<">operator<</A></B>( const deque<Ty, Alloc>& left, const deque<Ty, Alloc>& right);template<class Ty, class Alloc> bool <B><A HREF="#operator>">operator></A></B>( const deque<Ty, Alloc>& left, const deque<Ty, Alloc>& right);template<class Ty, class Alloc> bool <B><A HREF="#operator<=">operator<=</A></B>( const deque<Ty, Alloc>& left, const deque<Ty, Alloc>& right);template<class Ty, class Alloc> bool <B><A HREF="#operator>=">operator>=</A></B>( const deque<Ty, Alloc>& left, const deque<Ty, Alloc>& right);template<class Ty, class Alloc> void <B><A HREF="#swap">swap</A></B>( deque<Ty, Alloc>& left, deque<Ty, Alloc>& right); };</PRE><H2><A NAME="deque"><CODE>deque</CODE></A></H2><HR><P><B><CODE><A HREF="#deque::allocator_type">allocator_type</A>· <A HREF="#deque::assign">assign</A>· <A HREF="#deque::at">at</A>· <A HREF="#deque::back">back</A>· <A HREF="#deque::begin">begin</A>· <A HREF="#deque::clear">clear</A>· <A HREF="#deque::const_iterator">const_iterator</A>· <A HREF="#deque::const_pointer">const_pointer</A>· <A HREF="#deque::const_reference">const_reference</A>· <A HREF="#deque::const_reverse_iterator">const_reverse_iterator</A>· <A HREF="#deque::deque">deque</A>· <A HREF="#deque::difference_type">difference_type</A>· <A HREF="#deque::empty">empty</A>· <A HREF="#deque::end">end</A>· <A HREF="#deque::erase">erase</A>· <A HREF="#deque::front">front</A>· <A HREF="#deque::get_allocator">get_allocator</A>· <A HREF="#deque::insert">insert</A>· <A HREF="#deque::iterator">iterator</A>· <A HREF="#deque::max_size">max_size</A>· <A HREF="#deque::operator[]">operator[]</A>· <A HREF="#deque::pointer">pointer</A>· <A HREF="#deque::pop_back">pop_back</A>· <A HREF="#deque::pop_front">pop_front</A>· <A HREF="#deque::push_back">push_back</A>· <A HREF="#deque::push_front">push_front</A>· <A HREF="#deque::rbegin">rbegin</A>· <A HREF="#deque::reference">reference</A>· <A HREF="#deque::rend">rend</A>· <A HREF="#deque::resize">resize</A>· <A HREF="#deque::reverse_iterator">reverse_iterator</A>· <A HREF="#deque::size">size</A>· <A HREF="#deque::size_type">size_type</A>· <A HREF="#deque::swap">swap</A>· <A HREF="#deque::value_type">value_type</A></CODE></B></P><HR><PRE>template<class Ty, class Alloc = allocator<Ty> > class <B>deque</B> {public: typedef Alloc <B><A HREF="#deque::allocator_type">allocator_type</A></B>; typedef typename Alloc::pointer <B><A HREF="#deque::pointer">pointer</A></B>; typedef typename Alloc::const_pointer <B><A HREF="#deque::const_pointer">const_pointer</A></B>; typedef typename Alloc::reference <B><A HREF="#deque::reference">reference</A></B>; typedef typename Alloc::const_reference <B><A HREF="#deque::const_reference">const_reference</A></B>; typedef typename Alloc::value_type <B><A HREF="#deque::value_type">value_type</A></B>; typedef T0 <B><A HREF="#deque::iterator">iterator</A></B>; typedef T1 <B><A HREF="#deque::const_iterator">const_iterator</A></B>; typedef T2 <B><A HREF="#deque::size_type">size_type</A></B>; typedef T3 <B><A HREF="#deque::difference_type">difference_type</A></B>; typedef reverse_iterator<const_iterator> <B><A HREF="#deque::const_reverse_iterator">const_reverse_iterator</A></B>; typedef reverse_iterator<iterator> <B><A HREF="#deque::reverse_iterator">reverse_iterator</A></B>; <B><A HREF="#deque::deque">deque</A></B>(); explicit <B><A HREF="#deque::deque">deque</A></B>(const Alloc& al); explicit <B><A HREF="#deque::deque">deque</A></B>(size_type count); <B><A HREF="#deque::deque">deque</A></B>(size_type count, const Ty& val); <B><A HREF="#deque::deque">deque</A></B>(size_type count, const Ty& val, const Alloc& al); <B><A HREF="#deque::deque">deque</A></B>(const deque& right); template<class InIt> <B><A HREF="#deque::deque">deque</A></B>(InIt first, InIt last); template<class InIt> <B><A HREF="#deque::deque">deque</A></B>(InIt first, InIt last, const Alloc& al); iterator <B><A HREF="#deque::begin">begin</A></B>(); const_iterator <B><A HREF="#deque::begin">begin</A></B>() const; iterator <B><A HREF="#deque::end">end</A></B>(); const_iterator <B><A HREF="#deque::end">end</A></B>() const; reverse_iterator <B><A HREF="#deque::rbegin">rbegin</A></B>(); const_reverse_iterator <B><A HREF="#deque::rbegin">rbegin</A></B>() const; reverse_iterator <B><A HREF="#deque::rend">rend</A></B>(); const_reverse_iterator <B><A HREF="#deque::rend">rend</A></B>() const; void <B><A HREF="#deque::resize">resize</A></B>(size_type newsize); void <B><A HREF="#deque::resize">resize</A></B>(size_type newsize, Ty val); size_type <B><A HREF="#deque::size">size</A></B>() const; size_type <B><A HREF="#deque::max_size">max_size</A></B>() const; bool <B><A HREF="#deque::empty">empty</A></B>() const; Alloc <B><A HREF="#deque::get_allocator">get_allocator</A></B>() const; reference <B><A HREF="#deque::at">at</A></B>(size_type pos); const_reference <B><A HREF="#deque::at">at</A></B>(size_type pos) const; reference <B><A HREF="#deque::operator[]">operator[]</A></B>(size_type pos); const_reference <B><A HREF="#deque::operator[]">operator[]</A></B>(size_type pos); reference <B><A HREF="#deque::front">front</A></B>(); const_reference <B><A HREF="#deque::front">front</A></B>() const; reference <B><A HREF="#deque::back">back</A></B>(); const_reference <B><A HREF="#deque::back">back</A></B>() const; void <B><A HREF="#deque::push_front">push_front</A></B>(const Ty& val); void <B><A HREF="#deque::pop_front">pop_front</A></B>(); void <B><A HREF="#deque::push_back">push_back</A></B>(const Ty& val); void <B><A HREF="#deque::pop_back">pop_back</A></B>(); template<class InIt> void <B><A HREF="#deque::assign">assign</A></B>(InIt first, InIt last); void <B><A HREF="#deque::assign">assign</A></B>(size_type count, const Ty& val); iterator <B><A HREF="#deque::insert">insert</A></B>(iterator where, const Ty& val); void <B><A HREF="#deque::insert">insert</A></B>(iterator where, size_type count, const Ty& val); template<class InIt> void <B><A HREF="#deque::insert">insert</A></B>(iterator where, InIt first, InIt last); iterator <B><A HREF="#deque::erase">erase</A></B>(iterator where); iterator <B><A HREF="#deque::erase">erase</A></B>(iterator first, iterator last); void <B><A HREF="#deque::clear">clear</A></B>(); void <B><A HREF="#deque::swap">swap</A></B>(deque& right); };</PRE><P>The template class describes an object that controls avarying-length sequence of elements of type <CODE>Ty</CODE>.The sequence is represented in a way that permits insertionand removal of an element at either end with a single element copy(constant time).Such operations in the middle of the sequence require elementcopies and assignments proportional to the number of elementsin the sequence (linear time).</P><P>The object allocates and frees storage for the sequence it controlsthrough a stored <A HREF="memory.html#allocator object">allocator object</A>of class <CODE>Alloc</CODE>. Such an allocator object must havethe same external interface as an object of template class<A HREF="memory.html#allocator"><CODE>allocator</CODE></A>.Note that the stored allocator object is <I>not</I> copied when the containerobject is assigned.</P><P><B><A NAME="deque reallocation">Deque reallocation</A></B>occurs when a member function must insert or erase elements ofthe controlled sequence:</P><UL><LI>If an element is inserted into an empty sequence,or if an element is erased to leave an empty sequence, theniterators earlier returned by<CODE><A HREF="#deque::begin">begin</A>()</CODE> and<CODE><A HREF="#deque::end">end</A>()</CODE> become<B><A NAME="invalid deque iterators">invalid</A></B>.</LI><LI>If an element is inserted at <CODE>begin()</CODE> or at<CODE><A HREF="#deque::end">end</A>()</CODE>,then all iterators become invalid, but no referencesthat designate existing elements become invalid.</LI><LI>If an element is erased at <CODE>begin()</CODE> or at<CODE><A HREF="#deque::end">end</A>()</CODE>,then only iterators and references that designate the erased elementbecome invalid.</LI><LI>Otherwise, inserting or erasing an element invalidatesall iterators and references.</LI></UL><H3><CODE><A NAME="deque::allocator_type">deque::allocator_type</A></CODE></H3><PRE>typedef Alloc <B>allocator_type</B>;</PRE><P>The type is a synonym for the template parameter <CODE>Alloc</CODE>.</P><H3><CODE><A NAME="deque::assign">deque::assign</A></CODE></H3><PRE>template<class InIt> void <B>assign</B>(InIt first, InIt last);void <B>assign</B>(size_type count, const Ty& val);</PRE><P>If <CODE>InIt</CODE> is an integer type, the first memberfunction behaves the same as <CODE>assign((size_type)first, (Ty)last)</CODE>.Otherwise, thefirst member function replaces the sequencecontrolled by <CODE>*this</CODE> with the sequence<CODE>[first, last)</CODE>, which must <I>not</I> overlapthe initial controlled sequence.The second member function replaces the sequencecontrolled by <CODE>*this</CODE> with a repetition of <CODE>count</CODE>elements of value <CODE>val</CODE>.</P><H3><CODE><A NAME="deque::at">deque::at</A></CODE></H3><PRE>const_reference <B>at</B>(size_type pos) const;reference <B>at</B>(size_type pos);</PRE><P>The member function returns a reference to the element of thecontrolled sequence at position <CODE>pos</CODE>. If that position isinvalid, the function throws an object of class<CODE>out_of_range</CODE>.</P><H3><CODE><A NAME="deque::back">deque::back</A></CODE></H3><PRE>reference <B>back</B>();const_reference <B>back</B>() const;</PRE><P>The member function returns a reference to the last element of thecontrolled sequence, which must be non-empty.</P><H3><CODE><A NAME="deque::begin">deque::begin</A></CODE></H3><PRE>const_iterator <B>begin</B>() const;iterator <B>begin</B>();</PRE><P>The member function returns a random-access iterator that points atthe first element of the sequence (or just beyond the end of an emptysequence).</P><H3><CODE><A NAME="deque::clear">deque::clear</A></CODE></H3><PRE>void <B>clear</B>();</PRE><P>The member function calls<CODE><A HREF="#deque::erase">erase</A>(<A HREF="#deque::begin">begin</A>(),<A HREF="#deque::end">end</A>())</CODE>.</P><H3><CODE><A NAME="deque::const_iterator">deque::const_iterator</A></CODE></H3><PRE>typedef T1 <B>const_iterator</B>;</PRE><P>The type describes an object that can serve as a constantrandom-access iterator for the controlled sequence.It is described here as asynonym for the implementation-defined type <CODE>T1</CODE>.</P><H3><CODE><A NAME="deque::const_pointer">deque::const_pointer</A></CODE></H3><PRE>typedef typename Alloc::const_pointer <B>const_pointer</B>;</PRE><P>The type describes an object that can serve as a constant pointerto an element of the controlled sequence.</P><H3><CODE><A NAME="deque::const_reference">deque::const_reference</A></CODE></H3><PRE>typedef typename Alloc::const_reference <B>const_reference</B>;</PRE><P>The type describes an object that can serve as a constant referenceto an element of the controlled sequence.</P><H3><CODE><A NAME="deque::const_reverse_iterator">deque::const_reverse_iterator</A></CODE></H3><PRE>typedef reverse_iterator<const_iterator> <B>const_reverse_iterator</B>;</PRE><P>The type describes an object that can serve as a constant reverserandom-access iterator for the controlled sequence.</P><H3><CODE><A NAME="deque::deque">deque::deque</A></CODE></H3><PRE><B>deque</B>();explicit <B>deque</B>(const Alloc& al);explicit <B>deque</B>(size_type count);<B>deque</B>(size_type count, const Ty& val);<B>deque</B>(size_type count, const Ty& val, const Alloc& al);<B>deque</B>(const deque& right);template<class InIt> <B>deque</B>(InIt first, InIt last);template<class InIt> <B>deque</B>(InIt first, InIt last, const Alloc& al);</PRE><P>All constructors store an<A HREF="memory.html#allocator object">allocator object</A> andinitialize the controlled sequence. The allocator object is the argument<CODE>al</CODE>, if present. For the copy constructor, it is<CODE>right.<A HREF="#deque::get_allocator">get_allocator</A>()</CODE>.Otherwise, it is <CODE>Alloc()</CODE>.</P><P>The first two constructors specify anempty initial controlled sequence. The third constructor specifiesa repetition of <CODE>count</CODE> elements of value <CODE>Ty()</CODE>.The fourth and fifth constructors specifya repetition of <CODE>count</CODE> elements of value <CODE>val</CODE>.The sixth constructor specifies a copy of the sequence controlled by<CODE>right</CODE>.If <CODE>InIt</CODE> is an integer type, the last two constructorsspecify a repetition of <CODE>(size_type)first</CODE> elements of value<CODE>(Ty)last</CODE>. Otherwise, thelast two constructors specify the sequence<CODE>[first, last)</CODE>.</P><H3><CODE><A NAME="deque::difference_type">deque::difference_type</A></CODE></H3><PRE>typedef T3 <B>difference_type</B>;</PRE><P>The signed integer type describes an object that can represent thedifference between the addresses of any two elements in the controlledsequence. It is described here as asynonym for the implementation-defined type <CODE>T3</CODE>.</P><H3><CODE><A NAME="deque::empty">deque::empty</A></CODE></H3><PRE>bool <B>empty</B>() const;</PRE><P>The member function returns true for an empty controlled sequence.</P><H3><CODE><A NAME="deque::end">deque::end</A></CODE></H3>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -