220 11887 <1b70888c-eb6a-49e5-b254-a475ef015570@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 02:10:02 -0700 (PDT)
Lines: 378
Approved: news@gmane.org
Message-ID: <1b70888c-eb6a-49e5-b254-a475ef015570@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>
 <4c42f7c9-0588-4ab9-9af5-b2e692513993@isocpp.org>
 <225BBAAC-B3FA-4014-9FB6-64C48DF4208E@gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_543_20324844.1405156202697"
X-Trace: ger.gmane.org 1405156213 17675 80.91.229.3 (12 Jul 2014 09:10:13 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Sat, 12 Jul 2014 09:10:13 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDNPVXXG6IGBB27WQOPAKGQER6EECQA@isocpp.org Sat Jul 12 11:10:06 2014
Return-path: <std-proposals+bncBDNPVXXG6IGBB27WQOPAKGQER6EECQA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ig0-f197.google.com ([209.85.213.197])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDNPVXXG6IGBB27WQOPAKGQER6EECQA@isocpp.org>)
	id 1X5tJl-0007z9-KD
	for gclcip-std-proposals@m.gmane.org; Sat, 12 Jul 2014 11:10:06 +0200
Original-Received: by mail-ig0-f197.google.com with SMTP id r2sf1014029igi.4
        for <gclcip-std-proposals@m.gmane.org>; Sat, 12 Jul 2014 02:10:04 -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=62K4i60YbMOlSns/ctXLyuPC99f4iVbSS0iDcr4epUs=;
        b=fGi1JmCtpi5pqOxhM95QgAQnOW8MfOgD411hcqHWeHXok22l+C3lnPzsa/gbJHcOty
         HA3C/vmI4oPv1iyBXFliE5MYU4f9cZscaVN2GDwBZeL9oDi6k8H1jH3f6s80xeldcla7
         Rp5OXZt4ymA73ifDeuaWcYskmh8ct6vvL68Jr6zi1CadlasWAkyIYDljTsC26xcngcOU
         QSn19/XXC543zDNkwq7cqm21Jh5qYshci431ywlCaxTwKQOTBMYke/yDAPVXPckzU0Xb
         Pls2tLT2QMP7KjDbaTnHBaqqV3tTWdv0AwwfXdd4YOie3s3paed+fHbfsfD5pITw6g8L
         TsrA==
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=62K4i60YbMOlSns/ctXLyuPC99f4iVbSS0iDcr4epUs=;
        b=i71edQgPtQ/61oFJOCvIVvo1ISDtZ6zXd4h4YhYRnMC8ZslbY81THus+EOQmBIpIwh
         /a0oqxB2PIzuGcRUFQxBfzSw9/ReX5pREZzwJ371+o+5eqD0zSTuaEd3qGiJEe8R6K2Q
         /nhfELxeqgyYAtRVhwSUXwhniKK5ZeFLEPDOC5TflNjeS25QgZ4VbUdoT2LpGP5pKpHE
         3n12PsmvCfrQLhjrgt5OuFuGedBrFrz55X5vWjSx3kzuOx1/wJ0rsUuxiKDgk5sZ2ejs
         YLxl8Fr31xrMPaczedaexoS/3+NPeP0OZ3Wl/743FQmlDUErdD/4mz58/hhhKGz28Bvb
         jpDQ==
X-Gm-Message-State: ALoCoQmFo/LTqZl/r6v3NKub/nz5wkgGBW50UcLeKLIDbmNG5RxsNxP+6EaFWfUVJn/tUjkvdJxQ
X-Received: by 10.50.41.3 with SMTP id b3mr4353424igl.0.1405156204706;
        Sat, 12 Jul 2014 02:10:04 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.182.65.138 with SMTP id x10ls666822obs.53.gmail; Sat, 12 Jul
 2014 02:10:03 -0700 (PDT)
X-Received: by 10.182.131.232 with SMTP id op8mr43obb.40.1405156203605;
        Sat, 12 Jul 2014 02:10:03 -0700 (PDT)
In-Reply-To: <225BBAAC-B3FA-4014-9FB6-64C48DF4208E@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:11887
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/11887>

------=_Part_543_20324844.1405156202697
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

