Resurrecting an old thread, but I am surprised that nobody mentioned std::make_move_iterator
combined with insert
. It has the important performance benefit of preallocating space in the target vector:
v2.insert(v2.end(), std::make_move_iterator(v1.begin() + 7),
std::make_move_iterator(v1.end()));
As others have pointed out, first vector v1
is now in indeterminate state, so use erase
to clear the mess:
v1.erase(v1.begin() + 7, v1.end());
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…