C++ Language/Type/Shortcuts/TrailingReturnType

From Wikibooks, open books for an open world
Jump to navigation Jump to search

In templated code (using template-parameter T), if you want your compiler to infer a function's return type from an expression that involves a parameter's type, then use this "trailing return type" syntax: auto AddTwo(T x) -> decltype(x+2) { return x+2; }.

Additional information about the trailing return syntax