220 11802 <c09b91d2-e63f-4a58-954b-de49dac643de@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: tomaszkam@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 03:24:50 -0700 (PDT)
Lines: 225
Approved: news@gmane.org
Message-ID: <c09b91d2-e63f-4a58-954b-de49dac643de@isocpp.org>
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>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_49_17651027.1404987890892"
X-Trace: ger.gmane.org 1404987902 4958 80.91.229.3 (10 Jul 2014 10:25:02 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Thu, 10 Jul 2014 10:25:02 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDNPVXXG6IGBB5GT7GOQKGQEVY4ZYHQ@isocpp.org Thu Jul 10 12:24:55 2014
Return-path: <std-proposals+bncBDNPVXXG6IGBB5GT7GOQKGQEVY4ZYHQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-qa0-f72.google.com ([209.85.216.72])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDNPVXXG6IGBB5GT7GOQKGQEVY4ZYHQ@isocpp.org>)
	id 1X5BX3-0004lX-PR
	for gclcip-std-proposals@m.gmane.org; Thu, 10 Jul 2014 12:24:54 +0200
Original-Received: by mail-qa0-f72.google.com with SMTP id s7sf8960223qap.7
        for <gclcip-std-proposals@m.gmane.org>; Thu, 10 Jul 2014 03:24:52 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe
         :content-type;
        bh=cKToDHbN92bxjpvFZWjzqnBoaE5f9yRAyTmAqUwXhXQ=;
        b=BrqfWmBgYn/xrnz83g16FxClxr9KBusdyz7dF773nrxZekmsu4Q2hQL9xprdhMiv9+
         DPSJ1DLgbzb9bE75J52Q/ZIj+/BjOKtpel3Qj06zXyA9Rbp5tiNcpID+kqTfNiiKQuGR
         EZqZ+zaGQtiCh1TB9J/DBb2LTrVhvrbobqPOsr5b6oWfy0CZ9ABhVqCRwTsn2ArRSBKU
         NzUKvJYRvZaKG2D2Zs91UYOUlxlExAzu+EZfL1L/Is9wFYfo7P89eaj28JJCq/tTX6ly
         WiCZge3mfA/7YXP/nMSabxGLACjNowdQg5FBjyST9onpSeV1XKLUPSeIgwyH+VB3C9vd
         u0vQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:date:from:to:message-id:in-reply-to:references
         :subject:mime-version:x-original-sender:reply-to:precedence
         :mailing-list:list-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe:content-type;
        bh=cKToDHbN92bxjpvFZWjzqnBoaE5f9yRAyTmAqUwXhXQ=;
        b=lj/OPvO3xMUZ3msTi4VMb2ZdsD4yR07Gt55PZWGYDa1t2V/BJvHF3qMgl6v0alJIHM
         ZQC0UkutEgJ9Sujh+oDyUXw5KDeA+oDZ1h/O+x8wEGR8ekW7F7uvaH7oV76ySxtwpm2M
         Phl7KaPPWUZUvrRzjwlQmR+liW4u8frF7IiipPX88plOju3F4NrsAOT+BedfLYlbdz81
         lu34MRd/wu1P2XcmOJ0mF2pl196uzIcMgawH53yKWJ4syhkTL+HhQb9e2EJtvysrF1JI
         375FmAPPurVH2QbNq42LaFKCXYMFACct7ZgRkaQImh8vuBAKuj3w4w003Sr5xnIyn1B5
         rz/g==
X-Gm-Message-State: ALoCoQnylr31Hu0H0M73GKtsiVPaX7No38VQpHAEhcxf7slD8O5uf/u5Wwxvkd4QK2AJohYgwR85
X-Received: by 10.236.98.33 with SMTP id u21mr19323952yhf.39.1404987892837;
        Thu, 10 Jul 2014 03:24:52 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.182.181.99 with SMTP id dv3ls24101obc.4.gmail; Thu, 10 Jul
 2014 03:24:51 -0700 (PDT)
X-Received: by 10.182.176.37 with SMTP id cf5mr59466obc.22.1404987891817;
        Thu, 10 Jul 2014 03:24:51 -0700 (PDT)
In-Reply-To: <74CEDDAC-1B1B-4F06-9E58-2F025921FE55@gmail.com>
X-Original-Sender: tomaszkam@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:11802
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/11802>

------=_Part_49_17651027.1404987890892
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable



W dniu czwartek, 10 lipca 2014 12:00:56 UTC+2 u=C5=BCytkownik David Krauss=
=20
napisa=C5=82:
>
>
> On 2014=E2=80=9307=E2=80=9310, at 5:29 PM, toma...@gmail.com <javascript:=
> wrote:
>
> Which makes following invoaction f(expr.value()) where takes T by const&=
=20
> and expr is value of type optional<T>, introducing has additonal=20
> possibly-copy dependin on expr being lvalue or r-value. And makes using=
=20
> optional in generic context when perfect forwardin us used a pain. I=20
> propose to set of methods to look like:
>   T& value() &;
>   T const& value() const &;
>   T&& value() &&;
>  To achieve consistency with std::get function or even simple meber acces=
=20
> with procudes same cateogry value for subobject.
>
>
> Here=E2=80=99s the issue: std::get cannot reliably produce the same value=
 category=20
