| <HTML> |
| <HEAD> |
| <TITLE>reverse_copy()</TITLE> |
| <LINK REL=StyleSheet HREF="../rw.css" TYPE="text/css" TITLE="Apache stdcxx Stylesheet"></HEAD> |
| <BODY BGCOLOR=#FFFFFF> |
| <A HREF="reverse.html"><IMG SRC="images/bprev.gif" WIDTH=20 HEIGHT=21 ALT="Previous file" BORDER=O></A><A HREF="noframes.html"><IMG SRC="images/btop.gif" WIDTH=56 HEIGHT=21 ALT="Top of Document" BORDER=O></A><A HREF="booktoc.html"><IMG SRC="images/btoc.gif" WIDTH=56 HEIGHT=21 ALT="Contents" BORDER=O></A><A HREF="tindex.html"><IMG SRC="images/bindex.gif" WIDTH=56 HEIGHT=21 ALT="Index page" BORDER=O></A><A HREF="reverse-iterator.html"><IMG SRC="images/bnext.gif" WIDTH=25 HEIGHT=21 ALT="Next file" BORDER=O></A><DIV CLASS="DOCUMENTNAME"><B>Apache C++ Standard Library Reference Guide</B></DIV> |
| <H2>reverse_copy()</H2> |
| <P><B>Library:</B> <A HREF="2-9.html">Algorithms</A></P> |
| |
| <PRE><HR><B><I>Function</I></B><HR></PRE> |
| |
| <UL> |
| <LI><A HREF="#sec1">Local Index</A></LI> |
| <LI><A HREF="#sec2">Summary</A></LI> |
| <LI><A HREF="#sec3">Synopsis</A></LI> |
| <LI><A HREF="#sec4">Description</A></LI> |
| <LI><A HREF="#sec5">Complexity</A></LI> |
| <LI><A HREF="#sec6">Example</A></LI> |
| <LI><A HREF="#sec7">See Also</A></LI> |
| <LI><A HREF="#sec8">Standards Conformance</A></LI> |
| </UL> |
| <A NAME="sec1"><H3>Local Index</H3></A> |
| No Entries |
| <A NAME="sec2"><H3>Summary</H3></A> |
| <P>An algorithm that reverses the order of elements in a sequence while copying them to a new sequence</P> |
| <A NAME="sec3"><H3>Synopsis</H3></A> |
| |
| <PRE>#include <algorithm> |
| |
| namespace std { |
| template <class BidirectionalIterator, class OutputIterator> |
| OutputIterator reverse_copy(BidirectionalIterator start, |
| BidirectionalIterator finish, |
| OutputIterator result); |
| } |
| </PRE> |
| <A NAME="sec4"><H3>Description</H3></A> |
| <P>The <SAMP>reverse_copy()</SAMP> algorithm copies the range <SAMP>[start, finish)</SAMP> to the range <SAMP>[result, result + (finish - start))</SAMP> such that for any nonnegative integer<SAMP> i < (finish - start)</SAMP>, the following assignment takes place:</P> |
| <P><SAMP>*(result + (finish - start) - i) = *(start + i)</SAMP></P> |
| <P><SAMP>reverse_copy()</SAMP> returns<SAMP> result + (finish - start)</SAMP>. The ranges <SAMP>[start, finish)</SAMP> and <SAMP>[result, result + (finish - start))</SAMP> must not overlap. </P> |
| <A NAME="sec5"><H3>Complexity</H3></A> |
| <P><SAMP>reverse_copy()</SAMP> performs exactly <SAMP>(finish - start)</SAMP> assignments.</P> |
| <A NAME="sec6"><H3>Example</H3></A> |
| |
| <UL><PRE>// |
| // reverse.cpp |
| // |
| |
| #include <algorithm> // for reverse, reverse_copy |
| #include <vector> // for vector |
| #include <iostream> // for cout, endl |
| #include <iterator> // for ostream_iterator |
| |
| |
| |
| int main () |
| { |
| typedef std::vector<int, std::allocator<int> > Vector; |
| typedef std::ostream_iterator<int, char, |
| std::char_traits<char> > |
| Iter; |
| |
| // Initialize a vector with an array of integers. |
| const Vector::value_type a[] = { 1, 2, 3, 4, 5, |
| 6, 7, 8, 9, 10 }; |
| |
| Vector v (a + 0, a + sizeof a / sizeof *a); |
| |
| // Print out elements in original (sorted) order. |
| std::cout << "Elements before reverse: \n "; |
| std::copy (v.begin (), v.end (), Iter (std::cout, " ")); |
| |
| // Reverse the ordering. |
| std::reverse (v.begin (), v.end ()); |
| |
| // Print out the reversed elements. |
| std::cout << "\n\nElements after reverse: \n "; |
| std::copy (v.begin (), v.end (), Iter (std::cout, " ")); |
| |
| std::cout << "\n\nA reverse_copy to cout: \n "; |
| std::reverse_copy (v.begin (), v.end (), |
| Iter (std::cout, " ")); |
| std::cout << std::endl; |
| |
| return 0; |
| } |
| |
| |
| Program Output: |
| </PRE></UL> |
| <UL><PRE>Elements before reverse: |
| 1 2 3 4 5 6 7 8 9 10 |
| |
| Elements after reverse: |
| 10 9 8 7 6 5 4 3 2 1 |
| |
| A reverse_copy to cout: |
| 1 2 3 4 5 6 7 8 9 10 |
| </PRE></UL> |
| <A NAME="sec7"><H3>See Also</H3></A> |
| <P><SAMP><A HREF="reverse.html">reverse()</A></SAMP></P> |
| <A NAME="sec8"><H3>Standards Conformance</H3></A> |
| <P><I>ISO/IEC 14882:1998 -- International Standard for Information Systems -- Programming Language C++, Section 25.2.9</I></P> |
| |
| <BR> |
| <HR> |
| <A HREF="reverse.html"><IMG SRC="images/bprev.gif" WIDTH=20 HEIGHT=21 ALT="Previous file" BORDER=O></A><A HREF="noframes.html"><IMG SRC="images/btop.gif" WIDTH=56 HEIGHT=21 ALT="Top of Document" BORDER=O></A><A HREF="booktoc.html"><IMG SRC="images/btoc.gif" WIDTH=56 HEIGHT=21 ALT="Contents" BORDER=O></A><A HREF="tindex.html"><IMG SRC="images/bindex.gif" WIDTH=56 HEIGHT=21 ALT="Index page" BORDER=O></A><A HREF="reverse-iterator.html"><IMG SRC="images/bnext.gif" WIDTH=20 HEIGHT=21 ALT="Next file" BORDER=O></A> |
| |
| <!-- Google Analytics tracking code --> |
| <script src="http://www.google-analytics.com/urchin.js" type="text/javascript"> |
| </script> |
| <script type="text/javascript"> |
| _uacct = "UA-1775151-1"; |
| urchinTracker(); |
| </script> |
| <!-- end of Google Analytics tracking code --> |
| |
| </BODY> |
| </HTML> |