mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 20:12:57 +01:00
Merge #17134: doc: Add switch on enum example to developer notes
c8961c7d9fed07190628cf01f9dfad971a942b99 doc: Add switch on enum example (Hennadii Stepanov) 11e3d5eb1d4a4b399b180083ec52484d53ebf724 util: Add AllowShortCaseLabelsOnASingleLine option (Hennadii Stepanov) Pull request description: This PR documents a recurring issue: - #15938 - #17105 ACKs for top commit: laanwj: Seems like good advice to me. ACK c8961c7d9fed07190628cf01f9dfad971a942b99 practicalswift: ACK c8961c7d9fed07190628cf01f9dfad971a942b99 promag: ACK c8961c7d9fed07190628cf01f9dfad971a942b99, no excuse now, thanks! Tree-SHA512: 530da5117094ed1bfaa6e447089521bd2c86b0742758dbacec4e4f934dc07b0e24f15a1448c4d58e49905e8fd3797d87bcae5669a346d33ed4c2878a04891699
This commit is contained in:
parent
f4ca9529b5
commit
db662cf843
@ -95,7 +95,6 @@ code.
|
|||||||
- `nullptr` is preferred over `NULL` or `(void*)0`.
|
- `nullptr` is preferred over `NULL` or `(void*)0`.
|
||||||
- `static_assert` is preferred over `assert` where possible. Generally; compile-time checking is preferred over run-time checking.
|
- `static_assert` is preferred over `assert` where possible. Generally; compile-time checking is preferred over run-time checking.
|
||||||
- Align pointers and references to the left i.e. use `type& var` and not `type &var`.
|
- Align pointers and references to the left i.e. use `type& var` and not `type &var`.
|
||||||
- `enum class` is preferred over `enum` where possible. Scoped enumerations avoid two potential pitfalls/problems with traditional C++ enumerations: implicit conversions to int, and name clashes due to enumerators being exported to the surrounding scope.
|
|
||||||
|
|
||||||
Block style example:
|
Block style example:
|
||||||
```c++
|
```c++
|
||||||
@ -582,6 +581,34 @@ class A
|
|||||||
int. If the signed int is some negative `N`, it'll become `INT_MAX - N` which might cause unexpected consequences.
|
int. If the signed int is some negative `N`, it'll become `INT_MAX - N` which might cause unexpected consequences.
|
||||||
|
|
||||||
|
|
||||||
|
- Prefer `enum class` (scoped enumerations) over `enum` (traditional enumerations) where possible.
|
||||||
|
|
||||||
|
- *Rationale*: Scoped enumerations avoid two potential pitfalls/problems with traditional C++ enumerations: implicit conversions to `int`, and name clashes due to enumerators being exported to the surrounding scope.
|
||||||
|
|
||||||
|
- `switch` statement on an enumeration example:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
enum class Tabs {
|
||||||
|
INFO,
|
||||||
|
CONSOLE,
|
||||||
|
GRAPH,
|
||||||
|
PEERS
|
||||||
|
};
|
||||||
|
|
||||||
|
int GetInt(Tabs tab)
|
||||||
|
{
|
||||||
|
switch (tab) {
|
||||||
|
case Tabs::INFO: return 0;
|
||||||
|
case Tabs::CONSOLE: return 1;
|
||||||
|
case Tabs::GRAPH: return 2;
|
||||||
|
case Tabs::PEERS: return 3;
|
||||||
|
} // no default case, so the compiler can warn about missing cases
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
*Rationale*: The comment documents skipping `default:` label, and it complies with `clang-format` rules. The assertion prevents firing of `-Wreturn-type` warning on some compilers.
|
||||||
|
|
||||||
Strings and formatting
|
Strings and formatting
|
||||||
------------------------
|
------------------------
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ AlignEscapedNewlinesLeft: true
|
|||||||
AlignTrailingComments: true
|
AlignTrailingComments: true
|
||||||
AllowAllParametersOfDeclarationOnNextLine: true
|
AllowAllParametersOfDeclarationOnNextLine: true
|
||||||
AllowShortBlocksOnASingleLine: false
|
AllowShortBlocksOnASingleLine: false
|
||||||
|
AllowShortCaseLabelsOnASingleLine: true
|
||||||
AllowShortFunctionsOnASingleLine: All
|
AllowShortFunctionsOnASingleLine: All
|
||||||
AllowShortIfStatementsOnASingleLine: true
|
AllowShortIfStatementsOnASingleLine: true
|
||||||
AllowShortLoopsOnASingleLine: false
|
AllowShortLoopsOnASingleLine: false
|
||||||
|
Loading…
Reference in New Issue
Block a user