# HG changeset patch # User David Demelier # Date 1532954038 -7200 # Node ID 3bf12964697993ec804f0517026964f13309a53e # Parent 793a60620477e3dac2c32d76b85339d127e835b4 Add TRS paragraph diff -r 793a60620477 -r 3bf129646979 STYLE.md --- a/STYLE.md Wed Jul 18 13:58:51 2018 +0200 +++ b/STYLE.md Mon Jul 30 14:33:58 2018 +0200 @@ -73,11 +73,22 @@ References and pointers are always next to the type name and not the variable. ```cpp -T& get(const std::string& name); +auto get(const std::string& name) -> T&; int* p = &x; ``` +### Trailing return syntax + +We use trailing return syntax everywhere, it has the following benefits: + +- Inner types don't need to be prefixed by class name, +- Functions are kept aligned correctly, focusing on the function name. + +```cpp +auto func() -> std::string; +``` + ### Naming - English names, @@ -98,10 +109,7 @@ std::string name_; public: - inline const std::string& name() const noexcept - { - return name_; - } + auto name() const noexcept -> const std::string&; }; template @@ -233,7 +241,7 @@ is better to take it by value and modify it directly. ```cpp -std::string clean(std::string input) +auto clean(std::string input) -> std::string { if (!input.empty() && input.back() == '\r') input.pop_back(); @@ -253,7 +261,7 @@ between the bounds of an array: ```cpp -T& operator[](unsigned index) +auto operator[](unsigned index) -> T& { assert(index < length_); @@ -296,7 +304,7 @@ ```cpp namespace util { -std::string clean(std::string input); +auto clean(std::string input) -> std::string } // !util ``` @@ -420,7 +428,7 @@ But do not use `auto` to write code like in python, this is not acceptable: ```cpp - auto o = my_object("foo"); +auto o = my_object("foo"); ``` ### String views