> as a simple member access, because functions (in C++11, at least) cannot=
=20
> distinguish xvalue arguments from prvalues. A member access on a prvalue=
=20
> produces a prvalue, but a member access get< N >( prvalue() ).mem produce=
s=20
> an xvalue.
>
> Why not put the adjustment into the forwarding function itself?
>
> template< typename owner_type, typename value_type >
> std::enable_if_t< std::is_lvalue_reference< owner_type >::value,
>     value_type & >
> forward_component( value_type & v )
>     { return v; } // Container passed as lvalue yields a reference to=20
> lvalue.
>
> template< typename owner_type, typename value_type >
> std::enable_if_t< ! std::is_lvalue_reference< owner_type >::value,
>     value_type && >
> forward_component( value_type & v )
>     { return std::move( v ); } // Container passed as prvalue or xvalue=
=20
> yields xvalue.
>
> Usage in the example context:
>
>   return u ? std::forward<FV>(fv)(forward_component<U>(*u)) :=20
> std::forward<FN>(fn);
>
> forward_component trusts the user that the function argument is owned by=
=20
> an object of the template argument type. It handles vector::front and=20
> unique_ptr::operator* with equal aplomb, and we don=E2=80=99t even have t=
o add=20
> rvalue reference overloads to anything. (Although doing so may still be a=
=20
> good idea.)
>

And this wis actually break every use of forward with non-owning semenatics=
=20
(shared_ptr<T>). Please remember that forward function was designed to=20
perfectly forward value of any type in generic context without=20
introspection, but introducing separate forward_compoent kills the idea,=20
because we me differentiate between shared_ptr and unique_ptr.

Acutally defininig the rvalue reference overload for member getters=20
returning rvalue reference (T&& meber() &&) is the way a type can=20
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=20
traversable constructor:=20
https://groups.google.com/a/isocpp.org/forum/?fromgroups#!topic/std-proposa=
ls/sOw68ogy6BM

If the original set  of the methods was:
>   T  value() const;
> I would argee tthe the new function should be declared as:
>   T  value() const &;
>   T  value() &&;
> But this is not true in the case of optional. And also not having safe=20
> version of operator* , that will allow you to modyfy value inplace, would=
=20
> be a failure. Maybe the name is wrong.
>
> ?
>
> By the way, you might as well keep the const && overload. =E2=80=9C&&=E2=
=80=9D and =E2=80=9Cconst=20
> &&=E2=80=9D usually have identical semantics. It is possible to have an=
=20
> expression of const class type.
>
> Now const&& should have the same semenantics as the const& so the additio=
n=20
overload is not neccessary.=20
=20

--=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/.

------=_Part_49_17651027.1404987890892
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>W dniu czwartek, 10 lipca 2014 12:00:56 UTC+2 u=C5=
=BCytkownik David Krauss napisa=C5=82:<blockquote class=3D"gmail_quote" sty=
le=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left=
: 1ex;"><div style=3D"word-wrap:break-word"><br><div><div>On 2014=E2=80=930=
7=E2=80=9310, at 5:29 PM, <a href=3D"javascript:" target=3D"_blank" gdf-obf=
uscated-mailto=3D"hCccXhJmq3sJ" onmousedown=3D"this.href=3D'javascript:';re=
turn true;" onclick=3D"this.href=3D'javascript:';return true;">toma...@gmai=
l.com</a> wrote:</div><br><blockquote type=3D"cite"><div dir=3D"ltr">Which =
makes following invoaction f(expr.value()) where takes T by const&amp; and =
expr is value of type optional&lt;T&gt;, introducing has additonal possibly=
-copy dependin on expr being lvalue or r-value. And makes using optional in=
 generic context when perfect forwardin us used a pain. I propose to set of=
 methods to look like:<br>&nbsp;  T&amp; value() &amp;;<br>&nbsp; T const&a=
