220 29632 <DA325640-1898-4835-844F-290FC7A482BA@gmail.com> article
Path: news.gmane.org!.POSTED!not-for-mail
From: David Krauss <potswa@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Use stateless lambdas without capturing
Date: Sat, 3 Dec 2016 19:47:07 +0800
Lines: 89
Approved: news@gmane.org
Message-ID: <DA325640-1898-4835-844F-290FC7A482BA@gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0 (Mac OS X Mail 9.1 \(3096.5\))
Content-Type: multipart/alternative; boundary="Apple-Mail=_0E270FA7-5D96-41CA-BA51-E99B482376E1"
X-Trace: blaine.gmane.org 1480765633 24707 195.159.176.226 (3 Dec 2016 11:47:13 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Sat, 3 Dec 2016 11:47:13 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCW25A7E3QCRBPXBRLBAKGQE6A3QPWA@isocpp.org Sat Dec 03 12:47:09 2016
Return-path: <std-proposals+bncBCW25A7E3QCRBPXBRLBAKGQE6A3QPWA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-pf0-f198.google.com ([209.85.192.198])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCW25A7E3QCRBPXBRLBAKGQE6A3QPWA@isocpp.org>)
	id 1cD8ma-0005Py-Jv
	for gclcip-std-proposals@m.gmane.org; Sat, 03 Dec 2016 12:47:08 +0100
Original-Received: by mail-pf0-f198.google.com with SMTP id 144sf433786799pfv.5
        for <gclcip-std-proposals@m.gmane.org>; Sat, 03 Dec 2016 03:47:12 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=from:subject:message-id:date:to:mime-version:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=gXP98QtbXdb8Zv5MFe+J3M0Mbi5CJEw/7pUZLIieVwk=;
        b=acCPy8v6UZx1YyewCTwNnBnZhOKfe8Uqw9xYhzKebqY8DnCLzHrVWzcnbH9fX7ET1n
         rvvyWn86ydkX3IEwFBj4vcXNWombInfPmaDcGs+MyHI9lklhKR5pdmpOPcb1lwnRJXjY
         UbsfAo3w1BZABsa704tL3K17gwJfqYVPFQRuCAPJIW71wTmvJt4L7w+UCZqWAMzoeRwW
         OSjShmTchsYG115of1sQwO9FQJdv2xXW1VTygjRo4yjCK1+jDngt0mGNAutrucnvTiWD
         g9l+XsmJfADK9mFXz98lEWj6XmlWLvQ7z9BSNezOQDzZF5VrH6pg+2BZbNERfuzLHQLA
         jwiw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:from:subject:message-id:date:to:mime-version
         :x-original-sender:x-original-authentication-results:reply-to
         :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post
         :list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=gXP98QtbXdb8Zv5MFe+J3M0Mbi5CJEw/7pUZLIieVwk=;
        b=SfiKXa2e1BXbZ4H/0in3Q/XDXaIWl28Asmpic7rnmx9HIew2ySsqhkrX+Fj11SQ6BF
         PTA4o9KDZcb6/OWKnwX6zI5MBKf/eNT0gvz/LeuOzAcPYIs+xyzz02WxjJC3S2kz9HQY
         mBJ4G2p6byA+JFoIe87CZ1ayIKo9UbzoguPAsp96UkgHjIndGJ56aYL8337xacm7zgwF
         jUi5lMbkjONbP3ICQ68pTYIlOuwMtCA0DuV3FXg1oAdCMn1VA4PatWbBJi8QhKGDPn/a
         NW9BnEW+EEI5i8JVg0fbM6zsuIHWak2fhiunjJH4Ey27GjFNvyY6/S3axXxyRuK7umKh
         KL7g==
X-Gm-Message-State: AKaTC00hvJ/0vzgfNV6xZpzG+DHEhhOnTDyb0afr/dUcmhgLkB1rBa33KSCgvIlgr3E8nQ==
X-Received: by 10.99.53.5 with SMTP id c5mr22227040pga.127.1480765632306;
        Sat, 03 Dec 2016 03:47:12 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.107.169.209 with SMTP id f78ls6734857ioj.29.gmail; Sat, 03 Dec
 2016 03:47:10 -0800 (PST)
X-Received: by 10.99.113.68 with SMTP id b4mr88076569pgn.33.1480765630646;
        Sat, 03 Dec 2016 03:47:10 -0800 (PST)
Original-Received: from mail-pg0-x230.google.com (mail-pg0-x230.google.com. [2607:f8b0:400e:c05::230])
        by mx.google.com with ESMTPS id q17si8514858pgh.96.2016.12.03.03.47.10
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Sat, 03 Dec 2016 03:47:10 -0800 (PST)
Received-SPF: pass (google.com: domain of potswa@gmail.com designates 2607:f8b0:400e:c05::230 as permitted sender) client-ip=2607:f8b0:400e:c05::230;
Original-Received: by mail-pg0-x230.google.com with SMTP id p66so117673297pga.2
        for <std-proposals@isocpp.org>; Sat, 03 Dec 2016 03:47:10 -0800 (PST)
