Topic: Default constructor for lambdas


Author: Vincent Reverdy <vince.rev@gmail.com>
Date: Fri, 16 Dec 2016 14:47:45 -0800 (PST)
Raw View
------=_Part_2411_169816189.1481928465523
Content-Type: multipart/alternative;
 boundary="----=_Part_2412_2115786499.1481928465524"

------=_Part_2412_2115786499.1481928465524
Content-Type: text/plain; charset=UTF-8

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?

Thank you very much.
Best,
Vincent Reverdy

--
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/13497310-30de-4542-9ba4-fb1fbd730cb6%40isocpp.org.

------=_Part_2412_2115786499.1481928465524
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hello.<br><br>What is the reason why lambdas have no defau=
lt 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; 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">template</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</sp=
an><span style=3D"color: #008;" class=3D"styled-by-prettify">class</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> F</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: =
#008;" class=3D"styled-by-prettify">class</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">object</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-=
by-prettify">constexpr</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettif=
y">object</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify">F</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=
: #660;" class=3D"styled-by-prettify">{}</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0</s=
pan><span style=3D"color: #800;" class=3D"styled-by-prettify">// Constructo=
r</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=
=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-prettify"=
>constexpr</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
 </span><span style=3D"color: #008;" class=3D"styled-by-prettify">void</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> execute</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">()</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify">F</span><span 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: #800;" class=3D"styled-by=
-prettify">// Default-construct the lambda, and run it</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"><br></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;" c=
lass=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: #000;" class=3D"=
styled-by-prettify">std</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify">cout</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&=
lt;&lt;</span><span style=3D"color: #080;" class=3D"styled-by-prettify">&qu=
ot;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-p=
rettify">std</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">::</span><span style=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>myobject</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">.</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify">execute</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">();</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br></span></div></code></div><br>W=
hat do you think? Remarks? Comments?<br><br>Thank you very much.<br>Best,<b=
r>Vincent Reverdy<br></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/13497310-30de-4542-9ba4-fb1fbd730cb6%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/13497310-30de-4542-9ba4-fb1fbd730cb6=
%40isocpp.org</a>.<br />

------=_Part_2412_2115786499.1481928465524--

------=_Part_2411_169816189.1481928465523--

.


Author: "D. B." <db0451@gmail.com>
Date: Fri, 16 Dec 2016 23:15:13 +0000
Raw View
--001a114ccb68fe113a0543cebdf9
Content-Type: text/plain; charset=UTF-8

My uninformed guess is that it's because lambdas are primarily intended to
be called and passed around as opaque entities, and the fact they have
types is a kind of unavoidable baggage, rather than a design goal or
something to exploit. But I'm quite likely to be wrong :)

Could you elaborate on where an ability to construct another instance of
the templated type would be useful? As written, I can't see why you
wouldn't just stash it as a member in the ctor and call it again later. it
seems wasteful, constructing a lambda initially, only to discard it and
rebuild on each execute(); the one in the ctor is merely a surrogate for
type deduction. If the type had mutable or static members, that could cause
different behaviour, but then why would you pass such a type into the above
pattern? There must be motivations this doesn't illuminate (or maybe it's
just too late in the day for me to be thinking about things like this!)

--
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/CACGiwhHpOT%2BZ-gM7ypjxTVvBA6%3DL0R-j1DFx6PsQdVWA1Rg%3DoQ%40mail.gmail.com.

--001a114ccb68fe113a0543cebdf9
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div><div>My uninformed guess is that it&#39;s because lam=
bdas are primarily intended to be called and passed around as opaque entiti=
es, and the fact they have types is a kind of unavoidable baggage, rather t=
han a design goal or something to exploit. But I&#39;m quite likely to be w=
rong :)<br><br></div>Could you elaborate on where an ability to construct a=
nother instance of the templated type would be useful? As written, I can&#3=
9;t see why you wouldn&#39;t just stash it as a member in the ctor and call=
 it again later. it seems wasteful, constructing a lambda initially, only t=
o discard it and rebuild on each execute(); the one in the ctor is merely a=
 surrogate for type deduction. If the type had mutable or static members, t=
