220 29862 <bc756ba0-1e7f-4237-baf4-fb2185ea5087@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: Default constructor for lambdas
Date: Fri, 16 Dec 2016 20:46:08 -0800 (PST)
Lines: 161
Approved: news@gmane.org
Message-ID: <bc756ba0-1e7f-4237-baf4-fb2185ea5087@isocpp.org>
References: <13497310-30de-4542-9ba4-fb1fbd730cb6@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_763_984198195.1481949968238"
X-Trace: blaine.gmane.org 1481949972 23738 195.159.176.226 (17 Dec 2016 04:46:12 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Sat, 17 Dec 2016 04:46:12 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCEKFTV6ZUMBBEEG2PBAKGQEQ4ZP5FQ@isocpp.org Sat Dec 17 05:46:08 2016
Return-path: <std-proposals+bncBCEKFTV6ZUMBBEEG2PBAKGQEQ4ZP5FQ@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+bncBCEKFTV6ZUMBBEEG2PBAKGQEQ4ZP5FQ@isocpp.org>)
	id 1cI6sn-0004r7-D2
	for gclcip-std-proposals@m.gmane.org; Sat, 17 Dec 2016 05:46:05 +0100
Original-Received: by mail-pf0-f198.google.com with SMTP id j128sf151942271pfg.4
        for <gclcip-std-proposals@m.gmane.org>; Fri, 16 Dec 2016 20:46:10 -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=8fh81VltZx5byIxaIaFoH70H2L/5wysPokG9UxUJOII=;
        b=pSjbe4lJ8CZ671ADzJy8Ust5bvbKPT/8DayEQ8iuHmsPvaKnxLPnd7rqk2tdgp12g6
         rD1/vXubnNGEtBP9qPt017h9N4CB/2lCLjykAETz/WaYZ/LlSzxoFbHv0Xz58csLGEb1
         K+VyG4fWtgbcnFIBicF2pQBd4aUx24KOxnSze3gIPnKajeBQRiLpUPzeN+i4OoS+Dlfp
         lkVXoDlRjjldz8DndJ8KwlyHLvCL9H96IKL2PdoeHzTfkYc5UXB0pzF9fbYgruq93lpe
         IdVecYzt7bDCwv+CJdTv+/+1gBcTGtgE6kMAnEPUp210F9EAz/AqLF3v5SCw+w5ys9L5
         8Erw==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        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=8fh81VltZx5byIxaIaFoH70H2L/5wysPokG9UxUJOII=;
        b=d4zu8AFdC1XCVXrtmmz5QLrkyNBeCXWfMZArUbZBm0u5BfWwazRxh/x+jQkVU9hjru
         AAYDspjzV4Zssc1Hdz93PrNDSOmzagbThVvplpMBNC09W7PairkYEpYm1IO3RX74lDwV
         xGMUzUe67bAkKFDZ9as1RfVSPUMGz9s4m1YTx3/4j5v/GNdO5cDragttNFnVDswRoAoK
         /Loq8iRxl4Gm6EcfKvqJfto+Oet1yvynLqlG1qcECjq2KAlcszptyQ8jXPt10B25Ar5R
         htmI5/VGj4qmx/QY4jqwrLEcZ1YJ4dQhzWOzJjfL7ZtZMX8GDxthjdexyu+SF+CPJIOq
         d+qA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        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=8fh81VltZx5byIxaIaFoH70H2L/5wysPokG9UxUJOII=;
        b=XKnIH6ajjdPFO0+Mk4bjqYzREEuyfIceAXbtVfdRF97dD71G3S1LPR3ZEMcc950rQl
         3Cj1lZ4gAs9urEn5xF7UgUmOw5rIXCCHKC4laSGCRwptYjI0ZvKoN46XgWRbVVdyTbob
         UU+I9zCs3hdvOyO2Jw0cvgAOp+ynyDjX1X3Z3XKOHM5pp1uLA58OkWNihQoSK30eDN4t
         35oRoGLg5ntjdbTjaYOgL5DHrLw69Fd0OiGsC3+bXuoX+kqo+V4pwO0sxsY28o0+OHsp
         YFaFIySe6mxpRf1wWT8VRp3BlyFwhDbsS4IYLkD9d+d6gCxqmaPhHVvIjgKtegrB2dYQ
         JLHA==
