Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

copy & copy_if vs remove_copy & remove_copy_if

Tags:

c++

algorithm

I try to find any difference between copy(copy_if) and remove_copy(remove_copy_if) stl algorithms but it seems that there are no any practical differences instead of that:

Source and destination ranges cannot overlap in remove_copy algorithm

Is there really any significant and practical difference in these algorithms?

like image 406
Anton Avatar asked Aug 17 '17 11:08

Anton


1 Answers

copy_if only copies elements satisfying a given predicate, remove_copy_if on the other hand copies only elements that do not satisfy a specified predicate. Thus the two functions complement each other, they do not do the same.

By the way for copy_if there is also similar statement The behavior is undefined if the source and the destination ranges overlap. Thus it may not be checked but it is very bad idea to have the source and destination overlapping.

like image 162
Ivaylo Strandjev Avatar answered Oct 06 '22 08:10

Ivaylo Strandjev