In general, optional. When you assign one vector to another, the post condition is that both arrays will contain equivalent objects at the end of the operation.
If the capacity
target vector is sufficient, the operation can be performed by calling the assignment operator on the set of elements min( v1.size(), v2.size() )
, and then either destroying the remaining elements if the destination vector contains more elements, or copying additional elements in the end. In this case, freeing or allocating memory will not be performed.
If the target vector does not have sufficient capacity, it will create a new buffer with sufficient capacity and copy-construct the elements in the new buffer from the original vector. Then it will replace the old and new buffers, destroy all old objects and release the old buffer. In this case, the old objects are destroyed, and the old memory is freed, but this is just one case.
source share