Just trying to improve slightly the answer of @Daniel: the function should not be defined twice, the source should be passed by value.
// std::vector<T>&& src - src MUST be an rvalue reference
// std::vector<T> src - src MUST NOT, but MAY be an rvalue reference
template <typename T>
inline void append(std::vector<T> source, std::vector<T>& destination)
{
if (destination.empty())
destination = std::move(source);
else
destination.insert(std::end(destination),
std::make_move_iterator(std::begin(source)),
std::make_move_iterator(std::end(source)));
}
Now the caller can decide whether to copy or move.
std::vector<int> source {1,2,3,4,5};
std::vector<int> destination {0};
auto v1 = append<int>(source,destination); // copied once
auto v2 = append<int>(std::move(source),destination); // copied 0 times!!
Never use &&
for arguments, unless you have to (for example: std::ifstream&&).