W dniu sobota, 12 lipca 2014 09:51:15 UTC+2 u=C5=BCytkownik David Krauss na=
pisa=C5=82:
>
>
> On 2014=E2=80=9307=E2=80=9312, at 3:27 PM, toma...@gmail.com <javascript:=
> wrote:
>
> 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 nullabl=
e.
>
>
> Yes, but in that case what does the std::forward express? Reading that=20
> function, I would intuitively expect addressof(value) to become a=20
> dangling reference. Any other interpretation requires thinking hard about=
=20
> what did **not** happen to the result of forward. It wasn=E2=80=99t passe=
d to a=20
> function, but absence of some common thing isn=E2=80=99t a good discrimin=
ating=20
> factor. (And in fact, it was passed to a function, operator *.)
>
> Because function_taking_pointer(pointer) passes a non-owning observer,=20
> nullable must live at least through that call. The intent is best=20
> expressed by simply value =3D * nullable; do not use forward(). This can =
be=20
> declared as auto && or auto & equivalently.
>
> Am I missing something?
>

No, your are ok, But let me use your previous example.=20
template< typename container_handle >
void operate_on_fifth_thing( container_handle && ch ) {
    // Get only the fifth element. We don=E2=80=99t need the rest; OK to fr=
ee those=20
resources.
    // However, if not assuming ownership, there=E2=80=99s no need to make =
a copy.
    auto && fifth_thing =3D=3D ( * std::forward< container_handle >( ch ) )=
[ 5=20
];

    // This is illustrated as a function call, but there might as well be a=
=20
loop here.
    process_for_a_long_time( std::forward< decltype( thing ) >( fifth_thing=
=20
) );
}

Then assume than we want add some log information:
template< typename container_handle >
void operate_on_fifth_thing( container_handle && ch ) {
    // Get only the fifth element. We don=E2=80=99t need the rest; OK to fr=
ee those=20
resources.
    // However, if not assuming ownership, there=E2=80=99s no need to make =
a copy.
    auto && fifth_thing =3D=3D ( * std::forward< container_handle >( ch ) )=
[ 5=20
];
    //Added some logging information
    log_value_of_fifth_thing(fifth_thing);

    // This is illustrated as a function call, but there might as well be a=
=20
loop here.
    process_for_a_long_time( std::forward< decltype( thing ) >( fifth_thing=
=20
) );
}

Then the user find the extract part of the function being to big and move=
=20
it to separate function:
template< typename container_handle >
decltype(auto) get_fifth_thing(container_handle && ch)
{
  // Get only the fifth element. We don=E2=80=99t need the rest; OK to free=
 those=20
resources.
  // However, if not assuming ownership, there=E2=80=99s no need to make a =
copy.
  auto && fifth_thing =3D=3D ( * std::forward< container_handle >( ch ) )[ =
5 ];
  //Some loging
  log_value_of_fifth_thing(fifth_thing);
  return fifth_thing;
}

template< typename container_handle >
void operate_on_fifth_thing( container_handle && ch ) {
    // Get only the fifth element. We don=E2=80=99t need the rest; OK to fr=
ee those=20
resources.
       auto && fifth_thing =3D get_fifth_thing(std::forward< container_hand=
le=20
>( ch))

    // This is illustrated as a function call, but there might as well be a=
=20
loop here.
    process_for_a_long_time( std::forward< decltype( thing ) >( fifth_thing=
=20
) );
}

I perceive all above transformation as being acceptable and I think that=20
the programmer expectation that the code will still be valid after them is=
=20
vald. Do you agree?

So lets analyze the situation:
  1. Status quo (no r-value overloads for operator[] this time): The code=
=20
is working before and after transformation the same way.
  2. R-value reference r-value overload for operator[]: The code is working=
=20
before and after transformation the same way.
  3. Value r-value overload for operator[]: In the decltype(auto)=20
get_fifth_thing(container_handle && ch) the auto && fifth_thing =3D=3D ( *=
=20
std::forward< container_handle >( ch ) )[ 5 ]; will cause fifth_thing to be=
=20
type of
      T&&, meaning the return type of function will be reference and that=
=20
will cause auto && fifth_thing =3D get_fifth_thing(std::forward<=20
container_handle >( ch)) to be a dangling reference. The code will be=20
broken by this transormation.

Breaking the connection between lifetime of object and lifetime of=20
expression that should reference for subobject is not good think.


I would like to summarize the arguments pros/cons that come in the thread.=
=20
This is aimed to be objective
  a) addition of T&& value()&&;
     + makes a following code auto&& s =3D temporary_of_optional().value()=
=20
use move semantics
     + std::forward<T>(t).value() correctly forwards value as prvalue
     - auto&& cs =3D temporary_of_optional().value() still not works
  b) addition of T value()&&;
     + makes a: auto&& cs =3D temporary_of_optional().value()
     - breaks connection between lifetime of opt.value() and opt
     - introduce additional temporaries (copies) if the places that=20
captures temporary by const reference: f(temporary_of_optional().value())

In addition we found that for auto&& cs =3D expr;
    a) If we make auto&& cs =3D expr1.expr2 work by changing extending the=
=20
lifetime of object if subobject is captured or having value r-value=20
overloads, the following transformation of code will introduce dangling=20
reference:
        after simple transformation:
        template<typename T>
        delctype(auto) some_getter(T&& t)
        {
           auto&& cs =3D std::forward<T>(t).expr;
           /// some code that causes this transformation to be applied
           return cs;
        }

        auto&& cs =3Df(expr1);
    b) auto&& cs =3D expr1; does not work if the expr1 will return by value=
=20
some kind of expression object that bound references to temporaries (result=
=20
of expression template)

My personal opinion:
  I would recommend to add T&& value()&& because it is introducing the move=
=20
semantics to be trigger seamlessly when a rvalue of optional<T> is used in=
=20
the code. The only drawback of this change is that it will still wont fix=
=20
the auto&& cs =3D f().value() statement.=20

  The only argument for T value()&& presented in this tread was that it=20
will make auto&& cs =3D f().value() work, but will cause performance=20
downgrade in other parts of code, combining that will fact that auto&& cs =
=3D=20
expr; still may create an dangling reference in other context I do not find=
=20
this a good motivation, especially when the main argument to make auto&& cs=
=20
work is that it will allow you to capture any value type in generic code.

--=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_543_20324844.1405156202697
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">W dniu sobota, 12 lipca 2014 09:51:15 UTC+2 u=C5=BCytkowni=
k David Krauss napisa=C5=82:<blockquote class=3D"gmail_quote" style=3D"marg=
in: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><d=
iv style=3D"word-wrap:break-word"><br><div><div>On 2014=E2=80=9307=E2=80=93=
12, at 3:27 PM, <a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-ma=
ilto=3D"gHq7TNKRVfoJ" onmousedown=3D"this.href=3D'javascript:';return true;=
" onclick=3D"this.href=3D'javascript:';return true;">toma...@gmail.com</a> =
wrote:</div><br><blockquote type=3D"cite"><div dir=3D"ltr">3. The above cod=
e does not work if if the passed Nullable type define &amp;&amp; overload o=
f operator* that returns by value.<br><div>&nbsp;&nbsp;&nbsp; Lifetime of o=
bject bound by auto&amp;&amp; value =3D *std::forward&lt;Nullable&gt;(<wbr>=
nullable); is not the same as lifetime of nullable.<br></div></div></blockq=
uote><div><br></div></div>Yes, but in that case what does the <font face=3D=
"Courier">std::forward</font> express? Reading that function, I would intui=
tively expect <font face=3D"Courier">addressof(value)</font> to become a da=
ngling reference. Any other interpretation requires thinking hard about wha=
t did *<i>not</i>* happen to&nbsp;the result of <font face=3D"Courier">forw=
ard</font>. It wasn=E2=80=99t passed to a function, but absence of some com=
mon thing isn=E2=80=99t a good discriminating factor. (And in fact, it was =
passed to a function, <font face=3D"Courier">operator *</font>.)<div><br></=
div><div>Because&nbsp;<font face=3D"Courier">function_taking_<wbr>pointer(p=
ointer)</font>&nbsp;passes a non-owning observer, <font face=3D"Courier">nu=
llable</font> must live at least through that call. The intent is best expr=
essed by simply&nbsp;<font face=3D"Courier">value =3D * nullable</font>; do=
 not use&nbsp;<font face=3D"Courier">forward()</font>. This can be declared=
 as&nbsp;<font face=3D"Courier">auto &amp;&amp;</font> or <font face=3D"Cou=
rier">auto &amp;</font> equivalently.</div><div><br></div><div>Am I missing=
 something?</div></div></blockquote><div><br>No, your are ok, But let me us=
e your previous example. <br><div class=3D"GGCIKMHDGHB"><div><font face=3D"=
Courier">template&lt; typename container_handle &gt;</font></div><div><font=
 face=3D"Courier">void operate_on_fifth_thing( container_handle &amp;&amp; =
ch ) {</font></div></div><div><font face=3D"Courier">&nbsp; &nbsp; // Get o=
nly the fifth element. We don=E2=80=99t need the rest; OK to free those res=
ources.</font></div><div><font face=3D"Courier">&nbsp; &nbsp; // However, i=
f not assuming ownership, there=E2=80=99s no need to make a&nbsp;copy.</fon=
t></div><div><font face=3D"Courier">&nbsp; &nbsp; auto &amp;&amp; fifth_thi=
ng =3D=3D ( * std::forward&lt; container_handle &gt;( ch ) )[ 5 ];</font></=
div><div><font face=3D"Courier"><br></font></div><div><font face=3D"Courier=
">&nbsp; &nbsp; // This is illustrated as a function call, but there might =
as well be a loop here.</font></div><div><font face=3D"Courier">&nbsp; &nbs=
p; process_for_a_long_time( std::forward&lt; decltype( thing ) &gt;( fifth_=
thing ) );</font></div><div><font face=3D"Courier">}<br><br></font></div>Th=
en assume than we want add some log information:<br><div class=3D"GGCIKMHDG=
HB"><div><font face=3D"Courier">template&lt; typename container_handle &gt;=
</font></div><div><font face=3D"Courier">void operate_on_fifth_thing( conta=
iner_handle &amp;&amp; ch ) {</font></div></div><div><font face=3D"Courier"=
>&nbsp; &nbsp; // Get only the fifth element. We don=E2=80=99t need the res=
t; OK to free those resources.</font></div><div><font face=3D"Courier">&nbs=
p; &nbsp; // However, if not assuming ownership, there=E2=80=99s no need to=
 make a&nbsp;copy.</font></div><div><font face=3D"Courier">&nbsp; &nbsp; au=
to &amp;&amp; fifth_thing =3D=3D ( * std::forward&lt; container_handle &gt;=
( ch ) )[ 5 ];<br>&nbsp;&nbsp;&nbsp; //Added some logging information<br>&n=
bsp;&nbsp;&nbsp; log_value_of_fifth_thing(</font><font face=3D"Courier">fif=
th_thing);</font></div><div><font face=3D"Courier"><br></font></div><div><f=
ont face=3D"Courier">&nbsp; &nbsp; // This is illustrated as a function cal=
l, but there might as well be a loop here.</font></div><div><font face=3D"C=
ourier">&nbsp; &nbsp; process_for_a_long_time( std::forward&lt; decltype( t=
hing ) &gt;( fifth_thing ) );</font></div><div><font face=3D"Courier">}</fo=
nt></div><br>Then the user find the extract part of the function being to b=
ig and move it to separate function:<br><div><span style=3D"font-family: co=
urier new,monospace;">template&lt; typename container_handle &gt;</span></d=
iv><span style=3D"font-family: courier new,monospace;">decltype(auto) get_f=
ifth_thing(container_handle &amp;&amp; ch)<br>{<br></span><div><span style=
=3D"font-family: courier new,monospace;">&nbsp; // Get only the fifth eleme=
nt. We don=E2=80=99t need the rest; OK to free those resources.</span></div=
><div><span style=3D"font-family: courier new,monospace;">&nbsp; // However=
, if not assuming ownership, there=E2=80=99s no need to make a&nbsp;copy.</=
span></div><div><span style=3D"font-family: courier new,monospace;">&nbsp; =
auto &amp;&amp; fifth_thing =3D=3D ( * std::forward&lt; container_handle &g=
t;( ch ) )[ 5 ];<br>&nbsp; //Some loging<br>&nbsp; log_value_of_fifth_thing=
(fifth_thing);</span></div><span style=3D"font-family: courier new,monospac=
e;">&nbsp; return fifth_thing;<br>}</span><br><br><div class=3D"GGCIKMHDGHB=
"><div><font face=3D"Courier">template&lt; typename container_handle &gt;</=
font></div><div><font face=3D"Courier">void operate_on_fifth_thing( contain=
er_handle &amp;&amp; ch ) {<br></font><span style=3D"font-family: courier n=
ew,monospace;">&nbsp;&nbsp;&nbsp; // Get only the fifth element. We don=E2=
=80=99t need the rest; OK to free those resources.</span><br></div></div>&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font face=3D"Courier">auto &amp;&amp; f=
ifth_thing =3D </font><span style=3D"font-family: courier new,monospace;">g=
et_fifth_thing(</span><span style=3D"font-family: courier new,monospace;">s=
td::forward&lt; container_handle &gt;( ch))</span><div><font face=3D"Courie=
r"><br></font></div><div><font face=3D"Courier">&nbsp; &nbsp; // This is il=
lustrated as a function call, but there might as well be a loop here.</font=
></div><div><font face=3D"Courier">&nbsp; &nbsp; process_for_a_long_time( s=
td::forward&lt; decltype( thing ) &gt;( fifth_thing ) );</font></div><div><=
font face=3D"Courier">}</font></div><br>I perceive all above transformation=
 as being acceptable and I think that the programmer expectation that the c=
ode will still be valid after them is vald. Do you agree?<br><br></div><div=
>So lets analyze the situation:<br>&nbsp; 1. Status quo (no r-value overloa=
ds for operator[] this time): The code is working before and after transfor=
mation the same way.<br>&nbsp; 2. R-value reference r-value overload for op=
erator[]: The code is working before and after transformation the same way.=
<br>&nbsp; 3. Value r-value overload for operator[]: In the <span style=3D"=
font-family: courier new,monospace;">decltype(auto) get_fifth_thing(contain=
er_handle &amp;&amp; ch)</span> the <span style=3D"font-family: courier new=
,monospace;">auto &amp;&amp; fifth_thing =3D=3D ( * std::forward&lt; contai=
ner_handle &gt;( ch ) )[ 5 ]; </span> will cause fifth_thing to be type of<=
br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; T&amp;&amp;, meaning the return type of f=
unction will be reference and that will cause <font face=3D"Courier">auto &=
amp;&amp; fifth_thing =3D </font><span style=3D"font-family: courier new,mo=
nospace;">get_fifth_thing(</span><span style=3D"font-family: courier new,mo=
nospace;">std::forward&lt; container_handle &gt;( ch))</span> to be a dangl=
ing reference. The code will be broken by this transormation.<br><br>Breaki=
ng the connection between lifetime of object and lifetime of expression tha=
t should reference for subobject is not good think.<br><br><br>I would like=
 to summarize the arguments pros/cons that come in the thread. This is aime=
