Topic: Short-form for function and/or lambda bodies.
Author: andrewtomazos@gmail.com
Date: Tue, 9 Jul 2013 11:47:42 -0700 (PDT)
Raw View
------=_Part_624_4824136.1373395662854
Content-Type: text/plain; charset=ISO-8859-1
As an alternative short-form for defining a function:
function-body:
... // existing bodies
= expression ;
= braced-init-list
Where such a form is equivalent to { return expression; } and { return
braced-init-list; } respectively, except where a pure virtual specifier (=
0) would not be ill-formed. (In cases where `= 0` is well-formed
parenthesis can be used to disambiguate `= (0)`)
So:
int f(int a, int b) = a + b;
is the same as:
int f(int a, int b) { return a + b; }
and
vector<int> g(int a, int b) = {a, b}
is the same as:
vector<int> g(int a, int b) { return {a, b}; }
Likewise for lambdas maybe:
lambda-expression:
lambda-introducer lambda-declarator_opt lambda-body
lambda-body:
compound-statement
= expression
= braced-init-list
Some thought would have to be given to termination of the `= expression`
case. Perhaps it can greedily match the longest expression.
But the general idea is the same:
foo([] = a + b);
is the same as:
foo([] { return a + b; });
(Inspired from Scala, and the mostly empty syntactic space after
function-declarator=) .
Enjoy,
Andrew.
--
---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_624_4824136.1373395662854
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<br>As an alternative short-form for defining a function:<br><br> &nbs=
p; function-body:<br> ... /=
/ existing bodies<br> =3D express=
ion ;<br> =3D braced-init-list<br=
><br>Where such a form is equivalent to { return expression; } and { return=
braced-init-list; } respectively, except where a pure virtual specifier (=
=3D 0) would not be ill-formed. (In cases where `=3D 0` is well-forme=
d parenthesis can be used to disambiguate `=3D (0)`)<br><br>So:<br><br>&nbs=
p; int f(int a, int b) =3D a + b;<br><br>is the same as:<br><br=
> int f(int a, int b) { return a + b; }<br><br>and<br><br=
> vector<int> g(int a, int b) =3D {a, b}<br><br>is =
the same as:<br><br> vector<int> g(int a, int b) { =
return {a, b}; }<br><br>Likewise for lambdas maybe:<br><br> &nbs=
p; lambda-expression:<br> lambda-=
introducer lambda-declarator_opt lambda-body<br><br> lamb=
da-body:<br> compound-statement<b=
r> =3D expression<br> =
=3D braced-init-list<br><br>Some thought wou=
ld have to be given to termination of the `=3D expression` case. Perh=
aps it can greedily match the longest expression.<br><br>But the general id=
ea is the same:<br><br> foo([] =3D a + b);<br><br>is the =
same as:<br><br> foo([] { return a + b; });<br><br>(Inspi=
red from Scala, and the mostly empty syntactic space after function-declara=
tor=3D) .<br><br>Enjoy,<br>Andrew.<br><br>
<p></p>
-- <br />
<br />
--- <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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
<br />
<br />
------=_Part_624_4824136.1373395662854--
.
Author: sgheeren@gmail.com
Date: Tue, 9 Jul 2013 13:38:27 -0700 (PDT)
Raw View
------=_Part_2090_799305.1373402307871
Content-Type: text/plain; charset=ISO-8859-1
On Tuesday, July 9, 2013 8:47:42 PM UTC+2, andrew...@gmail.com wrote:
>
>
> As an alternative short-form for defining a function:
>
> You do realize this is C++, and having too few alternative syntax
construct is not one of the main language impediments?
--
---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_2090_799305.1373402307871
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<br><br>On Tuesday, July 9, 2013 8:47:42 PM UTC+2, andrew...@gmail.com wrot=
e:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;b=
order-left: 1px #ccc solid;padding-left: 1ex;"><br>As an alternative short-=
form for defining a function:<br><br></blockquote><div>You do realize this =
is C++, and having too few alternative syntax construct is not one of the m=
ain language impediments? </div>
<p></p>
-- <br />
<br />
--- <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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
<br />
<br />
------=_Part_2090_799305.1373402307871--
.