andrew...@gmail.com
unread,Jul 9, 2013, 2:47:42 PM7/9/13Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to std-pr...@isocpp.org
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.