220 11781 <F80F564C-1208-4A65-AA1F-382144A3D16A@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 14:12:50 +0800
Lines: 85
Approved: news@gmane.org
Message-ID: <F80F564C-1208-4A65-AA1F-382144A3D16A@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> <CAFk2RUa5foB0ySVSjfc3t6cBOWE-+Qt76jnRv3X=FHP6ntpPjw@mail.gmail.com>
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=_5D3D7484-C4AA-4437-8142-084D173768DC"
X-Trace: ger.gmane.org 1404972784 21066 80.91.229.3 (10 Jul 2014 06:13:04 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Thu, 10 Jul 2014 06:13:04 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCW25A7E3QCRBZW57COQKGQE6ZS77XQ@isocpp.org Thu Jul 10 08:12:57 2014
Return-path: <std-proposals+bncBCW25A7E3QCRBZW57COQKGQE6ZS77XQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-pa0-f70.google.com ([209.85.220.70])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCW25A7E3QCRBZW57COQKGQE6ZS77XQ@isocpp.org>)
	id 1X57bF-0004CK-1C
	for gclcip-std-proposals@m.gmane.org; Thu, 10 Jul 2014 08:12:57 +0200
Original-Received: by mail-pa0-f70.google.com with SMTP id lj1sf57151453pab.5
        for <gclcip-std-proposals@m.gmane.org>; Wed, 09 Jul 2014 23:12: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=EE9cAXi+3kD24VjAWKnEklh5Rwm5zMHm1u3qMyck970=;
        b=URUI12G4TzUr+2fJ0zCfvruUympy2aHJpdBwmF96fZJuxGDdDnxxLDmFfqE46uB/OD
         y4ehYHVo3X/BPT77N19KfOjcrGhR/ITrFF9lW/CKocinZR7pHbcaT5/10PP15Wz3OHcI
         R3PUjpeufS5MzZoXjha7b7H9/RVxcBgdtXRyxkjwr/VQhnAlyeTViAHJF7X4/5h+EHi+
         3XjgCzIQATZtShRKtaabpGGn5JY+2TJ+XHD32TCr63O4P/r2jyHTlvazYAJKulzwsj6X
         6F6UxO10OxuHSaLv0yBBIClehTBxOEXVVQIQagE7PEC4uPtKTA9Fr/6jpFBzJEBCP4mY
         /qLw==
X-Gm-Message-State: ALoCoQmZ6H/qZONADsAv+Nh/+DUeJ9GtTjuAPfzIgwHVVnyEYgMMg7CjkDDse/AmBCKr2qZ0lHHg
X-Received: by 10.66.121.2 with SMTP id lg2mr11786123pab.43.1404972775315;
        Wed, 09 Jul 2014 23:12:55 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.51.17.39 with SMTP id gb7ls822igd.17.gmail; Wed, 09 Jul 2014
 23:12:54 -0700 (PDT)
X-Received: by 10.42.240.20 with SMTP id ky20mr9995icb.97.1404972774750;
        Wed, 09 Jul 2014 23:12:54 -0700 (PDT)
Original-Received: from mail-ie0-x22b.google.com (mail-ie0-x22b.google.com [2607:f8b0:4001:c03::22b])
        by mx.google.com with ESMTPS id z7si60582669icx.45.2014.07.09.23.12.54
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Wed, 09 Jul 2014 23:12:54 -0700 (PDT)
Received-SPF: pass (google.com: domain of potswa@gmail.com designates 2607:f8b0:4001:c03::22b as permitted sender) client-ip=2607:f8b0:4001:c03::22b;
Original-Received: by mail-ie0-f171.google.com with SMTP id at1so2518388iec.16
        for <std-proposals@isocpp.org>; Wed, 09 Jul 2014 23:12:54 -0700 (PDT)
X-Received: by 10.50.70.99 with SMTP id l3mr18921714igu.1.1404972774552;
        Wed, 09 Jul 2014 23:12:54 -0700 (PDT)
Original-Received: from [172.20.10.2] ([121.54.54.63])
        by mx.google.com with ESMTPSA id z6sm22355982igl.1.2014.07.09.23.12.53
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Wed, 09 Jul 2014 23:12:54 -0700 (PDT)
In-Reply-To: <CAFk2RUa5foB0ySVSjfc3t6cBOWE-+Qt76jnRv3X=FHP6ntpPjw@mail.gmail.com>
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:c03::22b 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:11781
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/11781>

--Apple-Mail=_5D3D7484-C4AA-4437-8142-084D173768DC
Content-Type: text/plain; charset=ISO-8859-1


On 2014-07-10, at 2:04 PM, Ville Voutilainen <ville.voutilainen@gmail.com> wrote:

>> As a very general policy in C++ library design, every accessor to a strictly
>> owned resource should be lvalue-qualified and/or return by value. This best
>> practice should be applied across the standard library.
> 
> I fail to see how that is "best practice".

The resource is strictly owned and the owner is represented by an xvalue. Therefore the resource will be going away very soon. It would be incorrect to return a reference to it.

Returning by rvalue reference may be tempting, but that is the semantic of move(). It does not transfer ownership, it only provides the caller with a handle to accept ownership. Returning an rvalue reference is something only special functions should do.

>> Whether returning a direct member or something owned elsewhere, methods of
>> an xvalue should always return by value. If a temporary might be introduced
>> elsewhere, correctness is always worth the cost -- and copy elision will
>> probably eliminate it anyway.
> 
> Except that copy elision will not eliminate it, and this correctness
> is not worth
> the cost.

Then perhaps we need more cases for copy elision. Sneaky rvalue reference hacks will only provide surprises and make user code more brittle. If there must be an rvalue reference overload, it should be named move_value() to indicate the different semantic.

-- 

--- 
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 email 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-proposals/.

--Apple-Mail=_5D3D7484-C4AA-4437-8142-084D173768DC
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 2:04 PM, Ville Voutilainen &lt;<a href=3D"mailto:vill=
e.voutilainen@gmail.com">ville.voutilainen@gmail.com</a>&gt; wrote:</div><b=
r><blockquote type=3D"cite"><blockquote type=3D"cite">As a very general pol=
icy in C++ library design, every accessor to a strictly<br>owned resource s=
hould be lvalue-qualified and/or return by value. This best<br>practice sho=
uld be applied across the standard library.<br></blockquote><br>I fail to s=
ee how that is "best practice&rdquo;.<br></blockquote><div><br></div><div>T=
he resource is strictly owned and the owner is represented by an xvalue. Th=
erefore the resource will be going away very soon. It would be incorrect to=
 return a reference to it.</div><div><br></div><div>Returning by rvalue ref=
erence may be tempting, but that is the semantic of move(). It does not tra=
nsfer ownership, it only provides the caller with a handle to accept owners=
hip. Returning an rvalue reference is something only special functions shou=
ld do.</div><br><blockquote type=3D"cite"><blockquote type=3D"cite">Whether=
 returning a direct member or something owned elsewhere, methods of<br>an x=
value should always return by value. If a temporary might be introduced<br>=
elsewhere, correctness is always worth the cost &mdash; and copy elision wi=
ll<br>probably eliminate it anyway.<br></blockquote><br>Except that copy el=
ision will not eliminate it, and this correctness<br>is not worth<br>the co=
st.<br></blockquote></div><br><div>Then perhaps we need more cases for copy=
 elision. Sneaky rvalue reference hacks will only provide surprises and mak=
e user code more brittle. If there must be an rvalue reference overload, it=
 should be named <font face=3D"Courier">move_value()</font> to indicate the=
 different semantic.</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=_5D3D7484-C4AA-4437-8142-084D173768DC--

.
