220 17432 <5533C099.2050307@cloudius-systems.com> article
Path: news.gmane.org!not-for-mail
From: Avi Kivity <avi@cloudius-systems.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Proposal: lambda move capture
Date: Sun, 19 Apr 2015 17:50:01 +0300
Lines: 45
Approved: news@gmane.org
Message-ID: <5533C099.2050307@cloudius-systems.com>
References: <0c39ed29-d389-4894-bc65-71a9bb79cbe5@isocpp.org> <CAFk2RUYre=zG1oX+rZKGm-mJ37gGvQkwWsa56eEkCmyQRq+Lew@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
X-Trace: ger.gmane.org 1429455018 8708 80.91.229.3 (19 Apr 2015 14:50:18 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Sun, 19 Apr 2015 14:50:18 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDHJFOWD7YCRBHEBZ6UQKGQEB3QDLNY@isocpp.org Sun Apr 19 16:50:09 2015
Return-path: <std-proposals+bncBDHJFOWD7YCRBHEBZ6UQKGQEB3QDLNY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-la0-f70.google.com ([209.85.215.70])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDHJFOWD7YCRBHEBZ6UQKGQEB3QDLNY@isocpp.org>)
	id 1YjqXt-0007xv-VS
	for gclcip-std-proposals@m.gmane.org; Sun, 19 Apr 2015 16:50:06 +0200
Original-Received: by labgx2 with SMTP id gx2sf33993505lab.1
        for <gclcip-std-proposals@m.gmane.org>; Sun, 19 Apr 2015 07:50:05 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to
         :subject:references:in-reply-to:content-type:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe;
        bh=+9C28LE67/SHFDwz4MjoFYWyBkLcu/V2hReCVnF5zmw=;
        b=SoHLo54zI4p9nlJJnsx/6S3Yi4SHl+NLA/rCOE3KYIZ3B55I1wrvbxIoGvmBKxsBXa
         ap1oDMrBjtGb3Npz65ARIqgCwDyQ14jfYK4pG3Avsw5Nq8T42P7vu3eSwcp0CAiAqxMo
         coEXGV1sJtrIK/MNXoUXRycyDmbU5qtwk6cPWBddJO9ZriMvikUJhhw8QOKrb6ySb2KR
         2Nvijb9ODWgIcfiSh5HGzQITJ6o+OEO6M9Bguui94ouzAn3d007PY4CFfcDIl/72UbME
         B+Z2UBuXZ7WWNyb9u8bMPROtF6dwIS5af0/Q8rva9bA72CfT+Pk6wvmbvoZwo7YL6fG/
         e26w==
X-Gm-Message-State: ALoCoQmxDUxdGxWzdHC6fKZBqZuTmeJRtoWrTKVUEspt9dHmv5H+E5VYiBEtRKgEGp7nf+dmXUUT
X-Received: by 10.112.203.168 with SMTP id kr8mr5437722lbc.10.1429455005304;
        Sun, 19 Apr 2015 07:50:05 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.180.216.105 with SMTP id op9ls369675wic.7.canary; Sun, 19 Apr
 2015 07:50:04 -0700 (PDT)
X-Received: by 10.194.179.38 with SMTP id dd6mr23196285wjc.149.1429455004237;
        Sun, 19 Apr 2015 07:50:04 -0700 (PDT)
Original-Received: from mail-wg0-f53.google.com (mail-wg0-f53.google.com. [74.125.82.53])
        by mx.google.com with ESMTPS id f18si27821898wjz.182.2015.04.19.07.50.03
        for <std-proposals@isocpp.org>
        (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Sun, 19 Apr 2015 07:50:03 -0700 (PDT)
Received-SPF: pass (google.com: domain of avi@cloudius-systems.com designates 74.125.82.53 as permitted sender) client-ip=74.125.82.53;
Original-Received: by wgso17 with SMTP id o17so155444238wgs.1
        for <std-proposals@isocpp.org>; Sun, 19 Apr 2015 07:50:03 -0700 (PDT)
X-Received: by 10.180.104.4 with SMTP id ga4mr17817494wib.86.1429455003836;
        Sun, 19 Apr 2015 07:50:03 -0700 (PDT)
Original-Received: from avi.cloudius ([212.143.139.214])
        by mx.google.com with ESMTPSA id gi17sm13109935wjc.8.2015.04.19.07.50.02
        (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Sun, 19 Apr 2015 07:50:03 -0700 (PDT)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0
In-Reply-To: <CAFk2RUYre=zG1oX+rZKGm-mJ37gGvQkwWsa56eEkCmyQRq+Lew@mail.gmail.com>
X-Original-Sender: avi@cloudius-systems.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of avi@cloudius-systems.com designates 74.125.82.53 as permitted
 sender) smtp.mail=avi@cloudius-systems.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:17432
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/17432>

On 04/19/2015 05:26 PM, Ville Voutilainen wrote:
> On 19 April 2015 at 17:06, Avi Kivity <avi@cloudius-systems.com> wrote:
>> Lambdas currently support three styles of capture:
>>
>> 1. Init capture (fully generic) [x = expression]
>> 2. Copy capture: [x], equivalent to [x = x]
>> 3. Reference capture: [&x], roughly equivalent to [x = std::ref(x)]
>>
>> As I find myself typing [x = std::move(x)] more and more, I propose to
>> support a fourth style:
>>
>> 4. Move capture: [&&x], equivalent to [x = std::move(x)]
>>
>> This would be very useful for move-only types such as unique_ptr<>.
>
> I don't see that as a good idea. It looks like a
> capture-by-rvalue-reference, but
> you don't want to capture an rvalue reference, you want to capture a
> value initialized
> from an rvalue. Consistently, when you want to move into a function or
> into a constructor,
> you need to use std::move. For a lambda, you're initializing a
> capture, which is rather
> similar to calling a constructor, so using std::move there makes sense.
>
> This syntax has been proposed in the committee too - we found it undesirable
> due to the points above, and went for init-captures since they can do much more
> than initialize from an rvalue.

Well, it's a pity.  In a not-so-large code base I have about 100 
instances of this pattern, some with multiple variables move-captured in 
the same lambda.  This syntax would greatly reduce verbosity for a very 
repetitive pattern.

But I appreciate the subtle different between &x and &&x (clobbering of 
the source).

-- 

--- 
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/.

.
