std::copy for overlapping ranges?

S

Simon Elliott

Is there an equivalent of std::copy which works on STL containers for
overlapping ranges?
 
H

Howard Hinnant

Simon Elliott said:
Is there an equivalent of std::copy which works on STL containers for
overlapping ranges?

std::copy works for overlapping ranges as long as the destination is
earlier in the sequence than the source. Else you want
std::copy_backward. There is no std::algorithm which will make that
decision for you. You could write such an algorithm but it would be
limited to random access iterators, and would /require/ that the source
and destination point into the same sequence (or that all of the
iterators be pointers).

-Howard
 
S

Simon Elliott

std::copy works for overlapping ranges as long as the destination is
earlier in the sequence than the source. Else you want
std::copy_backward. There is no std::algorithm which will make that
decision for you. You could write such an algorithm but it would be
limited to random access iterators, and would require that the source
and destination point into the same sequence (or that all of the
iterators be pointers).

Thanks for this, my STL docs are none too clear on this point.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top