mp; value() const &amp;;<br>&nbsp; T&amp;&amp; value() &amp;&amp;;<br>&nbsp=
;To achieve consistency with std::get function or even simple meber acces w=
ith procudes same cateogry value for subobject.<br></div></blockquote><div>=
<br></div><div>Here=E2=80=99s the issue: std::get cannot reliably produce t=
he same value category as a simple member access, because functions (in C++=
11, at least) cannot distinguish xvalue arguments from prvalues. A member a=
ccess on a prvalue produces a prvalue, but a member access&nbsp;<font face=
=3D"Courier">get&lt; N &gt;( prvalue() ).mem</font>&nbsp;produces an xvalue=
..</div><div><br></div><div>Why not put the adjustment into the forwarding f=
unction itself?</div><div><br></div><div><font face=3D"Courier">template&lt=
; typename owner_type, typename value_type &gt;</font></div><div><font face=
=3D"Courier">std::enable_if_t&lt; std::is_lvalue_reference&lt;&nbsp;</font>=
<span style=3D"font-family:Courier">owne<wbr>r_type</span><font face=3D"Cou=
rier">&nbsp;&gt;::value,</font></div><div><font face=3D"Courier">&nbsp; &nb=
sp; value_type &amp; &gt;</font></div><div><font face=3D"Courier">forward_c=
omponent( value_type &amp; v )</font></div><div><font face=3D"Courier">&nbs=
p; &nbsp; { return v; } // Container passed as lvalue yields a reference to=
 lvalue.</font></div><div><font face=3D"Courier"><br></font></div><div styl=
e=3D"word-wrap:break-word"><div><font face=3D"Courier">template&lt; typenam=
e owner_type, typename value_type &gt;</font></div><div><font face=3D"Couri=
er">std::enable_if_t&lt; ! std::is_lvalue_reference&lt;&nbsp;</font><span s=
tyle=3D"font-family:Courier">owne<wbr>r_type</span><font face=3D"Courier">&=
nbsp;&gt;::value,</font></div><div><font face=3D"Courier">&nbsp; &nbsp; val=
ue_type &amp;&amp; &gt;</font></div><div><font face=3D"Courier">forward_com=
ponent( value_type &amp; v )</font></div><div><font face=3D"Courier">&nbsp;=
 &nbsp; { return std::move( v ); } // Container passed as prvalue or xvalue=
 yields xvalue.</font></div><div><br></div><div>Usage in the example contex=
t:</div><div><br></div><div><font face=3D"Courier">&nbsp; return u ? std::f=
orward&lt;FV&gt;(fv)(forward_<wbr>component&lt;U&gt;(*u)) : std::forward&lt=
;FN&gt;(fn);</font></div><div><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 argument type. It handles <font face=3D"Courier">ve=
ctor::front</font>&nbsp;and <font face=3D"Courier">unique_ptr::operator*</f=
ont> with equal aplomb, and we don=E2=80=99t even have to add rvalue refere=
nce overloads to anything. (Although doing so may still be a good idea.)<br=
></div></div></div></div></blockquote><div><br>And this wis actually break =
every use of forward with non-owning semenatics (shared_ptr&lt;T&gt;). Plea=
se remember that forward function was designed to perfectly forward value o=
f any type in generic context without introspection, but introducing separa=
te forward_compoent kills the idea, because we me differentiate between sha=
red_ptr and unique_ptr.<br><br>Acutally defininig the rvalue reference over=
load for member getters returning rvalue reference (T&amp;&amp; meber() &am=
p;&amp;) is the way a type can signialize to forward that it owning this me=
mber. That means we could have:<br>T&amp;&amp; operator*() &amp;&amp;; //fo=
r unique_ptr, bot not for shared_ptr<br>Or for vector&lt;T&gt;:<br>T&amp;&a=
mp; front() &amp;&amp;;<br>T&amp;&amp; back() &amp;&amp;;<br>Or even for be=
gin/end members that will allows us to have better traversable constructor:=
 https://groups.google.com/a/isocpp.org/forum/?fromgroups#!topic/std-propos=
als/sOw68ogy6BM<br><div><br></div><div><blockquote class=3D"gmail_quote" st=
yle=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-lef=
t: 1ex;"><div style=3D"word-wrap:break-word"><div><blockquote type=3D"cite"=
><div dir=3D"ltr">If the original set&nbsp; of the methods was:<br>&nbsp; T=
&nbsp; value() const;<br>I would argee tthe the new function should be decl=
ared as:<br>&nbsp; T&nbsp; value() const &amp;;<br>&nbsp; T&nbsp; value() &=
amp;&amp;;<br>But this is not true in the case of optional. And also not ha=
ving safe version of operator* , that will allow you to modyfy value inplac=
e, would be a failure. Maybe the name is wrong.<br></div></blockquote></div=
><div>?</div><div><br></div><div>By the way, you might as well keep the <fo=
nt face=3D"Courier">const &amp;&amp;</font>&nbsp;overload. =E2=80=9C<font f=
ace=3D"Courier">&amp;&amp;</font>=E2=80=9D and =E2=80=9C<font face=3D"Couri=
er">const &amp;&amp;</font>=E2=80=9D usually have identical semantics. It i=
s possible to have an expression of const class type.</div><div><br></div><=
/div></blockquote>Now const&amp;&amp; should have the same semenantics as t=
he const&amp; so the addition overload is not neccessary. </div>&nbsp;</div=
></div>

<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 />

------=_Part_49_17651027.1404987890892--

.
