220 29634 <f2e7975d-3c7e-411e-8237-b60041603378@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Nicol Bolas <jmckesson@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Use stateless lambdas without capturing
Date: Sat, 3 Dec 2016 07:46:04 -0800 (PST)
Lines: 113
Approved: news@gmane.org
Message-ID: <f2e7975d-3c7e-411e-8237-b60041603378@isocpp.org>
References: <DA325640-1898-4835-844F-290FC7A482BA@gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_1045_194412753.1480779964130"
X-Trace: blaine.gmane.org 1480779968 10136 195.159.176.226 (3 Dec 2016 15:46:08 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Sat, 3 Dec 2016 15:46:08 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCEKFTV6ZUMBBPGRRPBAKGQEH27SYZA@isocpp.org Sat Dec 03 16:46:03 2016
Return-path: <std-proposals+bncBCEKFTV6ZUMBBPGRRPBAKGQEH27SYZA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-pg0-f69.google.com ([74.125.83.69])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCEKFTV6ZUMBBPGRRPBAKGQEH27SYZA@isocpp.org>)
	id 1cDCVm-0001JX-D2
	for gclcip-std-proposals@m.gmane.org; Sat, 03 Dec 2016 16:46:02 +0100
Original-Received: by mail-pg0-f69.google.com with SMTP id f188sf243553504pgc.1
        for <gclcip-std-proposals@m.gmane.org>; Sat, 03 Dec 2016 07:46:06 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=W9m2QwiIep96L/Fr35v/XpHzuPV0mvub5W+PtxwR41A=;
        b=v+AUaTkL633iDDyZ1ziiXXW8495tVsd219YwKfVO53mMQUd6ADGuqpydq30oGXoy8x
         zx3nRBkHLbiO6l4Kl+25Im0KVQ5SHA4vsP00FVMpflOvoY38i2xNTay23WvXXE9iGLWN
         bVwNSNH309/m/hkXaOEpX2xpbzbGVLpi64Yo5h7gtCP+/cIV2ruX2oE9H+lI9xmQL+nP
         KHr1CRhDonBHzkN97vWLeNyZOAtk8xmUjtnSM9SEbP8JD//WLPTDEFBVHIL/0kkpfC8e
         oe60gcV9wFhGi2VBgoBt9UaYmb8cb5B9Xi5v0/Tzx5bXGNAY+PE9z29Mv3n2PdlurZgS
         ytOg==
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
         :x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=W9m2QwiIep96L/Fr35v/XpHzuPV0mvub5W+PtxwR41A=;
        b=c/1PmEBQb5nb9oU1UDhsFdhGzpiWw2quV77/tTy+Oyvn9kwT5+E3kxE3OkJfn8N5vR
         Y+wtf/Zbe9TZ/4zvP/2a0O7whqrgsxgxseJaMrDcW0dZkAs6mUkSi0OHckUwv9wJ2e9B
         6/MHw8CWvVjKcBhcFmHHyNUiaso6N2tXVsfSiDPZbs0Wzpo2+mntAS7MMgyy8kdhx12r
         lHFx0kYRL5QbagZriWTOaJc6iG8BaDBFL8SFT7hMXFtkEw+Ncjha3vYDvnwe+fZ7f/1J
         oZM6UhNCvMWAxgVnUZBA0K26QbaF3V9r+kBgwJt1laOkLBDucLwpImlmdHi0PnpMKdlK
         fmpQ==
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:x-spam-checked-in-group:list-post:list-help
         :list-archive:list-subscribe:list-unsubscribe;
        bh=W9m2QwiIep96L/Fr35v/XpHzuPV0mvub5W+PtxwR41A=;
        b=N5L64rR+uDcnmUi16EUU8mTLPpankPksYBCICoXFriq1FTA0EvC+1T2ClAxNtSnVOC
         k1/nFEBzQpmqgZBJVL0xVfxILQIqi6vlum9DOIeGHcBIkTee8L8WZu6jDgFvFyFU884w
         mB6UecArPWGZzdxqMFdcr7GbW8UrSRar936yw/Ld4oJopD6gqDXsFPebtnva36X42zvJ
         DAvjCcDVgZPo2ya0pILE7FyvMMupeVpFwyOfd3pkRX7RJGwBts48oC2ugO/7kKMztKBj
         /KvW43LCuKO7PNJxAbWNqH/UUrC3Mh49vLwyQSZx4oOY+72VDTS6bI3MFAMHdKMXzTU9
         vcKA==
