Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

copy_backward or copy with reverse_iterators?

Tags:

c++

stl

In terms of practical usage what differences are there between

a) copy_backward

b) copy with reverse_iterators for source and destination

In particular is one more generally applicable than the other? Are there any other differences?

Update: If there's really no difference, then any reference in C++ literature to this equivalence is appreciated. The motivation behind this question is to understand if this was by design or one of those slip ups (like missing copy_if)

like image 934
hawk Avatar asked May 14 '12 08:05

hawk


People also ask

How does std copy work?

std::copy. Copies the elements in the range [first,last) into the range beginning at result . The function returns an iterator to the end of the destination range (which points to the element following the last element copied).

What is reverse copy?

COPYING AN ORIGINAL IN REVERSE PAGE ORDER (REVERSE ORDER)The Reverse Order function outputs printed sheets in top-to-bottom order with the printed side facing up, resulting in a set of copies stacked in the opposite order to the original.

What is STD copy?

C++ STL std::copy() function copy() function is a library function of algorithm header, it is used to copy the elements of a container, it copies the elements of a container from given range to another container from a given beginning position.


1 Answers

http://www.cplusplus.com/reference/algorithm/copy/ has a implementation of std::copy

http://www.cplusplus.com/reference/algorithm/copy_backward/ has a implementation of std::copy_backward

You can see the differences by yourself.

Note: If I were you I would use std::copy_backward, because calling std::copy with the std::reverse_iterator<T> class might be a little slower (it needs more memory than a bidirectional iterator)

like image 141
Rontogiannis Aristofanis Avatar answered Oct 16 '22 23:10

Rontogiannis Aristofanis