I have two STL vectors A
and B
and I'd like to clear all elements of A
and move all elements of B
to A
and then clear out B
. Simply put, I want to do this:
std::vector<MyClass> A;
std::vector<MyClass> B;
....
A = B;
B.clear();
Since B
could be pretty long, it takes k*O(N)
to do this operation, where k
is a constant, and N
is max(size_of(A), size_of(B))
. I was wondering if there could be a more efficient way to do so. One thing that I could think of is to define A
and B
as pointers and then copy pointers in constant time and clear out B
.