220 11784 <F1CBA358-0AD8-4ADD-99DA-6D00FCFE150F@gmail.com> article
Path: news.gmane.org!not-for-mail
From: David Krauss <potswa@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: N4078: Rvalue reference overloads for value()
 method returns object by value
Date: Thu, 10 Jul 2014 14:20:10 +0800
Lines: 187
Approved: news@gmane.org
Message-ID: <F1CBA358-0AD8-4ADD-99DA-6D00FCFE150F@gmail.com>
References: <b538efba-faf4-4ffc-a553-302b9d2ba2c0@isocpp.org> <CANh-dX=M7niArNp-1sCcqxaREEJSxmjMftgw7uMHN9YnZC-h+w@mail.gmail.com> <4DA018C3-2327-4F55-B7F8-7988EC7B789A@gmail.com> <1a858a77-310b-4591-aaf5-960c40d9f5fc@isocpp.org> <66AF41C1-CB37-4311-98EA-D47DBC6068DC@gmail.com> <66c38b61-7a95-4ace-b34f-2346bb334fb9@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\))
Content-Type: multipart/alternative; boundary="Apple-Mail=_2FA755DB-8D95-40E3-86AF-7CADEF8F0222"
X-Trace: ger.gmane.org 1404973229 25747 80.91.229.3 (10 Jul 2014 06:20:29 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Thu, 10 Jul 2014 06:20:29 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCW25A7E3QCRBH7B7COQKGQEZ4WGXNA@isocpp.org Thu Jul 10 08:20:21 2014
Return-path: <std-proposals+bncBCW25A7E3QCRBH7B7COQKGQEZ4WGXNA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-pa0-f71.google.com ([209.85.220.71])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCW25A7E3QCRBH7B7COQKGQEZ4WGXNA@isocpp.org>)
	id 1X57iL-0001TU-BG
	for gclcip-std-proposals@m.gmane.org; Thu, 10 Jul 2014 08:20:17 +0200
Original-Received: by mail-pa0-f71.google.com with SMTP id eu11sf57204096pac.2
        for <gclcip-std-proposals@m.gmane.org>; Wed, 09 Jul 2014 23:20:16 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:from:message-id:mime-version:subject:date
         :references:to:in-reply-to:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe:content-type;
        bh=2jMeU9peKd7K38ITmxcGAidhv3Kp2QWKEMaUJAKyHu4=;
        b=GTP6h8PcZaYj964OGT1ZQgdT00A4JxLddAyDSddThM7M0ep1f8eRJLWEQJXxrc/2am
         KE0pMcjRn/lO7GMafUEkeexP3pfluD4qr84zN3L8s4Duc9BSkx6fJEKojwGY/4PWeh4V
         CmsFwZ898IiDvIwc4EJ75cMv988ZE/mUevthH3wuA7aYP49SyatMN3qoZB42N7r56uX6
         nqC5BjWre65tsU1xDZ0OyE7iZqmq4sA8NR3nb2UVjmQBaPWCeO21HPyJ8vVSh6w06hwG
         ndFyO6iVuoH+LTp980W6qmtKRwlQu+gKaVxHD1N8jTy+X7sKqwet9LfNpFtuFe93ONnv
         Bh8w==
X-Gm-Message-State: ALoCoQnkig5qA+UuXG/AWQYjKy68lVdC5EiBJ+RKAWaYQg3LZ7+FYII+5lT/EC213x0tfPejbS3g
X-Received: by 10.70.44.46 with SMTP id b14mr7814161pdm.4.1404973216135;
        Wed, 09 Jul 2014 23:20:16 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.50.79.230 with SMTP id m6ls2761igx.39.gmail; Wed, 09 Jul 2014
 23:20:15 -0700 (PDT)
X-Received: by 10.51.17.97 with SMTP id gd1mr19530104igd.18.1404973215427;
        Wed, 09 Jul 2014 23:20:15 -0700 (PDT)
Original-Received: from mail-ie0-x234.google.com (mail-ie0-x234.google.com [2607:f8b0:4001:c03::234])
        by mx.google.com with ESMTPS id b11si74884590icj.83.2014.07.09.23.20.15
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Wed, 09 Jul 2014 23:20:15 -0700 (PDT)
Received-SPF: pass (google.com: domain of potswa@gmail.com designates 2607:f8b0:4001:c03::234 as permitted sender) client-ip=2607:f8b0:4001:c03::234;
Original-Received: by mail-ie0-f180.google.com with SMTP id at20so612238iec.11
        for <std-proposals@isocpp.org>; Wed, 09 Jul 2014 23:20:15 -0700 (PDT)
X-Received: by 10.50.225.98 with SMTP id rj2mr18950785igc.42.1404973215247;
        Wed, 09 Jul 2014 23:20:15 -0700 (PDT)
