Move a range of elements between containers?
-
30-09-2019 - |
Pergunta
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)
Solução
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.
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow