What's the best way to extend a vector with the contents of a vector returned from a function?
I can do:
std::vector<int> base;
{
std::vector<int> tmp = getVec(); //RVO will make this efficient
base.reserve(base.size() + tmp.size());
base.insert(base.end(), std::make_move_iterator(tmp.begin()), std::make_move_iterator(tmp.end()));
}
But is it possible to do it without creating tmp? I could pass base in to getVec by reference, but I feel parameters should be for inputs and the return value for outputs. Ideally I would be able to do:
base.extend(getVec());
But I can't see how to do this with the normal vector functions.