Original-Received: from [172.20.10.2] ([121.54.54.63])
        by mx.google.com with ESMTPSA id n17sm22334738igk.19.2014.07.09.23.20.13
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Wed, 09 Jul 2014 23:20:14 -0700 (PDT)
In-Reply-To: <66c38b61-7a95-4ace-b34f-2346bb334fb9@isocpp.org>
X-Mailer: Apple Mail (2.1878.6)
X-Original-Sender: potswa@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of potswa@gmail.com designates 2607:f8b0:4001:c03::234 as permitted
 sender) smtp.mail=potswa@gmail.com;       dkim=pass header.i=@gmail.com;
       dmarc=pass (p=NONE dis=NONE) header.from=gmail.com
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: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:11784
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/11784>

--Apple-Mail=_2FA755DB-8D95-40E3-86AF-7CADEF8F0222
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8


On 2014=E2=80=9307=E2=80=9310, at 2:10 PM, tomaszkam@gmail.com wrote:

>=20
> W dniu czwartek, 10 lipca 2014 07:48:29 UTC+2 u=C5=BCytkownik David Kraus=
s napisa=C5=82:
>=20
> On 2014=E2=80=9307=E2=80=9310, at 1:11 PM, toma...@gmail.com wrote:
>=20
>> W dniu czwartek, 10 lipca 2014 01:17:39 UTC+2 u=C5=BCytkownik David Krau=
ss napisa=C5=82:
>>=20
>> auto && has some strong proponents, and although nothing is a silver bul=
let, it will always work except when a function returns an rvalue reference=
 =E2=80=94 which, as the title of this thread and most of the early message=
s indicate, is a problem to be fixed.
>=20
>> No, the auto&& does not work with any function that return a any kind of=
 reference to subobject of it parameter (including this) is invoked on an r=
value. In the examples above you my find:
>> std::vector<std::string> f();
>> auto&& s =3D f.front();
>> //This creates a dangling lvalue reference, and front() has not r-value =
overloads.
>=20
> I think you mean f().front(). As per this thread, or maybe it=E2=80=99s j=
ust my extrapolation, the solution is to add an rvalue-ref qualified overlo=
ad returning by value.
>=20
> As a very general policy in C++ library design, every accessor to a stric=
tly owned resource should be lvalue-qualified and/or return by value. This =
best practice should be applied across the standard library.
>=20
> And dou you expect the following to also work (example presented above): =
 =20
>       auto&& s =3D *f.begin();

Assuming you mean * ( f().begin() ), I would expect that to be currently br=
oken, but the fix is to forbid begin() and end() on an xvalue because they =
are fundamentally nonsense. It=E2=80=99s a minor issue that some would-be i=
ll-formed code is currently accepted.

> In addition: "Of course binding a reference to a subobject extends the co=
mplete object. What else do you want, destruction of the rest of the object=
 *except* the subobject??"
> Llets assume following scenario:
> struct Result
> {
>     std::string array[100];
>     std::string& best; //best points to one element of array, making it b=
y reference stop at least assigment
> };=20
>=20
> //Lets assume that the following class returns array of 100 elements and =
hint for the best element
> Result foo();
>=20
> //Then you would like the following to work
> auto&& cs =3D foo().best;

No, lifetime extension doesn=E2=80=99t work like that. It=E2=80=99s never b=
een transitive. However even in C++98 this worked:

std::string const & cs =3D foo().best; // Lifetime extension since C++98

See 14882:1998 =C2=A712.2/5:

> The temporary to which the reference is bound or the temporary that is th=
e complete object to a subobject of which the temporary is bound persists f=
or the lifetime of the reference except as specified below.

It does not mention base subobjects specifically.

> Please stop this make "auto&&" movment, becuase it is now going insea wit=
h breaking existing code, to make this single statment work. The problem li=
es in usign the extension of temporaries by binding in block scope.

No existing code is getting broken. The semantics of rvalue references are =
understood pretty well now and it=E2=80=99s a completely consistent system.

--=20

---=20
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 e=
mail 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-proposa=
ls/.

--Apple-Mail=_2FA755DB-8D95-40E3-86AF-7CADEF8F0222
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dutf-8"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: s=
pace; -webkit-line-break: after-white-space;"><br><div><div>On 2014=E2=80=
=9307=E2=80=9310, at 2:10 PM, <a href=3D"mailto:tomaszkam@gmail.com">tomasz=
kam@gmail.com</a> wrote:</div><br class=3D"Apple-interchange-newline"><bloc=
kquote type=3D"cite"><div dir=3D"ltr"><br>W dniu czwartek, 10 lipca 2014 07=
:48:29 UTC+2 u=C5=BCytkownik David Krauss napisa=C5=82:<blockquote class=3D=
"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc s=
olid;padding-left: 1ex;"><div style=3D"word-wrap:break-word"><br><div><div>=
On 2014=E2=80=9307=E2=80=9310, at 1:11 PM, <a href=3D"javascript:" target=
=3D"_blank" gdf-obfuscated-mailto=3D"2_2y_Hm6SEcJ" onmousedown=3D"this.href=
=3D'javascript:';return true;" onclick=3D"this.href=3D'javascript:';return =
true;">toma...@gmail.com</a> wrote:</div><br><blockquote type=3D"cite"><div=
 dir=3D"ltr">W dniu czwartek, 10 lipca 2014 01:17:39 UTC+2 u=C5=BCytkownik =
