220 5198 <8e156cc1-8136-48e6-96f2-8dca72fee7d4@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Xeo <hivemaster@hotmail.de>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Teachability problems with std::move
Date: Mon, 24 Jun 2013 13:08:29 -0700 (PDT)
Lines: 219
Approved: news@gmane.org
Message-ID: <8e156cc1-8136-48e6-96f2-8dca72fee7d4@isocpp.org>
References: <CA+cyFgsYFbjG1M98PJS-XVzuJYbQmt7=4GOqS5_V5-WVJ0caLg@mail.gmail.com>
 <CAOfiQq==HeEUmRGhashVO2486N+XCkH25dJY9xxEPc87w0omBQ@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_296_23524625.1372104509838"
X-Trace: ger.gmane.org 1372105131 20065 80.91.229.3 (24 Jun 2013 20:18:51 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Mon, 24 Jun 2013 20:18:51 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCCNBYNYXMJRBPWOUKHAKGQESBOETDA@isocpp.org Mon Jun 24 22:18:52 2013
Return-path: <std-proposals+bncBCCNBYNYXMJRBPWOUKHAKGQESBOETDA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-gh0-f200.google.com ([209.85.160.200])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCCNBYNYXMJRBPWOUKHAKGQESBOETDA@isocpp.org>)
	id 1UrDDv-0008Mw-Q0
	for gclcip-std-proposals@m.gmane.org; Mon, 24 Jun 2013 22:18:52 +0200
Original-Received: by mail-gh0-f200.google.com with SMTP id 10sf11942087ghy.11
        for <gclcip-std-proposals@m.gmane.org>; Mon, 24 Jun 2013 13:18:50 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=google.com; s=20120113;
        h=x-beenthere:date:from:to:message-id:in-reply-to:references:subject
         :mime-version:x-original-sender:reply-to:precedence:mailing-list
         :list-id:x-google-group-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe:content-type;
        bh=jpUXSIRkmzy4sdcmxd3zpVyEaYF7fwwkzqAUfJ8/fho=;
        b=aDDdz2bmbguaHWh9mSlod5xjpaWgt1Xjv3rXF5cVzTAq6acDazuCEDLnGEf2o5Q4cu
         vigqgwJlhuwyB584hXs2Cfuw7hNEA133CPM/Y0jMBuXjUKJ9cbCZ3ywVEzI3L8wPzTDJ
         RhoOH4NCrL6toGclktxxqwBSswUts2mxaxQksGKQA6r1JQYYHLKbtKoZZxkQWfPGcnAH
         jFfPjCY82nXP4ZTH80au8wnImmyaMFD92af8e3z5WIFUOHD8TcEUJnkl6rY+qaEPmdIU
         GMO3HZmJFArsxHoVxhZZ26F8OTCoxaupxJmnYf9b3AMLjSgPv/XIEtQpHYydIph12jAi
         oS7Q==
X-Received: by 10.224.205.138 with SMTP id fq10mr27171435qab.1.1372104511314;
        Mon, 24 Jun 2013 13:08:31 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.49.61.166 with SMTP id q6ls2129534qer.70.gmail; Mon, 24 Jun
 2013 13:08:30 -0700 (PDT)
X-Received: by 10.49.62.3 with SMTP id u3mr564963qer.26.1372104510279;
        Mon, 24 Jun 2013 13:08:30 -0700 (PDT)
In-Reply-To: <CAOfiQq==HeEUmRGhashVO2486N+XCkH25dJY9xxEPc87w0omBQ@mail.gmail.com>
X-Original-Sender: hivemaster@hotmail.de
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:5198
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/5198>

------=_Part_296_23524625.1372104509838
Content-Type: text/plain; charset=ISO-8859-1

I remember sending you and Mike a reminder about that some months ago, and 
was wondering, did you actually talk about this at the Bristol meeting?

On Monday, June 24, 2013 9:14:17 PM UTC+2, Richard Smith wrote:
>
> On Mon, Jun 24, 2013 at 11:42 AM, Geoffrey Romer <gro...@google.com<javascript:>> 
> wrote: 
> > It's surprisingly hard to come up with a good, teachable set of rules 
> for 
> > when to use std::move. For example, it would be nice to be able to say 
> "you 
> > can leave out std::move when returning a named local variable", but this 
> is 
> > not always the case. Consider: 
> > 
> > std::unique_ptr<const Foo> FooFactory() { 
> >   std::unique_ptr<Foo> result(new Foo); 
> >   // ... 
> >   return std::move(result); 
> > } 
> > 
> > The "std::move" is mandatory here, because an lvalue can only be 
> implicitly 
> > treated as an rvalue during copy operations, and in "return result;", 
> > 'result' is not copied, but used as the input for an implicit 
> conversion. It 
> > seems like this should be fixable, perhaps by expanding the 
> implicit-rvalue 
> > rules, but I'm not sure what all the consequences would be (at a 
> minimum, 
> > this could change the behavior of existing code that has separate rvalue 
> and 
> > lvalue overloads for an implicit conversion operation). 
>
> Yes, for NRVO, I think the "same cv-unqualified type as the function 
> return type" restriction only needs to apply to copy-elision and not 
> to implicit move. That is, I think we should treat 'result' as an 
> xvalue here: 
>
> T f() { 
>   U result; 
>   return result; 
> } 
>
> ... independent of the types of T and U, but we should only be 
> permitted to perform copy-elision of they're the same cv-unqualified 
> type. Most generalizations of the implicit-rvalue rules are fraught 
> with peril, but this one seems relatively safe. 
>
> > Conversely, it would be nice to be able to say "When in doubt, just use 
> > std::move if you want move semantics, because it never hurts", but 
> std::move 
> > can in fact be a pessimization: 
> > 
> > std::array<Foo, 10000> MakeHugeArray() { 
> >   std::array<Foo, 10000> result; 
> >   // ... 
> >   return std::move(result); 
> > } 
>
> I suggest you talk to your compiler vendor (Hi!) and ask for a warning 
> for this case. 
>
> > As written, the return statement incurs 10,000 invocations of Foo's move 
> > constructor (or, worse, its copy constructor), but if std::move is 
> > eliminated, the return statement becomes effectively free, because it's 
> an 
> > elidable copy/move. In this case it's not at all clear to me how to fix 
> the 
> > problem; it seems like a fix would either require special-casing 
> std::move 
> > (which seems like a hack, and breaks the convention that the 
> core-language 
> > standard tries not to refer to the library standard), or require the 
> > implementation to 'see into' the implementation of a function called in 
> a 
> > return statement (which seems impractical). 
> > 
> > I think it's worth trying to fix these issues, despite the difficulties, 
> > because being able to provide reliable "rules of thumb" would 
> substantially 
> > improve the learning curve for std::move. Can anyone suggest how these 
> > issues could be fixed? 
>
> Per the above, I think we can make "you can leave out std::move when 
> returning a named local variable" be the right advice, with the added 
> bonus of a compiler warning if you put in a pessimizing std::move. 
>

