220 11891 <6CFC366C-D196-4A2E-B4EE-D1E6B26AE6C0@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: Sat, 12 Jul 2014 19:14:27 +0800
Lines: 169
Approved: news@gmane.org
Message-ID: <6CFC366C-D196-4A2E-B4EE-D1E6B26AE6C0@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>
 <F1CBA358-0AD8-4ADD-99DA-6D00FCFE150F@gmail.com> <CAFk2RUZENmaMW5NwBaiF6byfhgRyPUsSmuyVjnRDhbjcfaTtQA@mail.gmail.com>
 <CC03CC1C-8487-40C8-97DF-2CA7661DAD55@gmail.com> <CAFk2RUa7-WTcL=XFYO8KMyU4rdpjDEfFM6n6SkUZ=SW_U7s5XQ@mail.gmail.com>
 <EF930317-EB97-402E-A3A0-CC46E7E2D998@gmail.com> <CAFk2RUZigiwLwFpfVXuFS8cqy38hPG3OGhGUi+iNwSYuYvyAyQ@mail.gmail.com>
 <A46ADDB4-C9B0-4163-81BE-900CD879D8C8@gmail.com> <CAFk2RUZ-DqEcMeehjH8KedYgErxKMq4O9kmeN4FZzjkXMYSsiw@mail.gmail.com>
 <6F4B3C72-9962-48DC-8527-0C89EA1B9710@gmail.com> <CAFk2RUb5xynaoQx-j4cQuXC8t-0GGc9-CZyRA2V=j6cfuNQV=g@mail.gmail.com>
 <35873CE5-ED8C-4C03-A6A1-E4132DECD91F@gmail.com> <CAFk2RUYRJSNcXykj9oPd=3EehSozf7PcX8ACM_hrqhK+Ur2V8A@mail.gmail.com>
 <335948E6-8140-4673-B958-930356A52070@gmail.com> <CAFk2RUYf+tpBvxiK00O=FncB01BWe6+SXiYBN7fixd4mhm+Z-w@mail.gmail.com>
 <76ACA175-5A44-4BE8-B49F-BAC6DA65E6B1@gmail.com> <CAFk2RUah5k9zy_mQqeNN9mec0PYkmKDZp7LVXm64dTeSLaw6nQ@mail.gmail.com>
 <4D3852AD-1AEB-44BA-941C-D645BAD19405@gmail.com> <6a4b6425-1167-40c1-acd8-3945c8cd4c74@isocpp.org>
 <13DD0D7A-A146-4667-9F30-6FB3739CDBE0@gmail.com> <CADGW59=9uFv-fXRVuBCE+3fdycqTzaqCJnuVmmaT6mOF=1=-MA@mail.gmail.com>
 <E9F36B2C-A142-4B6C-ADFD-57D0E11F2C5B@gmail.com> <CAOenAXiBW+BiUkPWdGQHS9fkyEVWJg343NXH9kRSn9owk6FmgQ@mail.gmail.com>
 <DABFDEB7-ADF9-40EC-B4DB-672205A99FEB@gmail.com> <CAFk2RUa-kPWGy29siK4dUu6jbydfwbUeuzCpYOi+b9xc4-msSg@mail.gmail.com>
 <C3BA0F43-683E-4FFE-B04C-9015EB9C7CB0@gmail.com> <CAFk2RUYzt26HjKhYCZtJ4BMrjLzu9MQvZ0ynuaULWTYbE6MBAA@mail.gmail.com>
 <6B925FF7-2940-44C7-BF1D-13209A703BA2@gmail.com> <CAA7U3HOtwZ+9M1E2GUZjmT4J6onk3EdZSnskd-1OaKHv+-wJ7g@mail.gmail.com>
 <944C9C01-865B-4215-8C91-95F01AEA256E@gmail.com> <CAA7U3HPT_z2H3E84v9vOxKhAvCnv2SB2ikJDDkR7W1M+Sd-JSg@mail.gmail.com>
 <8DC3E474-3957-40B2-B492-D4AF2FDDD451@gmail.com> <0ACAE525-4FB2-4932-BBD2-F0623C4EBBFB@gmail.com>
 <52187852-ff8e-4e59-a8cf-7a29fd0a405b@isocpp.org> <8209A2E9-D947-4C00-A1F3-38F5676A4E52@gmail.com>
 <4c42f7c9-0588-4ab9-9af5-b2e692513993@isocpp.org> <225BBAAC-B3FA-4014-9FB6-64C48DF4208E@gmail.com>
 <1b70888c-eb6a-49e5-b254-a475ef015570@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=_A140FED6-ED88-4EAA-B521-AB8B212D20B8"