d to be objective<br>&nbsp; a) addition of T&amp;&amp; value()&amp;&amp;;<b=
r>&nbsp;&nbsp;&nbsp;&nbsp; + makes a following code auto&amp;&amp; s =3D te=
mporary_of_optional().value() use move semantics<br>&nbsp;&nbsp;&nbsp;&nbsp=
; + std::forward&lt;T&gt;(t).value() correctly forwards value as prvalue<br=
>&nbsp;&nbsp;&nbsp;&nbsp; - auto&amp;&amp; cs =3D temporary_of_optional().v=
alue() still not works<br>&nbsp; b) addition of T value()&amp;&amp;;<br>&nb=
sp;&nbsp;&nbsp;&nbsp; + makes a: auto&amp;&amp; cs =3D temporary_of_optiona=
l().value()<br>&nbsp;&nbsp;&nbsp;&nbsp; - breaks connection between lifetim=
e of opt.value() and opt<br>&nbsp;&nbsp;&nbsp;&nbsp; - introduce additional=
 temporaries (copies) if the places that captures temporary by const refere=
nce: f(temporary_of_optional().value())<br><br>In addition we found that fo=
r auto&amp;&amp; cs =3D expr;<br>&nbsp;&nbsp;&nbsp; a) If we make auto&amp;=
&amp; cs =3D expr1.expr2 work by changing extending the lifetime of object =
if subobject is captured or having value r-value overloads, the following t=
ransformation of code will introduce dangling reference:<br>&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp; after simple transformation:<br>&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp; template&lt;typename T&gt;<br>&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp; delctype(auto) some_getter(T&amp;&amp; t)<br>&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp; auto&amp;&amp; cs =3D std::forward&lt;T&gt;(t=
).expr;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ///=
 some code that causes this transformation to be applied<br>&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return cs;<br>&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp; auto&amp;&amp; cs =3Df(expr1);<br>&nbsp;&nbsp;&nbsp; b) auto&amp;&amp;=
 cs =3D expr1; does not work if the expr1 will return by value some kind of=
 expression object that bound references to temporaries (result of expressi=
on template)<br><br>My personal opinion:<br>&nbsp; I would recommend to add=
 T&amp;&amp; value()&amp;&amp; because it is introducing the move semantics=
 to be trigger seamlessly when a rvalue of optional&lt;T&gt; is used in the=
 code. The only drawback of this change is that it will still wont fix the =
auto&amp;&amp; cs =3D f().value() statement. <br><br>&nbsp; The only argume=
nt for T value()&amp;&amp; presented in this tread was that it will make au=
to&amp;&amp; cs =3D f().value() work, but will cause performance downgrade =
in other parts of code, combining that will fact that auto&amp;&amp; cs =3D=
 expr; still may create an dangling reference in other context I do not fin=
d this a good motivation, especially when the main argument to make auto&am=
p;&amp; cs work is that it will allow you to capture any value type in gene=
ric code.<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_543_20324844.1405156202697--

.