-- 

--- 
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.



------=_Part_296_23524625.1372104509838
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

I remember sending you and Mike a reminder about that some months ago, and =
was wondering, did you actually talk about this at the Bristol meeting?<br>=
<br>On Monday, June 24, 2013 9:14:17 PM UTC+2, Richard Smith wrote:<blockqu=
ote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left=
: 1px #ccc solid;padding-left: 1ex;">On Mon, Jun 24, 2013 at 11:42 AM, Geof=
frey Romer &lt;<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mai=
lto=3D"aTEsPprxzZgJ">gro...@google.com</a>&gt; wrote:
<br>&gt; It's surprisingly hard to come up with a good, teachable set of ru=
les for
<br>&gt; when to use std::move. For example, it would be nice to be able to=
 say "you
<br>&gt; can leave out std::move when returning a named local variable", bu=
t this is
<br>&gt; not always the case. Consider:
<br>&gt;
<br>&gt; std::unique_ptr&lt;const Foo&gt; FooFactory() {
<br>&gt; &nbsp; std::unique_ptr&lt;Foo&gt; result(new Foo);
<br>&gt; &nbsp; // ...
<br>&gt; &nbsp; return std::move(result);
<br>&gt; }
<br>&gt;
<br>&gt; The "std::move" is mandatory here, because an lvalue can only be i=
mplicitly
<br>&gt; treated as an rvalue during copy operations, and in "return result=
;",
<br>&gt; 'result' is not copied, but used as the input for an implicit conv=
ersion. It
<br>&gt; seems like this should be fixable, perhaps by expanding the implic=
it-rvalue
<br>&gt; rules, but I'm not sure what all the consequences would be (at a m=
inimum,
<br>&gt; this could change the behavior of existing code that has separate =
rvalue and
<br>&gt; lvalue overloads for an implicit conversion operation).
<br>
<br>Yes, for NRVO, I think the "same cv-unqualified type as the function
<br>return type" restriction only needs to apply to copy-elision and not
<br>to implicit move. That is, I think we should treat 'result' as an
<br>xvalue here:
<br>
<br>T f() {
<br>&nbsp; U result;
<br>&nbsp; return result;
<br>}
<br>
<br>... independent of the types of T and U, but we should only be
<br>permitted to perform copy-elision of they're the same cv-unqualified
<br>type. Most generalizations of the implicit-rvalue rules are fraught
<br>with peril, but this one seems relatively safe.
<br>
<br>&gt; Conversely, it would be nice to be able to say "When in doubt, jus=
t use
<br>&gt; std::move if you want move semantics, because it never hurts", but=
 std::move
<br>&gt; can in fact be a pessimization:
<br>&gt;
<br>&gt; std::array&lt;Foo, 10000&gt; MakeHugeArray() {
<br>&gt; &nbsp; std::array&lt;Foo, 10000&gt; result;
<br>&gt; &nbsp; // ...
<br>&gt; &nbsp; return std::move(result);
<br>&gt; }
<br>
<br>I suggest you talk to your compiler vendor (Hi!) and ask for a warning
<br>for this case.
<br>
<br>&gt; As written, the return statement incurs 10,000 invocations of Foo'=
s move
<br>&gt; constructor (or, worse, its copy constructor), but if std::move is
<br>&gt; eliminated, the return statement becomes effectively free, because=
 it's an
<br>&gt; elidable copy/move. In this case it's not at all clear to me how t=
o fix the
<br>&gt; problem; it seems like a fix would either require special-casing s=
td::move
<br>&gt; (which seems like a hack, and breaks the convention that the core-=
language
<br>&gt; standard tries not to refer to the library standard), or require t=
he
<br>&gt; implementation to 'see into' the implementation of a function call=
ed in a
<br>&gt; return statement (which seems impractical).
<br>&gt;
<br>&gt; I think it's worth trying to fix these issues, despite the difficu=
lties,
<br>&gt; because being able to provide reliable "rules of thumb" would subs=
tantially
<br>&gt; improve the learning curve for std::move. Can anyone suggest how t=
hese
<br>&gt; issues could be fixed?
<br>
<br>Per the above, I think we can make "you can leave out std::move when
<br>returning a named local variable" be the right advice, with the added
<br>bonus of a compiler warning if you put in a pessimizing std::move.
<br></blockquote>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_296_23524625.1372104509838--

.
