This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]