.\" ident @(#)swap_ranges.3 .\" Standard Template Library .\" $$RW_INSERT_HEADER "slyrs.man" .TH swap_ranges 3C++ "02 Apr 1998" "Rogue Wave Software" "-" .ce2 Standard C++ Library Copyright 1998, Rogue Wave Software, Inc. .SH NAME \f2swap_ranges\fP \ - Exchanges a range of values in one location with those in another. .SH SYNOPSIS .br #include .br template .RE .RS 1 ForwardIterator2 .RE .RS 0 swap_ranges (ForwardIterator1 first1, .RE .RS 16 ForwardIterator1 last1, .br ForwardIterator2 first2); .SH DESCRIPTION The swap_ranges algorithm exchanges corresponding values in two ranges, in the following manner: For each non-negative integer \f2n < (last - first)\fP, the function exchanges \f2*(first1 + n)\fP with \f2*(first2 + n))\fP. After completing all exchanges, swap_ranges returns an iterator that points to the end of the second container (in other words, \f2first2 + (last1 -first1)\fP). The result of swap_ranges is undefined if the two ranges \f2[first, last)\fP and \f2[first2, first2 + (last1 - first1))\fP overlap. .SH EXAMPLE .RE .RS 0 // .br // swap.cpp .br // .br #include .br #include .br #include .br using namespace std; .br .br int main() .br { .br int d1[] = {6, 7, 8, 9, 10, 1, 2, 3, 4, 5}; .br // Set up a vector .br vector v(d1+0,d1 + 10); .br .br // Output original vector .br cout << "For the vector: "; .br copy(v.begin(),v.end(), .RE .RS 4 ostream_iterator(cout," ")); .RE .RS 0 .br // Swap the first five elements with the last five elements .br swap_ranges(v.begin(),v.begin()+5, v.begin()+5); .br // Output result .br cout << endl << endl .br << "Swapping the first five elements " .br << "with the last five gives: " .br << endl << " "; .br copy(v.begin(),v.end(), .RE .RS 4 ostream_iterator(cout," ")); .RE .RS 0 return 0; .br } .br .RE .RS 0 Program Output .br .br For the vector: 6 7 8 9 10 1 2 3 4 5 .br Swapping the first five elements with the last five gives: .br 1 2 3 4 5 6 7 8 9 10 .br Swapping the first and last elements gives: .br 10 2 3 4 5 6 7 8 9 1 .SH WARNINGS If your compiler does not support default template parameters, 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 iter_swap, swap