You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Suggestion: mention built-in arrays, `std::array`, and `std::vector` as examples of contiguous storage. May be helpful for readers who don't immediately recognize "contiguous" or "back-to-back". Feel free to discard.
* "indexed by the size of the objects" is unclear - it's talking about indexing from `[0, N)` but at first it sounds like it might be talking about `sizeof(Object)`. Suggestion: simply say "using a pointer and an index".
* "part of the template declaration" isn't the right terminology. The Standard Library contains the declaration (and definition) of `std::span`. The user provides template arguments to `span` when they say `span<int, 5>`.
* `dynamic-size` is nonexistent; replace with `dynamic_extent`.
* Suggestion: Rephrase the descriptions of `const_pointer` and `const_reference` to make it clear where the constness applies.
* FIXME: `operator[]` is mentioned in the table twice, as an accessor and an operator. I added a FIXME note but don't know how to resolve this.
* Monospace `array` and `vector`.
* Replace a smart quote with a plain quote.
* Mention `/std:c++latest` as a requirement.
* Add FIXME notes to examples (didn't attempt to fix all examples)
* Missing semicolon in the declaration of `begin()`.
* `data()` said: "If the span is empty, returns `nullptr`." This is incorrect, so I've removed the sentence. The truth is complicated: a default-constructed span indeed has null `data` and zero `size`. However, it's possible for an empty (zero `size`) span to have non-null `data`; this can be manually constructed, or obtained from `subspan`. This seems weird, but it can be meaningful to have a span denoting a location but zero elements. For example, the `equal_range` algorithm returns a sub-range of equivalent elements in a range; if there are no such elements, it returns an empty subrange located where such elements could be inserted while preserving the ordering. I am unsure how to explain this behavior of `data` briefly.
* Removed apparently-spurious `difference_type` link right before that section; apologies if I misunderstood what was happening there.
* Fixed typoed and incorrect `difference_type` example - it was subtracting the `int` elements. Instead, `difference_type` is the result of subtracting iterators. Attempted to correct example; haven't actually verified that this compiles (modulo std/void issues).
* Added missing semicolon to `empty` declaration.
* Added missing `noexcept` to `end` declaration (present for `begin`).
* NO CHANGE MADE: `end` talks about "the sentinel" but I am unsure whether this is good terminology. I usually speak of a sentinel node in node-based containers (because such a node physically exists), but for contiguous containers like `vector`, I speak of a "past-the-end location". This is possibly more important for `span` because `span` isn't placing anything special there.
* Remove top-level `const` from `first(size_type count)`'s parameter - this has meaning only to implementers, not to callers.
* Fix `front` example which was calling `first`.
* Don't specify `iterator` as `_Span_iterator<T>`, which is an STL-internal type. I've replaced this with `implementation-defined-iterator-type` (the Standard just says `implementation-defined`).
* Remove `const` from `operator[]`'s parameter. Mark the member function as `const`. Add a semicolon.
* Remove unused (copy-pasted?) `auto i` variable from `operator[]` example.
* FIXME NOTE: The `operator=` example depicts copy-initialization, not copy assignment. Just noted, haven't fixed.
* FIXME NOTE: Also commented for-loop in that example
* Add `noexcept` to `rend` (already present on `rbegin`).
* Replaced incorrect `size_type` description.
* Fixed misleading `size_type` example - it is meant to be used with `size` calculations, not `sizeof` (although it is ultimately `size_t`, the same type).
* FIXME NOTE: `dynamicExtent` in span constructors should be `dynamic_extent`; noted but not fixed.
* ASK CASEY: The `requires` depicted for the `span()` default ctor appears to be incorrectly positioned but I don't really understand concept syntax yet.
* Fix `template <It>` and `template <It, End>` which are not valid syntax.
* Fix `span(It first, End last)` description - it referred to `end` but the variable's name is `last`.
* FIXME: The `subspan` signature had a missing part of a conditional expression; noted as FIXME.
* `subspan` `count` was described as "from the end this span" which is damaged and appears to be copy-pasted from `last`. I believe removing this fixes the description.
* `subspan` `count` also said "If span is `dynamic_extent`" which was a typo; fixed.
* FIXME NOTE: The example prints `subspan<1>` but calls `subspan(1)`. It's unclear to me whether you meant to depict both the 1-function-argument and 1-template-argument forms.
* Removed duplicated `subspan` signature.
* NOT FIXED: `subspan` has a declaration repeatedly mentioning `size_t`. All occurrences of `size_t` in this page should be audited to see whether they should be `size_type` (likely).
* Deduction guides mentioned the STL-internal macro `_RANGES`; replaced with `ranges::` as `std::` appears to be assumed here.
Provides a lightweight view over a contiguous sequence of objects. A span provides a safe way to iterate over, and index into, objects that are arranged back-to-back in memory.
11
+
Provides a lightweight view over a contiguous sequence of objects. A span provides a safe way to iterate over, and index into, objects that are arranged back-to-back in memory (for example, objects stored in a built-in array, `std::array`, or `std::vector`).
12
12
13
-
If you typically access a sequence of back-to-back objects using a pointer indexed by the size of the objects, span is a safer, lightweight alternative.
13
+
If you typically access a sequence of back-to-back objects using a pointer and an index, span is a safer, lightweight alternative.
14
14
15
-
A span's size is determined at compile time by specifying it as part of the template declaration, or at runtime by specifying `dynamic-size`.
15
+
A span's size is determined at compile time by specifying it as a template argument, or at runtime by specifying `dynamic_extent`.
16
16
17
17
## Syntax
18
18
@@ -34,8 +34,8 @@ class span;
34
34
35
35
| **Type Definitions** | **Description** |
36
36
|-|-|
37
-
| [const_pointer](#pointer) | The type of a const pointer to a span element. |
38
-
| [const_reference](#reference) | The type of a const reference to an element. |
37
+
| [const_pointer](#pointer) | The type of a pointer to a `const` element. |
38
+
| [const_reference](#reference) | The type of a reference to a `const` element. |
39
39
| [difference_type](#difference_type) | The type of a signed distance between two elements. |
40
40
| [element_type](#element_type) | The type of a span element. |
41
41
| [iterator](#iterator) | The type of an iterator for a span. |
@@ -66,20 +66,22 @@ class span;
66
66
| [subspan](#sub_view) | Gets a subspan from anywhere in the span.|
67
67
| **Operators** | **Description** |
68
68
|[span::operator=](#op_eq)| Replaces the span.|
69
-
|[span::operator\[\]](#op_at)| Access an element at a specified position.|
69
+
|[span::operator\[\]](#op_at)| Access an element at a specified position. (FIXME: MENTIONED TWICE?) |
70
70
71
71
## Remarks
72
72
73
73
All `span` member functions have constant time complexity.
74
74
75
-
Unlike array or vector, a span doesn't "own” the elements inside it. A span doesn't free any storage for the items inside it because it doesn't own the storage for those objects.
75
+
Unlike `array` or `vector`, a span doesn't "own" the elements inside it. A span doesn't free any storage for the items inside it because it doesn't own the storage for those objects.
76
76
77
77
## Requirements
78
78
79
79
**Header:** \<span>
80
80
81
81
**Namespace:** std
82
82
83
+
**Compiler Option:** /std:c++latest
84
+
83
85
## <a name="back"></a> `span::back`
84
86
85
87
Returns the last element in the span.
@@ -97,11 +99,12 @@ A reference to the last element in the span.
97
99
```cpp
98
100
#include<span>
99
101
#include<iostream>
102
+
usingnamespacestd;// FIXME: Lack of qualification occurs in many examples below; need using or std::
100
103
101
-
voidmain()
104
+
intmain() // FIXME: void main() occurs in many examples below
102
105
{
103
106
int a[] = { 0,1,2 };
104
-
span<int> mySpan(a);
107
+
span<int> mySpan(a); // FIXME, STYLE: span <int> with an unnecessary space occurs in many examples below
105
108
106
109
cout << mySpan.back();
107
110
}
@@ -116,7 +119,7 @@ void main()
116
119
Returns an iterator pointing at the first element in the span.
span(It first, End last) noexcept(noexcept(last - first))
818
820
@@ -874,7 +876,7 @@ A span doesn't free storage for items in the span because it doesn't own the sto
874
876
|---------|---------|
875
877
|`span()` | Constructs an empty span. Only considered during overload resolution when the template parameter `Extent` is `0` or `dynamic_extent`.|
876
878
|`span(It first, size_type count)` | Constructs a span from the first `count` elements from iterator `first`. Only considered during overload resolution when template parameter `Extent` isn't `dynamic_extent`. |
877
-
|`span(It first, End last)` | Constructs a span from the elements in iterator `first` until the sentinel `end` is reached. Only considered during overload resolution when template parameter `Extent` isn't `dynamic_extent`. `It` must be a `contiguous_iterator`. |
879
+
|`span(It first, End last)` | Constructs a span from the elements in iterator `first` until the sentinel `last` is reached. Only considered during overload resolution when template parameter `Extent` isn't `dynamic_extent`. `It` must be a `contiguous_iterator`. |
878
880
|`span(array<T, N>& arr) noexcept;`<br /><br />`span(const array<T, N>& arr) noexcept;`<br /><br />`span(type_identity_t<element_type> (&arr)[N]) noexcept;` | Constructs a span from `N` elements of the specified array. Only considered during overload resolution when template parameter `Extent` is `dynamic_extent` or equals `N`. |
879
881
|`span(R&& r)` | Constructs a span from a range. Only participates in overload resolution if template parameter `Extent` isn't `dynamic_extent`.|
880
882
|`span(const span& other)` | The compiler-generated copy constructor. A shallow copy of the data pointer is safe because the span doesn't allocate the memory to hold the elements. |
@@ -910,21 +912,18 @@ Gets a subspan from this span.
The number of elements from the end this span to put in the subspan. If span is `dynamic_extent` (the default value), then gets the elements from `offset` to the end of this span.
926
+
The number of elements to put in the subspan. If `count` is `dynamic_extent` (the default value), then gets the elements from `offset` to the end of this span.
928
927
929
928
*offset*\
930
929
The location in this span to start the subspan.
@@ -958,7 +957,7 @@ void main()
958
957
{
959
958
cout << i;
960
959
}
961
-
cout << "\nmySpan.subspan<1>: ";
960
+
cout << "\nmySpan.subspan<1>: "; // FIXME: Doesn't match actual call
0 commit comments