220 11801 <74CEDDAC-1B1B-4F06-9E58-2F025921FE55@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 18:00:49 +0800
Lines: 151
Approved: news@gmane.org
Message-ID: <74CEDDAC-1B1B-4F06-9E58-2F025921FE55@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>
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=_B46A0D6D-F4A5-4917-8000-88BB4C0A21D4"
X-Trace: ger.gmane.org 1404986468 19253 80.91.229.3 (10 Jul 2014 10:01:08 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Thu, 10 Jul 2014 10:01:08 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCW25A7E3QCRBV6I7GOQKGQETICJX4Y@isocpp.org Thu Jul 10 12:00:59 2014
Return-path: <std-proposals+bncBCW25A7E3QCRBV6I7GOQKGQETICJX4Y@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-pa0-f71.google.com ([209.85.220.71])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCW25A7E3QCRBV6I7GOQKGQETICJX4Y@isocpp.org>)
	id 1X5B9t-0002sV-0m
	for gclcip-std-proposals@m.gmane.org; Thu, 10 Jul 2014 12:00:57 +0200
Original-Received: by mail-pa0-f71.google.com with SMTP id eu11sf58425869pac.2
        for <gclcip-std-proposals@m.gmane.org>; Thu, 10 Jul 2014 03:00:55 -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=9qvJXvbaVv8pYBgFS27olJOvzeCUxx2wWW7Q3lve2Uw=;
        b=LJFdMsx+6MkPHeLuKsMOZfwVGA1RntkSo9namMV/YcO53h6lKR9t0cgEwoIixIhdvf
         suF2vPCitwmNsK12YH/Y2qBwWYGuj1Ps8p7ZoZzClGP0y9orwqFqLwwmzXQOAItxHO7l
         CpA1lwiPIDKOLFwPGFrup0FnPv7Imof+TNanYkhfev1n/+U/qkRN4n2h9OpsxMLNkphs
         PWRB2z1os7Fekk4LV2YKTz9kDJzQ7N6mbl/WdGSgAmh0Y86YZooCNI4fzmwagOJq20MB
         lXyCjPUKZcioPGFEhw7tp2lqdg8c8bBoJM7A8yS5ElRRlZAtQF89Wy0zdH441EwxDKs6
         Cvbg==
X-Gm-Message-State: ALoCoQlOMTbw7T/lw/atZzfzyTCJciBAPA/UafnVy47Jpav8IirkwkBp/mOUgEu0RIzFhvYuURFN
X-Received: by 10.66.102.9 with SMTP id fk9mr20882974pab.2.1404986455767;
        Thu, 10 Jul 2014 03:00:55 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.50.23.101 with SMTP id l5ls1338080igf.9.canary; Thu, 10 Jul
 2014 03:00:55 -0700 (PDT)
X-Received: by 10.43.129.74 with SMTP id hh10mr51725411icc.48.1404986454985;
        Thu, 10 Jul 2014 03:00:54 -0700 (PDT)
Original-Received: from mail-ig0-x231.google.com (mail-ig0-x231.google.com [2607:f8b0:4001:c05::231])
        by mx.google.com with ESMTPS id z6si75746007icm.20.2014.07.10.03.00.54
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Thu, 10 Jul 2014 03:00:54 -0700 (PDT)
Received-SPF: pass (google.com: domain of potswa@gmail.com designates 2607:f8b0:4001:c05::231 as permitted sender) client-ip=2607:f8b0:4001:c05::231;
Original-Received: by mail-ig0-f177.google.com with SMTP id r10so2883394igi.4
        for <std-proposals@isocpp.org>; Thu, 10 Jul 2014 03:00:54 -0700 (PDT)
X-Received: by 10.42.240.20 with SMTP id ky20mr1011914icb.97.1404986454881;
        Thu, 10 Jul 2014 03:00:54 -0700 (PDT)
Original-Received: from [172.20.10.2] ([121.54.54.43])
        by mx.google.com with ESMTPSA id n10sm23729618igv.21.2014.07.10.03.00.52
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Thu, 10 Jul 2014 03:00:54 -0700 (PDT)
In-Reply-To: <072cf8b4-4c74-438e-9999-0aab13bf3182@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::231 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:11801
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/11801>

--Apple-Mail=_B46A0D6D-F4A5-4917-8000-88BB4C0A21D4
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=ISO-8859-1


On 2014-07-10, at 5:29 PM, tomaszkam@gmail.com wrote:

> Which makes following invoaction f(expr.value()) where takes T by const& =
and expr is value of type optional<T>, introducing has additonal possibly-c=
opy dependin on expr being lvalue or r-value. And makes using optional in g=
eneric context when perfect forwardin us used a pain. I propose to set of m=
ethods to look like:
>   T& value() &;
>   T const& value() const &;
>   T&& value() &&;
>  To achieve consistency with std::get function or even simple meber acces=
 with procudes same cateogry value for subobject.

