Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.std.c++ > #464

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

From brangdon@cix.compulink.co.uk (Dave Harris)
Newsgroups comp.std.c++
Subject Re: Request for std::vector and possibly others: mi
Date 2012-03-24 19:24 -0700
Organization unknown
Message-ID <memo.20120324124948.40100A@cix.co.uk> (permalink)
References <b94ffa35-1289-4a00-b9fd-92a56dfee459@w32g2000vbt.googlegroups.com>

Show all headers | View raw


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                      ]

Back to comp.std.c++ | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Request för std::vector and possibly others: minimal initalization henrikv <henrik.vallgren@stream-space.com> - 2012-03-19 23:35 -0700
  Re: Request för std::vector and possibly others: minimal initalization Francis Glassborow<francis.glassborow@btinternet.com> - 2012-03-21 11:35 -0700
    Re: Request för std::vector and possibly others: minimal initalization henrikv<henrik.vallgren@stream-space.com> - 2012-03-23 17:09 -0700
      Re: Request för std::vector and possibly others: minimal initalization Daniel Krügler <daniel.kruegler@googlemail.com> - 2012-03-24 19:25 -0700
      Re: Request för std::vector and possibly others: minimal initalization Francis Glassborow <francis.glassborow@btinternet.com> - 2012-03-24 19:28 -0700
  Re: Request för std::vector and possibly others: minimal initalization Jason McKesson<jmckesson@gmail.com> - 2012-03-21 11:35 -0700
    Re: Request för std::vector and possibly others: minimal initalization henrikv<henrik.vallgren@stream-space.com> - 2012-03-23 17:10 -0700
      Re: Request för std::vector and possibly others: minimal initalization Jason McKesson<jmckesson@gmail.com> - 2012-03-24 17:55 -0700
      Re: Request for std::vector and possibly others: mi brangdon@cix.compulink.co.uk (Dave Harris) - 2012-03-24 19:24 -0700
      Re: Re: Request för std::vector and possibly others: minimal initalization jgk@panix.com (Joe keane) - 2012-03-27 12:10 -0700
    Re: Request för std::vector and possibly others: minimal initalization Kevin McCarty<kmccarty@gmail.com> - 2012-03-23 17:11 -0700
      Re: Request för std::vector and possibly others:   minimal initalization Miles Bader<miles@gnu.org> - 2012-03-24 17:55 -0700
        Re: Request för std::vector and possibly others: minimal initalization henrikv <henrik.vallgren@stream-space.com> - 2012-03-25 23:14 -0700
      Re: Request för std::vector and possibly others: minimal initalization Jason McKesson <jmckesson@gmail.com> - 2012-03-24 19:27 -0700
      Re: Request för std::vector and possibly others: minimal initalization Pedro Lamarão<pedro.lamarao@gmail.com> - 2012-03-29 12:28 -0700
        Re: Request för std::vector and possibly others: minimal initalization Daniel Krügler <daniel.kruegler@googlemail.com> - 2012-03-29 13:17 -0700

csiph-web