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