Take the following code:
std::vector a;
a.reserve(65536);
std::vector b(a); //NOTE: b is constructed from a
a.reserve(65536); // no r
Is capacity copied?
In practice, no. I tested it online in Clang and GCC as well as MSVC and none of them copy the capacity.
Will there be a reallocation on the last line?
If the capacity is less than the argument to reserve (i.e. it doesn't get copied) then yes.
Does the standard say anything about this or is it silent?
No definitions for the copy constructor are provided in vector.cons. Instead we have to look at the container.requirements
Xdenotes a container class containing objects of typeT,aandbdenote values of typeX,udenotes an identifier,rdenotes a non-const value of typeX, andrvdenotes a non-const rvalue of typeX.
X u(a)
X u = a;Requires:
TisCopyInsertableintoX(see below).post:
u == a
Now what does it mean for two containers to be equal?
a == b
==is an equivalence relation.equal(a.begin(), a.end(), b.begin(), b.end())
In other words, since it doesn't require capacity to be equal in the comparison, then there's no reason to copy the capacity.