hat could cause different behaviour, but then why would you pass such a typ=
e into the above pattern? There must be motivations this doesn&#39;t illumi=
nate (or maybe it&#39;s just too late in the day for me to be thinking abou=
t things like this!)<br><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/CACGiwhHpOT%2BZ-gM7ypjxTVvBA6%3DL0R-j=
1DFx6PsQdVWA1Rg%3DoQ%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfoote=
r">https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CACGiwhHpOT=
%2BZ-gM7ypjxTVvBA6%3DL0R-j1DFx6PsQdVWA1Rg%3DoQ%40mail.gmail.com</a>.<br />

--001a114ccb68fe113a0543cebdf9--

.


Author: szollosi.lorand@gmail.com
Date: Fri, 16 Dec 2016 15:21:12 -0800 (PST)
Raw View
------=_Part_712_106992050.1481930472538
Content-Type: multipart/alternative;
 boundary="----=_Part_713_1238446629.1481930472538"

------=_Part_713_1238446629.1481930472538
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Hi,

Minor thing - it will only work if all the captures of the lambda are=20
copyable. Even then it's non-trivial sometimes to choose schematics.

Thanks,
-lorro

2016. december 16., p=C3=A9ntek 23:47:45 UTC+1 id=C5=91pontban Vincent Reve=
rdy a=20
k=C3=B6vetkez=C5=91t =C3=ADrta:
>
> Hello.
>
> What is the reason why lambdas have no default constructor? Is there any=
=20
> 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=20
> 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,=20
> and run it
> };
>
> object myobject([](){std::cout<<"Hello world!"<<std::endl;});
> myobject.execute();
>
> What do you think? Remarks? Comments?
>
> Thank you very much.
> Best,
> Vincent Reverdy
>

--=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/902b08de-322b-4a97-8ba2-dfd8d3eb88e6%40isocpp.or=
g.

------=_Part_713_1238446629.1481930472538
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hi,<br><br>Minor thing - it will only work if all the capt=
ures of the lambda are copyable. Even then it&#39;s non-trivial sometimes t=
o choose schematics.<br><br>Thanks,<br>-lorro<br><br>2016. december 16., p=
=C3=A9ntek 23:47:45 UTC+1 id=C5=91pontban Vincent Reverdy a k=C3=B6vetkez=
=C5=91t =C3=ADrta:<blockquote class=3D"gmail_quote" style=3D"margin: 0;marg=
in-left: 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 construct=
or? 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><b=
r>Thank you very much.<br>Best,<br>Vincent Reverdy<br></div></blockquote></=
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/902b08de-322b-4a97-8ba2-dfd8d3eb88e6%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/902b08de-322b-4a97-8ba2-dfd8d3eb88e6=
%40isocpp.org</a>.<br />

------=_Part_713_1238446629.1481930472538--

------=_Part_712_106992050.1481930472538--

.


Author: Nicol Bolas <jmckesson@gmail.com>
Date: Fri, 16 Dec 2016 20:46:08 -0800 (PST)
Raw View
------=_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--

.


Author: Thiago Macieira <thiago@macieira.org>
Date: Fri, 16 Dec 2016 22:33:51 -0800
Raw View
On sexta-feira, 16 de dezembro de 2016 14:47:45 PST 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?

What would you initialise the captures-by-reference to?

 [i] { ++i; }

has struct equivalent:

struct Lambda
{
 int &i;
 Lambda(int &i) : i(i) {}
 operator()() { ++i; }
};

The above cannot have a default constructor.

--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center

--
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/296450916.pPnEejVmnO%40tjmaciei-mobl1.

.


Author: Thiago Macieira <thiago@macieira.org>
Date: Fri, 16 Dec 2016 22:48:17 -0800
Raw View
On sexta-feira, 16 de dezembro de 2016 22:33:51 PST Thiago Macieira wrote:
>         [i] { ++i; }

I meant [&i] { ++i; }

--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center

--
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/19819060.gaamCJ8YJz%40tjmaciei-mobl1.

.