reverse_copy
Reverses the order of the elements within a source range while copying them into a destination range
template<class BidirectionalIterator, class OutputIterator>
OutputIterator reverse_copy(
BidirectionalIterator _First,
BidirectionalIterator _Last,
OutputIterator _Result
);
매개 변수
_First
A bidirectional iterator pointing to the position of the first element in the source range within which the elements are being permuted._Last
A bidirectional iterator pointing to the position one past the final element in the source range within which the elements are being permuted._Result
An output iterator pointing to the position of the first element in the destination range to which elements are being copied.
반환 값
An output iterator pointing to the position one past the final element in the destination range to where the altered sequence of elements is being copied.
설명
The source and destination ranges referenced must be valid; all pointers must be dereferenceable and within the sequence the last position is reachable from the first by incrementation.
reverse_copy은 두 가지 관련된 폼이 있습니다.
이러한 기능이 동작하는 방식에 대한 자세한 내용은 Checked Iterators을 참조하십시오.
예제
// alg_reverse_copy.cpp
// compile with: /EHsc
#include <vector>
#include <algorithm>
#include <iostream>
int main( ) {
using namespace std;
vector <int> v1, v2( 10 );
vector <int>::iterator Iter1, Iter2;
int i;
for ( i = 0 ; i <= 9 ; i++ )
{
v1.push_back( i );
}
cout << "The original vector v1 is:\n ( " ;
for ( Iter1 = v1.begin( ) ; Iter1 != v1.end( ) ; Iter1++ )
cout << *Iter1 << " ";
cout << ")." << endl;
// Reverse the elements in the vector
reverse_copy (v1.begin( ), v1.end( ), v2.begin( ) );
cout << "The copy v2 of the reversed vector v1 is:\n ( " ;
for ( Iter2 = v2.begin( ) ; Iter2 != v2.end( ) ; Iter2++ )
cout << *Iter2 << " ";
cout << ")." << endl;
cout << "The original vector v1 remains unmodified as:\n ( " ;
for ( Iter1 = v1.begin( ) ; Iter1 != v1.end( ) ; Iter1++ )
cout << *Iter1 << " ";
cout << ")." << endl;
}
Output
The original vector v1 is:
( 0 1 2 3 4 5 6 7 8 9 ).
The copy v2 of the reversed vector v1 is:
( 9 8 7 6 5 4 3 2 1 0 ).
The original vector v1 remains unmodified as:
( 0 1 2 3 4 5 6 7 8 9 ).
요구 사항
헤더: <algorithm>
네임스페이스: std