220 11803 <A02F32A1-295C-44BA-9EB7-00C5B9B89A4C@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 19:12:42 +0800
Lines: 160
Approved: news@gmane.org
Message-ID: <A02F32A1-295C-44BA-9EB7-00C5B9B89A4C@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> <072cf8b4-4c74-438e-9999-0aab13bf3182@isocpp.org>
 <74CEDDAC-1B1B-4F06-9E58-2F025921FE55@gmail.com> <c09b91d2-e63f-4a58-954b-de49dac643de@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=_E9E7CE9F-821B-476B-9720-FAD3FC0F878E"
X-Trace: ger.gmane.org 1404990787 6401 80.91.229.3 (10 Jul 2014 11:13:07 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Thu, 10 Jul 2014 11:13:07 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCW25A7E3QCRBOPK7GOQKGQEL6FMMHA@isocpp.org Thu Jul 10 13:13:00 2014
Return-path: <std-proposals+bncBCW25A7E3QCRBOPK7GOQKGQEL6FMMHA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-yh0-f71.google.com ([209.85.213.71])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCW25A7E3QCRBOPK7GOQKGQEL6FMMHA@isocpp.org>)
	id 1X5CHa-0003nn-DR
	for gclcip-std-proposals@m.gmane.org; Thu, 10 Jul 2014 13:12:58 +0200
Original-Received: by mail-yh0-f71.google.com with SMTP id t59sf34965659yho.6
        for <gclcip-std-proposals@m.gmane.org>; Thu, 10 Jul 2014 04:12: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=+UIi2VkB6n+J/058dhSOF/k65o5GUsgLalLCSLa0Sh8=;
        b=Ph3qjOcR3IX2N1Wa9b33PidJFuH0OaXIuiLsAnFCEwzpDZv/gP0FVDItC+otCbFL58
         rx1MmvYe81WQIYj38hiA/0TfP8zNPa59NfRDAwQGW/ltDYTDhNCttsHh7UaO6tuWugwL
         M3sIM3iiMJj7pAcpVCO6j6Uh7iPKrmFAJouQCMS2HBcalRAnYtlGlGpgnuXKrqxFrzr5
         Mte44gxumP/1i+1t4ld0cvi/3DelU10Xk2vl+Ie+DRRS9+O/BoibLXTTURrLOC1nTHnV
         tC9ZY5nxXgTBdXbOZDyMN49nsX+f5I/kvZYLpY3fEs8MHmgjKBZBzH3DWkhQzCDx5axR
         flYg==
X-Gm-Message-State: ALoCoQnpFMlFuhdcWVI9niPmVhgZHPlJeO1kg177mj40JePRREbzwjGQp46Jq6v3dKx6wXVSuNKz
X-Received: by 10.224.72.74 with SMTP id l10mr22473708qaj.4.1404990777564;
        Thu, 10 Jul 2014 04:12:57 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.50.97.4 with SMTP id dw4ls113123igb.10.gmail; Thu, 10 Jul 2014
 04:12:56 -0700 (PDT)
X-Received: by 10.42.51.204 with SMTP id f12mr55662021icg.21.1404990776848;
        Thu, 10 Jul 2014 04:12:56 -0700 (PDT)
Original-Received: from mail-ig0-x236.google.com (mail-ig0-x236.google.com [2607:f8b0:4001:c05::236])
        by mx.google.com with ESMTPS id z3si3044536icw.105.2014.07.10.04.12.56
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Thu, 10 Jul 2014 04:12:56 -0700 (PDT)
Received-SPF: pass (google.com: domain of potswa@gmail.com designates 2607:f8b0:4001:c05::236 as permitted sender) client-ip=2607:f8b0:4001:c05::236;
Original-Received: by mail-ig0-f182.google.com with SMTP id c1so2929120igq.9
        for <std-proposals@isocpp.org>; Thu, 10 Jul 2014 04:12:56 -0700 (PDT)
X-Received: by 10.50.129.104 with SMTP id nv8mr20960626igb.45.1404990776720;
        Thu, 10 Jul 2014 04:12:56 -0700 (PDT)
