Using auto in function signatures

Although discouraged by some C++ programmers, in our experience the use of auto in function signatures vastly increases readability when browsing and viewing header files.

Here is how the new auto syntax looks compared to the old syntax with explicit types:

Old syntax with explicit type: New syntax with auto:
struct Foo {  int val() const {    return m_;   }  const int& cref() const {    return m_;   }  int& mref() {    return m_;   }  int m_{};};
struct Foo {  auto val() const {    return m_;   }  auto& cref() const {    return m_;   }  auto& mref() {    return m_;   }  int m_{};};

The auto syntax can be used both with and without trailing return type. The trailing return is necessary if you put the function definition in the ...

Get C++ High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.