reverse_copy


Create a reversed copy of a sequence.

Copy a reverse of the sequence [ first ... last ) into a sequence of the same size, starting at result . Return an iterator positioned immediately after the last new element.

Library

Standards<ToolKit>

Declaration


#include <algorithm>

template< class BidirectionalIterator, class OutputIterator >
OutputIterator reverse_copy
  (
  BidirectionalIterator first,
  BidirectionalIterator last,
  OutputIterator result
  );
  

Complexity

Time complexity is linear, as ( last - first ) comparisons are performed. Space complexity is constant.

Example <ospace/stls/examples/revcopy1.cpp>
#include <iostream>
#include <algorithm>

int numbers[ 6 ] = { 0, 1, 2, 3, 4, 5 };

void
main()
  {
  int result[ 6 ];

  reverse_copy( numbers, numbers + 6, result );

  int i;
  for ( i = 0; i < 6; ++i )
    cout << numbers[ i ] << ` `;
  cout << "\n";
  for ( i = 0; i < 6; ++i )
    cout << result[ i ] << ` `;
  cout << "\n";
  }

0 1 2 3 4 5
5 4 3 2 1 0

Copyright©1994-2026 Recursion Software LLC
All Rights Reserved - For use by licensed users only.