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
memcpyandmemmove.For non-overlapping ranges usually
std::copyis used, butstd::copy_backwardscan also be used.For overlapping ranges you need to use
std::copyorstd::copy_backwardsdepending on the nature of the overlap.Also for copy-expensive objects
std::move(<algorithm>) andstd::move_backwardrespectively can be used instead if the original objects don't need to keep their value.std::copy
std::copy_backward