diff options
author | Andrew Toth <andrewstoth@gmail.com> | 2024-02-23 13:14:41 -0500 |
---|---|---|
committer | Andrew Toth <andrewstoth@gmail.com> | 2024-02-23 13:19:19 -0500 |
commit | eb5d78c649c9ad55b3809473b0d5ec4b88ed923d (patch) | |
tree | fff77afd15b94ee68daa4317b128d333a57c0756 /doc | |
parent | 1ac627c485a43e50a9a49baddce186ee3ad4daad (diff) |
doc: document preference for list-initialization
Diffstat (limited to 'doc')
-rw-r--r-- | doc/developer-notes.md | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/doc/developer-notes.md b/doc/developer-notes.md index ece36cb088..8c3845c66c 100644 --- a/doc/developer-notes.md +++ b/doc/developer-notes.md @@ -113,6 +113,8 @@ code. between integer types, use functional casts such as `int(x)` or `int{x}` instead of `(int) x`. When casting between more complex types, use `static_cast`. Use `reinterpret_cast` and `const_cast` as appropriate. + - Prefer [`list initialization ({})`](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Res-list) where possible. + For example `int x{0};` instead of `int x = 0;` or `int x(0);` For function calls a namespace should be specified explicitly, unless such functions have been declared within it. Otherwise, [argument-dependent lookup](https://en.cppreference.com/w/cpp/language/adl), also known as ADL, could be @@ -138,7 +140,7 @@ int main() Block style example: ```c++ -int g_count = 0; +int g_count{0}; namespace foo { class Class @@ -150,7 +152,7 @@ public: { // Comment summarising what this section of code does for (int i = 0; i < n; ++i) { - int total_sum = 0; + int total_sum{0}; // When something fails, return early if (!Something()) return false; ... |