Original-Received: from [172.20.10.2] ([121.54.54.43])
        by mx.google.com with ESMTPSA id d10sm24229012igz.11.2014.07.10.04.12.52
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Thu, 10 Jul 2014 04:12:56 -0700 (PDT)
In-Reply-To: <c09b91d2-e63f-4a58-954b-de49dac643de@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::236 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:11803
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/11803>

--Apple-Mail=_E9E7CE9F-821B-476B-9720-FAD3FC0F878E
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8


On 2014=E2=80=9307=E2=80=9310, at 6:24 PM, tomaszkam@gmail.com wrote:

> W dniu czwartek, 10 lipca 2014 12:00:56 UTC+2 u=C5=BCytkownik David Kraus=
s napisa=C5=82:
>=20
> forward_component trusts the user that the function argument is owned by =
an object of the template argument type. It handles vector::front and uniqu=
e_ptr::operator* with equal aplomb, and we don=E2=80=99t even have to add r=
value reference overloads to anything. (Although doing so may still be a go=
od idea.)
>=20
> And this wis actually break every use of forward with non-owning semenati=
cs (shared_ptr<T>). Please remember that forward function was designed to p=
erfectly forward value of any type in generic context without introspection=
, but introducing separate forward_compoent kills the idea, because we me d=
ifferentiate between shared_ptr and unique_ptr.

Shared ownership fails to satisfy the stated requirement. No suitable forwa=
rding semantics exist for shared_ptr, and the value category of the pointer=
 carries no information about the shared object. You just have to assume th=
at it=E2=80=99s not-owned, unless shared_ptr::unique returns true, in which=
 case forward_component works.

No =E2=80=9Cgeneric context=E2=80=9D can handle different pointer types. un=
ique_ptr<T> always owns its referent but T* never does. You seem to suggest=
 I=E2=80=99ve =E2=80=9Ckilled=E2=80=9D an alternative that never existed in=
 the first place.

Yes, it=E2=80=99s impossible to call make_shared, destroy the sharing pool,=
 and still safely bind the erstwhile-shared value to a universal reference =
all in one declaration. This sounds pretty contrived, though. Use of shared=
_ptr at all implies that the object existed before the line in question, an=
d if you want to continue using a subobject after the line, don=E2=80=99t m=
ove() the shared_pointer.

> Acutally defininig the rvalue reference overload for member getters retur=
ning rvalue reference (T&& meber() &&) is the way a type can signialize to =
forward that it owning this member. That means we could have:
> T&& operator*() &&; //for unique_ptr, bot not for shared_ptr
> Or for vector<T>:
> T&& front() &&;
> T&& back() &&;
> Or even for begin/end members that will allows us to have better traversa=
ble constructor: https://groups.google.com/a/isocpp.org/forum/?fromgroups#!=
topic/std-proposals/sOw68ogy6BM

Yes, I mentioned that hypothetically to Ville. Considering the implementati=
on effort and added compilation complexity of that strategy, you might as w=
ell use forward_component() with no adjustment to the container (or plain-o=
ld move() when not forwarding).

> Now const&& should have the same semenantics as the const& so the additio=
n overload is not necessary.

Strange, I didn=E2=80=99t realize that const& is preferred over && for a co=
nst rvalue implicit argument, but so it is. GCC even fails to prefer const&=
& over const&.

--=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=_E9E7CE9F-821B-476B-9720-FAD3FC0F878E
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 6:24 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">W dniu czwartek, 10 lipca 2014 12:00:=
56 UTC+2 u=C5=BCytkownik David Krauss napisa=C5=82:<br><blockquote class=3D=
"gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex; border-left-width: 1px; b=
order-left-color: rgb(204, 204, 204); border-left-style: solid; padding-lef=
t: 1ex; position: static; z-index: auto;"><div style=3D"word-wrap:break-wor=
d"><br><div><div><font face=3D"Courier">forward_component</font> trusts the=
 user that the function argument is owned by an object of the template argu=
