Skip to content

Commit fab57e2

Browse files
committed
doc: Mention Span in developer-notes.md
1 parent 3502a60 commit fab57e2

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

doc/developer-notes.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,19 @@ class A
620620
- *Rationale*: Easier to understand what is happening, thus easier to spot mistakes, even for those
621621
that are not language lawyers.
622622
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+
623636
- Prefer `enum class` (scoped enumerations) over `enum` (traditional enumerations) where possible.
624637

625638
- *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

Comments
 (0)