X-Received: by 10.99.228.5 with SMTP id a5mr88085264pgi.1.1480765630315;
        Sat, 03 Dec 2016 03:47:10 -0800 (PST)
Original-Received: from [172.20.10.2] ([175.158.200.160])
        by smtp.gmail.com with ESMTPSA id o29sm14515070pgn.28.2016.12.03.03.47.08
        for <std-proposals@isocpp.org>
        (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128);
        Sat, 03 Dec 2016 03:47:09 -0800 (PST)
X-Mailer: Apple Mail (2.3096.5)
X-Original-Sender: potswa@gmail.com
X-Original-Authentication-Results: mx.google.com;       dkim=pass
 header.i=@gmail.com;       spf=pass (google.com: domain of potswa@gmail.com
 designates 2607:f8b0:400e:c05::230 as permitted sender) smtp.mailfrom=potswa@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: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <https://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>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:29632
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/29632>


--Apple-Mail=_0E270FA7-5D96-41CA-BA51-E99B482376E1
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8

int main() {
    auto a =3D []{ return 5; };
    auto b =3D []{ +a; a(); }; // Error, =E2=80=9Ca=E2=80=9D not captured.
}

A stateless lambda object is empty, so it=E2=80=99s unfortunate that they m=
ust be captured for use by another lambda. In this case, b cannot be statel=
ess.

C++17 constexpr lambdas offer a partial workaround:

int main() {
    constexpr auto a =3D +[]{ return 5; };
    auto b =3D []{ +a; a(); }; // OK, =E2=80=9Ca=E2=80=9D is a constant id-=
expression used with L-to-R conversion.
}

This is a bit esoteric, and it can possibly cost some performance.

Perhaps it should be permissible to call, convert, and even copy a stateles=
s lambda from an enclosing scope. (Binding to a reference or taking an addr=
ess are genuinely problematic, though. Pass-by-reference would be broken, b=
ut fortunately <algorithm> and such pass by value.)

--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/DA325640-1898-4835-844F-290FC7A482BA%40gmail.com=
..

--Apple-Mail=_0E270FA7-5D96-41CA-BA51-E99B482376E1
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dutf-8"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: s=
pace; -webkit-line-break: after-white-space;" class=3D""><div class=3D""><f=
ont face=3D"Courier" class=3D"">int main() {</font></div><div class=3D""><f=
ont face=3D"Courier" class=3D"">&nbsp; &nbsp; auto a =3D []{ return 5; };</=
font></div><div class=3D""><font face=3D"Courier" class=3D"">&nbsp; &nbsp; =
auto b =3D []{ +a; a(); }; // Error, =E2=80=9Ca=E2=80=9D not captured.</fon=
t></div><div class=3D""><font face=3D"Courier" class=3D"">}</font></div><di=
v class=3D""><br class=3D""></div>A stateless lambda object is empty, so it=
=E2=80=99s unfortunate that they must be captured for use by another lambda=
.. In this case, <font face=3D"Courier" class=3D"">b</font> cannot be statel=
ess.<div class=3D""><br class=3D""></div><div class=3D"">C++17 constexpr la=
mbdas offer a partial workaround:</div><div class=3D""><br class=3D""></div=
><div class=3D""><div class=3D""><font face=3D"Courier" class=3D"">int main=
() {</font></div><div class=3D""><font face=3D"Courier" class=3D"">&nbsp; &=
nbsp; constexpr auto a =3D +[]{ return 5; };</font></div><div class=3D""><f=
ont face=3D"Courier" class=3D"">&nbsp; &nbsp; auto b =3D []{ +a; a(); }; //=
 OK, =E2=80=9Ca=E2=80=9D is a constant id-expression used with L-to-R conve=
rsion.</font></div><div class=3D""><font face=3D"Courier" class=3D"">}</fon=
t></div></div><div class=3D""><br class=3D""></div><div class=3D"">This is =
a bit esoteric, and it can possibly cost some performance.</div><div class=
=3D""><br class=3D""></div><div class=3D"">Perhaps it should be permissible=
 to call, convert, and even copy a stateless lambda from an enclosing scope=
.. (Binding to a reference or taking an address are genuinely problematic, t=
hough. Pass-by-reference would be broken, but fortunately&nbsp;<font face=
=3D"Courier" class=3D"">&lt;algorithm&gt;</font>&nbsp;and such pass by valu=
e.)</div><div class=3D""><br class=3D""></div></body></html>

<p></p>

-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/DA325640-1898-4835-844F-290FC7A482BA%=
40gmail.com?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/DA325640-1898-4835-844F-290FC7A482BA%=
40gmail.com</a>.<br />

--Apple-Mail=_0E270FA7-5D96-41CA-BA51-E99B482376E1--

.
