Small change to a function declaration: allow to drop the return type specification.

56 views
Skip to first unread message

Mikhail Semenov

unread,
May 30, 2013, 4:26:13 AM5/30/13
to std-pr...@isocpp.org
Now-a-days we often write
auto f(...)->decltype(expression) { ... return expression; }
 
I propose to drop the result type:
 
auto f(...) {... return expression; }
 
but on two conditions:
(1) only if there is only one return in the function body (a bit similar to a newly proposed lambda);
(2) you are not allowed to refer to this function using a header (forward declaration, etc).
 
The second option will guard against the abuse of the usage.
 
I find it looks ugly, when a long expression is written in the decltype construct.
 
I think this feature may be particularly useful when writing templates.
 

Daniel Krügler

unread,
May 30, 2013, 4:32:33 AM5/30/13
to std-pr...@isocpp.org
2013/5/30 Mikhail Semenov <mikhailse...@gmail.com>:
> Now-a-days we often write
> auto f(...)->decltype(expression) { ... return expression; }
>
> I propose to drop the result type:
>
> auto f(...) {... return expression; }

We have this language feature since the Bristol meeting by acceptance of

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3638.html

- Daniel

Mikhail Semenov

unread,
May 30, 2013, 4:47:52 AM5/30/13
to std-pr...@isocpp.org
Daniel,
 
Thank you.
 
Mikhail.
Reply all
Reply to author
Forward
0 new messages