220 11797 <A46ADDB4-C9B0-4163-81BE-900CD879D8C8@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 16:58:29 +0800
Lines: 146
Approved: news@gmane.org
Message-ID: <A46ADDB4-C9B0-4163-81BE-900CD879D8C8@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>
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=_21E15F34-7244-4CA2-97E4-8D9FDF9F6CD9"
X-Trace: ger.gmane.org 1404982732 4912 80.91.229.3 (10 Jul 2014 08:58:52 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Thu, 10 Jul 2014 08:58:52 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCW25A7E3QCRBP5L7GOQKGQE2OS2SYI@isocpp.org Thu Jul 10 10:58:45 2014
Return-path: <std-proposals+bncBCW25A7E3QCRBP5L7GOQKGQE2OS2SYI@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+bncBCW25A7E3QCRBP5L7GOQKGQE2OS2SYI@isocpp.org>)
	id 1X5ABd-0003sH-Bo
	for gclcip-std-proposals@m.gmane.org; Thu, 10 Jul 2014 10:58:41 +0200
Original-Received: by mail-ob0-f197.google.com with SMTP id uz6sf46982278obc.4
        for <gclcip-std-proposals@m.gmane.org>; Thu, 10 Jul 2014 01:58:40 -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=7UQYBXQfBRDzxmYQxM/ISguj+KxUY8uc5+lF8juzdxw=;
        b=gGqR+IvEQYW0KrU4wO2yZCH7SIKlw+X9U/8ouRWGE4ENowudYf6p2HUMZkHSwHfTQg
         eIdLu16X2SXm4qflnhJngUTIpRDXz7Ll6SwGgLPzjMG8GgW0oaKKUH/mSBxLtLWpETXe
         ioPd0Z8S+vmvEaAQipGI5irqVkt7DJpCtkUlAefIJoqcfnF+IyOT8xpYX5HMabkP8h97
         BN+Znd4Iox1+BTCTigriLtgdJFMTsCdW4D8nMSBuQ5RsT58m55OItFo3GfG8cFZPytRL
         +8kaCgaUoGvfKn8DAs+9mhslaeJoI5qXcENcz23IbaADdIGjUQ92CYnqJ34iUeY+gkvU
         4TLQ==
X-Gm-Message-State: ALoCoQlOCehBJIMKjQTY1i95uXr6Duk3TFlH36OXjIWa2EfCwSPBEM3y2yXLohA8nKfusc8z6muq
X-Received: by 10.43.92.195 with SMTP id br3mr22142939icc.1.1404982720254;
        Thu, 10 Jul 2014 01:58:40 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.50.138.38 with SMTP id qn6ls1458053igb.28.canary; Thu, 10 Jul
 2014 01:58:39 -0700 (PDT)
X-Received: by 10.43.179.73 with SMTP id oz9mr52534120icc.18.1404982719540;
        Thu, 10 Jul 2014 01:58:39 -0700 (PDT)
Original-Received: from mail-ig0-x22a.google.com (mail-ig0-x22a.google.com [2607:f8b0:4001:c05::22a])
        by mx.google.com with ESMTPS id h11si21379558icl.65.2014.07.10.01.58.39
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Thu, 10 Jul 2014 01:58:39 -0700 (PDT)
Received-SPF: pass (google.com: domain of potswa@gmail.com designates 2607:f8b0:4001:c05::22a as permitted sender) client-ip=2607:f8b0:4001:c05::22a;
Original-Received: by mail-ig0-f170.google.com with SMTP id h15so2842897igd.1
        for <std-proposals@isocpp.org>; Thu, 10 Jul 2014 01:58:39 -0700 (PDT)
X-Received: by 10.50.137.73 with SMTP id qg9mr19893181igb.19.1404982719400;
        Thu, 10 Jul 2014 01:58:39 -0700 (PDT)
Original-Received: from [172.20.10.2] ([121.54.54.43])
        by mx.google.com with ESMTPSA id qa4sm23377385igb.10.2014.07.10.01.58.37
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Thu, 10 Jul 2014 01:58:38 -0700 (PDT)
In-Reply-To: <CAFk2RUZigiwLwFpfVXuFS8cqy38hPG3OGhGUi+iNwSYuYvyAyQ@mail.gmail.com>
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::22a 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:11797
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/11797>

--Apple-Mail=_21E15F34-7244-4CA2-97E4-8D9FDF9F6CD9
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=ISO-8859-1


On 2014-07-10, at 2:49 PM, Ville Voutilainen <ville.voutilainen@gmail.com> =
wrote:

> On 10 July 2014 09:41, David Krauss <potswa@gmail.com> wrote:
>> If you're going to iterate over a sequence within a container, but you g=
ot
>> the first iterator from an xvalue, then the sequence is presumed to be d=
ead
>> by the first statement in the loop.
>=20
> The sequence is not dead if I pass the iterator onto a processing functio=
n
> before the xvalue expires. Which is precisely what the general forwarding=
 cases
> do, and what emplace does.

Passing an iterator with the guarantee that the function will not retain a =
reference into the sequence is fine, but that doesn't lend meaning to std::=
forward< Container >( container ).begin(). If the container is still expect=
ed to be valid at the semicolon, then do not move/forward. If the sequence =
algorithm is supposed to move-from the sequence, then use a std::move_itera=
tor instead. Perhaps there's a use-case for a std::forward_iterator (perhap=
s just as an alias template) but I don't see that following directly from w=
hat you've suggested so far.

