doc: Mention Span in developer-notes.md
This commit is contained in:
parent
3502a60418
commit
fab57e2b9b
1 changed files with 13 additions and 0 deletions
|
@ -620,6 +620,19 @@ class A
|
|||
- *Rationale*: Easier to understand what is happening, thus easier to spot mistakes, even for those
|
||||
that are not language lawyers.
|
||||
|
||||
- Use `Span` as function argument when it can operate on any range-like container.
|
||||
|
||||
- *Rationale*: Compared to `Foo(const vector<int>&)` this avoids the need for a (potentially expensive)
|
||||
conversion to vector if the caller happens to have the input stored in another type of container.
|
||||
However, be aware of the pitfalls documented in [span.h](../src/span.h).
|
||||
|
||||
```cpp
|
||||
void Foo(Span<const int> data);
|
||||
|
||||
std::vector<int> vec{1,2,3};
|
||||
Foo(vec);
|
||||
```
|
||||
|
||||
- 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.
|
||||
|
|
Loading…
Reference in a new issue