Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| Message-ID | <b65eaae4-66a2-4db9-93ec-d7b87c0eb68f@h25g2000prf.googlegroups.com> (permalink) |
|---|---|
| Newsgroups | comp.std.c++ |
| From | Rani Sharoni <ranisharoni75@gmail.com> |
| Subject | Re: Kidnapping std::move |
| Organization | http://groups.google.com |
| References | <4aa1dab3-6dfb-481b-83cf-28f88ad52633@a15g2000pri.googlegroups.com> <dfa20d15-6a50-43fa-b442-1b0b990e7ccc@w4g2000yqm.googlegroups.com> <97b9edFcv1U1@mid.individual.net> |
| Date | 2011-07-06 01:15 -0600 |
> > auto res1 = aSet.insert(move(spB)); > > assert(res1.second ^ !spB); // take ownership on successful insert > > > auto res2 = aSet.insert(move(spD)); > > assert(res2.second ^ !spD); // BUGBUG - spD is always null > > </code> > > I don't think this is any worse than that the language lets you divide > by zero or index an array out of range. I think that the programmer is responsible to avoid such bugs while in the above move issue the language/library can be of help with balancing the safety of such constructs. > By using std::move(spD) you say "take it, I don't care about it > anymore". Then on the next line you DO care! I actually wondered if std::move should be thought of as "allow move" or "always move". Syntactically speaking std::move only enables transfer of ownership but doesn't force it so it's up to the programmer. I personally got used that transfer of ownership is optional to allow things like strong failure guarantee (e.g. no side effects if std::insert failed). > Isn't it a rare condition to try to insert into a set, but still std::insert is just an example. > wanting to keep the duplicate? Why not use a multiset in that case? Maybe for retry on some transient state or insert to another collection. (I often use use maps but never the "multi" ones, i.e. map of lists). In general users can write functions that uses rvalue-ref and need to assure the strong guarantee. I think that std::move(l-value) is expected to obey the "no side effects" strong guarantee in general and the above unique_ptr case seems cornered enough to cause much problems. Rani -- [ 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
Kidnapping std::move Rani Sharoni <ranisharoni75@gmail.com> - 2011-06-30 10:31 -0600
Re: Kidnapping std::move Rani Sharoni <ranisharoni75@gmail.com> - 2011-07-02 01:17 -0600
Re: Kidnapping std::move Daniel Krügler <daniel.kruegler@googlemail.com> - 2011-07-03 01:39 -0600
Re: Kidnapping std::move Rani Sharoni <ranisharoni75@gmail.com> - 2011-07-04 09:14 -0600
Re: Kidnapping std::move Daniel Krügler <daniel.kruegler@googlemail.com> - 2011-07-06 01:16 -0600
Re: Kidnapping std::move "Bo Persson" <bop@gmb.dk> - 2011-07-04 09:14 -0600
Re: Kidnapping std::move Rani Sharoni <ranisharoni75@gmail.com> - 2011-07-06 01:15 -0600
Re: Kidnapping std::move SG <s.gesemann@gmail.com> - 2011-08-18 07:52 -0600
csiph-web