220 8277 <4d4d821b-029b-42c9-81b2-e41e4a36aaae@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Mikhail Semenov <mikhailsemenov1957@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Re: Generalized lambda capture: returning values
 not captured by reference, should not they be moved?
Date: Sat, 28 Dec 2013 09:37:46 -0800 (PST)
Lines: 132
Approved: news@gmane.org
Message-ID: <4d4d821b-029b-42c9-81b2-e41e4a36aaae@isocpp.org>
References: <9a553579-08d1-4d60-a288-b1cb95056127@isocpp.org> <02f29ec5-63e7-4ac9-9cef-1e4c374b3614@isocpp.org> <CAD6_Qj-L1+c9m9_dxmm4wwc0jsj4Keva9st5rAYjWuo81Wmvow@mail.gmail.com> <b0d7e002-0e5f-478a-8114-3ddec24b0131@isocpp.org>
 <52BE834B.1020608@gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_201_12863888.1388252267005"
X-Trace: ger.gmane.org 1388252262 2655 80.91.229.3 (28 Dec 2013 17:37:42 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Sat, 28 Dec 2013 17:37:42 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDC55PNFRYGRB24Y7SKQKGQEYGIHYAQ@isocpp.org Sat Dec 28 18:37:49 2013
Return-path: <std-proposals+bncBDC55PNFRYGRB24Y7SKQKGQEYGIHYAQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-oa0-f71.google.com ([209.85.219.71])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDC55PNFRYGRB24Y7SKQKGQEYGIHYAQ@isocpp.org>)
	id 1Vwxpd-00047m-4u
	for gclcip-std-proposals@m.gmane.org; Sat, 28 Dec 2013 18:37:49 +0100
Original-Received: by mail-oa0-f71.google.com with SMTP id i4sf49288882oah.2
        for <gclcip-std-proposals@m.gmane.org>; Sat, 28 Dec 2013 09:37:48 -0800 (PST)
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=rIzToldOlPDZKYnsBNTmI3Va4vwI8NQU06NOToN12yY=;
        b=dVqo5XNtc0JTmRgloTdpOnhKiStVQuFay3N4nAH+ZteE/VJuQr2rvK2khnOVt91Oy7
         YZP+16E8W9z/1rTizDr0mjr6wXFB3V9UHJsaXp7B914F7Wh0hn7W5sMMXo6y2s6P2z51
         je9w2xSQ3iwYqao+tDrBiBizfGRKre8nlcImUnkBB4o7f1x4i+8h6vY57aypz3td1XtS
         FK3iEOunADN7DhEVwtIgNr14CI5aipBkaYLbDgcZcbYkfWO1b2nRDliRi+ZUmoT3cLZS
         OTQ84LTO+iPtCdviL2iE4/wIGNAGI2tiuFreVbxr3HiQ5eRbM333DDkQiSAzPKexiD35
         ZfZw==
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=rIzToldOlPDZKYnsBNTmI3Va4vwI8NQU06NOToN12yY=;
        b=GQwEma7psMlaE9wYQg6yfRi7tPb3q1OdgEtS7+DVJbArY6yiv0h3T+ydnE11WsS8JU
         AZ+TEEb76PCr5tyM1IBdmPYMCqS2wgv8N15c5DJvcan+4U7YuzCTOxLxL2OPfT7FYsDj
         OBvjZLiLdwtpJEDlFPKBbjPun1JSSO47dz8o+0tR15O5/A1ReqRJE8g32/qh7no3fx3c
         BzH+ii/na16T1cSYQ/TRjrNQEGD+QjWbKYo+5xMJzLQJxTRuZqJegGYVtNtaeDlOZgmP
         AcgrmmWn2gR0uTOJA+1rVki2VB6OCczvQr+3CDeNpqinHGWKjV09oLqZzcFXX+unNOaX
         C1sw==
X-Gm-Message-State: ALoCoQmKes1UoiMMzHEbv2oTdRIEjr2OA0SzxjssXwUKtHx1VPQ6k0V8FnY6asPiCkMI+Hkok5wn
X-Received: by 10.182.108.136 with SMTP id hk8mr22200160obb.11.1388252268166;
        Sat, 28 Dec 2013 09:37:48 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.49.37.195 with SMTP id a3ls3029605qek.88.gmail; Sat, 28 Dec
 2013 09:37:47 -0800 (PST)
X-Received: by 10.49.24.109 with SMTP id t13mr169805qef.7.1388252267537;
        Sat, 28 Dec 2013 09:37:47 -0800 (PST)
