mirror of
https://github.com/bitcoin/bitcoin.git
synced 2024-11-20 10:38:42 +01:00
doc: document preference for list-initialization
This commit is contained in:
parent
1ac627c485
commit
eb5d78c649
@ -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;
|
||||
...
|
||||
|
Loading…
Reference in New Issue
Block a user