📄 reverseiterator.html
字号:
<HTML><!-- -- Copyright (c) 1996-1999 -- Silicon Graphics Computer Systems, Inc. -- -- Permission to use, copy, modify, distribute and sell this software -- and its documentation for any purpose is hereby granted without fee, -- provided that the above copyright notice appears in all copies and -- that both that copyright notice and this permission notice appear -- in supporting documentation. Silicon Graphics makes no -- representations about the suitability of this software for any -- purpose. It is provided "as is" without express or implied warranty. -- -- Copyright (c) 1994 -- Hewlett-Packard Company -- -- Permission to use, copy, modify, distribute and sell this software -- and its documentation for any purpose is hereby granted without fee, -- provided that the above copyright notice appears in all copies and -- that both that copyright notice and this permission notice appear -- in supporting documentation. Hewlett-Packard Company makes no -- representations about the suitability of this software for any -- purpose. It is provided "as is" without express or implied warranty. -- --><Head><Title>reverse_iterator<RandomAccessIterator, T, Reference, Distance></Title><!-- Generated by htmldoc --></HEAD><BODY TEXT="#000000" LINK="#006600" ALINK="#003300" VLINK="#7C7F87" BGCOLOR="#FFFFFF"><A HREF="/"><IMG SRC="/images/common/sgilogo_small.gif" ALT="SGI Logo" WIDTH="80" HEIGHT="72" BORDER="0"></A><P><!--end header--><BR Clear><H1>reverse_iterator<RandomAccessIterator, T, Reference, Distance></H1><Table CellPadding=0 CellSpacing=0 width=100%><TR><TD Align=left><Img src = "iterators.gif" Alt="" WIDTH = "194" HEIGHT = "38" ></TD><TD Align=right><Img src = "type.gif" Alt="" WIDTH = "194" HEIGHT = "38" ></TD></TR><TR><TD Align=left><Img src = "adaptors.gif" Alt="" WIDTH = "194" HEIGHT = "38" ></TD><TD Align=right></TD></TR><TR><TD Align=left VAlign=top><b>Categories</b>: iterators, adaptors</TD><TD Align=right VAlign=top><b>Component type</b>: type</TD></TR></Table><h3>Description</h3><tt>Reverse_iterator</tt> is an iterator adaptor that enables backwards traversalof a range. <tt>Operator++</tt> applied to an object of class <tt>reverse_iterator<<A href="RandomAccessIterator.html">RandomAccessIterator</A>></tt> means the same thing as<tt>operator--</tt> applied to an object of class <tt><A href="RandomAccessIterator.html">RandomAccessIterator</A></tt>.There are two different reverse iterator adaptors: the class<tt>reverse_iterator</tt> has a template argument that is a<A href="RandomAccessIterator.html">Random Access Iterator</A>, and the class <tt><A href="ReverseBidirectionalIterator.html">reverse_bidirectional_iterator</A></tt>has a template argument that is a <A href="BidirectionalIterator.html">Bidirectional Iterator</A>. <A href="#1">[1]</A><h3>Example</h3><pre>template <class T>void forw(const <A href="Vector.html">vector</A><T>& V){ vector<T>::iterator first = V.begin(); vector<T>::iterator last = V.end(); while (first != last) cout << *first++ << endl;} template <class T>void rev(const <A href="Vector.html">vector</A><T>& V){ typedef reverse_iterator<vector<T>::iterator, T, vector<T>::reference_type, vector<T>::difference_type> reverse_iterator; <A href="#2">[2]</A> reverse_iterator rfirst(V.end()); reverse_iterator rlast(V.begin()); while (rfirst != rlast) cout << *rfirst++ << endl;} </pre><P>In the function <tt>forw</tt>, the elements are printed in the order<tt>*first</tt>, <tt>*(first+1)</tt>, ..., <tt>*(last-1)</tt>. In the function <tt>rev</tt>, they are printed in the order <tt>*(last - 1)</tt>, <tt>*(last-2)</tt>, ...,<tt>*first</tt>. <A href="#3">[3]</A><h3>Definition</h3>Defined in the standard header <A href="iterator">iterator</A>, and in the nonstandardbackward-compatibility header <A href="iterator.h">iterator.h</A>.<h3>Template parameters</h3><Table border><TR><TH>Parameter</TH><TH>Description</TH><TH>Default</TH></TR><TR><TD VAlign=top><tt>RandomAccessIterator</tt></TD><TD VAlign=top>The base iterator class. Incrementing an object of class <tt>reverse_iterator<Iterator></tt> corresponds to decrementing an object of class <tt>Iterator</tt>.</TD><TD VAlign=top> </TD></TR><TR><TD VAlign=top><tt>T</tt></TD><TD VAlign=top>The reverse iterator's value type. This should always be the same as the base iterator's value type.</TD><TD VAlign=top> </TD></TR><TR><TD VAlign=top><tt>Reference</tt></TD><TD VAlign=top>The reverse iterator's reference type. This should always be the same as the base iterator's reference type.</TD><TD VAlign=top><tt>T&</tt></TD></TR><TR><TD VAlign=top><tt>Distance</tt></TD><TD VAlign=top>The reverse iterator's distance type. This should always be the same as the base iterator's distance type.</TD><TD VAlign=top><tt>ptrdiff_t</tt></TD></tr></table><h3>Model of</h3><A href="RandomAccessIterator.html">Random Access Iterator</A><h3>Type requirements</h3>The base iterator type (that is, the template parameter <tt>RandomAccessIterator</tt>)must be a <tt><A href="RandomAccessIterator.html">Random Access Iterator</A></tt>.The <tt>reverse_iterator</tt>'s value type, reference type, and distance type (that is, the template parameters<tt>T</tt>, <tt>Reference</tt>, and <tt>Distance</tt>, respectively) must be the same as thebase iterator's value type, reference type, and distance type.<h3>Public base classes</h3>None.<h3>Members</h3><Table border><TR><TH>Member</TH><TH>Where defined</TH><TH>Description</TH></TR><TR><TD VAlign=top><tt>self</tt></TD><TD VAlign=top><tt>reverse_iterator</tt></TD><TD VAlign=top>See below</TD></TR><TR><TD VAlign=top><tt>reverse_iterator()</tt></TD><TD VAlign=top> <A href="trivial.html">Trivial Iterator</A></TD><TD VAlign=top>The default constructor</TD></TR><TR><TD VAlign=top><tt>reverse_iterator(const reverse_iterator& x)</tt></TD><TD VAlign=top> <A href="trivial.html">Trivial Iterator</A></TD><TD VAlign=top>The copy constructor</TD></TR><TR><TD VAlign=top><tt>reverse_iterator& operator=(const reverse_iterator& x)</tt></TD><TD VAlign=top> <A href="trivial.html">Trivial Iterator</A></TD><TD VAlign=top>The assignment operator</TD></TR><TR><TD VAlign=top><tt>reverse_iterator(RandomAccessIterator x)</tt></TD><TD VAlign=top><tt>reverse_iterator</tt></TD><TD VAlign=top>See below.</TD></TR><TR><TD VAlign=top><tt>RandomAccessIterator base()</tt></TD><TD VAlign=top><tt>reverse_iterator</tt></TD><TD VAlign=top>See below.</TD></TR><TR><TD VAlign=top><tt>Reference operator*() const</tt></TD><TD VAlign=top> <A href="trivial.html">Trivial Iterator</A></TD><TD VAlign=top>The dereference operator</TD></TR><TR><TD VAlign=top><tt>reverse_iterator& operator++()</tt></TD><TD VAlign=top> <A href="ForwardIterator.html">Forward Iterator</A></TD><TD VAlign=top>Preincrement</TD></TR><TR><TD VAlign=top><tt>reverse_iterator operator++(int)</tt></TD><TD VAlign=top> <A href="ForwardIterator.html">Forward Iterator</A></TD><TD VAlign=top>Postincrement</TD></TR><TR><TD VAlign=top>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -