diff options
| author | Pieter Wuille <[email protected]> | 2020-06-26 13:47:48 -0700 |
|---|---|---|
| committer | Pieter Wuille <[email protected]> | 2020-06-26 13:53:49 -0700 |
| commit | fab57e2b9bc4577fcfcd9fbddbc35d96046c5d88 (patch) | |
| tree | b32cbddbb88ec6fd90092711c629f1eceeb572c7 /doc/developer-notes.md | |
| parent | doc: Document Span pitfalls (diff) | |
| download | discoin-fab57e2b9bc4577fcfcd9fbddbc35d96046c5d88.tar.xz discoin-fab57e2b9bc4577fcfcd9fbddbc35d96046c5d88.zip | |
doc: Mention Span in developer-notes.md
Diffstat (limited to 'doc/developer-notes.md')
| -rw-r--r-- | doc/developer-notes.md | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/doc/developer-notes.md b/doc/developer-notes.md index b33b3ad18..bd3daa320 100644 --- a/doc/developer-notes.md +++ b/doc/developer-notes.md @@ -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. |