X-Gm-Message-State: AKaTC00wHuooGZNy1Jr5W0qFslSBP6S8gPxJvfMe7z4i5KKag/Kz0tXvLXy14kjHVL5VDA==
X-Received: by 10.99.148.1 with SMTP id m1mr3221207pge.4.1481949969503;
        Fri, 16 Dec 2016 20:46:09 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.157.27.206 with SMTP id v14ls9686717otv.2.gmail; Fri, 16 Dec
 2016 20:46:08 -0800 (PST)
X-Received: by 10.157.8.134 with SMTP id 6mr369671otf.17.1481949968769;
        Fri, 16 Dec 2016 20:46:08 -0800 (PST)
In-Reply-To: <13497310-30de-4542-9ba4-fb1fbd730cb6@isocpp.org>
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:29862
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/29862>

------=_Part_763_984198195.1481949968238
Content-Type: multipart/alternative; 
	boundary="----=_Part_764_95023109.1481949968238"

------=_Part_764_95023109.1481949968238
Content-Type: text/plain; charset=UTF-8

On Friday, December 16, 2016 at 5:47:45 PM UTC-5, Vincent Reverdy wrote:
>
> Hello.
>
> What is the reason why lambdas have no default constructor? Is there any 
> technical reason behind that, or is it a pure design decision?
>
> I have a use case where not having a default constructor for lambda is 
> annoying.
>
> Given C++17 class template deduction, I would like to be able to do:
>
> template <class F>
> class object
> {
>     constexpr object(F) {}            // Constructor
>     constexpr void execute() {F()();} // Default-construct the lambda, 
> and run it
> };
>
> object myobject([](){std::cout<<"Hello world!"<<std::endl;});
> myobject.execute();
>
> What do you think? Remarks? Comments?
>

I think this would be much more reasonable as this:

struct HelloWorld { void operator()() {std::cout<<"Hello world!"<<std::endl
;}};

object myobject(HelloWorld());

I generally consider globally-scoped lambdas like these to be dubious 
constructs. There's nothing to capture, so the only thing you're doing is 
making it *slightly* more convenient to define a struct with an operator() 
overload.

That being said, I'm not against the feature, so long as it *only applies* 
to lambdas that have no captures. There was a long thread on this forum 
about applying default constructors to capturing lambdas, and it was 
generally agreed on that it broke the meaning of the lambda.

-- 
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/bc756ba0-1e7f-4237-baf4-fb2185ea5087%40isocpp.org.

------=_Part_764_95023109.1481949968238
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Friday, December 16, 2016 at 5:47:45 PM UTC-5, Vincent =
Reverdy wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-l=
eft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"=
>Hello.<br><br>What is the reason why lambdas have no default constructor? =
Is there any
 technical reason behind that, or is it a pure design decision?<br><br>I ha=
