Move a range of items between containers?

I looked at the C ++ documentation for a function that would move a series of elements from one container to another using the move semantics. However, I did not find such a function. What am I missing?

How to 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) 
+7
c ++ algorithm c ++ 11 move-semantics move
source share
1 answer

I think you are looking for std::move in <algorithm> :

 std::move(source.begin(), source.begin() + 10, std::insert_iterator(dest, dest.end())); 

It is just like std::copy , except that instead of assigning copies, move-assigns are assigned.

+7
source share

All Articles