vector capacity shows 0 even though it is reserved
This here
vector<uint32_t> v = test->getV();
Makes a copy. v
isn't actually a reference, so even though you return one, it has to make a copy anyway. Because it is a copy, it doesn't need that same amount of reserved space. If you actually get the reference instead like this:
vector<uint32_t> &v = test->getV();
The output is 32
both times.
The copy-initialized v
following vector<uint32_t> v = test->getV();
is a value copy of test->getV()
.
The C++ standard does not require the copying of the source vector's capacity following copy initialization, so the capacity of v
is allowed to be any value subject to it being greater than or equal to the number of elements.