Alternative function syntax
The arrow (->) in function heading in C++ is just another form of function syntax in C++11.
This is standard function declaration:
|
|
As C++ grew more complex, it exposed several limits. For example, in C++03 this is not allowed:
|
|
The compiler would not know what Ret
is. And this is still not possible with the new introduced decltype
keyword:
|
|
It’s not valid because Lhs
and Rhs
would not be valid identifiers until after the parser has passed the rest of the function prototype.
To work around this, C++11 introduced a new function declaration syntax, with a trailing-return-type:
|
|
In this syntax, auto
and decltype
keywords are combined.