Topic: Extending the scope of generalized lambda captures to
Author: Vittorio Romeo <vittorio.romeo.vee@gmail.com>
Date: Thu, 15 Dec 2016 05:27:06 -0800 (PST)
Raw View
------=_Part_194_566234722.1481808426684
Content-Type: multipart/alternative;
boundary="----=_Part_195_142503845.1481808426685"
------=_Part_195_142503845.1481808426685
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
int main(){
auto l =3D [x =3D 10]() -> decltype(x) {};}
-=20
=20
*clang++ 4.0* rejects this code=20
<http://melpon.org/wandbox/permlink/zsFICgiaMhCrIIwe> with the following=
=20
error:
-=20
=20
error: use of undeclared identifier 'x'
auto l =3D [x =3D 10]() -> decltype(x) {};
^
=20
-=20
=20
*g++ 7* rejects this code=20
<http://melpon.org/wandbox/permlink/LXamt4MieU6n77Xs> with the following=
=20
error:
=20
In function 'int main()':
error: 'x' was not declared in this scope
auto l =3D [x =3D 10]() -> decltype(x) {};
^
error: 'x' was not declared in this scopeIn lambda function:
warning: no return statement in function returning non-void [-Wreturn-ty=
pe]
auto l =3D [x =3D 10]() -> decltype(x) {};
^
=20
=20
=20
I posted this today on StackOverflow thinking it was a compiler bug:
http://stackoverflow.com/questions/41162200/
But it's not - the standard says that the scope of `x` is limited to the=20
body of the lambda. This answer has the details:=20
http://stackoverflow.com/a/41162972/598696
(quoted below)
---
*TL;DR*: Compilers behave as expected.
The standard defines lambda semantics as follows [expr.prim.lambda, section=
=20
1]:
lambda-expression:
lambda-introducer lambda-declarator_opt compound-statement
Here *compound-statement* is just the body of lambda between {}, because=20
everything else is included in *lambda-declarator*:
lambda-declarator:
( parameter-declaration-clause ) decl-specifier-seq_opt
exception-specification_opt attribute-specifier-seq_opt trailing-ret=
urn-type_opt
Also, in section 12 of the same chapter, it's said that
An init-capture behaves as if it declares and explicitly captures a=20
variable of the form =E2=80=9Cauto init-capture ;=E2=80=9D whose declarativ=
e region is the=20
lambda-expression=E2=80=99s compound-statement, except that:
(12.1) =E2=80=94 if the capture is by copy (see below), the non-static data=
member=20
declared for the capture and the variable are treated as two different ways=
=20
of referring to the same object, which has the lifetime of the non-static=
=20
data member, and no additional copy and destruction is performed, and
(12.2) =E2=80=94 if the capture is by reference, the variable=E2=80=99s lif=
etime ends when=20
the closure object=E2=80=99s lifetime ends.
So, in your first example, variable x scope is the lambda body only, not=20
including the decltypeexpression. In the second example, obviously, x scope=
=20
is the function main.
---
Do you think that writing a proposal to relax these rules and to explicitly=
=20
allow generalized captures to be used inside the trailing return type would=
=20
be worthwhile?
One possible use case is when the generalized captures are initialized with=
=20
complex expressions. I encountered this while experimenting today=20
(http://melpon.org/wandbox/permlink/aVasfHaK6boC6NZt).
In general, it would be beneficial to have this feature whenever the=20
generalized capture is used as part of the return expression in the lambda=
=20
body.
--=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/f804aae4-6aeb-4239-9deb-23c9daeed950%40isocpp.or=
g.
------=_Part_195_142503845.1481808426685
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><pre class=3D"lang-cpp prettyprint prettyprinted gmail_quo=
te" style=3D"margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204=
, 204); padding-left: 1ex;"><code style=3D"font-family: Consolas, Menlo, Mo=
naco, "Lucida Console", "Liberation Mono", "DejaVu=
Sans Mono", "Bitstream Vera Sans Mono", "Courier New&q=
uot;, monospace, sans-serif; white-space: inherit;"><span class=3D"typ" sty=
le=3D"color: rgb(43, 145, 175);">int</span><span class=3D"pln" style=3D"col=
or: rgb(48, 51, 54);"> main</span><span class=3D"pun" style=3D"color: rgb(4=
8, 51, 54);">()</span><span class=3D"pln" style=3D"color: rgb(48, 51, 54);"=
>
</span><span class=3D"pun" style=3D"color: rgb(48, 51, 54);">{</span><span =
class=3D"pln" style=3D"color: rgb(48, 51, 54);">
</span><span class=3D"kwd" style=3D"color: rgb(16, 16, 148);">auto</spa=
n><span class=3D"pln" style=3D"color: rgb(48, 51, 54);"> l </span><span cla=
ss=3D"pun" style=3D"color: rgb(48, 51, 54);">=3D</span><span class=3D"pln" =
style=3D"color: rgb(48, 51, 54);"> </span><span class=3D"pun" style=3D"colo=
r: rgb(48, 51, 54);">[</span><span class=3D"pln" style=3D"color: rgb(48, 51=
, 54);">x </span><span class=3D"pun" style=3D"color: rgb(48, 51, 54);">=3D<=
/span><span class=3D"pln" style=3D"color: rgb(48, 51, 54);"> </span><span c=
lass=3D"lit" style=3D"color: rgb(125, 39, 39);">10</span><span class=3D"pun=
" style=3D"color: rgb(48, 51, 54);">]()</span><span class=3D"pln" style=3D"=
color: rgb(48, 51, 54);"> </span><span class=3D"pun" style=3D"color: rgb(48=
, 51, 54);">-></span><span class=3D"pln" style=3D"color: rgb(48, 51, 54)=
;"> </span><span class=3D"kwd" style=3D"color: rgb(16, 16, 148);">decltype<=
/span><span class=3D"pun" style=3D"color: rgb(48, 51, 54);">(</span><span c=
lass=3D"pln" style=3D"color: rgb(48, 51, 54);">x</span><span class=3D"pun" =
style=3D"color: rgb(48, 51, 54);">)</span><span class=3D"pln" style=3D"colo=
r: rgb(48, 51, 54);"> </span><span class=3D"pun" style=3D"color: rgb(48, 51=
, 54);">{};</span><span class=3D"pln" style=3D"color: rgb(48, 51, 54);">
</span><span class=3D"pun" style=3D"color: rgb(48, 51, 54);">}
</span></code></pre><br><br><ul style=3D"margin: 0px 0px 1em 30px; padding:=
0px; border: 0px; font-size: 15px; font-family: Arial, "Helvetica Neu=
e", Helvetica, sans-serif; color: rgb(36, 39, 41);"><li style=3D"margi=
n: 0px 0px 0.5em; padding: 0px; border: 0px; word-wrap: break-word;"><p sty=
le=3D"clear: both;"><a href=3D"http://melpon.org/wandbox/permlink/zsFICgiaM=
hCrIIwe" rel=3D"nofollow noreferrer" style=3D"color: rgb(0, 89, 153); font-=
family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size=
: 15px; cursor: pointer;"><strong style=3D"color: rgb(0, 89, 153); font-fam=
ily: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 1=
5px; cursor: pointer;">clang++ 4.0</strong><font color=3D"#005999" style=3D=
"color: rgb(0, 89, 153); font-family: Arial, "Helvetica Neue", He=
lvetica, sans-serif; font-size: 15px; cursor: pointer;"><span style=3D"curs=
or: pointer;">=C2=A0rejects this code</span></font></a><font color=3D"#2427=
29" face=3D"Arial, Helvetica Neue, Helvetica, sans-serif"><span style=3D"fo=
nt-size: 15px;">=C2=A0with the following error:</span></font><br></p></li><=
li style=3D"margin: 0px 0px 0.5em; padding: 0px; border: 0px; word-wrap: br=
eak-word;"><pre class=3D"lang-cpp prettyprint prettyprinted" style=3D"margi=
n-top: 0.5em; margin-bottom: 1em; padding: 5px; font-size: 13px; width: aut=
o; max-height: 600px; overflow: auto; font-family: Consolas, Menlo, Monaco,=
"Lucida Console", "Liberation Mono", "DejaVu Sans=
Mono", "Bitstream Vera Sans Mono", "Courier New",=
monospace, sans-serif; background-color: rgb(239, 240, 241); color: rgb(57=
, 51, 24); word-wrap: normal;"><code style=3D"font-family: Consolas, Menlo,=
Monaco, "Lucida Console", "Liberation Mono", "Dej=
aVu Sans Mono", "Bitstream Vera Sans Mono", "Courier Ne=
w", monospace, sans-serif; white-space: inherit;"><span class=3D"pln" =
style=3D"color: rgb(48, 51, 54);">error</span><span class=3D"pun" style=3D"=
color: rgb(48, 51, 54);">:</span><span class=3D"pln" style=3D"color: rgb(48=
, 51, 54);"> use of undeclared identifier </span><span class=3D"str" style=
=3D"color: rgb(125, 39, 39);">'x'</span><span class=3D"pln" style=
=3D"color: rgb(48, 51, 54);">
</span><span class=3D"kwd" style=3D"color: rgb(16, 16, 148);">auto<=
/span><span class=3D"pln" style=3D"color: rgb(48, 51, 54);"> l </span><span=
class=3D"pun" style=3D"color: rgb(48, 51, 54);">=3D</span><span class=3D"p=
ln" style=3D"color: rgb(48, 51, 54);"> </span><span class=3D"pun" style=3D"=
color: rgb(48, 51, 54);">[</span><span class=3D"pln" style=3D"color: rgb(48=
, 51, 54);">x </span><span class=3D"pun" style=3D"color: rgb(48, 51, 54);">=
=3D</span><span class=3D"pln" style=3D"color: rgb(48, 51, 54);"> </span><sp=
an class=3D"lit" style=3D"color: rgb(125, 39, 39);">10</span><span class=3D=
"pun" style=3D"color: rgb(48, 51, 54);">]()</span><span class=3D"pln" style=
=3D"color: rgb(48, 51, 54);"> </span><span class=3D"pun" style=3D"color: rg=
b(48, 51, 54);">-></span><span class=3D"pln" style=3D"color: rgb(48, 51,=
54);"> </span><span class=3D"kwd" style=3D"color: rgb(16, 16, 148);">declt=
ype</span><span class=3D"pun" style=3D"color: rgb(48, 51, 54);">(</span><sp=
an class=3D"pln" style=3D"color: rgb(48, 51, 54);">x</span><span class=3D"p=
un" style=3D"color: rgb(48, 51, 54);">)</span><span class=3D"pln" style=3D"=
color: rgb(48, 51, 54);"> </span><span class=3D"pun" style=3D"color: rgb(48=
, 51, 54);">{};</span><span class=3D"pln" style=3D"color: rgb(48, 51, 54);"=
>
</span><span class=3D"pun" style=3D=
"color: rgb(48, 51, 54);">^</span></code></pre></li><li style=3D"margin: 0p=
x; padding: 0px; border: 0px; word-wrap: break-word;"><p style=3D"clear: bo=
th;"><a href=3D"http://melpon.org/wandbox/permlink/LXamt4MieU6n77Xs" rel=3D=
"nofollow noreferrer" style=3D"color: rgb(0, 89, 153); cursor: pointer;"><s=
trong>g++ 7</strong>=C2=A0rejects this code</a>=C2=A0with the following err=
or:</p><pre class=3D"lang-cpp prettyprint prettyprinted" style=3D"margin-to=
p: 0.5em; margin-bottom: 1em; padding: 5px; font-size: 13px; width: auto; m=
ax-height: 600px; overflow: auto; font-family: Consolas, Menlo, Monaco, &qu=
ot;Lucida Console", "Liberation Mono", "DejaVu Sans Mon=
o", "Bitstream Vera Sans Mono", "Courier New", mon=
ospace, sans-serif; background-color: rgb(239, 240, 241); color: rgb(57, 51=
, 24); word-wrap: normal;"><code style=3D"font-family: Consolas, Menlo, Mon=
aco, "Lucida Console", "Liberation Mono", "DejaVu =
Sans Mono", "Bitstream Vera Sans Mono", "Courier New&qu=
ot;, monospace, sans-serif; white-space: inherit;"><span class=3D"typ" styl=
e=3D"color: rgb(43, 145, 175);">In</span><span class=3D"pln" style=3D"color=
: rgb(48, 51, 54);"> function </span><span class=3D"str" style=3D"color: rg=
b(125, 39, 39);">'int main()'</span><span class=3D"pun" style=3D"co=
lor: rgb(48, 51, 54);">:</span><span class=3D"pln" style=3D"color: rgb(48, =
51, 54);">
error</span><span class=3D"pun" style=3D"color: rgb(48, 51, 54);">:</span><=
span class=3D"pln" style=3D"color: rgb(48, 51, 54);"> </span><span class=3D=
"str" style=3D"color: rgb(125, 39, 39);">'x'</span><span class=3D"p=
ln" style=3D"color: rgb(48, 51, 54);"> was not declared in </span><span cla=
ss=3D"kwd" style=3D"color: rgb(16, 16, 148);">this</span><span class=3D"pln=
" style=3D"color: rgb(48, 51, 54);"> scope
</span><span class=3D"kwd" style=3D"color: rgb(16, 16, 148);">auto</span>=
<span class=3D"pln" style=3D"color: rgb(48, 51, 54);"> l </span><span class=
=3D"pun" style=3D"color: rgb(48, 51, 54);">=3D</span><span class=3D"pln" st=
yle=3D"color: rgb(48, 51, 54);"> </span><span class=3D"pun" style=3D"color:=
rgb(48, 51, 54);">[</span><span class=3D"pln" style=3D"color: rgb(48, 51, =
54);">x </span><span class=3D"pun" style=3D"color: rgb(48, 51, 54);">=3D</s=
pan><span class=3D"pln" style=3D"color: rgb(48, 51, 54);"> </span><span cla=
ss=3D"lit" style=3D"color: rgb(125, 39, 39);">10</span><span class=3D"pun" =
style=3D"color: rgb(48, 51, 54);">]()</span><span class=3D"pln" style=3D"co=
lor: rgb(48, 51, 54);"> </span><span class=3D"pun" style=3D"color: rgb(48, =
51, 54);">-></span><span class=3D"pln" style=3D"color: rgb(48, 51, 54);"=
> </span><span class=3D"kwd" style=3D"color: rgb(16, 16, 148);">decltype</s=
pan><span class=3D"pun" style=3D"color: rgb(48, 51, 54);">(</span><span cla=
ss=3D"pln" style=3D"color: rgb(48, 51, 54);">x</span><span class=3D"pun" st=
yle=3D"color: rgb(48, 51, 54);">)</span><span class=3D"pln" style=3D"color:=
rgb(48, 51, 54);"> </span><span class=3D"pun" style=3D"color: rgb(48, 51, =
54);">{};</span><span class=3D"pln" style=3D"color: rgb(48, 51, 54);">
</span><span class=3D"pun" style=3D"color=
: rgb(48, 51, 54);">^</span><span class=3D"pln" style=3D"color: rgb(48, 51,=
54);">
error</span><span class=3D"pun" style=3D"color: rgb(48, 51, 54);">:</span><=
span class=3D"pln" style=3D"color: rgb(48, 51, 54);"> </span><span class=3D=
"str" style=3D"color: rgb(125, 39, 39);">'x'</span><span class=3D"p=
ln" style=3D"color: rgb(48, 51, 54);"> was not declared in </span><span cla=
ss=3D"kwd" style=3D"color: rgb(16, 16, 148);">this</span><span class=3D"pln=
" style=3D"color: rgb(48, 51, 54);"> scope
</span><span class=3D"typ" style=3D"color: rgb(43, 145, 175);">In</span><sp=
an class=3D"pln" style=3D"color: rgb(48, 51, 54);"> lambda function</span><=
span class=3D"pun" style=3D"color: rgb(48, 51, 54);">:</span><span class=3D=
"pln" style=3D"color: rgb(48, 51, 54);">
warning</span><span class=3D"pun" style=3D"color: rgb(48, 51, 54);">:</span=
><span class=3D"pln" style=3D"color: rgb(48, 51, 54);"> no </span><span cla=
ss=3D"kwd" style=3D"color: rgb(16, 16, 148);">return</span><span class=3D"p=
ln" style=3D"color: rgb(48, 51, 54);"> statement in function returning non<=
/span><span class=3D"pun" style=3D"color: rgb(48, 51, 54);">-</span><span c=
lass=3D"kwd" style=3D"color: rgb(16, 16, 148);">void</span><span class=3D"p=
ln" style=3D"color: rgb(48, 51, 54);"> </span><span class=3D"pun" style=3D"=
color: rgb(48, 51, 54);">[-</span><span class=3D"typ" style=3D"color: rgb(4=
3, 145, 175);">Wreturn</span><span class=3D"pun" style=3D"color: rgb(48, 51=
, 54);">-</span><span class=3D"pln" style=3D"color: rgb(48, 51, 54);">type<=
/span><span class=3D"pun" style=3D"color: rgb(48, 51, 54);">]</span><span c=
lass=3D"pln" style=3D"color: rgb(48, 51, 54);">
</span><span class=3D"kwd" style=3D"color: rgb(16, 16, 148);">auto</span>=
<span class=3D"pln" style=3D"color: rgb(48, 51, 54);"> l </span><span class=
=3D"pun" style=3D"color: rgb(48, 51, 54);">=3D</span><span class=3D"pln" st=
yle=3D"color: rgb(48, 51, 54);"> </span><span class=3D"pun" style=3D"color:=
rgb(48, 51, 54);">[</span><span class=3D"pln" style=3D"color: rgb(48, 51, =
54);">x </span><span class=3D"pun" style=3D"color: rgb(48, 51, 54);">=3D</s=
pan><span class=3D"pln" style=3D"color: rgb(48, 51, 54);"> </span><span cla=
ss=3D"lit" style=3D"color: rgb(125, 39, 39);">10</span><span class=3D"pun" =
style=3D"color: rgb(48, 51, 54);">]()</span><span class=3D"pln" style=3D"co=
lor: rgb(48, 51, 54);"> </span><span class=3D"pun" style=3D"color: rgb(48, =
51, 54);">-></span><span class=3D"pln" style=3D"color: rgb(48, 51, 54);"=
> </span><span class=3D"kwd" style=3D"color: rgb(16, 16, 148);">decltype</s=
pan><span class=3D"pun" style=3D"color: rgb(48, 51, 54);">(</span><span cla=
ss=3D"pln" style=3D"color: rgb(48, 51, 54);">x</span><span class=3D"pun" st=
yle=3D"color: rgb(48, 51, 54);">)</span><span class=3D"pln" style=3D"color:=
rgb(48, 51, 54);"> </span><span class=3D"pun" style=3D"color: rgb(48, 51, =
54);">{};</span><span class=3D"pln" style=3D"color: rgb(48, 51, 54);">
</span><span class=3D"pun" style=3D"color=
: rgb(48, 51, 54);">^</span></code></pre><br></li></ul><font color=3D"#3033=
36" face=3D"Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaV=
u Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, sans-serif">=
<span style=3D"white-space: pre;">I posted this today on StackOverflow thin=
king it was a compiler bug:</span></font><div><font color=3D"#303336" face=
=3D"Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans M=
ono, Bitstream Vera Sans Mono, Courier New, monospace, sans-serif"><span st=
yle=3D"white-space: pre;">http://stackoverflow.com/questions/41162200/</spa=
n><br></font></div><div><font color=3D"#303336" face=3D"Consolas, Menlo, Mo=
naco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera San=
s Mono, Courier New, monospace, sans-serif"><span style=3D"white-space: pre=
;"><br></span></font></div><div><font color=3D"#303336" face=3D"Consolas, M=
enlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream =
Vera Sans Mono, Courier New, monospace, sans-serif"><span style=3D"white-sp=
ace: pre;">But it's not - the standard says that the scope of `x` is li=
mited to the body of the lambda. This answer has the details:</span>
</font></div><div><font color=3D"#303336" face=3D"Consolas, Menlo, Monaco, =
Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono=
, Courier New, monospace, sans-serif"><span style=3D"white-space: pre;">htt=
p://stackoverflow.com/a/41162972/598696</span><br></font></div><div><font c=
olor=3D"#303336" face=3D"Consolas, Menlo, Monaco, Lucida Console, Liberatio=
n Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace,=
sans-serif"><span style=3D"white-space: pre;">(quoted below)</span></font>=
</div><div><font color=3D"#303336" face=3D"Consolas, Menlo, Monaco, Lucida =
Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Couri=
er New, monospace, sans-serif"><span style=3D"white-space: pre;"><br></span=
></font></div><div><font color=3D"#303336" face=3D"Consolas, Menlo, Monaco,=
Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mon=
o, Courier New, monospace, sans-serif"><span style=3D"white-space: pre;">--=
-</span></font></div><div><font color=3D"#303336" face=3D"Consolas, Menlo, =
Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera S=
ans Mono, Courier New, monospace, sans-serif"><span style=3D"white-space: p=
re;"><br></span></font></div><div><p style=3D"margin-bottom: 1em; font-size=
: 15px; clear: both; color: rgb(36, 39, 41); font-family: Arial, "Helv=
etica Neue", Helvetica, sans-serif;"><strong>TL;DR</strong>: Compilers=
behave as expected.</p><p style=3D"margin-bottom: 1em; font-size: 15px; cl=
ear: both; color: rgb(36, 39, 41); font-family: Arial, "Helvetica Neue=
", Helvetica, sans-serif;">The standard defines lambda semantics as fo=
llows [expr.prim.lambda, section 1]:</p><blockquote style=3D"margin: 0px 0p=
x 10px; padding: 10px; border-width: 0px 0px 0px 2px; border-top-style: ini=
tial; border-right-style: initial; border-bottom-style: initial; border-lef=
t-style: solid; border-top-color: initial; border-right-color: initial; bor=
der-bottom-color: initial; border-left-color: rgb(255, 235, 142); border-im=
age: initial; font-size: 15px; quotes: none; background-color: rgb(255, 248=
, 220); color: rgb(36, 39, 41); font-family: Arial, "Helvetica Neue&qu=
ot;, Helvetica, sans-serif;"><p style=3D"margin-bottom: 1em; clear: both;">=
lambda-expression:</p><pre class=3D"lang-cpp prettyprint prettyprinted" sty=
le=3D"padding: 5px; font-size: 13px; width: auto; max-height: 600px; overfl=
ow: auto; font-family: Consolas, Menlo, Monaco, "Lucida Console",=
"Liberation Mono", "DejaVu Sans Mono", "Bitstream=
Vera Sans Mono", "Courier New", monospace, sans-serif; back=
ground-color: rgb(239, 240, 241); color: rgb(57, 51, 24); word-wrap: normal=
;"><code style=3D"font-family: Consolas, Menlo, Monaco, "Lucida Consol=
e", "Liberation Mono", "DejaVu Sans Mono", "B=
itstream Vera Sans Mono", "Courier New", monospace, sans-ser=
if; white-space: inherit;"><span class=3D"pln" style=3D"color: rgb(48, 51, =
54);"> lambda</span><span class=3D"pun" style=3D"color: rgb(48, 51, 54);"=
>-</span><span class=3D"pln" style=3D"color: rgb(48, 51, 54);">introducer l=
ambda</span><span class=3D"pun" style=3D"color: rgb(48, 51, 54);">-</span><=
span class=3D"pln" style=3D"color: rgb(48, 51, 54);">declarator_opt compoun=
d</span><span class=3D"pun" style=3D"color: rgb(48, 51, 54);">-</span><span=
class=3D"pln" style=3D"color: rgb(48, 51, 54);">statement</span></code></p=
re></blockquote><p style=3D"margin-bottom: 1em; font-size: 15px; clear: bot=
h; color: rgb(36, 39, 41); font-family: Arial, "Helvetica Neue", =
Helvetica, sans-serif;">Here=C2=A0<em>compound-statement</em>=C2=A0is just =
the body of lambda between {}, because everything else is included in=C2=A0=
<em>lambda-declarator</em>:</p><blockquote style=3D"margin: 0px 0px 10px; p=
adding: 10px; border-width: 0px 0px 0px 2px; border-top-style: initial; bor=
der-right-style: initial; border-bottom-style: initial; border-left-style: =
solid; border-top-color: initial; border-right-color: initial; border-botto=
m-color: initial; border-left-color: rgb(255, 235, 142); border-image: init=
ial; font-size: 15px; quotes: none; background-color: rgb(255, 248, 220); c=
olor: rgb(36, 39, 41); font-family: Arial, "Helvetica Neue", Helv=
etica, sans-serif;"><p style=3D"margin-bottom: 1em; clear: both;">lambda-de=
clarator:</p><pre class=3D"lang-cpp prettyprint prettyprinted" style=3D"pad=
ding: 5px; font-size: 13px; width: auto; max-height: 600px; overflow: auto;=
font-family: Consolas, Menlo, Monaco, "Lucida Console", "Li=
beration Mono", "DejaVu Sans Mono", "Bitstream Vera San=
s Mono", "Courier New", monospace, sans-serif; background-co=
lor: rgb(239, 240, 241); color: rgb(57, 51, 24); word-wrap: normal;"><code =
style=3D"font-family: Consolas, Menlo, Monaco, "Lucida Console", =
"Liberation Mono", "DejaVu Sans Mono", "Bitstream =
Vera Sans Mono", "Courier New", monospace, sans-serif; white=
-space: inherit;"><span class=3D"pln" style=3D"color: rgb(48, 51, 54);"> =
</span><span class=3D"pun" style=3D"color: rgb(48, 51, 54);">(</span><span =
class=3D"pln" style=3D"color: rgb(48, 51, 54);"> parameter</span><span clas=
s=3D"pun" style=3D"color: rgb(48, 51, 54);">-</span><span class=3D"pln" sty=
le=3D"color: rgb(48, 51, 54);">declaration</span><span class=3D"pun" style=
=3D"color: rgb(48, 51, 54);">-</span><span class=3D"pln" style=3D"color: rg=
b(48, 51, 54);">clause </span><span class=3D"pun" style=3D"color: rgb(48, 5=
1, 54);">)</span><span class=3D"pln" style=3D"color: rgb(48, 51, 54);"> dec=
l</span><span class=3D"pun" style=3D"color: rgb(48, 51, 54);">-</span><span=
class=3D"pln" style=3D"color: rgb(48, 51, 54);">specifier</span><span clas=
s=3D"pun" style=3D"color: rgb(48, 51, 54);">-</span><span class=3D"pln" sty=
le=3D"color: rgb(48, 51, 54);">seq_opt
exception</span><span class=3D"pun" style=3D"color: rgb(48, 51, 54);=
">-</span><span class=3D"pln" style=3D"color: rgb(48, 51, 54);">specificati=
on_opt attribute</span><span class=3D"pun" style=3D"color: rgb(48, 51, 54);=
">-</span><span class=3D"pln" style=3D"color: rgb(48, 51, 54);">specifier</=
span><span class=3D"pun" style=3D"color: rgb(48, 51, 54);">-</span><span cl=
ass=3D"pln" style=3D"color: rgb(48, 51, 54);">seq_opt trailing</span><span =
class=3D"pun" style=3D"color: rgb(48, 51, 54);">-</span><span class=3D"kwd"=
style=3D"color: rgb(16, 16, 148);">return</span><span class=3D"pun" style=
=3D"color: rgb(48, 51, 54);">-</span><span class=3D"pln" style=3D"color: rg=
b(48, 51, 54);">type_opt</span></code></pre></blockquote><p style=3D"margin=
-bottom: 1em; font-size: 15px; clear: both; color: rgb(36, 39, 41); font-fa=
mily: Arial, "Helvetica Neue", Helvetica, sans-serif;">Also, in s=
ection 12 of the same chapter, it's said that</p><blockquote style=3D"m=
argin: 0px 0px 10px; padding: 10px; border-width: 0px 0px 0px 2px; border-t=
op-style: initial; border-right-style: initial; border-bottom-style: initia=
l; border-left-style: solid; border-top-color: initial; border-right-color:=
initial; border-bottom-color: initial; border-left-color: rgb(255, 235, 14=
2); border-image: initial; font-size: 15px; quotes: none; background-color:=
rgb(255, 248, 220); color: rgb(36, 39, 41); font-family: Arial, "Helv=
etica Neue", Helvetica, sans-serif;"><p style=3D"margin-bottom: 1em; c=
lear: both;">An init-capture behaves as if it declares and explicitly captu=
res a variable of the form =E2=80=9Cauto init-capture ;=E2=80=9D whose decl=
arative region is the lambda-expression=E2=80=99s compound-statement, excep=
t that:</p><p style=3D"margin-bottom: 1em; clear: both;">(12.1) =E2=80=94 i=
f the capture is by copy (see below), the non-static data member declared f=
or the capture and the variable are treated as two different ways of referr=
ing to the same object, which has the lifetime of the non-static data membe=
r, and no additional copy and destruction is performed, and</p><p style=3D"=
clear: both;">(12.2) =E2=80=94 if the capture is by reference, the variable=
=E2=80=99s lifetime ends when the closure object=E2=80=99s lifetime ends.</=
p></blockquote><p style=3D"margin-bottom: 1em; font-size: 15px; clear: both=
; color: rgb(36, 39, 41); font-family: Arial, "Helvetica Neue", H=
elvetica, sans-serif;">So, in your first example, variable=C2=A0<code style=
=3D"padding: 1px 5px; font-size: 13px; font-family: Consolas, Menlo, Monaco=
, "Lucida Console", "Liberation Mono", "DejaVu San=
s Mono", "Bitstream Vera Sans Mono", "Courier New"=
, monospace, sans-serif; background-color: rgb(239, 240, 241); white-space:=
pre-wrap;">x</code>=C2=A0scope is the lambda body only, not including the=
=C2=A0<code style=3D"padding: 1px 5px; font-size: 13px; font-family: Consol=
as, Menlo, Monaco, "Lucida Console", "Liberation Mono",=
"DejaVu Sans Mono", "Bitstream Vera Sans Mono", "=
Courier New", monospace, sans-serif; background-color: rgb(239, 240, 2=
41); white-space: pre-wrap;">decltype</code>expression. In the second examp=
le, obviously,=C2=A0<code style=3D"padding: 1px 5px; font-size: 13px; font-=
family: Consolas, Menlo, Monaco, "Lucida Console", "Liberati=
on Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono=
", "Courier New", monospace, sans-serif; background-color: r=
gb(239, 240, 241); white-space: pre-wrap;">x</code>=C2=A0scope is the funct=
ion=C2=A0<code style=3D"padding: 1px 5px; font-size: 13px; font-family: Con=
solas, Menlo, Monaco, "Lucida Console", "Liberation Mono&quo=
t;, "DejaVu Sans Mono", "Bitstream Vera Sans Mono", &qu=
ot;Courier New", monospace, sans-serif; background-color: rgb(239, 240=
, 241); white-space: pre-wrap;">main</code>.</p><p style=3D"margin-bottom: =
1em; font-size: 15px; clear: both; color: rgb(36, 39, 41); font-family: Ari=
al, "Helvetica Neue", Helvetica, sans-serif;">---</p><p style=3D"=
margin-bottom: 1em; font-size: 15px; clear: both; color: rgb(36, 39, 41); f=
ont-family: Arial, "Helvetica Neue", Helvetica, sans-serif;">Do y=
ou think that writing a proposal to relax these rules and to explicitly all=
ow generalized captures to be used inside the trailing return type would be=
worthwhile?</p><p style=3D"margin-bottom: 1em; font-size: 15px; clear: bot=
h; color: rgb(36, 39, 41); font-family: Arial, "Helvetica Neue", =
Helvetica, sans-serif;">One possible use case is when the generalized captu=
res are initialized with complex expressions. I encountered this while expe=
rimenting today (http://melpon.org/wandbox/permlink/aVasfHaK6boC6NZt).<br>I=
n general, it would be beneficial to have this feature whenever the general=
ized capture is used as part of the return expression in the lambda body.</=
p></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/f804aae4-6aeb-4239-9deb-23c9daeed950%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/f804aae4-6aeb-4239-9deb-23c9daeed950=
%40isocpp.org</a>.<br />
------=_Part_195_142503845.1481808426685--
------=_Part_194_566234722.1481808426684--
.