X-Trace: ger.gmane.org 1405163707 28317 80.91.229.3 (12 Jul 2014 11:15:07 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Sat, 12 Jul 2014 11:15:07 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCW25A7E3QCRBMFRQSPAKGQEH56F5JI@isocpp.org Sat Jul 12 13:15:00 2014
Return-path: <std-proposals+bncBCW25A7E3QCRBMFRQSPAKGQEH56F5JI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ob0-f197.google.com ([209.85.214.197])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCW25A7E3QCRBMFRQSPAKGQEH56F5JI@isocpp.org>)
	id 1X5vGc-0000aR-ED
	for gclcip-std-proposals@m.gmane.org; Sat, 12 Jul 2014 13:14:58 +0200
Original-Received: by mail-ob0-f197.google.com with SMTP id vb8sf2636778obc.8
        for <gclcip-std-proposals@m.gmane.org>; Sat, 12 Jul 2014 04:14:57 -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=lkS/dAqZvAkhkj3rx2FKm2KZ7phdnkJZNke3dW0ciQ0=;
        b=NN5uyMR2rf9wK9OOlUCSPTYaZQAm8Q50UPfinAm6e5DPXWecuFhLwvIcPLeEKqbbK/
         fA74ZMxKkovYG4QpVAs6adl+s64gU4rWvWE7yWsacznxf+a85IDyuo+oganmVPpCh6Ri
         heWpfO1t4v0d5AzGPqGTazOUkMU82TtS/QPuy2F5dZQbD2Hyyf3xUeMkUGlViH/15Jf7
         OhZx9gaiSPBr+5KpKt9eppjbCWbfHldgjvjeMaaOrmLhaZ2lbv9pqsTbuTl31gCIb/Tt
         3mJKj/jwu/71AjazDtx7/LPS2aoRmxmnjmf9iVrs7QSenhmoQb2fkvtIV/4GoDai6HG5
         pbrA==
X-Gm-Message-State: ALoCoQmkEFWyRi+6dIqIuoDSFgWw2blK+zFQFzgnkFEQmmH0VMKpdiqYUpBeNckLLLEbpudwx7/n
X-Received: by 10.182.102.34 with SMTP id fl2mr2418570obb.16.1405163697212;
        Sat, 12 Jul 2014 04:14:57 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.50.117.7 with SMTP id ka7ls784913igb.32.gmail; Sat, 12 Jul
 2014 04:14:56 -0700 (PDT)
X-Received: by 10.50.137.73 with SMTP id qg9mr11366482igb.19.1405163696427;
        Sat, 12 Jul 2014 04:14:56 -0700 (PDT)
Original-Received: from mail-ie0-x22e.google.com (mail-ie0-x22e.google.com [2607:f8b0:4001:c03::22e])
        by mx.google.com with ESMTPS id h11si9721315icl.65.2014.07.12.04.14.56
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Sat, 12 Jul 2014 04:14:56 -0700 (PDT)
Received-SPF: pass (google.com: domain of potswa@gmail.com designates 2607:f8b0:4001:c03::22e as permitted sender) client-ip=2607:f8b0:4001:c03::22e;
Original-Received: by mail-ie0-f174.google.com with SMTP id rd18so1740492iec.5
        for <std-proposals@isocpp.org>; Sat, 12 Jul 2014 04:14:56 -0700 (PDT)
X-Received: by 10.42.12.76 with SMTP id x12mr23528icx.96.1405163696309;
        Sat, 12 Jul 2014 04:14:56 -0700 (PDT)
Original-Received: from [172.20.10.2] ([121.54.54.44])
        by mx.google.com with ESMTPSA id lo3sm4689369igb.22.2014.07.12.04.14.54
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Sat, 12 Jul 2014 04:14:55 -0700 (PDT)
In-Reply-To: <1b70888c-eb6a-49e5-b254-a475ef015570@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::22e 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:11891
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/11891>

--Apple-Mail=_A140FED6-ED88-4EAA-B521-AB8B212D20B8
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=ISO-8859-1


On 2014-07-12, at 5:10 PM, tomaszkam@gmail.com wrote:

>   3. Value r-value overload for operator[]: In the decltype(auto) get_fif=
th_thing(container_handle && ch) theauto && fifth_thing =3D=3D ( * std::for=
ward< container_handle >( ch ) )[ 5 ]; will cause fifth_thing to be type of
>       T&&, meaning the return type of function will be reference and that=
 will cause auto && fifth_thing =3Dget_fifth_thing(std::forward< container_=
handle >( ch)) to be a dangling reference. The code will be broken by this =
transormation.

Actually, the program is ill-formed because the name fifth_thing is an lval=
ue and it will not bind to the returned rvalue reference. If it were change=
d to std::forward< decltype( fifth_thing ) >( fifth_thing ), then your argu=
ment holds, but that's not realistically intuitive. If the problem is inste=
ad fixed by changing the return type to auto (since only special move and f=
orward functions should return xvalues) then my argument holds, but then th=
e user gets one or two copies (only zero or one if they think to std::move(=
 fifth_thing )).

This interaction between decltype(auto) and a named rvalue reference sounds=
 like fodder for a core DR. It's nasty regardless of library policies, and =
considering that a diagnostic is already required, it's fixable. The safe s=
olution, considering the possibility of a bound temporary, is to deduce a n=
on-reference type (return a prvalue), and if the user wants to return an xv=
alue, they should write return std::forward(...). I'm also tempted to say t=
hat returning the name of an rvalue reference should be a copy elision case=
, but this needs further study. (I'm out on a limb, but given these two res=
olutions, then the code would work perfectly.)

Aside from named rvalue references, a policy of prvalue accessors will indu=
ce decltype(auto) to return by prvalue as well.

> Breaking the connection between lifetime of object and lifetime of expres=
sion that should reference for subobject is not good think.

The question is whether or not to reference a subobject of an xvalue at all=
.. An xvalue is usually assumed to be invalidated by the first thing to happ=
en to it, usually any time between getting bound to a parameter and the sem=
icolon. Once it's passed, we don't care what happens to it. Subobjects/comp=
onents of xvalues devolving to prvalues preserves this rule, because there =
is never an actual reference to a subobject in the first place.

> My personal opinion:
>=20
>   The only argument for T value()&& presented in this tread was that it w=
ill make auto&& cs =3D f().value() work, but will cause performance downgra=
de in other parts of code,

Maybe this is what came through the presentation of examples, but the core =
argument is the principle that an xvalue is dead (and reusable) once it goe=
s into any function. I don't think libraries scale well with any other rule=
, although functions that "only" perform access do intuitively seem special=
..

--=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=_A140FED6-ED88-4EAA-B521-AB8B212D20B8
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=ISO-8859-1

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dwindows-1252"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-=
mode: space; -webkit-line-break: after-white-space;"><br><div><div>On 2014&=
ndash;07&ndash;12, at 5:10 PM, <a href=3D"mailto:tomaszkam@gmail.com">tomas=
zkam@gmail.com</a> wrote:</div><br class=3D"Apple-interchange-newline"><blo=
ckquote type=3D"cite"><div style=3D"font-family: Helvetica; font-size: 12px=
; font-style: normal; font-variant: normal; font-weight: normal; letter-spa=
cing: normal; line-height: normal; orphans: auto; text-align: start; text-i=
ndent: 0px; text-transform: none; white-space: normal; widows: auto; word-s=
pacing: 0px; -webkit-text-stroke-width: 0px;"><div dir=3D"ltr"><div>&nbsp; =
3. Value r-value overload for operator[]: In the<span class=3D"Apple-conver=
ted-space">&nbsp;</span><span style=3D"font-family: 'courier new', monospac=
e;">decltype(auto) get_fifth_thing(container_handle &amp;&amp; ch)</span><s=
pan class=3D"Apple-converted-space">&nbsp;</span>the<span style=3D"font-fam=
ily: 'courier new', monospace;">auto &amp;&amp; fifth_thing =3D=3D ( * std:=
:forward&lt; container_handle &gt;( ch ) )[ 5 ];<span class=3D"Apple-conver=
ted-space">&nbsp;</span></span>will cause fifth_thing to be type of<br>&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp; T&amp;&amp;, meaning the return type of function=
 will be reference and that will cause<span class=3D"Apple-converted-space"=
