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
+13Lines changed: 13 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -620,6 +620,19 @@ class A
620
620
- *Rationale*: Easier to understand what is happening, thus easier to spot mistakes, even for those
621
621
that are not language lawyers.
622
622
623
+
- Use `Span` as function argument when it can operate on any range-like container.
624
+
625
+
- *Rationale*: Compared to `Foo(const vector<int>&)` this avoids the need for a (potentially expensive)
626
+
conversion to vector if the caller happens to have the input stored in another type of container.
627
+
However, be aware of the pitfalls documented in [span.h](../src/span.h).
628
+
629
+
```cpp
630
+
void Foo(Span<const int> data);
631
+
632
+
std::vector<int> vec{1,2,3};
633
+
Foo(vec);
634
+
```
635
+
623
636
- Prefer `enum class` (scoped enumerations) over `enum` (traditional enumerations) where possible.
624
637
625
638
-*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.
0 commit comments