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().


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().

Martin


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