You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/developer-notes.md
+28-1Lines changed: 28 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -87,7 +87,6 @@ code.
87
87
-`++i` is preferred over `i++`.
88
88
-`nullptr` is preferred over `NULL` or `(void*)0`.
89
89
-`static_assert` is preferred over `assert` where possible. Generally; compile-time checking is preferred over run-time checking.
90
-
-`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.
91
90
92
91
Block style example:
93
92
```c++
@@ -563,6 +562,34 @@ class A
563
562
- *Rationale*: Easier to understand what is happening, thus easier to spot mistakes, even for those
564
563
that are not language lawyers.
565
564
565
+
- Prefer `enum class` (scoped enumerations) over `enum` (traditional enumerations) where possible.
566
+
567
+
- *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.
568
+
569
+
- `switch` statement on an enumeration example:
570
+
571
+
```cpp
572
+
enum class Tabs {
573
+
INFO,
574
+
CONSOLE,
575
+
GRAPH,
576
+
PEERS
577
+
};
578
+
579
+
int GetInt(Tabs tab)
580
+
{
581
+
switch (tab) {
582
+
case Tabs::INFO: return 0;
583
+
case Tabs::CONSOLE: return 1;
584
+
case Tabs::GRAPH: return 2;
585
+
case Tabs::PEERS: return 3;
586
+
} // no default case, so the compiler can warn about missing cases
587
+
assert(false);
588
+
}
589
+
```
590
+
591
+
*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.
0 commit comments