I've been looking at the C++ documentation for a function which would move a range of elements from one container to another, using move semantics. However, I have not found such a function. What am I missing?
How would I do the following without copying and using explicit loops?
// Move 10 elements from beginning of source to end of dest
dest.end() <- move(source.begin(), source.begin() + 10)
I think you're looking for std::move
in <algorithm>
:
std::move(source.begin(), source.begin() + 10,
std::insert_iterator(dest, dest.end()));
It's just like std::copy
, except it move-assigns instead of copy-assigns.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With