ve a use case where not having a default constructor for lambda is annoying=
..<br><br>Given C++17 class template deduction, I would like to be able to d=
o:<br><br><div style=3D"background-color:rgb(250,250,250);border-color:rgb(=
187,187,187);border-style:solid;border-width:1px"><code><div><span style=3D=
"color:#008">template</span><span style=3D"color:#000"> </span><span style=
=3D"color:#660">&lt;</span><span style=3D"color:#008">class</span><span sty=
le=3D"color:#000"> F</span><span style=3D"color:#660">&gt;</span><span styl=
e=3D"color:#000"><br></span><span style=3D"color:#008">class</span><span st=
yle=3D"color:#000"> </span><span style=3D"color:#008">object</span><span st=
yle=3D"color:#000"><br></span><span style=3D"color:#660">{</span><span styl=
e=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#008">conste=
xpr</span><span style=3D"color:#000"> </span><span style=3D"color:#008">obj=
ect</span><span style=3D"color:#660">(</span><span style=3D"color:#000">F</=
span><span style=3D"color:#660">)</span><span style=3D"color:#000"> </span>=
<span style=3D"color:#660">{}</span><span style=3D"color:#000"> =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0</span><span style=3D"color:#800">// Constru=
ctor</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=
=3D"color:#008">constexpr</span><span style=3D"color:#000"> </span><span st=
yle=3D"color:#008">void</span><span style=3D"color:#000"> execute</span><sp=
an style=3D"color:#660">()</span><span style=3D"color:#000"> </span><span s=
tyle=3D"color:#660">{</span><span style=3D"color:#000">F</span><span style=
=3D"color:#660">()();}</span><span style=3D"color:#000"> </span><span style=
=3D"color:#800">// Default-construct the lambda, and run it</span><span sty=
le=3D"color:#000"><br></span><span style=3D"color:#660">};</span><span styl=
e=3D"color:#000"><br><br></span><span style=3D"color:#008">object</span><sp=
an style=3D"color:#000"> myobject</span><span style=3D"color:#660">([](){</=
span><span style=3D"color:#000">std</span><span style=3D"color:#660">::</sp=
an><span style=3D"color:#000">cout</span><span style=3D"color:#660">&lt;&lt=
;</span><span style=3D"color:#080">&quot;<wbr>Hello world!&quot;</span><spa=
n style=3D"color:#660">&lt;&lt;</span><span style=3D"color:#000">std</span>=
<span style=3D"color:#660">::</span><span style=3D"color:#000">endl</span><=
span style=3D"color:#660">;});</span><span style=3D"color:#000"><br>myobjec=
t</span><span style=3D"color:#660">.</span><span style=3D"color:#000">execu=
te</span><span style=3D"color:#660">();</span><span style=3D"color:#000"><b=
r></span></div></code></div><br>What do you think? Remarks? Comments?<br></=
div></blockquote><div><br>I think this would be much more reasonable as thi=
s:<br><br><div style=3D"background-color: rgb(250, 250, 250); border-color:=
 rgb(187, 187, 187); border-style: solid; border-width: 1px; overflow-wrap:=
 break-word;" class=3D"prettyprint"><code class=3D"prettyprint"><div class=
=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-by-prettif=
y">struct</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
</span><span style=3D"color: #606;" class=3D"styled-by-prettify">HelloWorld=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #008;" class=3D"styled-by-prettify">void</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">operator</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">()()</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
std</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify">cout</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">&lt;&lt;</span><span =
style=3D"color: #080;" class=3D"styled-by-prettify">&quot;Hello world!&quot=
;</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;&lt;<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify">std</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify">endl</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">;}};</span><span style=3D"color:=
 #000;" class=3D"styled-by-prettify"><br><br></span><span style=3D"color: #=
008;" class=3D"styled-by-prettify">object</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> myobject</span><span style=3D"color: #660;"=
 class=3D"styled-by-prettify">(</span><span style=3D"color: #606;" class=3D=
"styled-by-prettify">HelloWorld</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">());</span></div></code></div><br>I generally consider=
 globally-scoped lambdas like these to be dubious constructs. There&#39;s n=
othing to capture, so the only thing you&#39;re doing is making it <i>sligh=
tly</i> more convenient to define a struct with an operator() overload.<br>=
<br>That being said, I&#39;m not against the feature, so long as it <i>only=
 applies</i> to lambdas that have no captures. There was a long thread on t=
his forum about applying default constructors to capturing lambdas, and it =
was generally agreed on that it broke the meaning of the lambda.<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/bc756ba0-1e7f-4237-baf4-fb2185ea5087%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/bc756ba0-1e7f-4237-baf4-fb2185ea5087=
%40isocpp.org</a>.<br />

------=_Part_764_95023109.1481949968238--

------=_Part_763_984198195.1481949968238--

.
