Topic: Request =?utf-8?Q?f=C3=B6r?= std::vector and possibly others:
Author: Miles Bader<miles@gnu.org>
Date: Sat, 24 Mar 2012 17:55:26 -0700 (PDT)
Raw View
Kevin McCarty<kmccarty@gmail.com> writes:
>> All you need to do is use `std::vector::reserve` to allocate as
>> much space as you plan to use. Then use `emplace_back` to construct
>> each addition to the `vector` in-place.
>
> There are at least two situations I can think of, where it would be
> *very* useful to be able to initialize or resize a vector of PODs such
> that the newly allocated elements will have no initialization
> performed. (I'm ambivalent as to the exact mechanics Henrik
> proposed.)
Agreed, this would be a nice feature to have.
It's obviously a more dangerous operation than most, so a suitably
scary name ("resize_uninitialized_yes_yes_I_know_what_Im_doing")
might be called for...
Right now, I just use a wrapper class for the stored element type to
achieve this effect, but that's less flexible and can be awkward.
-Miles
--
Sabbath, n. A weekly festival having its origin in the fact that God made the
world in six days and was arrested on the seventh.
[ comp.std.c++ is moderated. To submit articles, try posting with your ]
[ newsreader. If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]