220 11778 <66AF41C1-CB37-4311-98EA-D47DBC6068DC@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 13:48:17 +0800
Lines: 109
Approved: news@gmane.org
Message-ID: <66AF41C1-CB37-4311-98EA-D47DBC6068DC@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>
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=_A330A76D-647A-412A-B8F6-CB5E58257283"
X-Trace: ger.gmane.org 1404971316 6254 80.91.229.3 (10 Jul 2014 05:48:36 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Thu, 10 Jul 2014 05:48:36 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCW25A7E3QCRBLGS7COQKGQEYEX72DY@isocpp.org Thu Jul 10 07:48:30 2014
Return-path: <std-proposals+bncBCW25A7E3QCRBLGS7COQKGQEYEX72DY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-yh0-f70.google.com ([209.85.213.70])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCW25A7E3QCRBLGS7COQKGQEYEX72DY@isocpp.org>)
	id 1X57DZ-000268-Ow
	for gclcip-std-proposals@m.gmane.org; Thu, 10 Jul 2014 07:48:30 +0200
Original-Received: by mail-yh0-f70.google.com with SMTP id a41sf33738791yho.9
        for <gclcip-std-proposals@m.gmane.org>; Wed, 09 Jul 2014 22:48:28 -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=MShBuRKueb3+Ckto5PzUNyu6EKKA6U9wNwHImKhiD8I=;
        b=E7awtGXcFklBkPGGudyDT9W6093AEUUxnX/0YOeOJvZtGCjrQCdafzenni7RbU+c4N
         3X/ZN71Rxq8OsAY3pugpiZfo0WgTeKOMSFihS/AGSHP1gLXpg5dbopCrwEHhtv0UF435
         6KyuWPBrT7VcYJwGnl2LNJvX2T9xnh4PpIQP0/cXcecrnBop7Y5es9vBgku9434li9oY
         i8j+PsC2woEz7qD+PRBFaZWHaTZBMFDw27zonK9g/fWWj5Yks1KlmgFkpvpWVrUPjrtK
         JSlRNIQzwiBvY3ga8DAH5yTGKv7q8MFNUI7/9Kol5i/xYGBzBp9HweDXsPUfMAj6NB+j
         dLUg==
X-Gm-Message-State: ALoCoQlxCAsPkSx+TCPN+7TS4xFQWa+SWGLyC9z4+gxOmsSc9Zbw8Gdyu4CFx9gxy8XNanGnAaHB
X-Received: by 10.58.19.227 with SMTP id i3mr21226108vee.2.1404971308827;
        Wed, 09 Jul 2014 22:48:28 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.50.79.135 with SMTP id j7ls1291217igx.20.gmail; Wed, 09 Jul
 2014 22:48:28 -0700 (PDT)
X-Received: by 10.42.11.74 with SMTP id t10mr50743971ict.27.1404971308158;
        Wed, 09 Jul 2014 22:48:28 -0700 (PDT)
Original-Received: from mail-ig0-x232.google.com (mail-ig0-x232.google.com [2607:f8b0:4001:c05::232])
        by mx.google.com with ESMTPS id is10si6559873igb.20.2014.07.09.22.48.28
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Wed, 09 Jul 2014 22:48:28 -0700 (PDT)
Received-SPF: pass (google.com: domain of potswa@gmail.com designates 2607:f8b0:4001:c05::232 as permitted sender) client-ip=2607:f8b0:4001:c05::232;
Original-Received: by mail-ig0-f178.google.com with SMTP id hn18so2707756igb.17
        for <std-proposals@isocpp.org>; Wed, 09 Jul 2014 22:48:28 -0700 (PDT)
X-Received: by 10.50.111.132 with SMTP id ii4mr19371159igb.18.1404971308000;
        Wed, 09 Jul 2014 22:48:28 -0700 (PDT)
