Anton Anton -3 years ago 146
C++ Question

copy & copy_if vs remove_copy & remove_copy_if

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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download