Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| Message-ID | <97b9edFcv1U1@mid.individual.net> (permalink) |
|---|---|
| Newsgroups | comp.std.c++ |
| From | "Bo Persson" <bop@gmb.dk> |
| Subject | Re: Kidnapping std::move |
| Organization | unknown |
| References | <4aa1dab3-6dfb-481b-83cf-28f88ad52633@a15g2000pri.googlegroups.com> <dfa20d15-6a50-43fa-b442-1b0b990e7ccc@w4g2000yqm.googlegroups.com> |
| Date | 2011-07-04 09:14 -0600 |
Rani Sharoni wrote:
> On Jun 30, 7:31 pm, Rani Sharoni <ranisharon...@gmail.com> wrote:
>> I recently encountered an interesting issue in which
>> func(std::move(x)) will actually =93move=94 x even when =91func=92
>> doesn=92=
>
> Sorry for the bad text. This is probably related to pasting from my
> text editor.
> I will try to give a better version of my concern.
>
> Consider the following code:
> struct B {};
> struct D : B {};
>
> set<unique_ptr<B>, ...> aSet;
>
> unique_ptr<B> spB = new D;
> auto res1 = aSet.insert(move(spB));
> assert(res1.second ^ !spB); // take ownership on successful insert
>
> unique_ptr<D> spD = new D;
> 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.
By using std::move(spD) you say "take it, I don't care about it
anymore". Then on the next line you DO care!
Isn't it a rare condition to try to insert into a set, but still
wanting to keep the duplicate? Why not use a multiset in that case?
Bo Persson
--
[ 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