mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2024-03-22 13:30:58 +08:00
span
s -> spans for readability
This commit is contained in:
parent
cafe186e42
commit
3794dc2f45
|
@ -26,7 +26,7 @@ You can try out the examples in this document on all major compilers and platfor
|
||||||
|
|
||||||
`gsl::span` is a replacement for `(pointer, length)` pairs to refer to a sequence of contiguous objects. It can be thought of as a pointer to an array, but that knows its bounds.
|
`gsl::span` is a replacement for `(pointer, length)` pairs to refer to a sequence of contiguous objects. It can be thought of as a pointer to an array, but that knows its bounds.
|
||||||
|
|
||||||
For example, a `span<int,7>` refers to a sequence of seven contiguous `int`s.
|
For example, a `span<int,7>` refers to a sequence of seven contiguous integers.
|
||||||
|
|
||||||
A `span` does not own the elements it points to. It is not a container like an `array` or a `vector`, it is a view into the contents of such a container.
|
A `span` does not own the elements it points to. It is not a container like an `array` or a `vector`, it is a view into the contents of such a container.
|
||||||
|
|
||||||
|
@ -190,7 +190,7 @@ void f(span<widget> s) {
|
||||||
|
|
||||||
## Comparison: "When I compare `span<T>`s, do I compare the `T` values or the underlying pointers?"
|
## Comparison: "When I compare `span<T>`s, do I compare the `T` values or the underlying pointers?"
|
||||||
|
|
||||||
Comparing two `span<T>`s compares the `T` values. To compare two `span`s for identity, to see if they're pointing to the same thing, use `.data()`.
|
Comparing two `span<T>`s compares the `T` values. To compare two spans for identity, to see if they're pointing to the same thing, use `.data()`.
|
||||||
|
|
||||||
~~~cpp
|
~~~cpp
|
||||||
int a[] = { 1, 2, 3};
|
int a[] = { 1, 2, 3};
|
||||||
|
@ -204,7 +204,7 @@ assert(sa.data() != sv.data()); // but sa and sv point to different memory areas
|
||||||
~~~
|
~~~
|
||||||
|
|
||||||
> Things to remember
|
> Things to remember
|
||||||
> - Comparing `span`s compares their contents, not whether they point to the same location.
|
> - Comparing spans compares their contents, not whether they point to the same location.
|
||||||
|
|
||||||
|
|
||||||
## Empty vs null: "Do I have to explicitly check whether a span is null?"
|
## Empty vs null: "Do I have to explicitly check whether a span is null?"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user