std::vector<std::string> v, orig;
orig.push_back("first");orig.push_back("second");
// BAD:v = orig;v.insert(v.end(), v.begin(), v.end());// Now v contains: { "first", "second", "", "" }
// BAD:v = orig;std::copy(v.begin(), v.end(), std::back_inserter(v));// std::bad_alloc exception is generated
// GOOD, but I can't guarantee it will work with any STL:v = orig;v.reserve(v.size()*2);v.insert(v.end(), v.begin(), v.end());// Now v contains: { "first", "second", "first", "second" }
// GOOD, but I can't guarantee it will work with any STL:v = orig;v.reserve(v.size()*2);std::copy(v.begin(), v.end(), std::back_inserter(v));// Now v contains: { "first", "second", "first", "second" }
// GOOD (best):v = orig;v.insert(v.end(), orig.begin(), orig.end()); // note: we use different vectors here// Now v contains: { "first", "second", "first", "second" }