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 (for example, objects stored in a built-in array, `std::array`, or `std::vector`).
10
+
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 such as objects stored in a built-in array, `std::array`, or `std::vector`.
11
11
12
-
If you typically access a sequence of back-to-back objects using a pointer and an index, span is a safer, lightweight alternative.
12
+
If you typically access a sequence of back-to-back objects using a pointer and an index, a `span` is a safer, lightweight alternative.
13
13
14
-
A span's size is determined at compile time by specifying it as a template argument, or at runtime by specifying `dynamic_extent`.
14
+
The size of a `span` can be set at compile time by specifying it as a template argument, or at runtime by specifying `dynamic_extent`.
15
15
16
16
## Syntax
17
17
@@ -42,30 +42,30 @@ class span;
42
42
| [reference](#reference) | The type of a reference to an element. |
43
43
| [reverse_iterator](#reverse_iterator) | The type of a reverse iterator for a span. |
44
44
| [size_type](#size_type) | The type for the result of the unsigned distance between two elements in the span. |
45
-
| [value_type](#value_type) | The type of an element without `const` or `volatile` qualifications. |
45
+
| [value_type](#value_type) | The type of an element, without `const` or `volatile` qualifications. |
46
46
| **Constructors** | **Description** |
47
-
|[span](#span)| Constructs a `span`.|
47
+
|[span](#span)| Construct a `span`.|
48
48
| **Iterator support** | **Description** |
49
-
|[begin](#begin) | Returns an iterator pointing to the first element in the span.|
50
-
|[end](#end) | Returns an iterator pointing to the end of the span. |
51
-
|[rbegin](#rbegin) | Returns a reverse iterator pointing to the last element of the span; that is, the beginning of the reversed span.|
52
-
|[rend](#rend) | Returns a reverse iterator pointing to the front of the span; that is, the end of the reversed span.|
49
+
|[begin](#begin) | Get an iterator pointing to the first element in the span.|
50
+
|[end](#end) | Get an iterator pointing to the end of the span. |
51
+
|[rbegin](#rbegin) | Get a reverse iterator pointing to the last element of the span; that is, the beginning of the reversed span.|
52
+
|[rend](#rend) | Get a reverse iterator pointing to the front of the span; that is, the end of the reversed span.|
53
53
| **Access elements**| **Description** |
54
54
|[back](#back) | Get the last element in the span.|
55
55
|[data](#data) | Get the address of the first element in the span.|
56
56
|[front](#front) | Get the first element in the span.|
57
57
|[operator\[\]](#op_at) | Access an element at a specified position.|
58
58
| **Observers** | **Description** |
59
-
|[empty](#empty)| Tests whether the span is empty.|
60
-
|[size](#size) | Returns the number of elements in the span.|
61
-
|[size_bytes](#size_bytes) | Returns the size of the span in bytes.|
59
+
|[empty](#empty)| Test whether the span is empty.|
60
+
|[size](#size) | Get the number of elements in the span.|
61
+
|[size_bytes](#size_bytes) | Get the size of the span in bytes.|
62
62
| **Subviews** | **Description**|
63
63
| [first](#first_view) | Get a subspan from the front of the span.|
64
64
| [last](#last_view) | Get a subspan from the back of the span.|
65
-
| [subspan](#sub_view) | Gets a subspan from anywhere in the span.|
65
+
| [subspan](#sub_view) | Get a subspan from anywhere in the span.|
66
66
| **Operators** | **Description** |
67
-
|[span::operator=](#op_eq)| Replaces the span.|
68
-
|[span::operator\[\]](#op_at)| Access an element at a specified position. |
67
+
|[span::operator=](#op_eq)| Replace the span.|
68
+
|[span::operator\[\]](#op_at)| Get the element at the specified position. |
69
69
70
70
## Remarks
71
71
@@ -83,7 +83,7 @@ Unlike `array` or `vector`, a span doesn't "own" the elements inside it. A span
83
83
84
84
## <a name="back"></a> `span::back`
85
85
86
-
Returns the last element in the span.
86
+
Get the last element in the span.
87
87
88
88
```cpp
89
89
constexpr reference back() const noexcept;
@@ -116,15 +116,15 @@ int main()
116
116
117
117
## <aname="begin"></a> `span::begin`
118
118
119
-
Returns an iterator pointing at the first element in the span.
119
+
Get an iterator pointing at the first element in the span.
120
120
121
121
```cpp
122
122
constexpr iterator begin() constnoexcept;
123
123
```
124
124
125
125
### Return value
126
126
127
-
An iterator that starts with the first element in the span.
127
+
An iterator pointing at the first element in the span.
128
128
129
129
### Example
130
130
@@ -150,7 +150,7 @@ int main()
150
150
151
151
## <aname="data"></a> `span::data`
152
152
153
-
Returns a pointer to the beginning of the span data.
This type represents the number of elements between two elements in a span.
186
+
The number of elements between two elements in a span.
187
187
188
188
```cpp
189
189
using difference_type = std::ptrdiff_t;
@@ -273,21 +273,21 @@ int main()
273
273
274
274
## <aname="end"></a> `span::end`
275
275
276
-
Returns an iterator to the end of the span.
276
+
Get an iterator to the end of the span.
277
277
278
278
```cpp
279
279
constexpr iterator end() constnoexcept;
280
280
```
281
281
282
282
### Return Value
283
283
284
-
An iterator to just beyond the end of the span.
284
+
An iterator pointing just beyond the end of the span.
285
285
286
286
### Remarks
287
287
288
288
`end` is used to test whether an iterator has passed the end of its range.
289
289
290
-
Don't dereference the value returned by the iterator. Use it to identify whether the iterator has reached beyond the last element in the span.
290
+
Don't dereference the value returned by this iterator. Use it to identify whether the iterator has reached beyond the last element in the span.
291
291
292
292
### Example
293
293
@@ -320,7 +320,7 @@ A span that contains `count` elements from the front of this span.
320
320
321
321
### Remarks
322
322
323
-
A template version of this function can be used to validate the count at compile time, and to preserve info about the span by returning a span of fixed extent when possible.
323
+
Use the template version of this function when possible to validate the `count` at compile time, and to preserve info about the span since it returns a span of fixed extent.
324
324
325
325
### Example
326
326
@@ -358,7 +358,7 @@ mySpan.first<2>: 01
358
358
359
359
## <aname="front"></a> `span::front`
360
360
361
-
Returns the first element in the span.
361
+
Get the first element in the span.
362
362
363
363
```cpp
364
364
constexpr reference front() constnoexcept;
@@ -445,7 +445,7 @@ A span containing the last `count` elements from this span.
445
445
446
446
### Remarks
447
447
448
-
A template version of this function can be used instead to check the count at compile time. The template version also preserves info about the span by returning a span of fixed extent, when possible.
448
+
Use the template version of this function when possible to validate the `count` at compile time, and to preserve info about the span since it returns a span of fixed extent.
449
449
450
450
### Example
451
451
@@ -483,7 +483,7 @@ mySpan.last<2>: 12
483
483
484
484
## <aname="op_at"></a> `span::operator[]`
485
485
486
-
Access an element in the span at a specified position.
486
+
Get the element in the span at a specified position.
@@ -537,7 +537,7 @@ The span to assign to this one.
537
537
538
538
### Remarks
539
539
540
-
Assignment does a shallow copy of the data pointer and the size. A shallow copy is safe because spans don't allocate memory for the elements they contain.
540
+
Assignment does a shallow copy of the data pointer and the size. A shallow copy is safe because a `span` doesn't allocate memory for the elements it contains.
541
541
542
542
### Example
543
543
@@ -566,7 +566,7 @@ int main()
566
566
567
567
## <aname="pointer"></a> `span::pointer`
568
568
569
-
The types for a pointer and `const` pointer to a span element.
569
+
The types for a pointer, and `const` pointer, to a span element.
570
570
571
571
```cpp
572
572
using pointer = T*;
@@ -677,7 +677,7 @@ int main()
677
677
678
678
## <aname="rend"></a> `span::rend`
679
679
680
-
Get a random-access iterator to just beyond the end of the reversed span.
680
+
Get a random-access iterator that points just beyond the end of the reversed span.
@@ -896,7 +896,7 @@ Iterator to just past the last element in the span.
896
896
The number of elements that will be in the span.
897
897
898
898
*other*\
899
-
Copy from this span.
899
+
Make a copy of this span.
900
900
901
901
*r*\
902
902
Construct a span from this range.
@@ -907,13 +907,13 @@ A span doesn't free storage for items in the span because it doesn't own the sto
907
907
908
908
|Constructor | Description |
909
909
|---------|---------|
910
-
|`span()` | Constructs an empty span. Only considered during overload resolution when the template parameter `Extent` is `0` or `dynamic_extent`.|
911
-
|`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`. |
912
-
|`span(It first, End last)` | Constructs a span from the elements in iterator `first` until the end `last` is reached. Only considered during overload resolution when template parameter `Extent` isn't `dynamic_extent`. `It` must be a `contiguous_iterator`. |
913
-
|`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`. |
914
-
|`span(R&& r)` | Constructs a span from a range. Only participates in overload resolution if template parameter `Extent` isn't `dynamic_extent`.|
910
+
|`span()` | Construct an empty span. Only considered during overload resolution when the template parameter `Extent` is `0` or `dynamic_extent`.|
911
+
|`span(It first, size_type count)` | Construct a span from the first `count` elements from iterator `first`. Only considered during overload resolution when template parameter `Extent` isn't `dynamic_extent`. |
912
+
|`span(It first, End last)` | Construct a span from the elements in iterator `first` until the end `last` is reached. Only considered during overload resolution when template parameter `Extent` isn't `dynamic_extent`. `It` must be a `contiguous_iterator`. |
913
+
|`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;` | Construct a span from `N` elements of the specified array. Only considered during overload resolution when template parameter `Extent` is `dynamic_extent` or equals `N`. |
914
+
|`span(R&& r)` | Construct a span from a range. Only participates in overload resolution if template parameter `Extent` isn't `dynamic_extent`.|
915
915
|`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. |
916
-
|`span(const span<OtherElementType, OtherExtent>& s) noexcept;` | Converting constructor: constructs a span from another span. Only participates in overload resolution if template parameter `Extent` is `dynamic_extent`, or `N` is `dynamic_extent` or equals `Extent`.|
916
+
|`span(const span<OtherElementType, OtherExtent>& s) noexcept;` | Converting constructor: construct a span from another span. Only participates in overload resolution if template parameter `Extent` is `dynamic_extent`, or `N` is `dynamic_extent` or equals `Extent`.|
917
917
918
918
### Example
919
919
@@ -953,18 +953,18 @@ constexpr auto subspan() const noexcept
953
953
### Parameters
954
954
955
955
*count*\
956
-
The number of elements to put in the subspan. If `count` is `dynamic_extent` (the default value), then gets the subspan from `offset` to the end of this span.
956
+
The number of elements to put in the subspan. If `count` is `dynamic_extent` (the default value), then the subspan is taken from `offset` to the end of this span.
957
957
958
958
*offset*\
959
959
The location in this span to start the subspan.
960
960
961
961
### Return Value
962
962
963
-
A span starting at `offset` in this span, containing `count` elements.
963
+
A span starting at `offset` in this span. Contains `count` elements.
964
964
965
965
### Remarks
966
966
967
-
A template version of this function is available that checks the count at compile time, and that preserves information about the span by returning a span of fixed extent, when possible.
967
+
A template version of this function is available that checks the count at compile time, which preserves information about the span by returning a span of fixed extent.
968
968
969
969
### Example
970
970
@@ -1005,7 +1005,7 @@ mySpan.subspan<1>: 12
1005
1005
1006
1006
## <aname="value_type"></a> `span::value_type`
1007
1007
1008
-
The type of the element in the span but without any`const` or `volatile` qualifications.
1008
+
The type of the element in the span, without `const` or `volatile` qualifications.
|[operator\[\]](span-class.md#op_at)| Element access |
62
64
63
65
### Functions
64
66
65
67
|||
66
-
|-|-|
68
+
|-|:-|
67
69
| [as_bytes](span-functions.md#as_bytes)| Get the underlying read-only bytes of the span. |
68
70
| [as_writable_bytes](span-functions.md#as_writable_bytes) | Get the underlying bytes of the span. |
69
71
70
72
### Constants
71
73
72
74
|||
73
-
|-|-|
74
-
| **dynamic_extent** | Indicates that the span size is determined at runtime rather than compile time. When the number of elements in the span is known at compile time, it's specified as the `Extent` template parameter. When the number isn't known until runtime, `dynamic_extent` is specified instead. |
75
+
|-|:-|
76
+
| **dynamic_extent** | Indicates that the span size is determined at runtime rather than compile time. When the number of elements in the span is known at compile time, it's specified as the `Extent` template parameter. When the number isn't known until runtime, specify `dynamic_extent` instead. |
0 commit comments