Skip to content

Commit e1cc6fe

Browse files
committed
In docs\gsl-intro, cleaned up stray notes into a "hints" section
1 parent 59eb770 commit e1cc6fe

File tree

1 file changed

+6
-45
lines changed

1 file changed

+6
-45
lines changed

docs/gsl-intro.md

Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
by Herb Sutter
55

6-
updated 2017-05-24
6+
updated 2018-01-08
77

88

99
## Overview: "Is this document a tutorial or a FAQ?"
@@ -277,51 +277,12 @@ Also, `span<T>` lets you distinguish between `.size()` and `.size_bytes()`; make
277277
> - Prefer `span<T>`'s `.size_bytes()` instead of `.size() * sizeof(T)`.
278278
279279
280+
## And a few `span`-related hints
280281
281-
<br><br><br>
282-
# *** TODO - Other span suggestions and questions back to Bjarne and Neil
282+
These are not directly related to `span` but can often come up while using `span`.
283283
284-
Bjarne suggested:
284+
* Use `byte` everywhere you are handling memory (as opposed to characters or integers). That is, when accessing a chunk of raw memory, use `gsl::span<std::byte>`.
285285
286-
- given an STL style interface ([b:e)), how do I implement it using a span?
287-
288-
HS: I couldn't think of an example so I skipped this
289-
290-
- show a use of string_span
291-
292-
HS: I think we're dropping this, so it doesn't need an example, right?
293-
294-
- I would concentrate on span and push not_null(), narrow(), and friends to a separate note.
295-
296-
HS: OK, stopping with the above for now -- what more can we say about span?
297-
298-
- I would be happy to review a rough draft.
299-
300-
HS: Here you go! :)
301-
302-
Neil suggested:
303-
304-
- some guidance on how to deal with standard lib container size_t vs span ptrdiff_t mismatch.
305-
306-
HS: Do you have an example in mind?
307-
308-
309-
<br><br><br><br><br>
310-
# MORE RAW NOTES
311-
312-
I'll continue with more of these, and possibly in a separate note as Bjarne suggests a few lines above, if everyone agrees.
313-
314-
## Neil
315-
316-
- use `byte` everywhere you are handling memory (as opposed to characters or integers)
317-
318-
- use `narrow()` when you cannot afford to be surprised by a value change during conversion to a smaller range (includes going between signed to unsigned)
319-
320-
- use `narrow_cast()` when you are *sure* you won’t be surprised by a value change during conversion to a smaller range
321-
322-
> - pass `not_null` by value
323-
324-
I suspect this isn't right -- I think it should be "pass `not_null<T>` the same as `T`". For example, `not_null<int*>` should be passed by value, but `not_null<shared_ptr<int>>` should probably be passed by `const&`.
325-
326-
- use `not_null` on any raw pointer parameter that should never contain nullptr
286+
* Use `narrow()` when you cannot afford to be surprised by a value change during conversion to a smaller range. This includes going between a signed `span` size or index and an unsigned today's-STL-container `.size()`, though the `span` constructors from containers nicely encapsulate many of these conversions.
327287
288+
* Similarly, use `narrow_cast()` when you are *sure* you won’t be surprised by a value change during conversion to a smaller range

0 commit comments

Comments
 (0)