David Krauss napisa=C5=82:<blockquote class=3D"gmail_quote" style=3D"margin=
:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204)=
;border-left-style:solid;padding-left:1ex"><div style=3D"word-wrap:break-wo=
rd"><br><div><font face=3D"Courier">auto &amp;&amp;</font> has some strong =
proponents, and although nothing is a silver bullet, it will always work ex=
cept when a function returns an rvalue reference =E2=80=94 which, as the ti=
tle of this thread and most of the early messages indicate, is a problem to=
 be fixed.</div></div></blockquote></div></blockquote><br><blockquote type=
=3D"cite"><div dir=3D"ltr">No, the auto&amp;&amp; does not work with any fu=
nction that return a any kind of reference to subobject of it parameter (in=
cluding this) is invoked on an rvalue. In the examples above you my find:<b=
r>std::vector&lt;std::string&gt; f();<br>auto&amp;&amp; s =3D f.front();<br=
>//This creates a dangling lvalue reference, and front() has not r-value ov=
erloads.<br></div></blockquote><div><br></div><div>I think you mean <font f=
ace=3D"Courier">f().front()</font>. As per this thread, or maybe it=E2=80=
=99s just my extrapolation, the solution is to add an rvalue-ref qualified =
overload returning by value.</div><div><br></div><div>As a very general pol=
icy in C++ library design, every accessor to a strictly owned resource shou=
ld be lvalue-qualified and/or return by value. This best practice should be=
 applied across the standard library.</div><div><br></div></div></div></blo=
ckquote><div>And dou you expect the following to also work (example present=
ed above):&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; auto&amp;&amp; s =
=3D *f.begin();<br></div></div></blockquote><div><br></div><div>Assuming yo=
u mean <font face=3D"Courier">* ( f().begin() )</font>, I would expect that=
 to be currently broken, but the fix is to forbid <font face=3D"Courier">be=
gin()</font> and <font face=3D"Courier">end()</font> on an xvalue because t=
hey are fundamentally nonsense. It=E2=80=99s a minor issue that some would-=
be ill-formed code is currently accepted.</div><br><blockquote type=3D"cite=
"><div dir=3D"ltr"><div>In addition: "Of course binding a reference to a su=
bobject extends
 the complete object. What else do you want, destruction of the rest of=20
the object *<i>except</i>* the subobject??"<br>Llets assume following scena=
rio:<br>struct Result<br>{<br>&nbsp;&nbsp;&nbsp; std::string array[100];<br=
>&nbsp;&nbsp;&nbsp; std::string&amp; best; //best points to one element of =
array, making it by reference stop at least assigment<br>}; <br><br>//Lets =
assume that the following class returns array of 100 elements and hint for =
the best element<br>Result foo();<br><br>//Then you would like the followin=
g to work<br>auto&amp;&amp; cs =3D foo().best;<br></div></div></blockquote>=
<div><br></div><div>No, lifetime extension doesn=E2=80=99t work like that. =
It=E2=80=99s never been transitive. However even in C++98 this worked:</div=
><div><br></div><div><font face=3D"Courier">std::string const &amp; cs =3D =
foo().best; // Lifetime extension since C++98</font></div><div><br></div><d=
iv>See 14882:1998 =C2=A712.2/5:</div><div><br></div><div></div><blockquote =
type=3D"cite"><div>The temporary to which the reference is&nbsp;bound or th=
e temporary that is the complete object to a subobject of which the&nbsp;te=
mporary is bound persists&nbsp;for the lifetime of the reference except as =
specified below.</div></blockquote><div><br></div>It does not mention base =
subobjects specifically.<br><br><blockquote type=3D"cite"><div dir=3D"ltr">=
<div>Please stop this make "auto&amp;&amp;" movment, becuase it is now goin=
g insea with breaking existing code, to make this single statment work. The=
 problem lies in usign the extension of temporaries by binding in block sco=
pe.</div></div></blockquote><div><br></div></div>No existing code is gettin=
g broken. The semantics of rvalue references are understood pretty well now=
 and it=E2=80=99s a completely consistent system.<br><div><br></div></body>=
</html>

<p></p>

-- <br />
<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 <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<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 />

--Apple-Mail=_2FA755DB-8D95-40E3-86AF-7CADEF8F0222--

.
