.\" ident @(#)reverse_copy.3 .\" Standard Template Library .\" $$RW_INSERT_HEADER "slyrs.man" .TH reverse_copy 3C++ "02 Apr 1998" "Rogue Wave Software" "-" .ce2 Standard C++ Library Copyright 1998, Rogue Wave Software, Inc. .SH NAME \f2reverse_copy\fP \ - Reverses the order of elements in a collection while copying them to a new collection. .SH SYNOPSIS .RE .RS 0 #include .br template .br OutputIterator reverse_copy (BidirectionalIterator first, .RE .RS 28 BidirectionalIterator last, .br OutputIterator result); .SH DESCRIPTION The reverse_copy algorithm copies the range \f2[first, last)\fP to the range \f2[result, result + (last - first))\fP such that for any non- negative integer\f2 i < (last - first)\fP, the following assignment takes place: \f2*(result + (last - first) -i) = *(first + i)\fP reverse_copy returns\f2 result + (last - first)\fP. The ranges \f2[first, last)\fP and \f2[result, result + (last - first))\fP must not overlap. .SH COMPLEXITY reverse_copy performs exactly \f2(last - first)\fP assignments. .SH EXAMPLE .RE .RS 0 // .br // reverse.cpp .br // .RE .RS 1 #include .br #include .br #include .RE .RS 0 using namespace std; .br .br int main () .RE .RS 1 { .RE .RS 3 // .br // Initialize a vector with an array of integers. .br // .RE .RS 2 int arr[10] = { 1,2,3,4,5,6,7,8,9,10 }; .br vector v(arr+0, arr+10); .RE .RS 3 // .br // Print out elements in original (sorted) order. .br // .RE .RS 2 cout << "Elements before reverse: " << endl << " "; .br copy(v.begin(), v.end(), .RE .RS 7 ostream_iterator(cout," ")); .RE .RS 2 cout << endl << endl; .RE .RS 3 // .br // Reverse the ordering. .br // .RE .RS 2 reverse(v.begin(), v.end()); .RE .RS 3 // .br // Print out the reversed elements. .br // .RE .RS 2 cout << "Elements after reverse: " << endl << " "; .br copy(v.begin(), v.end(), .RE .RS 7 ostream_iterator(cout," ")); .RE .RS 2 cout << endl << endl; .RE .RS 0 .RE .RS 2 cout << "A reverse_copy to cout: " << endl << " "; .RE .RS 3 reverse_copy(v.begin(), v.end(),
ostream_iterator(cout, " ")); .RE .RS 2 cout << endl; .RE .RS 0 .RE .RS 2 return 0; .RE .RS 1 } .br .RE .RS 0 Program Output .RE .RS 0 .br Elements before reverse: .RE .RS 4 1 2 3 4 5 6 7 8 9 10 .RE .RS 0 Elements after reverse: .RE .RS 4 10 9 8 7 6 5 4 3 2 1 .RE .RS 0 A reverse_copy to cout: .RE .RS 4 1 2 3 4 5 6 7 8 9 10 .SH WARNINGS If your compiler does not support default template parameters, then you always need to supply the \f2Allocator\fP template argument. For instance, you need to write: \f2vector >\fP instead of: \f2vector\fP If your compiler does not support namespaces, then you do not need the using declaration for \f2std\fP. .SH SEE ALSO reverse