Documentation: Add rule about "east const" to CodingStyle.md

Unfortunately we cannot enforce this with clang-format yet, as that
feature is not available. Until then, let's try to write new code
with this in mind, and convert old code as we go.
This commit is contained in:
Andreas Kling 2021-06-01 08:54:31 +02:00
parent 45117a4134
commit dd9b8ee7ef
Notes: sideshowbarker 2024-07-18 17:05:12 +09:00

View file

@ -396,7 +396,7 @@ struct Thingy {
class Doohickey { class Doohickey {
public: public:
const String& name() const { return m_name; } String const& name() const { return m_name; }
int frob_count() const { return m_frob_count; } int frob_count() const { return m_frob_count; }
void jam(); void jam();
@ -421,7 +421,7 @@ private:
class Doohickey { class Doohickey {
public: public:
const String& name() const { return this->name; } String const& name() const { return this->name; }
void jam(); void jam();
@ -583,3 +583,18 @@ public:
} }
``` ```
### Const placement
[](#east-const) Use "east const" style where `const` is written on the right side of the type being qualified. See [this article](https://mariusbancila.ro/blog/2018/11/23/join-the-east-const-revolution/) for more information about east const.
###### Right:
```cpp
Salt const& m_salt;
```
###### Wrong:
```cpp
const Salt& m_salt;
```