⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 deq_4164.htm

📁 ARM编辑、编译软件
💻 HTM
📖 第 1 页 / 共 2 页
字号:
void
<B>assign</B> (InputIterator first, InputIterator last);</PRE>
<UL><P>Erases all elements contained in self, then inserts new elements from the range <SAMP>[first, last)</SAMP>.</P>
</UL>
<PRE>template &#60;class Size, class T>
void 
<B>assign</B> (Size n);</PRE>
<UL><P>Erases all elements contained in self, then inserts <SAMP>n</SAMP> instances of the default value of type <SAMP>T</SAMP>.</P>
</UL>
<PRE>template &#60;class Size, class T>
void 
<B>assign</B> (Size n, const T&#38; t);</PRE>
<UL><P>Erases all elements contained in self, then inserts <SAMP>n</SAMP> instances of the value of <SAMP>t.</SAMP></P>
</UL>
<PRE>reference 
<B>at</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<SAMP> size() - 1</SAMP>.</P>
</UL>
<PRE>const_reference 
<B>at </B>(size_type) 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>
<PRE>reference 
<B>back</B> ();</PRE>
<UL><P>Returns a <SAMP>reference</SAMP> to the last element.</P>
</UL>
<PRE>const_reference 
<B>back</B> () const;</PRE>
<UL><P>Returns a constant reference to the last element.</P>
</UL>
<PRE>void
<B>clear</B> ();</PRE>
<UL><P>Erases all elements from the self.</P>
</UL>
<PRE>bool 
<B>empty</B> () const;</PRE>
<UL><P>Returns <SAMP>true</SAMP> if the size of self is zero.</P>
</UL>
<PRE>reference 
<B>front</B> ();</PRE>
<UL><P>Returns a <SAMP>reference</SAMP> to the first element.</P>
</UL>
<PRE>const_reference 
<B>front</B> () const;</PRE>
<UL><P>Returns a constant reference to the first element.</P>
</UL>
<PRE>iterator
<B>erase</B> (iterator first, iterator last);</PRE>
<UL><P>Deletes the elements in the range (<SAMP>first, last</SAMP>). Returns an <SAMP>iterator</SAMP> pointing to the element following the last deleted element, or <SAMP>end()</SAMP> if there were no elements after the deleted range.</P>
</UL>
<PRE>iterator
<B>erase</B> (iterator position);</PRE>
<UL><P>Removes the element pointed to by <SAMP>position</SAMP>. Returns an <SAMP>iterator</SAMP> pointing to the element following the deleted element, or <SAMP>end()</SAMP> if there were no elements after the deleted range.</P>
</UL>
<PRE>iterator 
<B>insert</B> (iterator position);</PRE>
<UL><P>Inserts a copy of the default value of type <SAMP>T</SAMP> before <SAMP>position</SAMP>.  The return value points to the inserted element.  Requires that type <SAMP>T</SAMP> have a default constructor.</P>
</UL>
<PRE>iterator 
<B>insert</B> (iterator position, const T&#38; x);</PRE>
<UL><P>Inserts <SAMP>x</SAMP> before <SAMP>position</SAMP>.  The return value points to the inserted <SAMP>x</SAMP>.</P>
</UL>
<PRE>void 
<B>insert</B> (iterator position, size_type n, const T&#38; x);</PRE>
<UL><P>Inserts <SAMP>n</SAMP> copies of <SAMP>x </SAMP>before <SAMP>position</SAMP>.</P>
</UL>
<PRE>template &#60;class InputIterator>
void 
<B>insert</B> (iterator position, InputIterator first,
        InputIterator last);</PRE>
<UL><P>Inserts copies of the elements in the range <SAMP>(first, last]</SAMP> before <SAMP>position</SAMP>.</P>
</UL>
<PRE>size_type 
<B>max_size </B>() const;</PRE>
<UL><P>    Returns <SAMP>size()</SAMP> of the largest possible deque.</P>
</UL>
<PRE>void 
<B>pop_back</B> ();</PRE>
<UL><P>Removes the last element.  Note that this function does not return the element.</P>
</UL>
<PRE>void 
<B>pop_front </B>();</PRE>
<UL><P>Removes the first element.  Note that this function does not return the element</P>
</UL>
<PRE>void
<B>push_back </B>(const T&#38; x);</PRE>
<UL><P>Appends a copy of <SAMP>x</SAMP> to the end.</P>
</UL>
<PRE>void 
<B>push_front </B>(const T&#38; x);</PRE>
<UL><P>Inserts a copy of <SAMP>x</SAMP> at the front.</P>
</UL>
<PRE>void 
<B>resize</B> (size_type sz);</PRE>
<UL><P>Alters the size of self.  If the new size (<SAMP>sz</SAMP>) is greater than the current size then <SAMP>sz-size()</SAMP> copies of the default value of type <SAMP>T</SAMP> are inserted at the end of the deque. If the new size is smaller than the current capacity, then the deque is truncated by erasing <SAMP>size()-sz</SAMP> elements off the end. Otherwise, no action is taken. Requires that type <SAMP>T</SAMP> have a default constructor.</P>
</UL>
<PRE>void 
<B>resize</B> (size_type sz, T c);</PRE>
<UL><P>Alters the size of self.  If the new size (<SAMP>sz</SAMP>) is greater than the current size then <SAMP>sz-size()</SAMP> <SAMP>c</SAMP>'s are  inserted at the end of the deque. If the new size is smaller than the current capacity, then the deque is truncated by erasing <SAMP>size()-sz</SAMP> elements off the end. Otherwise, no action is taken.</P>
</UL>
<PRE>size_type 
<B>size</B> () const;</PRE>
<UL><P>Returns the number of elements.</P>
</UL>
<PRE>void 
<B>swap</B> (deque&#60;T,Allocator>&#38; x);</PRE>
<UL><P>Exchanges self with <SAMP>x</SAMP>.</P>
</UL>
<A NAME="Non-member Functions"><H3>Non-member Functions</H3></A>
<PRE>template &#60;class T, class Allocator>
bool <B>operator== </B>(const deque&#60;T, Allocator>&#38; x,
                 const deque&#60;T, Allocator>&#38; y);</PRE>
<UL><P>Equality operator. Returns <SAMP>true</SAMP> if <SAMP>x</SAMP> is the same as <SAMP>y</SAMP>.</P>
</UL>
<PRE>template &#60;class T, class Allocator>
bool <B>operator&#60; </B>(const deque&#60;T, Allocator>&#38; x,
                const deque&#60;T, Allocator>&#38; y);</PRE>
<UL><P>Returns <SAMP>true</SAMP> if the elements contained in <SAMP>x</SAMP> are lexicographically less than the elements contained in <SAMP>y</SAMP>.</P>
</UL>
<PRE>template &#60;class T, class Allocator>
void <B>swap </B>(deque&#60;T, Allocator>&#38; a, deque&#60;T, Allocator>&#38; b);</PRE>
<UL><P>Efficiently swaps the contents of <SAMP>a</SAMP> and <SAMP>b</SAMP>.</P>
</UL>
<A NAME="Example"><H3>Example</H3></A>
<PRE>//
// deque.cpp
//
 #include &#60;deque>
 #include &#60;string>
 deque&#60;string, allocator> deck_of_cards; 
 deque&#60;string, allocator> current_hand;
 void initialize_cards(deque&#60;string, allocator>&#38; cards) {
   cards.push_front("aceofspades");
   cards.push_front("kingofspades");
   cards.push_front("queenofspades");
   cards.push_front("jackofspades");
   cards.push_front("tenofspades");
   // etc.
 }
 template &#60;class It, class It2> 
 void print_current_hand(It start, It2 end) 
 {
   while (start &#60; end) 
   cout &#60;&#60; *start++ &#60;&#60; endl;
 }
 template &#60;class It, class It2>
 void deal_cards(It, It2 end) {
   for (int i=0;i&#60;5;i++) {
     current_hand.insert(current_hand.begin(),*end);
     deck_of_cards.erase(end++);
   }
 }
 void play_poker() {
   initialize_cards(deck_of_cards);
   deal_cards(current_hand.begin(),deck_of_cards.begin()); 
 }
 int main() 
 {
   play_poker();
   print_current_hand(current_hand.begin(),current_hand.end());
   return 0;
 }
Output :
aceofspades
kingofspades
queenofspades
jackofspades
tenofspades</PRE>
<A NAME="Warnings"><H3>Warnings</H3></A>
<P>Member function templates are used in all containers provided by the Standard Template Library.  An example of this is the constructor for <B><I>deque&#60;T, Allocator></B></I> that takes two templated iterators: </P>
<PRE>template &#60;class InputIterator>
 deque (InputIterator, InputIterator);</PRE>

<P><B><I>deque</B></I> 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 we provide substitute functions that 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. </P>
<P>For example, if your compiler does not support member function templates you can construct a <B><I>deque</B></I> in the following two ways: </P>
<PRE>int intarray[10];
deque&#60;int, allocator> first_deque(intarray, intarray + 10);
deque&#60;int, allocator> second_deque(first_deque.begin(),  
                                   first_deque.end());</PRE>

<P>But not this way:</P>
<PRE>deque&#60;long, allocator> long_deque(first_deque.begin(),
                                  first_deque.end());
</PRE>
<P>since the<SAMP> long_deque</SAMP> and <SAMP>first_deque</SAMP> are not the same type.</P>
<P>Additionally, many compilers do not support default template arguments.  If your compiler is one of these, you need to always supply the <SAMP>Allocator</SAMP> template argument.  For instance, you'll have to write:</P>
<PRE>
deque&#60;int, allocator>
</PRE>
<UL><P>instead of:</P>
</UL>
<PRE>deque&#60;int>
</PRE>
<UL>
</UL>
<HR>
<A HREF="cou_2233.htm"><IMG SRC="images/prev.gif"></A> <A HREF="ref.htm#contents"><IMG SRC="images/toc.gif"></A> <A HREF="dis_0186.htm"><IMG SRC="images/next.gif"></A></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -