Skip to content

Commit eb5d78c

Browse files
committed
doc: document preference for list-initialization
1 parent 1ac627c commit eb5d78c

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

doc/developer-notes.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ code.
113113
between integer types, use functional casts such as `int(x)` or `int{x}`
114114
instead of `(int) x`. When casting between more complex types, use `static_cast`.
115115
Use `reinterpret_cast` and `const_cast` as appropriate.
116+
- Prefer [`list initialization ({})`](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Res-list) where possible.
117+
For example `int x{0};` instead of `int x = 0;` or `int x(0);`
116118

117119
For function calls a namespace should be specified explicitly, unless such functions have been declared within it.
118120
Otherwise, [argument-dependent lookup](https://en.cppreference.com/w/cpp/language/adl), also known as ADL, could be
@@ -138,7 +140,7 @@ int main()
138140
139141
Block style example:
140142
```c++
141-
int g_count = 0;
143+
int g_count{0};
142144
143145
namespace foo {
144146
class Class
@@ -150,7 +152,7 @@ public:
150152
{
151153
// Comment summarising what this section of code does
152154
for (int i = 0; i < n; ++i) {
153-
int total_sum = 0;
155+
int total_sum{0};
154156
// When something fails, return early
155157
if (!Something()) return false;
156158
...

0 commit comments

Comments
 (0)