A trailing return type places a function’s return type after its parameter list: auto main() -> int. C++11 introduced the syntax, which is optional for ordinary functions but helps express some template return types. section 1.4.2
A minimal program
Use the syntax in a small Hello World program: auto main() -> int. The traditional int main() remains valid, and main returns 0 by default. section 1.4.2
Listing 1.1 Hello, World
#include <iostream> #1
auto main() -> int { #2
std::cout << "Hello, world!\n"; #3
}
Inspect the complete Hello World listing to see auto, the arrow, and the return type working together. section 1.4.2
Template return types
A template can place decltype(lhs + rhs) after its parameters, allowing simple_plus to return the type produced by adding two potentially different operands. section 1.4.2
