doc: document preference for list-initialization

This commit is contained in:
Andrew Toth 2024-02-23 13:14:41 -05:00
parent 1ac627c485
commit eb5d78c649
No known key found for this signature in database
GPG Key ID: 60007AFC8938B018

View File

@ -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;
...