<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Hi, <br>
<br>
<div class="moz-cite-prefix">On 06/11/2015 19:08, Richard via
cfe-dev wrote:<br>
</div>
[...]<br>
<blockquote cite="mid:E1ZulQe-0000RA-Dj@shell.xmission.com"
type="cite">
<pre wrap="">
N2541 <a class="moz-txt-link-rfc2396E" href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2541.htm"><http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2541.htm></a>
introduced auto and the trailing return type syntax.
Now people are using auto and -> on function signatures where the
return type is stated explicitly anyway. This results in code like:
auto main() -> int
{
return 0;
}
</pre>
</blockquote>
so?<br>
<br>
<blockquote cite="mid:E1ZulQe-0000RA-Dj@shell.xmission.com"
type="cite">
<pre wrap="">
Srsly? Is this really improving anything over
int main()
{
return 0;
}
</pre>
</blockquote>
no, but it is not worse either.<br>
<br>
<blockquote cite="mid:E1ZulQe-0000RA-Dj@shell.xmission.com"
type="cite">
<pre wrap="">
To me this is introducing unnecessary clutter </pre>
</blockquote>
it is more uniform, and for mathematically inclined people it is
also more natural. <br>
just because it is a new syntax it doesn't make it more cluttered
or anything.<br>
<br>
Herb Sutter recommends this style in his Almost Always Auto article:<br>
<tt><br>
</tt><tt><strong style="padding: 0px; margin: 0px; color: rgb(31, 78, 121); font-size: medium; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 22.9632px; text-align: left; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px;">auto</strong></tt><tt><span style="color: rgb(31, 78, 121); font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 22.9632px; text-align: left; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px; display: inline ! important; float: none; background-color: rgb(255, 255, 204);"> f </span></tt><tt><strong style="padding: 0px; margin: 0px; color: rgb(31, 78, 121); font-size: medium; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 22.9632px; text-align: left; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px;">(double
) -> int</strong></tt><tt><span style="color: rgb(31, 78, 121); font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 22.9632px; text-align: left; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px; display: inline ! important; float: none; background-color: rgb(255, 255, 204);">;
</span></tt><tt><strong style="padding: 0px; margin: 0px; color: rgb(31, 78, 121); font-size: medium; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 22.9632px; text-align: left; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px;">auto</strong></tt><tt><span style="color: rgb(31, 78, 121); font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 22.9632px; text-align: left; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px; display: inline ! important; float: none; background-color: rgb(255, 255, 204);"> f </span></tt><tt><strong style="padding: 0px; margin: 0px; color: rgb(31, 78, 121); font-size: medium; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 22.9632px; text-align: left; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px;">(dou
ble)</strong></tt><tt><span style="color: rgb(31, 78, 121); font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 22.9632px; text-align: left; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px; display: inline ! important; float: none; background-color: rgb(255, 255, 204);"> { /*...*/ };
</span></tt><tt><strong style="padding: 0px; margin: 0px; color: rgb(31, 78, 121); font-size: medium; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 22.9632px; text-align: left; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px;">auto</strong></tt><tt><span style="color: rgb(31, 78, 121); font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 22.9632px; text-align: left; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px; display: inline ! important; float: none; background-color: rgb(255, 255, 204);"> f = [=]</span></tt><tt><strong style="padding: 0px; margin: 0px; color: rgb(31, 78, 121); font-size: medium; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 22.9632px; text-align: left; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px;"
>(double)</strong></tt><tt><span style="color: rgb(31, 78, 121); font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 22.9632px; text-align: left; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px; display: inline ! important; float: none; background-color: rgb(255, 255, 204);"> { /*...*/ };</span></tt><br>
<br>
I actually like the style especially when declaring interfaces:<br>
<br>
struct X {<br>
auto foo(int) -> bool;<br>
auto bar(double, Y) -> Z;<br>
...<br>
}; <br>
<br>
because it naturally aligns the most crucial information, the
function name at the beginning of the line and mostly at the same
column.<br>
<br>
<blockquote cite="mid:E1ZulQe-0000RA-Dj@shell.xmission.com"
type="cite">
<pre wrap="">and isn't the reason why
auto and -> for function return types were introduced.</pre>
</blockquote>
certainly not, but it is a nice side effect.<br>
<br>
<blockquote cite="mid:E1ZulQe-0000RA-Dj@shell.xmission.com"
type="cite">
<pre wrap="">
I would like to propose a clang-tidy readability check that turns the
former into the latter when the return type doesn't use anything that
needs auto. In other words, this code would be left alone:
template <typename T, typename U>
auto add(T x, U y) -> decltype(x + y)
{
return x + y;
}
There is one note in N2541 that states how the new syntax eliminates
an ambiguity with this example:
auto f() -> int (*)[4];
// function returning a pointer to array[4] of int,
// not function returning array[4] of pointer to int.
This seems to be another case that should be left unchanged.
Proposed check name: readability-redundant-auto-return-type
What are your thoughts?
</pre>
</blockquote>
I was thinking of exactly the opposite, turn all "classic"
declarations into the new style :)<br>
<br>
I guess this is really a matter of taste. <br>
I would hope that clang-tidy (or would this be in the realm of
clang-format?) would offer both options.<br>
<br>
Best<br>
Fabio<br>
<br>
<br>
<br /><br />
<hr style='border:none; color:#909090; background-color:#B0B0B0; height: 1px; width: 99%;' />
<table style='border-collapse:collapse;border:none;'>
<tr>
<td style='border:none;padding:0px 15px 0px 8px'>
<a href="https://www.avast.com/antivirus">
<img border=0 src="http://static.avast.com/emails/avast-mail-stamp.png" alt="Avast logo" />
</a>
</td>
<td>
<p style='color:#3d4d5a; font-family:"Calibri","Verdana","Arial","Helvetica"; font-size:12pt;'>
This email has been checked for viruses by Avast antivirus software.
<br><a href="https://www.avast.com/antivirus">www.avast.com</a>
</p>
</td>
</tr>
</table>
<br />
</body>
</html>