swap_ranges man page on SunOS

Man page or keyword search:  
man Server   20652 pages
apropos Keyword Search (all sections)
Output format
SunOS logo
[printable version]

swap_ranges(3C++)		       -		     swap_ranges(3C++)

Standard C++ Library Copyright 1998, Rogue Wave Software, Inc.

NAME
       swap_ranges

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

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
//
// swap.cpp
//
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

int main()
{
int d1[] = {6, 7, 8, 9, 10, 1, 2, 3, 4, 5};
// Set up a vector
vector<;int> v(d1+0,d1 + 10);

// Output original vector
cout <;< "For the vector: ";
copy(v.begin(),v.end(),
    ostream_iterator<int,char>(cout," "));

// Swap the first five elements with the last five elements
swap_ranges(v.begin(),v.begin()+5, v.begin()+5);
// Output result
cout <;< endl << endl
<< "Swapping the first five elements "
<< "with the last five gives: "
<< endl << "	 ";
copy(v.begin(),v.end(),
    ostream_iterator<int,char>(cout," "));
return 0;
}

Program Output

For the vector: 6 7 8 9 10 1 2 3 4 5
Swapping the first five elements with the last five gives:
1 2 3 4 5 6 7 8 9 10
Swapping the first and last elements gives:
10 2 3 4 5 6 7 8 9 1

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

Rogue Wave Software		  02 Apr 1998		     swap_ranges(3C++)
[top]

List of man pages available for SunOS

Copyright (c) for man pages and the logo by the respective OS vendor.

For those who want to learn more, the polarhome community provides shell access and support.

[legal] [privacy] [GNU] [policy] [cookies] [netiquette] [sponsors] [FAQ]
Tweet
Polarhome, production since 1999.
Member of Polarhome portal.
Based on Fawad Halim's script.
....................................................................
Vote for polarhome
Free Shell Accounts :: the biggest list on the net