Where did you find that in the C++ Standard?
23.1.1p4, Sequence requirements:
The semantics of a.clear() is erase(begin(), end()).
clear() is not otherwise defined for vector.
Same table:
erase(q1, q2): erases the elements in the range [q1, a2).
23.2.4.3p3-p5 goes on to further define erase(iter,iter) for vector but
does not address capacity issues one way or the other.
23.2.4.2p2-p5: Defines vector::reserve. The definition includes:
After reserve(), capacity() is greater or equal to the argument of reserve if
reallocation happens; and equal to the previous value of capacity()
otherwise. Reallocation happens at this point if and only if the current
capacity is less than the argument of reserve().
There is a note which further explains:
It is guaranteed that no reallocation takes place during insertions that
happen after a call to reserve() until the time when an insertion would make
the size of the vector greater than the size specified in the most recent
call to reserve().
Consider this code:
vector<int> v;
v.reserve(100);
v.resize(100);
v.clear();
v.resize(100);
According to the note above, neither the first nor second call to resize
should not be allowed to reallocate because of the preceding call to
reserve. There is no part of the definition of clear or erase which
otherwise grants such leeway.
Additionally the working draft for C++0X has already been changed via DR
329 to make it more clear that "most recent" really means "largest":
It is guaranteed that no reallocation takes place during insertions that
happen after a call to reserve()
until the time when an insertion would make the size of the vector greater
than the value of capacity().
There is interest in adding functionality to the C++0X vector allowing a
"shrink-to-fit" functionality as std::string already enjoys with its
reserve member.
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1870.html#add-me
mber-resize-capacity-to-vector-and-basic-string
This would have the effect of negating the "largest" reserve. Currently
the only way to achieve such functionality is to allocate a new smaller
buffer, copy the old data into it, and swap buffers. However here is a
proposal:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1953.html
which would allow the possibility that the vector could shrink in place
(e.g. without reallocating a new smaller buffer). Neither proposal has
been turned down, but neither is enjoying overwhelming support either.
-Howard