Given two vectors of equal length:
std::vector<Type> vec1;
std::vector<Type> vec2;
If the contents of vec2
need to be replaced with the contents of vec1
, is it more efficient to use
vec2.swap(vec1);
or
vec2 = vec1;
assuming that vec1
will remain in memory but its contents after the operation don't matter? Also, is there a more efficient method that I haven't considered?