X-Gm-Message-State: AKaTC03+moeG875BdCec9hcr78pjQCIsmrRFk/PDHHAZaw6xni22uwrNX04IK26hu1ZquA==
X-Received: by 10.99.168.74 with SMTP id i10mr22459396pgp.90.1480779965786;
        Sat, 03 Dec 2016 07:46:05 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.157.46.13 with SMTP id q13ls21558213otb.20.gmail; Sat, 03 Dec
 2016 07:46:04 -0800 (PST)
X-Received: by 10.157.8.134 with SMTP id 6mr3379904otf.17.1480779964809;
        Sat, 03 Dec 2016 07:46:04 -0800 (PST)
In-Reply-To: <DA325640-1898-4835-844F-290FC7A482BA@gmail.com>
X-Original-Sender: jmckesson@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:29634
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/29634>

------=_Part_1045_194412753.1480779964130
Content-Type: multipart/alternative; 
	boundary="----=_Part_1046_1489039637.1480779964130"

------=_Part_1046_1489039637.1480779964130
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On Saturday, December 3, 2016 at 6:47:13 AM UTC-5, David Krauss wrote:
>
> 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=
 must be=20
> captured for use by another lambda. In this case, b cannot be stateless.
>
> 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 i=
d-expression used=20
> 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=20
> stateless lambda from an enclosing scope. (Binding to a reference or taki=
ng=20
> an address are genuinely problematic, though. Pass-by-reference would be=
=20
> broken, but fortunately <algorithm> and such pass by value.)
>

Why is this important? If it is a stateless lambda, then there's really no=
=20
reason not to just make them named functions outside of the function's=20
scope. I fail to see why encouraging people to write a plethora of=20
functions within another function is a good idea.

Lambdas are fine things, when taken in moderation. But I don't like us=20
adding features that encourage people to use them more often than is=20
strictly necessary for code-clarity and functionality purposes.

--=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/f2e7975d-3c7e-411e-8237-b60041603378%40isocpp.or=
g.

------=_Part_1046_1489039637.1480779964130
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Saturday, December 3, 2016 at 6:47:13 AM UTC-5, David K=
rauss wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-lef=
t: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div style=3D"word=
-wrap:break-word"><div><font face=3D"Courier">int main() {</font></div><div=
><font face=3D"Courier">=C2=A0 =C2=A0 auto a =3D []{ return 5; };</font></d=
iv><div><font face=3D"Courier">=C2=A0 =C2=A0 auto b =3D []{ +a; a(); }; // =
Error, =E2=80=9Ca=E2=80=9D not captured.</font></div><div><font face=3D"Cou=
rier">}</font></div><div><br></div>A stateless lambda object is empty, so i=
t=E2=80=99s unfortunate that they must be captured for use by another lambd=
a. In this case, <font face=3D"Courier">b</font> cannot be stateless.<div><=
br></div><div>C++17 constexpr lambdas offer a partial workaround:</div><div=
><br></div><div><div><font face=3D"Courier">int main() {</font></div><div><=
font face=3D"Courier">=C2=A0 =C2=A0 constexpr auto a =3D +[]{ return 5; };<=
/font></div><div><font face=3D"Courier">=C2=A0 =C2=A0 auto b =3D []{ +a; a(=
); }; // OK, =E2=80=9Ca=E2=80=9D is a constant id-expression used with L-to=
-R conversion.</font></div><div><font face=3D"Courier">}</font></div></div>=
<div><br></div><div>This is a bit esoteric, and it can possibly cost some p=
erformance.</div><div><br></div><div>Perhaps it should be permissible to ca=
ll, convert, and even copy a stateless lambda from an enclosing scope. (Bin=
ding to a reference or taking an address are genuinely problematic, though.=
 Pass-by-reference would be broken, but fortunately=C2=A0<font face=3D"Cour=
ier">&lt;algorithm&gt;</font>=C2=A0and such pass by value.)</div></div></bl=
ockquote><div><br>Why is this important? If it is a stateless lambda, then =
there&#39;s really no reason not to just make them named functions outside =
of the function&#39;s scope. I fail to see why encouraging people to write =
a plethora of functions within another function is a good idea.<br><br>Lamb=
das are fine things, when taken in moderation. But I don&#39;t like us addi=
ng features that encourage people to use them more often than is strictly n=
ecessary for code-clarity and functionality purposes.<br></div></div>

<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/f2e7975d-3c7e-411e-8237-b60041603378%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/f2e7975d-3c7e-411e-8237-b60041603378=
%40isocpp.org</a>.<br />

------=_Part_1046_1489039637.1480779964130--

------=_Part_1045_194412753.1480779964130--

.