Here's the issue: std::get cannot reliably produce the same value category =
as a simple member access, because functions (in C++11, at least) cannot di=
stinguish xvalue arguments from prvalues. A member access on a prvalue prod=
uces a prvalue, but a member access get< N >( prvalue() ).mem produces an x=
value.

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 lvalu=
e.

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 yie=
lds xvalue.

Usage in the example context:

  return u ? std::forward<FV>(fv)(forward_component<U>(*u)) : std::forward<=
FN>(fn);

forward_component trusts the user that the function argument is owned by an=
 object of the template argument type. It handles vector::front and unique_=
ptr::operator* with equal aplomb, and we don't even have to add rvalue refe=
rence overloads to anything. (Although doing so may still be a good idea.)

> If the original set  of the methods was:
>   T  value() const;
> I would arrge tthe the new function should be declared as:
>   T  value() const;
>   T  value() &&;
> But this is not=20

?

By the way, you might as well keep the const && overload. "&&" and "const &=
&" usually have identical semantics. It is possible to have an expression o=
f const class type.

--=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=_B46A0D6D-F4A5-4917-8000-88BB4C0A21D4
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 5:29 PM, <a href=3D"mailto:tomaszkam@gmail.com">tomas=
zkam@gmail.com</a> wrote:</div><br><blockquote type=3D"cite"><div dir=3D"lt=
r">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 op=
tional 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&amp; value() const &amp;;<br>&nbsp; T&amp;&amp; value() &amp;&amp;;=
<br>&nbsp;To achieve consistency with std::get function or even simple mebe=
r acces with procudes same cateogry value for subobject.<br></div></blockqu=
ote><div><br></div><div>Here&rsquo;s the issue: std::get cannot reliably pr=
oduce the same value category as a simple member access, because functions =
(in C++11, at least) cannot distinguish xvalue arguments from prvalues. A m=
ember access on a prvalue produces a prvalue, but a member access&nbsp;<fon=
t 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 forwar=
ding function itself?</div><div><br></div><div><font face=3D"Courier">templ=
ate&lt; typename owner_type, typename value_type &gt;</font></div><div><fon=
t face=3D"Courier">std::enable_if_t&lt; std::is_lvalue_reference&lt;&nbsp;<=
/font><span style=3D"font-family: Courier;">owner_type</span><font face=3D"=
Courier">&nbsp;&gt;::value,</font></div><div><font face=3D"Courier">&nbsp; =
&nbsp; value_type &amp; &gt;</font></div><div><font face=3D"Courier">forwar=
d_component( value_type &amp; v )</font></div><div><font face=3D"Courier">&=
nbsp; &nbsp; { return v; } // Container passed as lvalue yields a reference=
 to lvalue.</font></div><div><font face=3D"Courier"><br></font></div><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; ! s=
td::is_lvalue_reference&lt;&nbsp;</font><span style=3D"font-family: Courier=
;">owner_type</span><font face=3D"Courier">&nbsp;&gt;::value,</font></div><=
div><font face=3D"Courier">&nbsp; &nbsp; value_type &amp;&amp; &gt;</font><=
/div><div><font face=3D"Courier">forward_component( value_type &amp; v )</f=
ont></div><div><font face=3D"Courier">&nbsp; &nbsp; { return std::move( v )=
; } // Container passed as prvalue or xvalue yields xvalue.</font></div><di=
v><br></div><div>Usage in the example context:</div><div><br></div><div><fo=
nt face=3D"Courier">&nbsp; return u ? std::forward&lt;FV&gt;(fv)(forward_co=
mponent&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 th=
at the function argument is owned by an object of the template argument typ=
e. It handles <font face=3D"Courier">vector::front</font>&nbsp;and <font fa=
ce=3D"Courier">unique_ptr::operator*</font> with equal aplomb, and we don&r=
squo;t even have to add rvalue reference overloads to anything. (Although d=
oing so may still be a good idea.)</div><div><br></div></div><blockquote ty=
pe=3D"cite"><div dir=3D"ltr">If the original set&nbsp; of the methods was:<=
br>&nbsp; T&nbsp; value() const;<br>I would arrge tthe the new function sho=
uld be declared as:<br>&nbsp; T&nbsp; value() const;<br>&nbsp; T&nbsp; valu=
e() &amp;&amp;;<br>But this is not <br></div></blockquote><br></div><div>?<=
/div><div><br></div><div>By the way, you might as well keep the <font face=
=3D"Courier">const &amp;&amp;</font>&nbsp;overload. &ldquo;<font face=3D"Co=
urier">&amp;&amp;</font>&rdquo; and &ldquo;<font face=3D"Courier">const &am=
p;&amp;</font>&rdquo; usually have identical semantics. It is possible to h=
ave an expression of const class type.</div><div><br></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=_B46A0D6D-F4A5-4917-8000-88BB4C0A21D4--

.
