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.span]]</a>
|
| 2 |
+
|
| 3 |
+
#### Overview <a id="span.overview">[[span.overview]]</a>
|
| 4 |
+
|
| 5 |
+
A `span` is a view over a contiguous sequence of objects, the storage of
|
| 6 |
+
which is owned by some other object.
|
| 7 |
+
|
| 8 |
+
All member functions of `span` have constant time complexity.
|
| 9 |
+
|
| 10 |
+
``` cpp
|
| 11 |
+
namespace std {
|
| 12 |
+
template<class ElementType, size_t Extent = dynamic_extent>
|
| 13 |
+
class span {
|
| 14 |
+
public:
|
| 15 |
+
// constants and types
|
| 16 |
+
using element_type = ElementType;
|
| 17 |
+
using value_type = remove_cv_t<ElementType>;
|
| 18 |
+
using size_type = size_t;
|
| 19 |
+
using difference_type = ptrdiff_t;
|
| 20 |
+
using pointer = element_type*;
|
| 21 |
+
using const_pointer = const element_type*;
|
| 22 |
+
using reference = element_type&;
|
| 23 |
+
using const_reference = const element_type&;
|
| 24 |
+
using iterator = implementation-defined // type of span::iterator; // see [span.iterators]
|
| 25 |
+
using reverse_iterator = std::reverse_iterator<iterator>;
|
| 26 |
+
static constexpr size_type extent = Extent;
|
| 27 |
+
|
| 28 |
+
// [span.cons], constructors, copy, and assignment
|
| 29 |
+
constexpr span() noexcept;
|
| 30 |
+
template<class It>
|
| 31 |
+
constexpr explicit(extent != dynamic_extent) span(It first, size_type count);
|
| 32 |
+
template<class It, class End>
|
| 33 |
+
constexpr explicit(extent != dynamic_extent) span(It first, End last);
|
| 34 |
+
template<size_t N>
|
| 35 |
+
constexpr span(type_identity_t<element_type> (&arr)[N]) noexcept;
|
| 36 |
+
template<class T, size_t N>
|
| 37 |
+
constexpr span(array<T, N>& arr) noexcept;
|
| 38 |
+
template<class T, size_t N>
|
| 39 |
+
constexpr span(const array<T, N>& arr) noexcept;
|
| 40 |
+
template<class R>
|
| 41 |
+
constexpr explicit(extent != dynamic_extent) span(R&& r);
|
| 42 |
+
constexpr span(const span& other) noexcept = default;
|
| 43 |
+
template<class OtherElementType, size_t OtherExtent>
|
| 44 |
+
constexpr explicit(see below) span(const span<OtherElementType, OtherExtent>& s) noexcept;
|
| 45 |
+
|
| 46 |
+
~span() noexcept = default;
|
| 47 |
+
|
| 48 |
+
constexpr span& operator=(const span& other) noexcept = default;
|
| 49 |
+
|
| 50 |
+
// [span.sub], subviews
|
| 51 |
+
template<size_t Count>
|
| 52 |
+
constexpr span<element_type, Count> first() const;
|
| 53 |
+
template<size_t Count>
|
| 54 |
+
constexpr span<element_type, Count> last() const;
|
| 55 |
+
template<size_t Offset, size_t Count = dynamic_extent>
|
| 56 |
+
constexpr span<element_type, see below> subspan() const;
|
| 57 |
+
|
| 58 |
+
constexpr span<element_type, dynamic_extent> first(size_type count) const;
|
| 59 |
+
constexpr span<element_type, dynamic_extent> last(size_type count) const;
|
| 60 |
+
constexpr span<element_type, dynamic_extent> subspan(
|
| 61 |
+
size_type offset, size_type count = dynamic_extent) const;
|
| 62 |
+
|
| 63 |
+
// [span.obs], observers
|
| 64 |
+
constexpr size_type size() const noexcept;
|
| 65 |
+
constexpr size_type size_bytes() const noexcept;
|
| 66 |
+
[[nodiscard]] constexpr bool empty() const noexcept;
|
| 67 |
+
|
| 68 |
+
// [span.elem], element access
|
| 69 |
+
constexpr reference operator[](size_type idx) const;
|
| 70 |
+
constexpr reference front() const;
|
| 71 |
+
constexpr reference back() const;
|
| 72 |
+
constexpr pointer data() const noexcept;
|
| 73 |
+
|
| 74 |
+
// [span.iterators], iterator support
|
| 75 |
+
constexpr iterator begin() const noexcept;
|
| 76 |
+
constexpr iterator end() const noexcept;
|
| 77 |
+
constexpr reverse_iterator rbegin() const noexcept;
|
| 78 |
+
constexpr reverse_iterator rend() const noexcept;
|
| 79 |
+
|
| 80 |
+
private:
|
| 81 |
+
pointer data_; // exposition only
|
| 82 |
+
size_type size_; // exposition only
|
| 83 |
+
};
|
| 84 |
+
|
| 85 |
+
template<class It, class EndOrSize>
|
| 86 |
+
span(It, EndOrSize) -> span<remove_reference_t<iter_reference_t<It>>>;
|
| 87 |
+
template<class T, size_t N>
|
| 88 |
+
span(T (&)[N]) -> span<T, N>;
|
| 89 |
+
template<class T, size_t N>
|
| 90 |
+
span(array<T, N>&) -> span<T, N>;
|
| 91 |
+
template<class T, size_t N>
|
| 92 |
+
span(const array<T, N>&) -> span<const T, N>;
|
| 93 |
+
template<class R>
|
| 94 |
+
span(R&&) -> span<remove_reference_t<ranges::range_reference_t<R>>>;
|
| 95 |
+
}
|
| 96 |
+
```
|
| 97 |
+
|
| 98 |
+
`ElementType` is required to be a complete object type that is not an
|
| 99 |
+
abstract class type.
|
| 100 |
+
|
| 101 |
+
#### Constructors, copy, and assignment <a id="span.cons">[[span.cons]]</a>
|
| 102 |
+
|
| 103 |
+
``` cpp
|
| 104 |
+
constexpr span() noexcept;
|
| 105 |
+
```
|
| 106 |
+
|
| 107 |
+
*Constraints:* `Extent == dynamic_extent || Extent == 0` is `true`.
|
| 108 |
+
|
| 109 |
+
*Ensures:* `size() == 0 && data() == nullptr`.
|
| 110 |
+
|
| 111 |
+
``` cpp
|
| 112 |
+
template<class It>
|
| 113 |
+
constexpr explicit(extent != dynamic_extent) span(It first, size_type count);
|
| 114 |
+
```
|
| 115 |
+
|
| 116 |
+
*Constraints:* Let `U` be `remove_reference_t<iter_reference_t<It>>`.
|
| 117 |
+
|
| 118 |
+
- `It` satisfies `contiguous_iterator`.
|
| 119 |
+
- `is_convertible_v<U(*)[], element_type(*)[]>` is `true`.
|
| 120 |
+
\[*Note 1*: The intent is to allow only qualification conversions of
|
| 121 |
+
the iterator reference type to `element_type`. — *end note*]
|
| 122 |
+
|
| 123 |
+
*Preconditions:*
|
| 124 |
+
|
| 125 |
+
- \[`first`, `first + count`) is a valid range.
|
| 126 |
+
- `It` models `contiguous_iterator`.
|
| 127 |
+
- If `extent` is not equal to `dynamic_extent`, then `count` is equal to
|
| 128 |
+
`extent`.
|
| 129 |
+
|
| 130 |
+
*Effects:* Initializes `data_` with `to_address(first)` and `size_` with
|
| 131 |
+
`count`.
|
| 132 |
+
|
| 133 |
+
*Throws:* Nothing.
|
| 134 |
+
|
| 135 |
+
``` cpp
|
| 136 |
+
template<class It, class End>
|
| 137 |
+
constexpr explicit(extent != dynamic_extent) span(It first, End last);
|
| 138 |
+
```
|
| 139 |
+
|
| 140 |
+
*Constraints:* Let `U` be `remove_reference_t<iter_reference_t<It>>`.
|
| 141 |
+
|
| 142 |
+
- `is_convertible_v<U(*)[], element_type(*)[]>` is `true`.
|
| 143 |
+
\[*Note 2*: The intent is to allow only qualification conversions of
|
| 144 |
+
the iterator reference type to `element_type`. — *end note*]
|
| 145 |
+
- `It` satisfies `contiguous_iterator`.
|
| 146 |
+
- `End` satisfies `sized_sentinel_for<It>`.
|
| 147 |
+
- `is_convertible_v<End, size_t>` is `false`.
|
| 148 |
+
|
| 149 |
+
*Preconditions:*
|
| 150 |
+
|
| 151 |
+
- If `extent` is not equal to `dynamic_extent`, then `last - first` is
|
| 152 |
+
equal to `extent`.
|
| 153 |
+
- \[`first`, `last`) is a valid range.
|
| 154 |
+
- `It` models `contiguous_iterator`.
|
| 155 |
+
- `End` models `sized_sentinel_for<It>`.
|
| 156 |
+
|
| 157 |
+
*Effects:* Initializes `data_` with `to_address(first)` and `size_` with
|
| 158 |
+
`last - first`.
|
| 159 |
+
|
| 160 |
+
*Throws:* When and what `last - first` throws.
|
| 161 |
+
|
| 162 |
+
``` cpp
|
| 163 |
+
template<size_t N> constexpr span(type_identity_t<element_type> (&arr)[N]) noexcept;
|
| 164 |
+
template<class T, size_t N> constexpr span(array<T, N>& arr) noexcept;
|
| 165 |
+
template<class T, size_t N> constexpr span(const array<T, N>& arr) noexcept;
|
| 166 |
+
```
|
| 167 |
+
|
| 168 |
+
*Constraints:* Let `U` be `remove_pointer_t<decltype(data(arr))>`.
|
| 169 |
+
|
| 170 |
+
- `extent == dynamic_extent || N == extent` is `true`, and
|
| 171 |
+
- `is_convertible_v<U(*)[], element_type(*)[]>` is `true`.
|
| 172 |
+
\[*Note 3*: The intent is to allow only qualification conversions of
|
| 173 |
+
the array element type to `element_type`. — *end note*]
|
| 174 |
+
|
| 175 |
+
*Effects:* Constructs a `span` that is a view over the supplied array.
|
| 176 |
+
|
| 177 |
+
[*Note 1*: `type_identity_t` affects class template argument
|
| 178 |
+
deduction. — *end note*]
|
| 179 |
+
|
| 180 |
+
*Ensures:* `size() == N && data() == data(arr)` is `true`.
|
| 181 |
+
|
| 182 |
+
``` cpp
|
| 183 |
+
template<class R> constexpr explicit(extent != dynamic_extent) span(R&& r);
|
| 184 |
+
```
|
| 185 |
+
|
| 186 |
+
*Constraints:* Let `U` be
|
| 187 |
+
`remove_reference_t<ranges::range_reference_t<R>>`.
|
| 188 |
+
|
| 189 |
+
- `R` satisfies `ranges::contiguous_range` and `ranges::sized_range`.
|
| 190 |
+
- Either `R` satisfies `ranges::borrowed_range` or
|
| 191 |
+
`is_const_v<element_type>` is `true`.
|
| 192 |
+
- `remove_cvref_t<R>` is not a specialization of `span`.
|
| 193 |
+
- `remove_cvref_t<R>` is not a specialization of `array`.
|
| 194 |
+
- `is_array_v<remove_cvref_t<R>>` is `false`.
|
| 195 |
+
- `is_convertible_v<U(*)[], element_type(*)[]>` is `true`.
|
| 196 |
+
\[*Note 4*: The intent is to allow only qualification conversions of
|
| 197 |
+
the range reference type to `element_type`. — *end note*]
|
| 198 |
+
|
| 199 |
+
*Preconditions:*
|
| 200 |
+
|
| 201 |
+
- If `extent` is not equal to `dynamic_extent`, then `ranges::size(r)`
|
| 202 |
+
is equal to `extent`.
|
| 203 |
+
- `R` models `ranges::contiguous_range` and `ranges::sized_range`.
|
| 204 |
+
- If `is_const_v<element_type>` is `false`, `R` models
|
| 205 |
+
`ranges::borrowed_range`.
|
| 206 |
+
|
| 207 |
+
*Effects:* Initializes `data_` with `ranges::data(r)` and `size_` with
|
| 208 |
+
`ranges::size(r)`.
|
| 209 |
+
|
| 210 |
+
*Throws:* What and when `ranges::data(r)` and `ranges::size(r)` throw.
|
| 211 |
+
|
| 212 |
+
``` cpp
|
| 213 |
+
constexpr span(const span& other) noexcept = default;
|
| 214 |
+
```
|
| 215 |
+
|
| 216 |
+
*Ensures:* `other.size() == size() && other.data() == data()`.
|
| 217 |
+
|
| 218 |
+
``` cpp
|
| 219 |
+
template<class OtherElementType, size_t OtherExtent>
|
| 220 |
+
constexpr explicit(see below) span(const span<OtherElementType, OtherExtent>& s) noexcept;
|
| 221 |
+
```
|
| 222 |
+
|
| 223 |
+
*Constraints:*
|
| 224 |
+
|
| 225 |
+
- `extent == dynamic_extent` `||` `OtherExtent == dynamic_extent` `||`
|
| 226 |
+
`extent == OtherExtent` is `true`, and
|
| 227 |
+
- `is_convertible_v<OtherElementType(*)[], element_type(*)[]>` is
|
| 228 |
+
`true`. \[*Note 5*: The intent is to allow only qualification
|
| 229 |
+
conversions of the `OtherElementType` to
|
| 230 |
+
`element_type`. — *end note*]
|
| 231 |
+
|
| 232 |
+
*Preconditions:* If `extent` is not equal to `dynamic_extent`, then
|
| 233 |
+
`s.size()` is equal to `extent`.
|
| 234 |
+
|
| 235 |
+
*Effects:* Constructs a `span` that is a view over the range
|
| 236 |
+
\[`s.data()`, `s.data() + s.size()`).
|
| 237 |
+
|
| 238 |
+
*Ensures:* `size() == s.size() && data() == s.data()`.
|
| 239 |
+
|
| 240 |
+
*Remarks:* The expression inside `explicit` is equivalent to:
|
| 241 |
+
|
| 242 |
+
``` cpp
|
| 243 |
+
extent != dynamic_extent && OtherExtent == dynamic_extent
|
| 244 |
+
```
|
| 245 |
+
|
| 246 |
+
``` cpp
|
| 247 |
+
constexpr span& operator=(const span& other) noexcept = default;
|
| 248 |
+
```
|
| 249 |
+
|
| 250 |
+
*Ensures:* `size() == other.size() && data() == other.data()`.
|
| 251 |
+
|
| 252 |
+
#### Deduction guides <a id="span.deduct">[[span.deduct]]</a>
|
| 253 |
+
|
| 254 |
+
``` cpp
|
| 255 |
+
template<class It, class EndOrSize>
|
| 256 |
+
span(It, EndOrSize) -> span<remove_reference_t<iter_reference_t<It>>>;
|
| 257 |
+
```
|
| 258 |
+
|
| 259 |
+
*Constraints:* `It` satisfies `contiguous_iterator`.
|
| 260 |
+
|
| 261 |
+
``` cpp
|
| 262 |
+
template<class R>
|
| 263 |
+
span(R&&) -> span<remove_reference_t<ranges::range_reference_t<R>>>;
|
| 264 |
+
```
|
| 265 |
+
|
| 266 |
+
*Constraints:* `R` satisfies `ranges::contiguous_range`.
|
| 267 |
+
|
| 268 |
+
#### Subviews <a id="span.sub">[[span.sub]]</a>
|
| 269 |
+
|
| 270 |
+
``` cpp
|
| 271 |
+
template<size_t Count> constexpr span<element_type, Count> first() const;
|
| 272 |
+
```
|
| 273 |
+
|
| 274 |
+
*Mandates:* `Count <= Extent` is `true`.
|
| 275 |
+
|
| 276 |
+
*Preconditions:* `Count <= size()` is `true`.
|
| 277 |
+
|
| 278 |
+
*Effects:* Equivalent to: `return R{data(), Count};` where `R` is the
|
| 279 |
+
return type.
|
| 280 |
+
|
| 281 |
+
``` cpp
|
| 282 |
+
template<size_t Count> constexpr span<element_type, Count> last() const;
|
| 283 |
+
```
|
| 284 |
+
|
| 285 |
+
*Mandates:* `Count <= Extent` is `true`.
|
| 286 |
+
|
| 287 |
+
*Preconditions:* `Count <= size()` is `true`.
|
| 288 |
+
|
| 289 |
+
*Effects:* Equivalent to: `return R{data() + (size() - Count), Count};`
|
| 290 |
+
where `R` is the return type.
|
| 291 |
+
|
| 292 |
+
``` cpp
|
| 293 |
+
template<size_t Offset, size_t Count = dynamic_extent>
|
| 294 |
+
constexpr span<element_type, see below> subspan() const;
|
| 295 |
+
```
|
| 296 |
+
|
| 297 |
+
*Mandates:*
|
| 298 |
+
|
| 299 |
+
``` cpp
|
| 300 |
+
Offset <= Extent && (Count == dynamic_extent || Count <= Extent - Offset)
|
| 301 |
+
```
|
| 302 |
+
|
| 303 |
+
is `true`.
|
| 304 |
+
|
| 305 |
+
*Preconditions:*
|
| 306 |
+
|
| 307 |
+
``` cpp
|
| 308 |
+
Offset <= size() && (Count == dynamic_extent || Count <= size() - Offset)
|
| 309 |
+
```
|
| 310 |
+
|
| 311 |
+
is `true`.
|
| 312 |
+
|
| 313 |
+
*Effects:* Equivalent to:
|
| 314 |
+
|
| 315 |
+
``` cpp
|
| 316 |
+
return span<ElementType, see below>(
|
| 317 |
+
data() + Offset, Count != dynamic_extent ? Count : size() - Offset);
|
| 318 |
+
```
|
| 319 |
+
|
| 320 |
+
*Remarks:* The second template argument of the returned `span` type is:
|
| 321 |
+
|
| 322 |
+
``` cpp
|
| 323 |
+
Count != dynamic_extent ? Count
|
| 324 |
+
: (Extent != dynamic_extent ? Extent - Offset
|
| 325 |
+
: dynamic_extent)
|
| 326 |
+
```
|
| 327 |
+
|
| 328 |
+
``` cpp
|
| 329 |
+
constexpr span<element_type, dynamic_extent> first(size_type count) const;
|
| 330 |
+
```
|
| 331 |
+
|
| 332 |
+
*Preconditions:* `count <= size()` is `true`.
|
| 333 |
+
|
| 334 |
+
*Effects:* Equivalent to: `return {data(), count};`
|
| 335 |
+
|
| 336 |
+
``` cpp
|
| 337 |
+
constexpr span<element_type, dynamic_extent> last(size_type count) const;
|
| 338 |
+
```
|
| 339 |
+
|
| 340 |
+
*Preconditions:* `count <= size()` is `true`.
|
| 341 |
+
|
| 342 |
+
*Effects:* Equivalent to: `return {data() + (size() - count), count};`
|
| 343 |
+
|
| 344 |
+
``` cpp
|
| 345 |
+
constexpr span<element_type, dynamic_extent> subspan(
|
| 346 |
+
size_type offset, size_type count = dynamic_extent) const;
|
| 347 |
+
```
|
| 348 |
+
|
| 349 |
+
*Preconditions:*
|
| 350 |
+
|
| 351 |
+
``` cpp
|
| 352 |
+
offset <= size() && (count == dynamic_extent || count <= size() - offset)
|
| 353 |
+
```
|
| 354 |
+
|
| 355 |
+
is `true`.
|
| 356 |
+
|
| 357 |
+
*Effects:* Equivalent to:
|
| 358 |
+
|
| 359 |
+
``` cpp
|
| 360 |
+
return {data() + offset, count == dynamic_extent ? size() - offset : count};
|
| 361 |
+
```
|
| 362 |
+
|
| 363 |
+
#### Observers <a id="span.obs">[[span.obs]]</a>
|
| 364 |
+
|
| 365 |
+
``` cpp
|
| 366 |
+
constexpr size_type size() const noexcept;
|
| 367 |
+
```
|
| 368 |
+
|
| 369 |
+
*Effects:* Equivalent to: `return size_;`
|
| 370 |
+
|
| 371 |
+
``` cpp
|
| 372 |
+
constexpr size_type size_bytes() const noexcept;
|
| 373 |
+
```
|
| 374 |
+
|
| 375 |
+
*Effects:* Equivalent to: `return size() * sizeof(element_type);`
|
| 376 |
+
|
| 377 |
+
``` cpp
|
| 378 |
+
[[nodiscard]] constexpr bool empty() const noexcept;
|
| 379 |
+
```
|
| 380 |
+
|
| 381 |
+
*Effects:* Equivalent to: `return size() == 0;`
|
| 382 |
+
|
| 383 |
+
#### Element access <a id="span.elem">[[span.elem]]</a>
|
| 384 |
+
|
| 385 |
+
``` cpp
|
| 386 |
+
constexpr reference operator[](size_type idx) const;
|
| 387 |
+
```
|
| 388 |
+
|
| 389 |
+
*Preconditions:* `idx < size()` is `true`.
|
| 390 |
+
|
| 391 |
+
*Effects:* Equivalent to: `return *(data() + idx);`
|
| 392 |
+
|
| 393 |
+
``` cpp
|
| 394 |
+
constexpr reference front() const;
|
| 395 |
+
```
|
| 396 |
+
|
| 397 |
+
*Preconditions:* `empty()` is `false`.
|
| 398 |
+
|
| 399 |
+
*Effects:* Equivalent to: `return *data();`
|
| 400 |
+
|
| 401 |
+
``` cpp
|
| 402 |
+
constexpr reference back() const;
|
| 403 |
+
```
|
| 404 |
+
|
| 405 |
+
*Preconditions:* `empty()` is `false`.
|
| 406 |
+
|
| 407 |
+
*Effects:* Equivalent to: `return *(data() + (size() - 1));`
|
| 408 |
+
|
| 409 |
+
``` cpp
|
| 410 |
+
constexpr pointer data() const noexcept;
|
| 411 |
+
```
|
| 412 |
+
|
| 413 |
+
*Effects:* Equivalent to: `return data_;`
|
| 414 |
+
|
| 415 |
+
#### Iterator support <a id="span.iterators">[[span.iterators]]</a>
|
| 416 |
+
|
| 417 |
+
``` cpp
|
| 418 |
+
using iterator = implementation-defined // type of span::iterator;
|
| 419 |
+
```
|
| 420 |
+
|
| 421 |
+
The type models `contiguous_iterator` [[iterator.concept.contiguous]],
|
| 422 |
+
meets the *Cpp17RandomAccessIterator*
|
| 423 |
+
requirements [[random.access.iterators]], and meets the requirements for
|
| 424 |
+
constexpr iterators [[iterator.requirements.general]]. All requirements
|
| 425 |
+
on container iterators [[container.requirements]] apply to
|
| 426 |
+
`span::iterator` as well.
|
| 427 |
+
|
| 428 |
+
``` cpp
|
| 429 |
+
constexpr iterator begin() const noexcept;
|
| 430 |
+
```
|
| 431 |
+
|
| 432 |
+
*Returns:* An iterator referring to the first element in the span. If
|
| 433 |
+
`empty()` is `true`, then it returns the same value as `end()`.
|
| 434 |
+
|
| 435 |
+
``` cpp
|
| 436 |
+
constexpr iterator end() const noexcept;
|
| 437 |
+
```
|
| 438 |
+
|
| 439 |
+
*Returns:* An iterator which is the past-the-end value.
|
| 440 |
+
|
| 441 |
+
``` cpp
|
| 442 |
+
constexpr reverse_iterator rbegin() const noexcept;
|
| 443 |
+
```
|
| 444 |
+
|
| 445 |
+
*Effects:* Equivalent to: `return reverse_iterator(end());`
|
| 446 |
+
|
| 447 |
+
``` cpp
|
| 448 |
+
constexpr reverse_iterator rend() const noexcept;
|
| 449 |
+
```
|
| 450 |
+
|
| 451 |
+
*Effects:* Equivalent to: `return reverse_iterator(begin());`
|
| 452 |
+
|
| 453 |
+
#### Views of object representation <a id="span.objectrep">[[span.objectrep]]</a>
|
| 454 |
+
|
| 455 |
+
``` cpp
|
| 456 |
+
template<class ElementType, size_t Extent>
|
| 457 |
+
span<const byte, Extent == dynamic_extent ? dynamic_extent : sizeof(ElementType) * Extent>
|
| 458 |
+
as_bytes(span<ElementType, Extent> s) noexcept;
|
| 459 |
+
```
|
| 460 |
+
|
| 461 |
+
*Effects:* Equivalent to:
|
| 462 |
+
`return R{reinterpret_cast<const byte*>(s.data()), s.size_bytes()};`
|
| 463 |
+
where `R` is the return type.
|
| 464 |
+
|
| 465 |
+
``` cpp
|
| 466 |
+
template<class ElementType, size_t Extent>
|
| 467 |
+
span<byte, Extent == dynamic_extent ? dynamic_extent : sizeof(ElementType) * Extent>
|
| 468 |
+
as_writable_bytes(span<ElementType, Extent> s) noexcept;
|
| 469 |
+
```
|
| 470 |
+
|
| 471 |
+
*Constraints:* `is_const_v<ElementType>` is `false`.
|
| 472 |
+
|
| 473 |
+
*Effects:* Equivalent to:
|
| 474 |
+
`return R{reinterpret_cast<byte*>(s.data()), s.size_bytes()};` where `R`
|
| 475 |
+
is the return type.
|
| 476 |
+
|
| 477 |
+
<!-- Link reference definitions -->
|
| 478 |
+
[alg.sorting]: algorithms.md#alg.sorting
|
| 479 |
+
[algorithm.stable]: library.md#algorithm.stable
|
| 480 |
+
[algorithms]: algorithms.md#algorithms
|
| 481 |
+
[algorithms.requirements]: algorithms.md#algorithms.requirements
|
| 482 |
+
[allocator.requirements]: library.md#allocator.requirements
|
| 483 |
+
[allocator.requirements.completeness]: library.md#allocator.requirements.completeness
|
| 484 |
+
[allocator.traits.members]: utilities.md#allocator.traits.members
|
| 485 |
+
[array]: #array
|
| 486 |
+
[array.cons]: #array.cons
|
| 487 |
+
[array.creation]: #array.creation
|
| 488 |
+
[array.members]: #array.members
|
| 489 |
+
[array.overview]: #array.overview
|
| 490 |
+
[array.special]: #array.special
|
| 491 |
+
[array.syn]: #array.syn
|
| 492 |
+
[array.tuple]: #array.tuple
|
| 493 |
+
[array.zero]: #array.zero
|
| 494 |
+
[associative]: #associative
|
| 495 |
+
[associative.general]: #associative.general
|
| 496 |
+
[associative.map.syn]: #associative.map.syn
|
| 497 |
+
[associative.reqmts]: #associative.reqmts
|
| 498 |
+
[associative.reqmts.except]: #associative.reqmts.except
|
| 499 |
+
[associative.set.syn]: #associative.set.syn
|
| 500 |
+
[basic.string]: strings.md#basic.string
|
| 501 |
+
[class.copy.ctor]: class.md#class.copy.ctor
|
| 502 |
+
[class.default.ctor]: class.md#class.default.ctor
|
| 503 |
+
[class.dtor]: class.md#class.dtor
|
| 504 |
+
[container.adaptors]: #container.adaptors
|
| 505 |
+
[container.adaptors.general]: #container.adaptors.general
|
| 506 |
+
[container.alloc.req]: #container.alloc.req
|
| 507 |
+
[container.assoc.req]: #container.assoc.req
|
| 508 |
+
[container.hash.req]: #container.hash.req
|
| 509 |
+
[container.insert.return]: #container.insert.return
|
| 510 |
+
[container.node]: #container.node
|
| 511 |
+
[container.node.compat]: #container.node.compat
|
| 512 |
+
[container.node.cons]: #container.node.cons
|
| 513 |
+
[container.node.dtor]: #container.node.dtor
|
| 514 |
+
[container.node.modifiers]: #container.node.modifiers
|
| 515 |
+
[container.node.observers]: #container.node.observers
|
| 516 |
+
[container.node.overview]: #container.node.overview
|
| 517 |
+
[container.opt]: #container.opt
|
| 518 |
+
[container.req]: #container.req
|
| 519 |
+
[container.requirements]: #container.requirements
|
| 520 |
+
[container.requirements.dataraces]: #container.requirements.dataraces
|
| 521 |
+
[container.requirements.general]: #container.requirements.general
|
| 522 |
+
[container.rev.req]: #container.rev.req
|
| 523 |
+
[container.seq.opt]: #container.seq.opt
|
| 524 |
+
[container.seq.req]: #container.seq.req
|
| 525 |
+
[containers]: #containers
|
| 526 |
+
[containers.general]: #containers.general
|
| 527 |
+
[containers.summary]: #containers.summary
|
| 528 |
+
[dcl.init.aggr]: dcl.md#dcl.init.aggr
|
| 529 |
+
[deque]: #deque
|
| 530 |
+
[deque.capacity]: #deque.capacity
|
| 531 |
+
[deque.cons]: #deque.cons
|
| 532 |
+
[deque.erasure]: #deque.erasure
|
| 533 |
+
[deque.modifiers]: #deque.modifiers
|
| 534 |
+
[deque.overview]: #deque.overview
|
| 535 |
+
[deque.syn]: #deque.syn
|
| 536 |
+
[forward.list.erasure]: #forward.list.erasure
|
| 537 |
+
[forward.list.syn]: #forward.list.syn
|
| 538 |
+
[forwardlist]: #forwardlist
|
| 539 |
+
[forwardlist.access]: #forwardlist.access
|
| 540 |
+
[forwardlist.cons]: #forwardlist.cons
|
| 541 |
+
[forwardlist.iter]: #forwardlist.iter
|
| 542 |
+
[forwardlist.modifiers]: #forwardlist.modifiers
|
| 543 |
+
[forwardlist.ops]: #forwardlist.ops
|
| 544 |
+
[forwardlist.overview]: #forwardlist.overview
|
| 545 |
+
[hash.requirements]: library.md#hash.requirements
|
| 546 |
+
[iterator.concept.contiguous]: iterators.md#iterator.concept.contiguous
|
| 547 |
+
[iterator.requirements]: iterators.md#iterator.requirements
|
| 548 |
+
[iterator.requirements.general]: iterators.md#iterator.requirements.general
|
| 549 |
+
[list]: #list
|
| 550 |
+
[list.capacity]: #list.capacity
|
| 551 |
+
[list.cons]: #list.cons
|
| 552 |
+
[list.erasure]: #list.erasure
|
| 553 |
+
[list.modifiers]: #list.modifiers
|
| 554 |
+
[list.ops]: #list.ops
|
| 555 |
+
[list.overview]: #list.overview
|
| 556 |
+
[list.syn]: #list.syn
|
| 557 |
+
[map]: #map
|
| 558 |
+
[map.access]: #map.access
|
| 559 |
+
[map.cons]: #map.cons
|
| 560 |
+
[map.erasure]: #map.erasure
|
| 561 |
+
[map.modifiers]: #map.modifiers
|
| 562 |
+
[map.overview]: #map.overview
|
| 563 |
+
[multimap]: #multimap
|
| 564 |
+
[multimap.cons]: #multimap.cons
|
| 565 |
+
[multimap.erasure]: #multimap.erasure
|
| 566 |
+
[multimap.modifiers]: #multimap.modifiers
|
| 567 |
+
[multimap.overview]: #multimap.overview
|
| 568 |
+
[multiset]: #multiset
|
| 569 |
+
[multiset.cons]: #multiset.cons
|
| 570 |
+
[multiset.erasure]: #multiset.erasure
|
| 571 |
+
[multiset.overview]: #multiset.overview
|
| 572 |
+
[priority.queue]: #priority.queue
|
| 573 |
+
[priqueue.cons]: #priqueue.cons
|
| 574 |
+
[priqueue.cons.alloc]: #priqueue.cons.alloc
|
| 575 |
+
[priqueue.members]: #priqueue.members
|
| 576 |
+
[priqueue.overview]: #priqueue.overview
|
| 577 |
+
[priqueue.special]: #priqueue.special
|
| 578 |
+
[queue]: #queue
|
| 579 |
+
[queue.cons]: #queue.cons
|
| 580 |
+
[queue.cons.alloc]: #queue.cons.alloc
|
| 581 |
+
[queue.defn]: #queue.defn
|
| 582 |
+
[queue.ops]: #queue.ops
|
| 583 |
+
[queue.special]: #queue.special
|
| 584 |
+
[queue.syn]: #queue.syn
|
| 585 |
+
[random.access.iterators]: iterators.md#random.access.iterators
|
| 586 |
+
[res.on.data.races]: library.md#res.on.data.races
|
| 587 |
+
[sequence.reqmts]: #sequence.reqmts
|
| 588 |
+
[sequences]: #sequences
|
| 589 |
+
[sequences.general]: #sequences.general
|
| 590 |
+
[set]: #set
|
| 591 |
+
[set.cons]: #set.cons
|
| 592 |
+
[set.erasure]: #set.erasure
|
| 593 |
+
[set.overview]: #set.overview
|
| 594 |
+
[span.cons]: #span.cons
|
| 595 |
+
[span.deduct]: #span.deduct
|
| 596 |
+
[span.elem]: #span.elem
|
| 597 |
+
[span.iterators]: #span.iterators
|
| 598 |
+
[span.objectrep]: #span.objectrep
|
| 599 |
+
[span.obs]: #span.obs
|
| 600 |
+
[span.overview]: #span.overview
|
| 601 |
+
[span.sub]: #span.sub
|
| 602 |
+
[span.syn]: #span.syn
|
| 603 |
+
[stack]: #stack
|
| 604 |
+
[stack.cons]: #stack.cons
|
| 605 |
+
[stack.cons.alloc]: #stack.cons.alloc
|
| 606 |
+
[stack.defn]: #stack.defn
|
| 607 |
+
[stack.ops]: #stack.ops
|
| 608 |
+
[stack.special]: #stack.special
|
| 609 |
+
[stack.syn]: #stack.syn
|
| 610 |
+
[strings]: strings.md#strings
|
| 611 |
+
[swappable.requirements]: library.md#swappable.requirements
|
| 612 |
+
[tab:container.opt]: #tab:container.opt
|
| 613 |
+
[tab:container.req]: #tab:container.req
|
| 614 |
+
[tab:container.rev.req]: #tab:container.rev.req
|
| 615 |
+
[tab:container.seq.opt]: #tab:container.seq.opt
|
| 616 |
+
[tab:container.seq.req]: #tab:container.seq.req
|
| 617 |
+
[temp.deduct]: temp.md#temp.deduct
|
| 618 |
+
[temp.param]: temp.md#temp.param
|
| 619 |
+
[temp.type]: temp.md#temp.type
|
| 620 |
+
[unord]: #unord
|
| 621 |
+
[unord.general]: #unord.general
|
| 622 |
+
[unord.hash]: utilities.md#unord.hash
|
| 623 |
+
[unord.map]: #unord.map
|
| 624 |
+
[unord.map.cnstr]: #unord.map.cnstr
|
| 625 |
+
[unord.map.elem]: #unord.map.elem
|
| 626 |
+
[unord.map.erasure]: #unord.map.erasure
|
| 627 |
+
[unord.map.modifiers]: #unord.map.modifiers
|
| 628 |
+
[unord.map.overview]: #unord.map.overview
|
| 629 |
+
[unord.map.syn]: #unord.map.syn
|
| 630 |
+
[unord.multimap]: #unord.multimap
|
| 631 |
+
[unord.multimap.cnstr]: #unord.multimap.cnstr
|
| 632 |
+
[unord.multimap.erasure]: #unord.multimap.erasure
|
| 633 |
+
[unord.multimap.modifiers]: #unord.multimap.modifiers
|
| 634 |
+
[unord.multimap.overview]: #unord.multimap.overview
|
| 635 |
+
[unord.multiset]: #unord.multiset
|
| 636 |
+
[unord.multiset.cnstr]: #unord.multiset.cnstr
|
| 637 |
+
[unord.multiset.erasure]: #unord.multiset.erasure
|
| 638 |
+
[unord.multiset.overview]: #unord.multiset.overview
|
| 639 |
+
[unord.req]: #unord.req
|
| 640 |
+
[unord.req.except]: #unord.req.except
|
| 641 |
+
[unord.set]: #unord.set
|
| 642 |
+
[unord.set.cnstr]: #unord.set.cnstr
|
| 643 |
+
[unord.set.erasure]: #unord.set.erasure
|
| 644 |
+
[unord.set.overview]: #unord.set.overview
|
| 645 |
+
[unord.set.syn]: #unord.set.syn
|
| 646 |
+
[vector]: #vector
|
| 647 |
+
[vector.bool]: #vector.bool
|
| 648 |
+
[vector.capacity]: #vector.capacity
|
| 649 |
+
[vector.cons]: #vector.cons
|
| 650 |
+
[vector.data]: #vector.data
|
| 651 |
+
[vector.erasure]: #vector.erasure
|
| 652 |
+
[vector.modifiers]: #vector.modifiers
|
| 653 |
+
[vector.overview]: #vector.overview
|
| 654 |
+
[vector.syn]: #vector.syn
|
| 655 |
+
[views]: #views
|
| 656 |
+
[views.general]: #views.general
|
| 657 |
+
[views.span]: #views.span
|
| 658 |
+
|
| 659 |
+
[^1]: Equality comparison is a refinement of partitioning if no two
|
| 660 |
+
objects that compare equal fall into different partitions.
|
| 661 |
+
|
| 662 |
+
[^2]: These member functions are only provided by containers whose
|
| 663 |
+
iterators are random access iterators.
|
| 664 |
+
|
| 665 |
+
[^3]: As specified in [[allocator.requirements]], the requirements in
|
| 666 |
+
this Clause apply only to lists whose allocators compare equal.
|
| 667 |
+
|
| 668 |
+
[^4]: `reserve()` uses `Allocator::allocate()` which may throw an
|
| 669 |
+
appropriate exception.
|