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


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

Re: Kidnapping std::move

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!news.glorb.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date Mon, 04 Jul 2011 09:20:01 -0500
Return-Path <cppmods@mcgurn.dreamhost.com>
Sender std-cpp-request@vandevoorde.com
Approved stephen.clamage@oracle.com
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>
X-Original-Date Sun, 3 Jul 2011 15:34:19 +0200
X-Submission-Address std-c++-submit@vandevoorde.com
To undisclosed-recipients:;
Date Mon, 4 Jul 2011 09:14:30 CST
Lines 49
X-Usenet-Provider http://www.giganews.com
X-Trace sv3-QpLa/lsx6Y5699nD5gelcFdI94Q6CsFVB5MCKdmuQLiQqG/cuicZatNa9Th7RUR4IkfjnRapuRDSCNJ!TLbe7qRg3Nri8OpB66H2zNkEY5AsaLWcqB3qDAyKaCagGvmNcZQsP30uNQ==
X-Complaints-To abuse@giganews.com
X-DMCA-Notifications http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info Otherwise we will be unable to process your complaint properly
X-Postfilter 1.3.40
X-Original-Bytes 2699
Xref x330-a1.tempe.blueboxinc.net comp.std.c++:194

Show key headers only | View raw


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 | NextPrevious in thread | Next in thread | Find similar


Thread

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