std::vector
is part of the STL, so any description of std::vector
will do. The underlying implementation may differ slightly, but all conformant versions of STL must provide the same interface and the same guarantees for std::vector
. I can't find in quickly on MSDN, but here are two such descriptions of operator=
:
- http://www.cplusplus.com/reference/stl/vector/operator=/
- http://www.sgi.com/tech/stl/Vector.html
Now, the second part of your question puzzles me. What would you expect operator=
to do on a vector if not "copy everything from A into B"?
In your example, your question was "how to make sure the old v get cleared?". I can interpret this in one of two ways: You might be asking "how do I know that this assignment v = vector<double>(200,2)
will overwrite the contents of v
and not append to it?". The answer is that you know that because that's the definition of how operator=
works for STL containers. Any standards compliant implementation is guaranteed to work that way.
You might also be asking "what happens to the contents of v
when I overwrite them using the assignment v = vector<double>(200,2)
?" The answer is that they are deallocated, and if they are objects, their destructors are called. Note the important distinction that if the vector contains pointers to objects, the pointers themselves are deallocated, but not what they point to.
If I didn't answer your question, please try to clarify it.