ronag
ronag

Reputation: 51283

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) 

Upvotes: 8

Views: 2024

Answers (1)

GManNickG
GManNickG

Reputation: 504273

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.

Upvotes: 9

Related Questions