... | ... | @@ -35,7 +35,8 @@ All header files should have `#define` guards to prevent multiple inclusion. The |
|
|
|
|
|
### Braces placement
|
|
|
|
|
|
Braces in namespaces, classes, functions, enums, unions, try-catch blocks, loops and if statements are always placed on the next line. When there is an if statement with a single line in the conditional branch, no braces are required. In loops braces are always required
|
|
|
Braces in namespaces, classes, functions, enums, unions, try-catch blocks, loops and if statements are always placed on the next line. When there is an if statement with a single line in the conditional branch, no braces are required. However, statements that follow the condition must be on a separate line.
|
|
|
In loops braces are always required.
|
|
|
|
|
|
```c++
|
|
|
namespace MyNamespace
|
... | ... | @@ -202,3 +203,9 @@ When definitions in a `.cpp` file do not need to be referenced outside that file |
|
|
### Preprocessor Macros
|
|
|
|
|
|
Avoid using macros; prefer inline functions, enums, `const` and `constexpr` variables.
|
|
|
|
|
|
# Further Reading
|
|
|
These are books and resources that considered to be good advice on coding style and best practices. It's preferable to follow their advice when it's reasonable:
|
|
|
1. Herb Sutter, Andrei Alexandrescu "C++ Coding Standards: 101 Rules, Guidelines, and Best Practices "
|
|
|
2. Scott Meyers "Effective Modern C++"
|
|
|
3. Bjarne Stroustrup, Herb Sutter ["C++ Core Guidelines"](C++ Coding Standards: 101 Rules, Guidelines, and Best Practices) |