About std::vector::resize().

Theodore Papadopoulo Theodore.Papadopoulo@sophia.inria.fr
Tue May 25 19:46:00 GMT 2004


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
 --------------------------------------------------------------------




More information about the Libstdc++ mailing list