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 ...