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 01:05:04PM -0600, Martin Sebor wrote:
> Theodore Papadopoulo wrote:
> The code below must not abort for any (n > 0) but if resize()
> constructed a new vector and swapped *this for it, it would.
>
> std::vector<T> v;
> v.resize (1);
> v.reserve (n);
> T *p = &v [0];
> v.resize (n); // must not reallocate
Because the (reserved) "size" is already n there is no need
for reallocation - so the mentioned algorithm will not
be used.
We are only interested to discuss the case in which
reallocation is needed (and THUS where the 'reserved'
size is too small) otherwise the algorithm is not
relevant.
--
Carlo Wood <carlo@alinoe.com>