>&nbsp;</span><font face=3D"Courier">auto &amp;&amp; fifth_thing =3D</font>=
<span style=3D"font-family: 'courier new', monospace;">get_fifth_thing(</sp=
an><span style=3D"font-family: 'courier new', monospace;">std::forward&lt; =
container_handle &gt;( ch))</span><span class=3D"Apple-converted-space">&nb=
sp;</span>to be a dangling reference. The code will be broken by this trans=
ormation.<br></div></div></div></blockquote><div><br></div><div>Actually, t=
he program is ill-formed because the name&nbsp;<font face=3D"Courier">fifth=
_thing</font> is an lvalue and it will not bind to the returned rvalue refe=
rence. If it were changed to <font face=3D"Courier">std::forward&lt; declty=
pe( fifth_thing ) &gt;( fifth_thing )</font>, then your argument holds, but=
 that&rsquo;s not realistically intuitive. If the problem is instead fixed =
by changing the return type to&nbsp;<font face=3D"Courier">auto</font>&nbsp=
;(since only special&nbsp;<font face=3D"Courier">move</font>&nbsp;and&nbsp;=
<font face=3D"Courier">forward</font>&nbsp;functions should return xvalues)=
 then my argument holds, but then the user gets one or two copies (only zer=
o or one if they think to <font face=3D"Courier">std::move( fifth_thing )</=
font>).</div><div><br></div><div>This interaction between <font face=3D"Cou=
rier">decltype(auto)</font> and a named rvalue reference sounds like fodder=
 for a core DR. It&rsquo;s nasty regardless of library policies, and consid=
ering that a diagnostic is already required, it&rsquo;s fixable. The safe s=
olution, considering the possibility of a bound temporary, is to deduce a n=
on-reference type (return a prvalue), and if the user wants to return an xv=
alue, they should write <font face=3D"Courier">return std::forward(&hellip;=
)</font>. I&rsquo;m also tempted to say that returning the name of an rvalu=
e reference should be a copy elision case, but this needs further study. (I=
&rsquo;m out on a limb, but given these two resolutions, then the code woul=
d work perfectly.)</div><div><br></div><div>Aside from named rvalue referen=
ces, a policy of prvalue accessors will induce <font face=3D"Courier">declt=
ype(auto)</font> to return by prvalue as well.</div><div><br></div><blockqu=
ote type=3D"cite"><div style=3D"font-family: Helvetica; font-size: 12px; fo=
nt-style: normal; font-variant: normal; font-weight: normal; letter-spacing=
: normal; line-height: normal; orphans: auto; text-align: start; text-inden=
t: 0px; text-transform: none; white-space: normal; widows: auto; word-spaci=
ng: 0px; -webkit-text-stroke-width: 0px;"><div dir=3D"ltr"><div>Breaking th=
e connection between lifetime of object and lifetime of expression that sho=
uld reference for subobject is not good think.<br></div></div></div></block=
quote><div><br></div><div>The question is whether or not to reference a sub=
object of an xvalue at all. An xvalue is usually assumed to be invalidated =
by the first thing to happen to it, usually any time between getting bound =
to a parameter and the semicolon. Once it&rsquo;s passed, we don&rsquo;t ca=
re what happens to it. Subobjects/components of xvalues devolving to prvalu=
es preserves this rule, because there is never an actual reference to a sub=
object in the first place.</div><div><br></div><blockquote type=3D"cite"><d=
iv style=3D"font-family: Helvetica; font-size: 12px; font-style: normal; fo=
nt-variant: normal; font-weight: normal; letter-spacing: normal; line-heigh=
t: normal; orphans: auto; text-align: start; text-indent: 0px; text-transfo=
rm: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-tex=
t-stroke-width: 0px;"><div dir=3D"ltr"><div>My personal opinion:<br><br>&nb=
sp; The only argument for T value()&amp;&amp; presented in this tread was t=
hat it will make auto&amp;&amp; cs =3D f().value() work, but will cause per=
formance downgrade in other parts of code, </div></div></div></blockquote><=
div><br></div><div>Maybe this is what came through the presentation of exam=
ples, but the core argument is the principle that an xvalue is dead (and re=
usable) once it goes into any function. I don&rsquo;t think libraries scale=
 well with any other rule, although functions that &ldquo;only&rdquo; perfo=
rm access do intuitively seem special.</div><div><br></div></div></body></h=
tml>

<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=_A140FED6-ED88-4EAA-B521-AB8B212D20B8--

.