In-Reply-To: <52BE834B.1020608@gmail.com>
X-Original-Sender: mikhailsemenov1957@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: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:8277
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/8277>

------=_Part_201_12863888.1388252267005
Content-Type: text/plain; charset=ISO-8859-1

I guess something positive might come out of this discussion. I think that 
for lambdas using && is not necessary, it's better to use *return 
std::move(x);*
 
But for && member functions this approach can be useful:
 
class A
{
    double *v;
    std::size_t n;
public:
....
    A operator+(A x) const &
    {
        for (std::size_t i = 0; i < n; i++)
        {
            x.v[i] += v[i];
        }
        return x; // copy elision according to the present standard
    }
 
    A operator+(const A& x) *&&*
    {       
        for (std::size_t i = 0; i < n; i++)
        {
             v[i] += x.v[i];
        }
        *return *this; // copy elision should be here as well!!! You have 
to write return std::move(*this); to get the desired affect*
    }
};
 

 

On Saturday, December 28, 2013 7:52:43 AM UTC, David Krauss wrote:

> On 12/28/13 4:36 AM, Mikhail Semenov wrote: 
> > I agree with your comments. My argument was fallacious. 
>
> For the sake of argument, we could have ref-qualified lambdas 
>
> auto fn = [x]() mutable && { return x; } // Automatic move would be 
> reasonable here 
> std::move( fn ) (); // because functor can only be called as an rvalue. 
> fn(); // Error: no matching operator() overload for lvalue fn. 
>
> One-shot functions do come up often enough that ref-qualfied lambdas 
> could be a useful language feature, but I don't know if the destructive 
> return rule in particular is worth implementing. Arguably if specified 
> it should apply to all rvalue ref-qualified functions returning a 
> member, not only lambdas, and that would be a serious breaking change. 
>
>

-- 

--- 
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/.

------=_Part_201_12863888.1388252267005
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>I guess something positive might come out of this dis=
cussion. I think that for lambdas using &amp;&amp; is not necessary, it's b=
etter to use <strong>return std::move(x);</strong></div><div>&nbsp;</div><d=
iv>But for &amp;&amp; member functions this approach can be useful:</div><d=
iv>&nbsp;</div><div>class A<br>{<br>&nbsp;&nbsp;&nbsp; double *v;<br>&nbsp;=
&nbsp;&nbsp; std::size_t n;<br>public:<br>...<br>&nbsp;&nbsp;&nbsp; A opera=
tor+(A x) const &amp;<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp; for (std::size_t i =3D 0; i &lt; n; i++)<br>&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp; x.v[i] +=3D v[i];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return x; //=
 copy elision according to the present standard<br>&nbsp;&nbsp;&nbsp; }</di=
v><div>&nbsp;</div><div>&nbsp;&nbsp;&nbsp; A operator+(const A&amp; x) <str=
ong>&amp;&amp;</strong><br>&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (std::size_t i =
=3D 0; i &lt; n; i++)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; v[i]=
 +=3D x.v[i];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong>return *this; // copy elision shou=
ld be here as well!!! You have to&nbsp;write return std::move(*this); to ge=
t the desired affect</strong><br>&nbsp;&nbsp;&nbsp; }<br>};</div><div>&nbsp=
;</div><div><br>&nbsp;</div><div><br>On Saturday, December 28, 2013 7:52:43=
 AM UTC, David Krauss wrote:</div><blockquote class=3D"gmail_quote" style=
=3D"margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(20=
4, 204, 204); border-left-width: 1px; border-left-style: solid;">On 12/28/1=
3 4:36 AM, Mikhail Semenov wrote:
<br>&gt; I agree with your comments. My argument was fallacious.
<br>
<br>For the sake of argument, we could have ref-qualified lambdas
<br>
<br>auto fn =3D [x]() mutable &amp;&amp; { return x; } // Automatic move wo=
uld be=20
<br>reasonable here
<br>std::move( fn ) (); // because functor can only be called as an rvalue.
<br>fn(); // Error: no matching operator() overload for lvalue fn.
<br>
<br>One-shot functions do come up often enough that ref-qualfied lambdas=20
<br>could be a useful language feature, but I don't know if the destructive=
=20
<br>return rule in particular is worth implementing. Arguably if specified=
=20
<br>it should apply to all rvalue ref-qualified functions returning a=20
<br>member, not only lambdas, and that would be a serious breaking change.
<br>
<br></blockquote></div>

<p></p>

-- <br />
&nbsp;<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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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_201_12863888.1388252267005--

.
