Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| Path | csiph.com!usenet.pasdenom.info!news.albasani.net!.POSTED!not-for-mail |
|---|---|
| From | Jason McKesson<jmckesson@gmail.com> |
| Newsgroups | comp.std.c++ |
| Subject | Re: Request för std::vector and possibly others: minimal initalization |
| Date | Sat, 24 Mar 2012 17:55:01 -0700 (PDT) |
| Organization | http://groups.google.com |
| Lines | 34 |
| Sender | std-cpp-request@vandevoorde.com |
| Approved | stephen.clamage@oracle.com |
| Message-ID | <23678521.1162.1332554396754.JavaMail.geo-discussion-forums@pbcp5> (permalink) |
| References | <abf103e0-7005-47b4-9888-af946353a525@v22g2000vby.googlegroups.com> <3008757.1215.1332274822853.JavaMail.geo-discussion-forums@pbjv6> <b94ffa35-1289-4a00-b9fd-92a56dfee459@w32g2000vbt.googlegroups.com> |
| NNTP-Posting-Host | 8t8qI5u/IvYgZiBucNDobfVzlXqB0H5Q0qNtzAAHQ4I= |
| Content-Type | text/plain; charset=ISO-8859-1 |
| X-Trace | news.albasani.net WSTx4k6GMXC6iJgaVwxSUKmdyHYdPLnHLIZCA4Rljl6FmhW2Z5I9Me5NO6l/3oami3NE4XRsSirfdDhZeIkwvw== |
| X-Complaints-To | abuse@albasani.net |
| NNTP-Posting-Date | Sun, 25 Mar 2012 00:55:18 +0000 (UTC) |
| X-Mailer | Perl5 Mail::Internet v2.05 |
| X-Submission-Address | std-cpp-submit@vandevoorde.com |
| Cancel-Lock | sha1:4A3lkLK2ewDwR7M8JfHJ3oDRTmw= |
| X-Original-Date | Fri, 23 Mar 2012 18:59:56 -0700 (PDT) |
| Xref | csiph.com comp.std.c++:461 |
Show key headers only | View raw
On Friday, March 23, 2012 5:10:25 PM UTC-7, henrikv wrote:
> On 21 mar, 19:35, Jason McKesson<jmckes...@gmail.com> wrote:
> > This looks more like an improper use of `std::vector` than anything that should be added to the specification.
>
> IMO, telling the vector which constructor to use isn't "improper use".
> I'm trying to achieve "minimal but proper initialization", so a class
> containing something like a std::string would require that member to
> be properly initialized. I can do the same thing today, all that's
> required is a default constructor that doesn't touch anything that's
> not required:
>
> struct NoInitDummy
> {
> NoInitDummy() {}
>
> // Make this behave like a Dummy using conversion operators etc
> int a;
> };
How "minimal" do you want? `std::vector::resize(size_t n)` will value-initialize each element. Why do you need it to be *default* initialized?
> > 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.
>
> Using reserve+emplace_back isn't a good idea. I'm thinking *parallel*
> loop here, so neither order, nor race conditions can be predicted.
I didn't say to use `emplace_back` as part of the parallel loop. I meant that you would do that to *initialize* the `vector`, using exactly the constructor you want.
--
[ 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 | Next — Previous in thread | Next in thread | Find similar
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