ment type. It handles <font face=3D"Courier">vector::front</font>&nbsp;and =
<font face=3D"Courier">unique_ptr::operator*</font> with equal aplomb, and =
we don=E2=80=99t even have to add rvalue reference overloads to anything. (=
Although doing so may still be a good idea.)</div></div></div></blockquote>=
<div><br>And this wis actually break every use of forward with non-owning s=
emenatics (shared_ptr&lt;T&gt;). Please remember that forward function was =
designed to perfectly forward value of any type in generic context without =
introspection, but introducing separate forward_compoent kills the idea, be=
cause we me differentiate between shared_ptr and unique_ptr.<br></div></div=
></blockquote><div><br></div><div>Shared ownership fails to satisfy the sta=
ted requirement. No suitable forwarding semantics exist for <font face=3D"C=
ourier">shared_ptr</font>, and the value category of the pointer carries no=
 information about the shared object. You just have to assume that it=E2=80=
=99s not-owned, unless <font face=3D"Courier">shared_ptr::unique</font> ret=
urns true, in which case <font face=3D"Courier">forward_component</font> wo=
rks.</div><div><br></div><div><div>No =E2=80=9Cgeneric context=E2=80=9D can=
 handle different pointer types.&nbsp;<font face=3D"Courier">unique_ptr&lt;=
T&gt;</font>&nbsp;always owns its referent but&nbsp;<font face=3D"Courier">=
T*</font>&nbsp;never does. You seem to suggest I=E2=80=99ve =E2=80=9Ckilled=
=E2=80=9D an alternative that never existed in the first place.</div><div><=
br></div></div><div>Yes, it=E2=80=99s impossible to call <font face=3D"Cour=
ier">make_shared</font>, destroy the sharing pool, and still safely bind th=
e erstwhile-shared value to a universal reference all in one declaration. T=
his sounds pretty contrived, though. Use of <font face=3D"Courier">shared_p=
tr</font> at all implies that the object existed before the line in questio=
n, and if you want to continue using a subobject after the line, don=E2=80=
=99t <font face=3D"Courier">move()</font> the <font face=3D"Courier">shared=
_pointer</font>.</div><div><br></div><blockquote type=3D"cite"><div dir=3D"=
ltr"><div>Acutally defininig the rvalue reference overload for member gette=
rs returning rvalue reference (T&amp;&amp; meber() &amp;&amp;) is the way a=
 type can signialize to forward that it owning this member. That means we c=
ould have:<br>T&amp;&amp; operator*() &amp;&amp;; //for unique_ptr, bot not=
 for shared_ptr<br>Or for vector&lt;T&gt;:<br>T&amp;&amp; front() &amp;&amp=
;;<br>T&amp;&amp; back() &amp;&amp;;<br>Or even for begin/end members that =
will allows us to have better traversable constructor: <a href=3D"https://g=
roups.google.com/a/isocpp.org/forum/?fromgroups#!topic/std-proposals/sOw68o=
gy6BM">https://groups.google.com/a/isocpp.org/forum/?fromgroups#!topic/std-=
proposals/sOw68ogy6BM</a><br></div></div></blockquote><div><br></div><div>Y=
es, I mentioned that hypothetically to Ville. Considering the implementatio=
n effort and added compilation complexity of that strategy, you might as we=
ll use <font face=3D"Courier">forward_component()</font>&nbsp;with no adjus=
tment to the container (or plain-old&nbsp;<font face=3D"Courier">move()</fo=
nt> when not forwarding).</div><br><blockquote type=3D"cite"><div dir=3D"lt=
r"><div>Now const&amp;&amp; should have the same semenantics as the const&a=
mp; so the addition overload is not necessary.</div></div></blockquote><div=
><br></div><div>Strange, I didn=E2=80=99t realize that <font face=3D"Courie=
r">const&amp;</font> is preferred over <font face=3D"Courier">&amp;&amp;</f=
ont> for a <font face=3D"Courier">const</font> rvalue implicit argument, bu=
t so it is. GCC even fails to prefer <font face=3D"Courier">const&amp;&amp;=
</font> over <font face=3D"Courier">const&amp;</font>.</div></div><br></bod=
y></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=_E9E7CE9F-821B-476B-9720-FAD3FC0F878E--

.
