std::string::reserve vs std::vector::reserve
chris jefferson
caj@cs.york.ac.uk
Thu Jun 16 13:01:00 GMT 2005
Jonathan Wakely wrote:
> Actually ...
>
>It occurs to me that it is possible that vectors capacity could change
>after an assignment, when we implement move semantics:
>
> std:vector<int> v;
> v.reserve(100);
> v = std::vector<int>();
>
>That would change the capacity, since the temporary would bind to the
>rvalref and the implmenetations would be swapped. Should we retain the
>old capacity in this case?
>
>e.g.
>
> vector&
> operator=(__gnu_cxx::__rvalref<vector> __x)
> {
> this->swap(__x.__ref);
>+ this->reserve(__x.capacity());
> return *this;
> }
>
>jon
>
>
>
While I'm not sure it's been properly finalised yet, I believe the plan
is to leave things that have been moved from in a valid, but unknown
state (sorry if that isn't the correct legalise). At some point it might
turn out what I should, or would be better, to do would be to destroy
the existing vector and just set the vector being moved from as an empty
vector.
I've been working under the assumption that after something has been
moved from, the only valid things to do to it are assign to it, move
assign a new value to it, or destroy it. These are possibly too strong,
but have the advantage that a) They are I believe the only reasonable
things anyone would want to do, and b) I'm sure they can be weaker than
what the final requirements will be :)
At present, any or all of these choices are totally invisable to users
of course :)
Chris
More information about the Libstdc++
mailing list