copy_backward man page on OpenIndiana

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

copy(3C++)			       -			    copy(3C++)

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

NAME
       copy, copy_backward

	- Copies a range of elements.

SYNOPSIS
       #include <algorithm>
       template <class InputIterator, class OutputIterator>
       OutputIterator copy(InputIterator first,
		    InputIterator last,
		    OutputIterator result);
template <;class BidirectionalIterator1,
	 class BidirectionalIterator2>
BidirectionalIterator2
 copy_backward(BidirectionalIterator1 first,
	       BidirectionalIterator1 last,
	       BidirectionalIterator2 result);

DESCRIPTION
       The  copy  algorithm  copies values from the range specified by [first,
       last) to the range specified by [result, result + (last - first)). copy
       can  be	used  to copy values from one container to another, or to copy
       values from one location in a container to another location in the same
       container, as long as result is not within the range [first-last). copy
       returns result + (last - first). For  each  non-negative	 integer  n  <
       (last  - first), copy assigns *(first + n) to *(result + n). The result
       of copy is undefined if result is in the range [first, last).

       Unless result is an insert iterator, copy assumes that at least as many
       elements follow result as are in the range [first, last).

       The  copy_backward  algorithm copies elements in the range specified by
       [first, last) into the range specified by [result  -  (last  -  first),
       result), starting from the end of the sequence (last-1) and progressing
       to the front (first). Note that	copy_backward  does  not  reverse  the
       order  of  the  elements,  it  simply  reverses	the order of transfer.
       copy_backward  returns  result  -  (last	 -  first).  You  should   use
       copy_backward instead of copy when last is in the range [result - (last
       - first), result). For each positive  integer  n	 <=  (last  -  first),
       copy_backward  assigns  *(last  -  n)  to  *(result - n). The result of
       copy_backward is undefined if result is in the range [first, last).

       Unless result is an insert iterator, copy_backward assumes  that	 there
       are  at	least  as  many	 elements  ahead of result as are in the range
       [first, last).

COMPLEXITY
       Both copy_and copy_backward perform exactly last - first assignments.

EXAMPLE
   //
   // stdlib/examples/manual/copyex.cpp
   //
 #include <algorithm>
 #include <vector>
 #include <iostream>
using namespace std;

int main()
 {
  int d1[4] = {1,2,3,4};
  int d2[4] = {5,6,7,8};

   // Set up three vectors
   //
  vector<int> v1(d1,d1 + 4), v2(d2,d2 + 4), v3(d2,d2 + 4);
   //
   // Set up one empty vector
   //
  vector<int> v4;
   //
   // Copy v1 to v2
   //
  copy(v1.begin(),v1.end(),v2.begin());
   //
   // Copy backwards v1 to v3
   //
  copy_backward(v1.begin(),v1.end(),v3.end());
   //
   // Use insert iterator to copy into empty vector
   //
  copy(v1.begin(),v1.end(),back_inserter(v4));
   //
   // Copy all four to cout
   //
  ostream_iterator<int,char> out(cout," ");
  copy(v1.begin(),v1.end(),out);
  cout << endl;
  copy(v2.begin(),v2.end(),out);
  cout << endl;
  copy(v3.begin(),v3.end(),out);
  cout << endl;
  copy(v4.begin(),v4.end(),out);
  cout << endl;

  return 0;
 }

Program Output

1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4

WARNINGS
       If your compiler does not support default template parameters, then you
       always  need  to	 supply the Allocator template argument. For instance,
       you have 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.

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

List of man pages available for OpenIndiana

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