Topic: [std-discussion] An implementation of Generic
Author: Daniel Biesiada <hollowonepl@gmail.com>
Date: Fri, 21 Dec 2012 14:02:13 +0100
Raw View
--Apple-Mail=_5ED7E440-596B-4B1C-A70E-5FB5E8DDBFB5
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=ISO-8859-2
Wow,
This is almost same crazy as Javascript's inside function scoping.=20
I'm terrified to think how people will use that in practice ;-)
-
Daniel Biesiada
Wiadomo=B6=E6 napisana przez Herb Sutter <hsutter@microsoft.com> w dniu 20 =
gru 2012, o godz. 21:09:
> Composition and currying are cool.
> =20
> Those who don't like the terse syntax may object that it's only slightly =
worse with the current syntax, though, right?
> =20
> auto compose =3D []( auto f, auto g ) { return
> [=3D]( auto x ) f( g(x) ); };
> =20
> auto curry3 =3D
> []( auto f ) { return
> [=3D](auto x) { return [=3D](auto y) { return [=3D](auto z) { retu=
rn
> f(x,y,z); }; }; }; };
> =20
> Though you do have to be a little careful to balance the {'s and };'s.
> =20
> Herb
> =20
> =20
> From: Scott Prager [mailto:splinterofchaos@gmail.com]=20
> Sent: Thursday, December 20, 2012 10:16 AM
> To: std-proposals@isocpp.org
> Cc: std-discussion@isocpp.org; faisalv@gmail.com
> Subject: [std-proposals] Re: An implementation of Generic lambdas (Reques=
t for feedback)
> =20
> Absolutely fantastic! A few things on interest:
>=20
> I had not realized this syntax supports nesting:
>=20
> auto compose =3D []( auto f, auto g )
> [=3D]( auto x ) f( g(x) );
>=20
> auto curry3 =3D
> []( auto f )
> [=3D](auto x) [=3D](auto y) [=3D](auto z)=20
> f(x,y,z);
>=20
> And variadic lambdas, too! Very nice.=20
> But I wonder why we couldn't...
> auto f =3D []( auto _f ) [](auto ...x) _f(x...);
>=20
> I wrote some tests. A few lines caused the compiler to crash so I comment=
ed them out and labelled them "Crash!".
>=20
> https://gist.github.com/4347130
>=20
>=20
> On Monday, December 17, 2012 2:05:37 PM UTC-5, faisalv wrote:
> Motivated by the positive feedback we received regarding Generic=20
> Lambdas (during the October 2012 ISO C++ Standards Meeting in=20
> Portland), I have implemented a reasonably complete (unless I am=20
> missing something obvious) implementation=20
> (http://faisalv.github.com/clang-glambda/) of most of the proposal=20
> (named lambda syntax for functions has not been attempted) using a=20
> fork of clang.=20
>=20
> We would like to encourage developers who are interested in this=20
> feature, to either compile the code or download the binaries (sorry,=20
> only windows for now) and play with the implementation and provide us=20
> with feedback so that we can incorporate it within our next revision=20
> of the document.=20
>=20
> The following link: http://faisalv.github.com/clang-glambda/, has some=20
> instructions (towards the bottom) on how to compile the code or use=20
> the binaries for windows.=20
>=20
> Any and all constructive feedback will be greatly appreciated.=20
>=20
> The current version (12/2012) implements subproposals 2.1, 2.2, 2.3 and 2=
..5.=20
>=20
> 2.1 Allow the type-specifier within a parameter declaration of a=20
> lambda to be auto (i.e. auto is mandatory)=20
>=20
> auto Sum =3D [](auto a, decltype(a) b) { return a + b; };=20
> int i =3D Sum(3, 4);=20
> double d =3D Sum(3.14, 2.77);=20
>=20
> 2.2 Allow the use of familiar template syntax in lambda expressions=20
>=20
> auto NumElements =3D []<int N>(auto (&a)[N]) { return N; };=20
> int arri[]{1, 2, 3};=20
> double arrd[]{3.14, 2.77, 6.626};=20
> auto total =3D NumElements(arri) + NumElements(arrd);=20
>=20
> 2.3 Permit a lambda body to be an expression=20
>=20
> int local =3D 10;=20
> auto L =3D [&](auto a) a + ++local;=20
>=20
> 2.5 Autogenerate a conversion to function pointer in captureless generic =
lambdas=20
>=20
> auto L =3D [](auto a, decltype(a) b) { return a + b; };=20
> int (*fp)(int, int) =3D L;=20
>=20
>=20
> Thank you and looking forward to the feedback!
> --=20
> =20
> =20
> =20
>=20
> --=20
> =20
> =20
> =20
--=20
--Apple-Mail=_5ED7E440-596B-4B1C-A70E-5FB5E8DDBFB5
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=ISO-8859-2
<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dwindows-1250"><base href=3D"x-msg://934/"></head><body style=3D"word-wra=
p: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-sp=
ace; ">Wow,<div><br></div><div>This is almost same crazy as Javascript's in=
side function scoping. </div><div>I'm terrified to think how people wi=
ll use that in practice ;-)</div><div><br></div><div>-</div><div>Daniel Bie=
siada</div><div><br></div><div><br><div><div><div>Wiadomo=B6=E6 napisana pr=
zez Herb Sutter <<a href=3D"mailto:hsutter@microsoft.com">hsutter@micros=
oft.com</a>> w dniu 20 gru 2012, o godz. 21:09:</div><br class=3D"Apple-=
interchange-newline"><blockquote type=3D"cite"><div lang=3D"EN-US" link=3D"=
blue" vlink=3D"purple" style=3D"font-family: Helvetica; font-size: medium; =
font-style: normal; font-variant: normal; font-weight: normal; letter-spaci=
ng: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text=
-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-sp=
acing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;=
"><div class=3D"WordSection1" style=3D"page: WordSection1; "><div style=3D=
"margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-seri=
f; ">Composition and currying are cool.<o:p></o:p></div><div style=3D"margi=
n: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "><=
o:p> </o:p></div><div style=3D"margin: 0in 0in 0.0001pt; font-size: 11=
pt; font-family: Calibri, sans-serif; ">Those who don’t like the ters=
e syntax may object that it’s only slightly worse with the current sy=
ntax, though, right?<o:p></o:p></div><div style=3D"margin: 0in 0in 0.0001pt=
; font-size: 11pt; font-family: Calibri, sans-serif; "><o:p> </o:p></d=
iv><div style=3D"margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Ca=
libri, sans-serif; ">auto compose =3D []( auto f, auto g ) { return<o:p></o=
:p></div><div style=3D"margin: 0in 0in 0.0001pt; font-size: 11pt; font-fami=
ly: Calibri, sans-serif; "> [=3D]( auto x ) f( g(x) ); };=
<o:p></o:p></div><div style=3D"margin: 0in 0in 0.0001pt; font-size: 11pt; f=
ont-family: Calibri, sans-serif; "><o:p> </o:p></div><div style=3D"mar=
gin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; "=
>auto curry3 =3D<o:p></o:p></div><div style=3D"margin: 0in 0in 0.0001pt; fo=
nt-size: 11pt; font-family: Calibri, sans-serif; "> []( auto f =
) { return<o:p></o:p></div><div style=3D"margin: 0in 0in 0.0001pt; font-siz=
e: 11pt; font-family: Calibri, sans-serif; "> =
[=3D](auto x) { return [=3D](auto y) { return [=3D](auto z) { return=
<o:p></o:p></div><div style=3D"margin: 0in 0in 0.0001pt; font-size: 11pt; f=
ont-family: Calibri, sans-serif; "> &nbs=
p; f(x,y,z); }; }; }; };<o:p></o:p></div><div style=3D"ma=
rgin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; =
"><o:p> </o:p></div><div style=3D"margin: 0in 0in 0.0001pt; font-size:=
11pt; font-family: Calibri, sans-serif; ">Though you do have to be a littl=
e careful to balance the {‘s and };’s.<o:p></o:p></div><div sty=
le=3D"margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans=
-serif; "><o:p> </o:p></div><div style=3D"margin: 0in 0in 0.0001pt; fo=
nt-size: 11pt; font-family: Calibri, sans-serif; ">Herb<o:p></o:p></div><di=
v style=3D"margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times N=
ew Roman', serif; "><span style=3D"font-size: 11pt; font-family: Calibri, s=
ans-serif; color: rgb(31, 73, 125); "> </span></div><div style=3D"marg=
in: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', seri=
f; "><span style=3D"font-size: 11pt; font-family: Calibri, sans-serif; colo=
r: rgb(31, 73, 125); "> </span></div><div style=3D"border-style: none =
none none solid; border-left-width: 1.5pt; border-left-color: blue; padding=
: 0in 0in 0in 4pt; "><div><div style=3D"border-style: solid none none; bord=
er-top-width: 1pt; border-top-color: rgb(181, 196, 223); padding: 3pt 0in 0=
in; "><div style=3D"margin: 0in 0in 0.0001pt; font-size: 12pt; font-family:=
'Times New Roman', serif; "><b><span style=3D"font-size: 10pt; font-family=
: Tahoma, sans-serif; ">From:</span></b><span style=3D"font-size: 10pt; fon=
t-family: Tahoma, sans-serif; "><span class=3D"Apple-converted-space"> =
;</span>Scott Prager [mailto:splinterofchaos@<a href=3D"http://gmail.com" s=
tyle=3D"color: purple; text-decoration: underline; ">gmail.com</a>]<span cl=
ass=3D"Apple-converted-space"> </span><br><b>Sent:</b><span class=3D"A=
pple-converted-space"> </span>Thursday, December 20, 2012 10:16 AM<br>=
<b>To:</b><span class=3D"Apple-converted-space"> </span><a href=3D"mai=
lto:std-proposals@isocpp.org" style=3D"color: purple; text-decoration: unde=
rline; ">std-proposals@isocpp.org</a><br><b>Cc:</b><span class=3D"Apple-con=
verted-space"> </span><a href=3D"mailto:std-discussion@isocpp.org" sty=
le=3D"color: purple; text-decoration: underline; ">std-discussion@isocpp.or=
g</a>;<span class=3D"Apple-converted-space"> </span><a href=3D"mailto:=
faisalv@gmail.com" style=3D"color: purple; text-decoration: underline; ">fa=
isalv@gmail.com</a><br><b>Subject:</b><span class=3D"Apple-converted-space"=
> </span>[std-proposals] Re: An implementation of Generic lambdas (Req=
uest for feedback)<o:p></o:p></span></div></div></div><div style=3D"margin:=
0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; =
"><o:p> </o:p></div><p class=3D"MsoNormal" style=3D"margin: 0in 0in 12=
pt; font-size: 12pt; font-family: 'Times New Roman', serif; ">Absolutely fa=
ntastic! A few things on interest:<br><br>I had not realized this syntax su=
pports nesting:<o:p></o:p></p><div style=3D"border: 1pt solid rgb(187, 187,=
187); padding: 0in; word-wrap: break-word; "><div style=3D"margin: 0in 0in=
0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; backgrou=
nd-color: rgb(250, 250, 250); "><span class=3D"styled-by-prettify"><span st=
yle=3D"font-size: 10pt; font-family: 'Courier New'; color: rgb(0, 0, 136); =
">auto</span></span><span class=3D"styled-by-prettify"><span style=3D"font-=
size: 10pt; font-family: 'Courier New'; "><span class=3D"Apple-converted-sp=
ace"> </span>compose<span class=3D"Apple-converted-space"> </span=
></span></span><span class=3D"styled-by-prettify"><span style=3D"font-size:=
10pt; font-family: 'Courier New'; color: rgb(102, 102, 0); ">=3D</span></s=
pan><span class=3D"styled-by-prettify"><span style=3D"font-size: 10pt; font=
-family: 'Courier New'; "> </span></span><span class=3D"styled-by-pret=
tify"><span style=3D"font-size: 10pt; font-family: 'Courier New'; color: rg=
b(102, 102, 0); ">[](</span></span><span class=3D"styled-by-prettify"><span=
style=3D"font-size: 10pt; font-family: 'Courier New'; "> </span></spa=
n><span class=3D"styled-by-prettify"><span style=3D"font-size: 10pt; font-f=
amily: 'Courier New'; color: rgb(0, 0, 136); ">auto</span></span><span clas=
s=3D"styled-by-prettify"><span style=3D"font-size: 10pt; font-family: 'Cour=
ier New'; "><span class=3D"Apple-converted-space"> </span>f</span></sp=
an><span class=3D"styled-by-prettify"><span style=3D"font-size: 10pt; font-=
family: 'Courier New'; color: rgb(102, 102, 0); ">,</span></span><span clas=
s=3D"styled-by-prettify"><span style=3D"font-size: 10pt; font-family: 'Cour=
ier New'; "> </span></span><span class=3D"styled-by-prettify"><span st=
yle=3D"font-size: 10pt; font-family: 'Courier New'; color: rgb(0, 0, 136); =
">auto</span></span><span class=3D"styled-by-prettify"><span style=3D"font-=
size: 10pt; font-family: 'Courier New'; "><span class=3D"Apple-converted-sp=
ace"> </span>g<span class=3D"Apple-converted-space"> </span></spa=
n></span><span class=3D"styled-by-prettify"><span style=3D"font-size: 10pt;=
font-family: 'Courier New'; color: rgb(102, 102, 0); ">)</span></span><spa=
n style=3D"font-size: 10pt; font-family: 'Courier New'; "><br><span class=
=3D"styled-by-prettify"> <span class=3D"Apple-converted-space">=
</span></span></span><span class=3D"styled-by-prettify"><span style=
=3D"font-size: 10pt; font-family: 'Courier New'; color: rgb(102, 102, 0); "=
>[=3D](</span></span><span class=3D"styled-by-prettify"><span style=3D"font=
-size: 10pt; font-family: 'Courier New'; "> </span></span><span class=
=3D"styled-by-prettify"><span style=3D"font-size: 10pt; font-family: 'Couri=
er New'; color: rgb(0, 0, 136); ">auto</span></span><span class=3D"styled-b=
y-prettify"><span style=3D"font-size: 10pt; font-family: 'Courier New'; "><=
span class=3D"Apple-converted-space"> </span>x<span class=3D"Apple-con=
verted-space"> </span></span></span><span class=3D"styled-by-prettify"=
><span style=3D"font-size: 10pt; font-family: 'Courier New'; color: rgb(102=
, 102, 0); ">)</span></span><span class=3D"styled-by-prettify"><span style=
=3D"font-size: 10pt; font-family: 'Courier New'; "><span class=3D"Apple-con=
verted-space"> </span>f</span></span><span class=3D"styled-by-prettify=
"><span style=3D"font-size: 10pt; font-family: 'Courier New'; color: rgb(10=
2, 102, 0); ">(</span></span><span class=3D"styled-by-prettify"><span style=
=3D"font-size: 10pt; font-family: 'Courier New'; "><span class=3D"Apple-con=
verted-space"> </span>g</span></span><span class=3D"styled-by-prettify=
"><span style=3D"font-size: 10pt; font-family: 'Courier New'; color: rgb(10=
2, 102, 0); ">(</span></span><span class=3D"styled-by-prettify"><span style=
=3D"font-size: 10pt; font-family: 'Courier New'; ">x</span></span><span cla=
ss=3D"styled-by-prettify"><span style=3D"font-size: 10pt; font-family: 'Cou=
rier New'; color: rgb(102, 102, 0); ">)</span></span><span class=3D"styled-=
by-prettify"><span style=3D"font-size: 10pt; font-family: 'Courier New'; ">=
</span></span><span class=3D"styled-by-prettify"><span style=3D"font-=
size: 10pt; font-family: 'Courier New'; color: rgb(102, 102, 0); ">);</span=
></span><span style=3D"font-size: 10pt; font-family: 'Courier New'; "><br><=
br></span><span class=3D"styled-by-prettify"><span style=3D"font-size: 10pt=
; font-family: 'Courier New'; color: rgb(0, 0, 136); ">auto</span></span><s=
pan class=3D"styled-by-prettify"><span style=3D"font-size: 10pt; font-famil=
y: 'Courier New'; "><span class=3D"Apple-converted-space"> </span>curr=
y3<span class=3D"Apple-converted-space"> </span></span></span><span cl=
ass=3D"styled-by-prettify"><span style=3D"font-size: 10pt; font-family: 'Co=
urier New'; color: rgb(102, 102, 0); ">=3D</span></span><span style=3D"font=
-size: 10pt; font-family: 'Courier New'; "><br><span class=3D"styled-by-pre=
ttify"> </span></span><span class=3D"styled-by-prettify"><span =
style=3D"font-size: 10pt; font-family: 'Courier New'; color: rgb(102, 102, =
0); ">[](</span></span><span class=3D"styled-by-prettify"><span style=3D"fo=
nt-size: 10pt; font-family: 'Courier New'; "> </span></span><span clas=
s=3D"styled-by-prettify"><span style=3D"font-size: 10pt; font-family: 'Cour=
ier New'; color: rgb(0, 0, 136); ">auto</span></span><span class=3D"styled-=
by-prettify"><span style=3D"font-size: 10pt; font-family: 'Courier New'; ">=
<span class=3D"Apple-converted-space"> </span>f<span class=3D"Apple-co=
nverted-space"> </span></span></span><span class=3D"styled-by-prettify=
"><span style=3D"font-size: 10pt; font-family: 'Courier New'; color: rgb(10=
2, 102, 0); ">)</span></span><span style=3D"font-size: 10pt; font-family: '=
Courier New'; "><br><span class=3D"styled-by-prettify"> =
</span></span><span class=3D"styled-by-prettify"><span style=3D"font=
-size: 10pt; font-family: 'Courier New'; color: rgb(102, 102, 0); ">[=3D](<=
/span></span><span class=3D"styled-by-prettify"><span style=3D"font-size: 1=
0pt; font-family: 'Courier New'; color: rgb(0, 0, 136); ">auto</span></span=
><span class=3D"styled-by-prettify"><span style=3D"font-size: 10pt; font-fa=
mily: 'Courier New'; "><span class=3D"Apple-converted-space"> </span>x=
</span></span><span class=3D"styled-by-prettify"><span style=3D"font-size: =
10pt; font-family: 'Courier New'; color: rgb(102, 102, 0); ">)</span></span=
><span class=3D"styled-by-prettify"><span style=3D"font-size: 10pt; font-fa=
mily: 'Courier New'; "> </span></span><span class=3D"styled-by-prettif=
y"><span style=3D"font-size: 10pt; font-family: 'Courier New'; color: rgb(1=
02, 102, 0); ">[=3D](</span></span><span class=3D"styled-by-prettify"><span=
style=3D"font-size: 10pt; font-family: 'Courier New'; color: rgb(0, 0, 136=
); ">auto</span></span><span class=3D"styled-by-prettify"><span style=3D"fo=
nt-size: 10pt; font-family: 'Courier New'; "><span class=3D"Apple-converted=
-space"> </span>y</span></span><span class=3D"styled-by-prettify"><spa=
n style=3D"font-size: 10pt; font-family: 'Courier New'; color: rgb(102, 102=
, 0); ">)</span></span><span class=3D"styled-by-prettify"><span style=3D"fo=
nt-size: 10pt; font-family: 'Courier New'; "> </span></span><span clas=
s=3D"styled-by-prettify"><span style=3D"font-size: 10pt; font-family: 'Cour=
ier New'; color: rgb(102, 102, 0); ">[=3D](</span></span><span class=3D"sty=
led-by-prettify"><span style=3D"font-size: 10pt; font-family: 'Courier New'=
; color: rgb(0, 0, 136); ">auto</span></span><span class=3D"styled-by-prett=
ify"><span style=3D"font-size: 10pt; font-family: 'Courier New'; "><span cl=
ass=3D"Apple-converted-space"> </span>z</span></span><span class=3D"st=
yled-by-prettify"><span style=3D"font-size: 10pt; font-family: 'Courier New=
'; color: rgb(102, 102, 0); ">)</span></span><span class=3D"styled-by-prett=
ify"><span style=3D"font-size: 10pt; font-family: 'Courier New'; "> </=
span></span><span style=3D"font-size: 10pt; font-family: 'Courier New'; "><=
br><span class=3D"styled-by-prettify"> &n=
bsp;f</span></span><span class=3D"styled-by-prettify"><span style=3D"font-s=
ize: 10pt; font-family: 'Courier New'; color: rgb(102, 102, 0); ">(</span><=
/span><span class=3D"styled-by-prettify"><span style=3D"font-size: 10pt; fo=
nt-family: 'Courier New'; ">x</span></span><span class=3D"styled-by-prettif=
y"><span style=3D"font-size: 10pt; font-family: 'Courier New'; color: rgb(1=
02, 102, 0); ">,</span></span><span class=3D"styled-by-prettify"><span styl=
e=3D"font-size: 10pt; font-family: 'Courier New'; ">y</span></span><span cl=
ass=3D"styled-by-prettify"><span style=3D"font-size: 10pt; font-family: 'Co=
urier New'; color: rgb(102, 102, 0); ">,</span></span><span class=3D"styled=
-by-prettify"><span style=3D"font-size: 10pt; font-family: 'Courier New'; "=
>z</span></span><span class=3D"styled-by-prettify"><span style=3D"font-size=
: 10pt; font-family: 'Courier New'; color: rgb(102, 102, 0); ">);</span></s=
pan><span style=3D"font-size: 10pt; font-family: 'Courier New'; "><o:p></o:=
p></span></div></div><div id=3D"file-generic-lambda-tests-cpp-LC13"><div id=
=3D"file-generic-lambda-tests-cpp-LC24"><pre style=3D"margin: 0in 0in 12pt;=
font-size: 10pt; font-family: 'Courier New'; "><br><span class=3D"p">And v=
ariadic lambdas, too! Very nice. </span><br><span class=3D"p">But I wonder =
why we couldn't...<o:p></o:p></span></pre><div style=3D"border: 1pt solid r=
gb(187, 187, 187); padding: 0in; word-wrap: break-word; "><pre style=3D"mar=
gin: 0in 0in 0.0001pt; font-size: 10pt; font-family: 'Courier New'; backgro=
und-color: rgb(250, 250, 250); background-position: initial initial; backgr=
ound-repeat: initial initial; "><span class=3D"styled-by-prettify"><span st=
yle=3D"color: rgb(0, 0, 136); ">auto</span><span style=3D""> f </span><span=
style=3D"color: rgb(102, 102, 0); ">=3D</span><span style=3D""> </span><sp=
an style=3D"color: rgb(102, 102, 0); ">[](</span><span style=3D""> </span><=
span style=3D"color: rgb(0, 0, 136); ">auto</span><span style=3D""> _f </sp=
an><span style=3D"color: rgb(102, 102, 0); ">)</span><span style=3D""> </sp=
an><span style=3D"color: rgb(102, 102, 0); ">[](</span><span style=3D"color=
: rgb(0, 0, 136); ">auto</span><span style=3D""> </span><span style=3D"colo=
r: rgb(102, 102, 0); ">...</span><span style=3D"">x</span><span style=3D"co=
lor: rgb(102, 102, 0); ">)</span><span style=3D""> _f</span><span style=3D"=
color: rgb(102, 102, 0); ">(</span><span style=3D"">x</span><span style=3D"=
color: rgb(102, 102, 0); ">...);</span></span><o:p></o:p></pre></div><pre s=
tyle=3D"margin: 0in 0in 0.0001pt; font-size: 10pt; font-family: 'Courier Ne=
w'; "><br><span class=3D"p">I wrote some tests. A few lines caused the comp=
iler to crash so I commented them out and labelled them "Crash!".</span><br=
><br><span class=3D"p"><a href=3D"https://gist.github.com/4347130" style=3D=
"color: purple; text-decoration: underline; ">https://gist.github.com/43471=
30</a></span><o:p></o:p></pre></div></div><div style=3D"margin: 0in 0in 0.0=
001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><br><br>On=
Monday, December 17, 2012 2:05:37 PM UTC-5, faisalv wrote:<o:p></o:p></div=
><div style=3D"margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Tim=
es New Roman', serif; ">Motivated by the positive feedback we received rega=
rding Generic<span class=3D"Apple-converted-space"> </span><br>Lambdas=
(during the October 2012 ISO C++ Standards Meeting in<span class=3D"Apple-=
converted-space"> </span><br>Portland), I have implemented a reasonabl=
y complete (unless I am<span class=3D"Apple-converted-space"> </span><=
br>missing something obvious) implementation<span class=3D"Apple-converted-=
space"> </span><br>(<a href=3D"http://faisalv.github.com/clang-glambda=
/" target=3D"_blank" style=3D"color: purple; text-decoration: underline; ">=
http://faisalv.github.com/clang-glambda/</a>) of most of the proposal<span =
class=3D"Apple-converted-space"> </span><br>(named lambda syntax for f=
unctions has not been attempted) using a<span class=3D"Apple-converted-spac=
e"> </span><br>fork of clang.<span class=3D"Apple-converted-space">&nb=
sp;</span><br><br>We would like to encourage developers who are interested =
in this<span class=3D"Apple-converted-space"> </span><br>feature, to e=
ither compile the code or download the binaries (sorry,<span class=3D"Apple=
-converted-space"> </span><br>only windows for now) and play with the =
implementation and provide us<span class=3D"Apple-converted-space"> </=
span><br>with feedback so that we can incorporate it within our next revisi=
on<span class=3D"Apple-converted-space"> </span><br>of the document.<s=
pan class=3D"Apple-converted-space"> </span><br><br>The following link=
:<span class=3D"Apple-converted-space"> </span><a href=3D"http://faisa=
lv.github.com/clang-glambda/" target=3D"_blank" style=3D"color: purple; tex=
t-decoration: underline; ">http://faisalv.github.com/clang-glambda/</a>, ha=
s some<span class=3D"Apple-converted-space"> </span><br>instructions (=
towards the bottom) on how to compile the code or use<span class=3D"Apple-c=
onverted-space"> </span><br>the binaries for windows.<span class=3D"Ap=
ple-converted-space"> </span><br><br>Any and all constructive feedback=
will be greatly appreciated.<span class=3D"Apple-converted-space"> </=
span><br><br>The current version (12/2012) implements subproposals 2.1, 2.2=
, 2.3 and 2.5.<span class=3D"Apple-converted-space"> </span><br><br>2.=
1 Allow the type-specifier within a parameter declaration of a<span class=
=3D"Apple-converted-space"> </span><br>lambda to be auto (i.e. auto is=
mandatory)<span class=3D"Apple-converted-space"> </span><br><br>auto =
Sum =3D [](auto a, decltype(a) b) { return a + b; };<span class=3D"Apple-co=
nverted-space"> </span><br>int i =3D Sum(3, 4);<span class=3D"Apple-co=
nverted-space"> </span><br>double d =3D Sum(3.14, 2.77);<span class=3D=
"Apple-converted-space"> </span><br><br>2.2 Allow the use of familiar =
template syntax in lambda expressions<span class=3D"Apple-converted-space">=
</span><br><br>auto NumElements =3D []<int N>(auto (&a)[N])=
{ return N; };<span class=3D"Apple-converted-space"> </span><br>int a=
rri[]{1, 2, 3};<span class=3D"Apple-converted-space"> </span><br>doubl=
e arrd[]{3.14, 2.77, 6.626};<span class=3D"Apple-converted-space"> </s=
pan><br>auto total =3D NumElements(arri) + NumElements(arrd);<span class=3D=
"Apple-converted-space"> </span><br><br>2.3 Permit a lambda body to be=
an expression<span class=3D"Apple-converted-space"> </span><br><br>in=
t local =3D 10;<span class=3D"Apple-converted-space"> </span><br>auto =
L =3D [&](auto a) a + ++local;<span class=3D"Apple-converted-space">&nb=
sp;</span><br><br>2.5 Autogenerate a conversion to function pointer in capt=
ureless generic lambdas<span class=3D"Apple-converted-space"> </span><=
br><br>auto L =3D [](auto a, decltype(a) b) { return a + b; };<span class=
=3D"Apple-converted-space"> </span><br>int (*fp)(int, int) =3D L;<span=
class=3D"Apple-converted-space"> </span><br><br><br>Thank you and loo=
king forward to the feedback!<o:p></o:p></div><div style=3D"margin: 0in 0in=
0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; ">--<spa=
n class=3D"Apple-converted-space"> </span><br> <br> <br>&nbs=
p;<o:p></o:p></div></div></div><div style=3D"margin-right: 0in; margin-left=
: 0in; font-size: 12pt; font-family: 'Times New Roman', serif; "><br class=
=3D"webkit-block-placeholder"></div>--<span class=3D"Apple-converted-space"=
> </span><br> <br> <br> <br></div></blockquote></div><b=
r></div></div></body></html>
<p></p>
-- <br />
<br />
<br />
<br />
--Apple-Mail=_5ED7E440-596B-4B1C-A70E-5FB5E8DDBFB5--
.
Author: =?ISO-8859-1?Q?Daniel_Kr=FCgler?= <daniel.kruegler@gmail.com>
Date: Sat, 12 Jan 2013 12:52:51 +0100
Raw View
2013/1/12 Andrea Proli <andy.prowl@gmail.com>:
> I was used to think of lambdas as syntactic sugar, but *generic* lambdas are
> not: the generated closure breaks the rule from paragraph 14/2:
>
> "A template-declaration can appear only as a namespace scope or class scope
> declaration".
>
> I am unaware of the reasons why this restriction exists in the first place
> (I did some research but with no success), so I cannot write a proposal on
> lifting it. However, if good reasons exist, I am curious whether the fact
> that generic lambdas break it will create troubles.
Polymorphic (or generic, if you prefer) lambda expressions don't
provide the full capacities of templates. As you say, they just are
syntactic sugar for some sub-space of possible template constructions.
It is therefore much simpler to add them compared to starting with a
support for local templates from begin with. This would not
necessarily result in a conflict with 14/2, you just add one
exceptional rule and that's it.
- Daniel
--
.