Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Move a range of elements between containers?

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) 
like image 911
ronag Avatar asked Nov 09 '10 22:11

ronag


1 Answers

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.

like image 129
GManNickG Avatar answered Sep 29 '22 11:09

GManNickG