This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: About std::vector::resize().
- From: Theodore Papadopoulo <Theodore dot Papadopoulo at sophia dot inria dot fr>
- To: Martin Sebor <sebor at roguewave dot com>
- Cc: libstdc++ <libstdc++ at gcc dot gnu dot org>
- Date: Tue, 25 May 2004 20:46:11 +0200
- Subject: Re: About std::vector::resize().
sebor@roguewave.com said:
>> 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().
I'm certainly dense tonight, but I do not see where reallocation
happen in the algorithm sketched above...
- Creating the vector is necessary (unless the size is already bigger
than n, but this is not the case of interest here). This is where
reserve is called.
- Swapping should do any reallocation as far as I can tell.
- Nor destroying.
There is clearly sthg I don't understand...
Theo.
--------------------------------------------------------------------
Theodore Papadopoulo
Email: Theodore.Papadopoulo@sophia.inria.fr Tel: (33) 04 92 38 76 01
--------------------------------------------------------------------