Rogue Wave banner
Previous fileTop of documentContentsIndexNext file

swap_ranges


Algorithm

Summary

Exchanges a range of values in one location with those in another.

Data Type and Member Function Indexes
(exclusive of constructors and destructors)

None

Synopsis

#include <algorithm>
template <class ForwardIterator1, class ForwardIterator2>
  ForwardIterator2 
    swap_ranges (ForwardIterator1 first1,
                 ForwardIterator1 last1,
                 ForwardIterator2 first2);

Description

The swap_ranges algorithm exchanges corresponding values in two ranges, in the following manner:

For each non-negative integer n < (last - first), the function exchanges *(first1 + n) with *(first2 + n)). After completing all exchanges, swap_ranges returns an iterator that points to the end of the second container (in other words, first2 + (last1 -first1)). The result of swap_ranges is undefined if the two ranges [first, last) and [first2, first2 + (last1 - first1)) overlap.

Example

Program Output

Warnings

If your compiler does not support default template parameters, you always need to supply the Allocator template argument. For instance, you need to write:

vector<int, allocator<int> >

instead of:

vector<int>

If your compiler does not support namespaces, then you do not need the using declaration for std.

See Also

iter_swap, swap



Previous fileTop of documentContentsIndexNext file
©Copyright 1998, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.
OEM Release, June 1998