220 11885 <4c42f7c9-0588-4ab9-9af5-b2e692513993@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: Sat, 12 Jul 2014 00:27:29 -0700 (PDT)
Lines: 170
Approved: news@gmane.org
Message-ID: <4c42f7c9-0588-4ab9-9af5-b2e692513993@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> <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>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_331_5533592.1405150049235"
X-Trace: ger.gmane.org 1405150059 22749 80.91.229.3 (12 Jul 2014 07:27:39 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Sat, 12 Jul 2014 07:27:39 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDNPVXXG6IGBBYWGQOPAKGQE5KTMM6I@isocpp.org Sat Jul 12 09:27:33 2014
Return-path: <std-proposals+bncBDNPVXXG6IGBBYWGQOPAKGQE5KTMM6I@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-qc0-f198.google.com ([209.85.216.198])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDNPVXXG6IGBBYWGQOPAKGQE5KTMM6I@isocpp.org>)
	id 1X5riW-00030w-Ck
	for gclcip-std-proposals@m.gmane.org; Sat, 12 Jul 2014 09:27:32 +0200
Original-Received: by mail-qc0-f198.google.com with SMTP id l6sf4593676qcy.1
        for <gclcip-std-proposals@m.gmane.org>; Sat, 12 Jul 2014 00:27:31 -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=erCaap4JjjJ193d7BR/ok2exVk5kgSrJV9JPafxnEu4=;
        b=eXSHvG8AiWJkKeGOt0EEv+xn6zQiows2prz24bY7gwP7+i2yqZxV6VmR30Z2RmTAW8
         rqQFak5Yx5xeMa7GkVRnmW30IySrL7I2g4Ba0zGnu9616aPv/hNWEc/4obkyRr+B8yoC
         MyFKiA8Pyy9xLeQqdfMtC6rns4+UOg5m4U9d0ECGDU00HA3WtzAJ1Jv+K5NFk5Dk6nuL
         KlNeWf4dA1kZcru2howAKn3fRhJFfQ/sH2PI7mqlx/nGJrIgXLbwTNC1MyyY4LB8JMkn
         /ID+C0CNCRHBJS6PL0YI0Q3PYL0EfvnbwSXla/tYlwYRxbaOwRG+MDUhEqKFuGcCdw2D
         qxng==
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=erCaap4JjjJ193d7BR/ok2exVk5kgSrJV9JPafxnEu4=;
        b=OdmwhuW1ptZhkI29lM0FYG1jwuVnqyLBoj233dQXmMCnfA8myEJ89OR4VBAlePYmrP
         0pf3mdksWlW+CqBNR8EXJF0bqbLwsqPBOgWAqGZykzX35oiPQpsp/AARZUPgVXyQ6NMV
         ibmooRStR4QjFYikgft4/WJ2WD5fAsnW9y/QlE5j0pnAAm4d6na1TRpCkaaFGJsYB1ez
         7steNgdnPLFr1pcpCqT2I0mBHHp5QEQK461ge7Wwlf49/dd+6srMIJIm57yrdI1HPQVE
         4dm0Z1ffuOsLBnJPAqOouv6/swMtKbl56iDFx1ReWJ/wK8Z23M0q+f8NHK6vWhhTLORd
         AScQ==
X-Gm-Message-State: ALoCoQmbW2SpiyTDXGcOLl57Zu9oZuZT2xA3Nzt1wXcBcpotls6nr2JlGuorw86FWFlLYK/ATeXn
X-Received: by 10.236.124.100 with SMTP id w64mr1752662yhh.57.1405150050949;
        Sat, 12 Jul 2014 00:27:30 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.182.53.170 with SMTP id c10ls636229obp.49.gmail; Sat, 12 Jul
 2014 00:27:29 -0700 (PDT)
X-Received: by 10.182.108.165 with SMTP id hl5mr476obb.27.1405150049933;
        Sat, 12 Jul 2014 00:27:29 -0700 (PDT)
In-Reply-To: <8209A2E9-D947-4C00-A1F3-38F5676A4E52@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:11885
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/11885>

------=_Part_331_5533592.1405150049235
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable



W dniu sobota, 12 lipca 2014 01:30:24 UTC+2 u=C5=BCytkownik David Krauss na=
pisa=C5=82:
>
>
> On 2014=E2=80=9307=E2=80=9311, at 6:57 PM, toma...@gmail.com <javascript:=
> wrote:
>
> Do we found any other argumentation for T member()&& overload except=20
> making auto&& s =3D f; work for some cases?=20
>
> In the follwoing example:
>   template<typename T>
>   delctype(auto) f(T&& t) { return std::addressof(*std::forward<T>(t)); }
>   =20
>   template<typename T>
>   delctype(auto) g(T&& t) {=20
>       auto&& ret =3D f(std::forward<T>(t));=20
>       //will create a dangling pointer, because the liftetime of result o=
f=20
> f.value() is not longer same a liftme of the owner t
>
>
> Once again you=E2=80=99ve omitted the parens after f in the comment. Plea=
se=20
> proofread before posting. f is a naked function and f() is a naked pointe=
r.=20
> Neither can have a member .value. You probably mean *f or f->value()=20
> under the assumption that f is type optional*.
>
>
I agree with you, in the way the post was written I failed to present my=20
point. Sorry for that.
=20

> A function that converts a possibly-owning smart pointer to merely an=20
> observing naked pointer is obviously not a candidate for move semantics, =
so=20
> the example is not reasonable.
>
>
Let me present my last point again, because I think it was never presented=
=20
in the thread.

I will begin with describing the issue: Having prvalue overloads (T=20
operator*()) for optional<T> breaks the connection between expression of=20
type optional (opt_expr) and the lifetime of bounded result of=20
(opt_expr.value()) bound to the reference.
This will only happen of opt_expr is rvalue, so the only situation when it=
=20
may happen by accident is the generic context.

Example:
template<typename Nullable>
void do_something(Nullable&& nullable)
{
  pointer_type_t<Nullable> pointer =3D nullptr;
  if (nullable)
  {
     auto&& value =3D *std::forward<Nullable>(nullable);
     //Do something with value
     pointer =3D addressof(value);
  }
  function_taking_pointer(pointer);
}
1.The above code works if the passed Nullable types does not define any=20
rvalue overloads for operator* - current status quo with library.=20
   Because the lifetime of object bound by auto&& value =3D=20
*std::forward<Nullable>(nullable); is always bound to the lifetime of=20
nullable.
2. The above code work if the passed Nullable type define && overload of=20
operator* that returns by rvalue-reference. Same reasoning apply as above.
3. The above code does not work if if the passed Nullable type define &&=20
overload of operator* that returns by value.
    Lifetime of object bound by auto&& value =3D=20
*std::forward<Nullable>(nullable); is not the same as lifetime of nullable.

--=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_331_5533592.1405150049235
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>W dniu sobota, 12 lipca 2014 01:30:24 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=9311, at 6:57 PM, <a href=3D"javascript:" target=3D"_blank" gdf-obf=
uscated-mailto=3D"tIDmZFmCIScJ" 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">Do we =
found any other argumentation for T member()&amp;&amp; overload except maki=
ng auto&amp;&amp; s =3D f; work for some cases? <br><br>In the follwoing ex=
ample:<br>&nbsp; template&lt;typename T&gt;<br>&nbsp; delctype(auto) f(T&am=
p;&amp; t) { return std::addressof(*std::forward&lt;<wbr>T&gt;(t)); }<br>&n=
bsp;&nbsp; <br>&nbsp; template&lt;typename T&gt;<br>&nbsp; delctype(auto) g=
(T&amp;&amp; t) { <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; auto&amp;&amp; ret =3D=
 f(std::forward&lt;T&gt;(t)); <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //will cre=
ate a dangling pointer, because the liftetime of result of f.value() is not=
 longer same a liftme of the owner t<br></div></blockquote><div><br></div><=
div>Once again you=E2=80=99ve omitted the parens after f in the comment. Pl=
ease proofread before posting. f is a naked function and f() is a naked poi=
nter. Neither can have a member <font face=3D"Courier">.value</font>. You p=
robably mean <font face=3D"Courier">*f</font> or <font face=3D"Courier">f-&=
gt;value()</font> under the assumption that f is type <font face=3D"Courier=
">optional*</font>.</div><div><br></div></div></div></blockquote><div><br>I=
 agree with you, in the way the post was written I failed to present my poi=
nt. Sorry for that.<br>&nbsp;</div><blockquote class=3D"gmail_quote" style=
=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: =
1ex;"><div style=3D"word-wrap:break-word"><div><div></div><div>A function t=
hat converts a possibly-owning smart pointer to merely an observing naked p=
ointer is obviously not a candidate for move semantics, so the example is n=
ot reasonable.</div><br></div></div></blockquote><div><br>Let me present my=
 last point again, because I think it was never presented in the thread.<br=
><br>I will begin with describing the issue: Having prvalue overloads (T op=
erator*()) for optional&lt;T&gt; breaks the connection between expression o=
f type optional (opt_expr) and the lifetime of bounded result of (opt_expr.=
value()) bound to the reference.<br>This will only happen of opt_expr is rv=
alue, so the only situation when it may happen by accident is the generic c=
ontext.<br><br>Example:<br>template&lt;typename Nullable&gt;<br>void do_som=
ething(Nullable&amp;&amp; nullable)<br>{<br>&nbsp; pointer_type_t&lt;Nullab=
le&gt; pointer =3D nullptr;<br>&nbsp; if (nullable)<br>&nbsp; {<br>&nbsp;&n=
bsp;&nbsp;&nbsp; auto&amp;&amp; value =3D *std::forward&lt;Nullable&gt;(nul=
lable);<br>&nbsp;&nbsp;&nbsp;&nbsp; //Do something with value<br>&nbsp;&nbs=
p;&nbsp;&nbsp; pointer =3D addressof(value);<br>&nbsp; }<br>&nbsp; function=
_taking_pointer(pointer);<br>}<br>1.The above code works if the passed Null=
able types does not define any rvalue overloads for operator* - current sta=
tus quo with library. <br>&nbsp;&nbsp; Because the lifetime of object bound=
 by auto&amp;&amp; value =3D *std::forward&lt;Nullable&gt;(nullable); is al=
ways bound to the lifetime of nullable.<br>2. The above code work if the pa=
ssed Nullable type define &amp;&amp; overload of operator* that returns by =
rvalue-reference. Same reasoning apply as above.<br>3. The above code does =
not work if if the passed Nullable type define &amp;&amp; overload of opera=
tor* that returns by value.<br>&nbsp;&nbsp;&nbsp; Lifetime of object bound =
by auto&amp;&amp; value =3D *std::forward&lt;Nullable&gt;(nullable); is not=
 the same as lifetime of nullable.<br></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_331_5533592.1405150049235--

.
