What is the best way to concatenate two vectors?
This is precisely what the member function std::vector::insert
is for
std::vector<int> AB = A;
AB.insert(AB.end(), B.begin(), B.end());
AB.reserve( A.size() + B.size() ); // preallocate memory
AB.insert( AB.end(), A.begin(), A.end() );
AB.insert( AB.end(), B.begin(), B.end() );