Original-Received: from [172.20.10.2] ([121.54.54.63])
        by mx.google.com with ESMTPSA id qa4sm22168495igb.10.2014.07.09.22.48.25
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Wed, 09 Jul 2014 22:48:27 -0700 (PDT)
In-Reply-To: <1a858a77-310b-4591-aaf5-960c40d9f5fc@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:c05::232 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: <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:11778
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/11778>

--Apple-Mail=_A330A76D-647A-412A-B8F6-CB5E58257283
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8


On 2014=E2=80=9307=E2=80=9310, at 1:11 PM, tomaszkam@gmail.com wrote:

> W dniu czwartek, 10 lipca 2014 01:17:39 UTC+2 u=C5=BCytkownik David Kraus=
s napisa=C5=82:
>=20
> auto && has some strong proponents, and although nothing is a silver bull=
et, 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 messages=
 indicate, is a problem to be fixed.

> 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 rv=
alue. 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 o=
verloads.

I think you mean f().front(). As per this thread, or maybe it=E2=80=99s jus=
t my extrapolation, the solution is to add an rvalue-ref qualified overload=
 returning by value.

As a very general policy in C++ library design, every accessor to a strictl=
y owned resource should be lvalue-qualified and/or return by value. This be=
st practice should be applied across the standard library.

> The whole discussion is about that the changes was made to the optional<T=
> that makes following work correctly in cost on introducing temporaries in=
 other places:

Whether returning a direct member or something owned elsewhere, methods of =
an xvalue should always return by value. If a temporary might be introduced=
 elsewhere, correctness is always worth the cost =E2=80=94 and copy elision=
 will probably eliminate it anyway.

--=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=_A330A76D-647A-412A-B8F6-CB5E58257283
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 1:11 PM, <a href=3D"mailto:tomaszkam@gmail.com">tomasz=
kam@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 Kraus=
s napisa=C5=82:<blockquote class=3D"gmail_quote" style=3D"margin: 0px 0px 0=
px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); bo=
rder-left-style: solid; padding-left: 1ex; position: static; z-index: auto;=
"><div style=3D"word-wrap:break-word"><br><div><div><font face=3D"Courier">=
auto &amp;&amp;</font> has some strong proponents, and although nothing is =
a silver bullet, it will always work except when a function returns an rval=
ue reference =E2=80=94 which, as the title of this thread and most of the e=
arly messages indicate, is a problem to be fixed.</div></div></div></blockq=
uote></div></blockquote><br><blockquote type=3D"cite"><div dir=3D"ltr"><div=
>No, the auto&amp;&amp; does not work with any function that return a any k=
ind of reference to subobject of it parameter (including this) is invoked o=
n an rvalue. In the examples above you my find:<br>std::vector&lt;std::stri=
ng&gt; f();<br>auto&amp;&amp; s =3D f.front();<br>//This creates a dangling=
 lvalue reference, and front() has not r-value overloads.<br></div></div></=
blockquote><div><br></div><div>I think you mean <font face=3D"Courier">f().=
front()</font>. As per this thread, or maybe it=E2=80=99s just my extrapola=
tion, the solution is to add an rvalue-ref qualified overload returning by =
value.</div><div><br></div><div>As a very general policy in C++ library des=
ign, every accessor to a strictly owned resource should be lvalue-qualified=
 and/or return by value. This best practice should be applied across the st=
andard library.</div><div><br></div><blockquote type=3D"cite"><div dir=3D"l=
tr"><div>The whole discussion is about that the changes was made to the opt=
ional&lt;T&gt; that makes following work correctly in cost on introducing t=
emporaries in other places:<br></div></div></blockquote><div><br></div></di=
v>Whether returning a direct member or something owned elsewhere, methods o=
f an xvalue should always return by value. If a temporary might be introduc=
ed elsewhere, correctness is always worth&nbsp;the cost&nbsp;=E2=80=94 and =
copy elision will probably eliminate it anyway.<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=_A330A76D-647A-412A-B8F6-CB5E58257283--

.
