The standard library offers std::copy
, which can be seen as a generalization/generification of C's memcpy()
. It also maintains the requirement of memcpy()
, for the range [first
, last
) to be disjoint from the range [d_first
, d_first + std::distance(first, last)
); otherwise we have undefined behavior.
My question: Is there a generic version of std::memmove
(i.e. which doesn't make that requirement and would typically be implemented using a temporary buffer)? If not, how come?
C++ doesn't have drop in replacements for
memcpy
andmemmove
.For non-overlapping ranges usually
std::copy
is used, butstd::copy_backwards
can also be used.For overlapping ranges you need to use
std::copy
orstd::copy_backwards
depending on the nature of the overlap.Also for copy-expensive objects
std::move
(<algorithm>
) andstd::move_backward
respectively can be used instead if the original objects don't need to keep their value.std::copy
std::copy_backward