I'd still like to see an example of what begin() on an xvalue is supposed t=
o accomplish.

>> The example is in this thread, as has been said multiple times already.
>> https://groups.google.com/a/isocpp.org/d/msg/std-proposals/jDRQyBWYl8Q/i=
LJFlolCOBgJ
>>=20
>>=20
>> That's just a link to this thread, to a message containing another link.=
 The
>> text begin() does not occur in that thread.
>=20
> Yeah, well, that message shows the "forwarding scenario".

OK, I'll try to parse it. It doesn't relate to a sequence. The function nam=
e means nothing. The point is simply that returning a reference avoids movi=
ng through a temporary in this case, so what? This isn't the kind of justif=
ication and writeup that I'd expect for something as broad as a library-wid=
e policy about the interaction of value category with function returns. (Th=
e author clearly didn't have such grand intent, to be fair.)

Risky micro-optimization should never be the default. If forward-by-referen=
ce returns are sometimes desired for performance, then add them under a fun=
ction name like forward_*() or provide a suitable additional sibling to std=
::forward() to handle such cases. Do not foist the hack on everyone.

Function returns should have predictable value category, whatever your pref=
erence for safety vs. speed. If the function specification must depend on p=
erformance, then the correct standard library specification would be to lea=
ve it implementation-defined. However, it's a false dichotomy because you c=
an always introduce a new name for new behavior.

--=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=_21E15F34-7244-4CA2-97E4-8D9FDF9F6CD9
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;10, at 2:49 PM, Ville Voutilainen &lt;<a href=3D"mailto:vill=
e.voutilainen@gmail.com">ville.voutilainen@gmail.com</a>&gt; wrote:</div><b=
r class=3D"Apple-interchange-newline"><blockquote type=3D"cite">On 10 July =
2014 09:41, David Krauss &lt;<a href=3D"mailto:potswa@gmail.com">potswa@gma=
il.com</a>&gt; wrote:<br><blockquote type=3D"cite">If you&rsquo;re going to=
 iterate over a sequence within a container, but you got<br>the first itera=
tor from an xvalue, then the sequence is presumed to be dead<br>by the firs=
t statement in the loop.<br></blockquote><br>The sequence is not dead if I =
pass the iterator onto a processing function<br>before the xvalue expires. =
Which is precisely what the general forwarding cases<br>do, and what emplac=
e does.<br></blockquote><div><br></div><div>Passing an iterator with the gu=
arantee that the function will not retain a reference into the sequence is =
fine, but that doesn&rsquo;t lend meaning to <font face=3D"Courier">std::fo=
rward&lt; Container &gt;( container ).begin()</font>. If the container is s=
till expected to be valid at the semicolon, then do not move/forward. If th=
e sequence algorithm is supposed to move-from the sequence, then use a <fon=
t face=3D"Courier">std::move_iterator</font> instead. Perhaps there&rsquo;s=
 a use-case for a <font face=3D"Courier">std::forward_iterator</font>&nbsp;=
(perhaps just as an alias template) but I don&rsquo;t see that following di=
rectly from what you&rsquo;ve suggested so far.</div><div><br></div><div>I&=
rsquo;d still like to see an example of what <font face=3D"Courier">begin()=
</font> on an xvalue is supposed to accomplish.</div><br><blockquote type=
=3D"cite"><blockquote type=3D"cite">The example is in this thread, as has b=
een said multiple times already.<br><a href=3D"https://groups.google.com/a/=
isocpp.org/d/msg/std-proposals/jDRQyBWYl8Q/iLJFlolCOBgJ">https://groups.goo=
gle.com/a/isocpp.org/d/msg/std-proposals/jDRQyBWYl8Q/iLJFlolCOBgJ</a><br><b=
r><br>That&rsquo;s just a link to this thread, to a message containing anot=
her link. The<br>text begin() does not occur in that thread.<br></blockquot=
e><br>Yeah, well, that message shows the "forwarding scenario&rdquo;.<br></=
blockquote><div><br></div><div>OK, I&rsquo;ll try to parse it. It doesn&rsq=
uo;t relate to a sequence. The function name means nothing. The point is si=
mply that returning a reference avoids moving through a temporary in this c=
ase, so what? This isn&rsquo;t the kind of justification and writeup that I=
&rsquo;d expect for something as broad as a library-wide policy about the i=
nteraction of value category with function returns. (The author clearly did=
n&rsquo;t have such grand intent, to be fair.)</div><div><br></div><div>Ris=
ky micro-optimization should never be the default. If forward-by-reference =
returns are sometimes desired for performance, then add them under a functi=
on name like <font face=3D"Courier">forward_*()</font>&nbsp;or provide a su=
itable additional sibling to&nbsp;<font face=3D"Courier">std::forward()</fo=
nt> to handle such cases. Do not foist the hack on everyone.</div><div><br>=
</div><div>Function returns should have predictable value category, whateve=
r your preference for safety vs. speed. If the function specification must =
depend on performance, then the correct standard library specification woul=
d be to leave it implementation-defined. However, it&rsquo;s a false dichot=
omy because you can always introduce a new name for new behavior.</div><div=
><br></div></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=_21E15F34-7244-4CA2-97E4-8D9FDF9F6CD9--

.
