C++.


copy_backward()


template < class BidirectionalIterator1,

class BidirectionalIterator2 >

BidirectionalIterator2

copy_backward( BidirectionalIterator1 first,

BidirectionalIterator1 last1,

BidirectionalIterator2 last2 )

copy_backward()

, copy(), : last1-1 first. , , last2-1, last1-first .

, {0,1,2,3,4,5}, (3,4,5) (0,1,2), first

0, last1 3, last2  5. 5 2, 4  1, 3  0. {3,4,5,3,4,5}.

#include <algorithm>

#include <vector>

#include <iterator>

#include <iostream.h>

 

class print_elements {

public:

void operator()( string elem ) {

cout << elem

<< ( _line_cnt++%8 ? " " : "\n\t" );

}

static void reset_line_cnt() { _line_cnt = 1; }

 

private:

static int _line_cnt;

};

 

int print_elements::_line_cnt = 1;

 

/* :

:

The light untonsured hair grained and hued like

pale oak

 

copy_backward( begin+1, end-3, end ):

The light untonsured hair light untonsured hair grained

and hued

*/

 

int main()

{

string sa[] = {

"The", "light", "untonsured", "hair",

"grained", "and", "hued", "like", "pale", "oak" };

 

vector< string, allocator > svec( sa, sa+10 );

 

cout << " :\n\t";

for_each( svec.begin(), svec.end(), print_elements() );

cout << "\n\n";

 

copy_backward( svec.begin()+1, svec.end()-3, svec.end() );

 

print_elements::reset_line_cnt();

 

cout << " copy_backward( begin+1, end-3, end ):\n";

for_each( svec.begin(), svec.end(), print_elements() );

cout << "\n";

}