This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: About std::vector::resize().
On Tue, May 25, 2004 at 12:36:30PM -0600, Martin Sebor wrote:
> Carlo Wood wrote:
>
> >As far as I know this is implementation dependend and using swap
> >would be allowed (or so I was told not long ago).
> >
> >From a practical point of view this seems a very good idea.
> >One could implement a resize from size m to size n (n > m) as:
> >
> >- Create new vector with size n, using the default constructor
> > for all elements.
> >- Swap the first m elements.
> >- Destroy the old vector.
>
> That's not allowed by 23.2.4.2, p5:
>
> 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().
That seems obvious and I fail to see how this is related with
the subject of interest.
--
Carlo Wood <carlo@alinoe.com>