Topic: Request for std::vector and possibly others: mi


Author: brangdon@cix.compulink.co.uk (Dave Harris)
Date: Sat, 24 Mar 2012 19:24:35 -0700 (PDT)
Raw View
henrik.vallgren@stream-space.com (henrikv) wrote (abridged):
> IMO, telling the vector which constructor to use isn't "improper
> use".

That's what emplace_back does. It seems to me to be exactly what you
want, except
it adds a single item instead of a range of them. Thus your:

   dummies.resize(1000, g_no_init);

would be written:
   dummies.reserve(1000);
   for (int i = 0; i < 1000; ++i)
       dummies.emplace_back(g_no_init);

Either way you'd be relying on the optimiser.


> I'm thinking *parallel* loop here, so neither order, nor race
> conditions can be predicted.

Your resize would need to be done before the parallel code kicked off,
and so would
the above loop. Emplace_back() is not used by the parallel code.

That said, replacing:
   resize( size_type count, const value_type &value );

with:
   template<class... Args>
   void resize( size_type count, Args&&... args );

does seem like a reasonable request to me. It would be useful whenever
constructing
a new value_type with args was preferable to copying a value_type that had been
constructed with args. I don't see a drawback, other than the issues that arise
whenever the standard is changed.

-- Dave Harris, Nottingham, UK.


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