1// -*- C++ -*- 2//===------------------------------ span ---------------------------------===// 3// 4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5// See https://llvm.org/LICENSE.txt for license information. 6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7// 8//===---------------------------------------------------------------------===// 9 10#ifndef _LIBCPP_SPAN 11#define _LIBCPP_SPAN 12 13/* 14 span synopsis 15 16namespace std { 17 18// constants 19inline constexpr size_t dynamic_extent = numeric_limits<size_t>::max(); 20 21// [views.span], class template span 22template <class ElementType, size_t Extent = dynamic_extent> 23 class span; 24 25// [span.objectrep], views of object representation 26template <class ElementType, size_t Extent> 27 span<const byte, ((Extent == dynamic_extent) ? dynamic_extent : 28 (sizeof(ElementType) * Extent))> as_bytes(span<ElementType, Extent> s) noexcept; 29 30template <class ElementType, size_t Extent> 31 span< byte, ((Extent == dynamic_extent) ? dynamic_extent : 32 (sizeof(ElementType) * Extent))> as_writable_bytes(span<ElementType, Extent> s) noexcept; 33 34 35namespace std { 36template <class ElementType, size_t Extent = dynamic_extent> 37class span { 38public: 39 // constants and types 40 using element_type = ElementType; 41 using value_type = remove_cv_t<ElementType>; 42 using size_type = size_t; 43 using difference_type = ptrdiff_t; 44 using pointer = element_type*; 45 using const_pointer = const element_type*; 46 using reference = element_type&; 47 using const_reference = const element_type&; 48 using iterator = implementation-defined; 49 using reverse_iterator = std::reverse_iterator<iterator>; 50 static constexpr size_type extent = Extent; 51 52 // [span.cons], span constructors, copy, assignment, and destructor 53 constexpr span() noexcept; 54 constexpr explicit(Extent != dynamic_extent) span(pointer ptr, size_type count); 55 constexpr explicit(Extent != dynamic_extent) span(pointer firstElem, pointer lastElem); 56 template <size_t N> 57 constexpr span(element_type (&arr)[N]) noexcept; 58 template <size_t N> 59 constexpr span(array<value_type, N>& arr) noexcept; 60 template <size_t N> 61 constexpr span(const array<value_type, N>& arr) noexcept; 62 template <class Container> 63 constexpr explicit(Extent != dynamic_extent) span(Container& cont); 64 template <class Container> 65 constexpr explicit(Extent != dynamic_extent) span(const Container& cont); 66 constexpr span(const span& other) noexcept = default; 67 template <class OtherElementType, size_t OtherExtent> 68 constexpr explicit(Extent != dynamic_extent) span(const span<OtherElementType, OtherExtent>& s) noexcept; 69 ~span() noexcept = default; 70 constexpr span& operator=(const span& other) noexcept = default; 71 72 // [span.sub], span subviews 73 template <size_t Count> 74 constexpr span<element_type, Count> first() const; 75 template <size_t Count> 76 constexpr span<element_type, Count> last() const; 77 template <size_t Offset, size_t Count = dynamic_extent> 78 constexpr span<element_type, see below> subspan() const; 79 80 constexpr span<element_type, dynamic_extent> first(size_type count) const; 81 constexpr span<element_type, dynamic_extent> last(size_type count) const; 82 constexpr span<element_type, dynamic_extent> subspan(size_type offset, size_type count = dynamic_extent) const; 83 84 // [span.obs], span observers 85 constexpr size_type size() const noexcept; 86 constexpr size_type size_bytes() const noexcept; 87 constexpr bool empty() const noexcept; 88 89 // [span.elem], span element access 90 constexpr reference operator[](size_type idx) const; 91 constexpr reference front() const; 92 constexpr reference back() const; 93 constexpr pointer data() const noexcept; 94 95 // [span.iterators], span iterator support 96 constexpr iterator begin() const noexcept; 97 constexpr iterator end() const noexcept; 98 constexpr reverse_iterator rbegin() const noexcept; 99 constexpr reverse_iterator rend() const noexcept; 100 101private: 102 pointer data_; // exposition only 103 size_type size_; // exposition only 104}; 105 106template<class T, size_t N> 107 span(T (&)[N]) -> span<T, N>; 108 109template<class T, size_t N> 110 span(array<T, N>&) -> span<T, N>; 111 112template<class T, size_t N> 113 span(const array<T, N>&) -> span<const T, N>; 114 115template<class Container> 116 span(Container&) -> span<typename Container::value_type>; 117 118template<class Container> 119 span(const Container&) -> span<const typename Container::value_type>; 120 121} // namespace std 122 123*/ 124 125#include <__config> 126#include <array> // for array 127#include <cstddef> // for byte 128#include <iterator> // for iterators 129#include <type_traits> // for remove_cv, etc 130 131#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 132#pragma GCC system_header 133#endif 134 135_LIBCPP_BEGIN_NAMESPACE_STD 136 137#if _LIBCPP_STD_VER > 17 138 139inline constexpr size_t dynamic_extent = (numeric_limits<size_t>::max)(); 140template <typename _Tp, size_t _Extent = dynamic_extent> class span; 141 142 143template <class _Tp> 144struct __is_span_impl : public false_type {}; 145 146template <class _Tp, size_t _Extent> 147struct __is_span_impl<span<_Tp, _Extent>> : public true_type {}; 148 149template <class _Tp> 150struct __is_span : public __is_span_impl<remove_cv_t<_Tp>> {}; 151 152template <class _Tp> 153struct __is_std_array_impl : public false_type {}; 154 155template <class _Tp, size_t _Sz> 156struct __is_std_array_impl<array<_Tp, _Sz>> : public true_type {}; 157 158template <class _Tp> 159struct __is_std_array : public __is_std_array_impl<remove_cv_t<_Tp>> {}; 160 161template <class _Tp, class _ElementType, class = void> 162struct __is_span_compatible_container : public false_type {}; 163 164template <class _Tp, class _ElementType> 165struct __is_span_compatible_container<_Tp, _ElementType, 166 void_t< 167 // is not a specialization of span 168 typename enable_if<!__is_span<_Tp>::value, nullptr_t>::type, 169 // is not a specialization of array 170 typename enable_if<!__is_std_array<_Tp>::value, nullptr_t>::type, 171 // is_array_v<Container> is false, 172 typename enable_if<!is_array_v<_Tp>, nullptr_t>::type, 173 // data(cont) and size(cont) are well formed 174 decltype(data(declval<_Tp>())), 175 decltype(size(declval<_Tp>())), 176 // remove_pointer_t<decltype(data(cont))>(*)[] is convertible to ElementType(*)[] 177 typename enable_if< 178 is_convertible_v<remove_pointer_t<decltype(data(declval<_Tp &>()))>(*)[], 179 _ElementType(*)[]>, 180 nullptr_t>::type 181 >> 182 : public true_type {}; 183 184 185template <typename _Tp, size_t _Extent> 186class _LIBCPP_TEMPLATE_VIS span { 187public: 188// constants and types 189 using element_type = _Tp; 190 using value_type = remove_cv_t<_Tp>; 191 using size_type = size_t; 192 using difference_type = ptrdiff_t; 193 using pointer = _Tp *; 194 using const_pointer = const _Tp *; 195 using reference = _Tp &; 196 using const_reference = const _Tp &; 197 using iterator = __wrap_iter<pointer>; 198 using reverse_iterator = _VSTD::reverse_iterator<iterator>; 199 200 static constexpr size_type extent = _Extent; 201 202// [span.cons], span constructors, copy, assignment, and destructor 203 template <size_t _Sz = _Extent, enable_if_t<_Sz == 0, nullptr_t> = nullptr> 204 _LIBCPP_INLINE_VISIBILITY constexpr span() noexcept : __data{nullptr} {} 205 206 constexpr span (const span&) noexcept = default; 207 constexpr span& operator=(const span&) noexcept = default; 208 209 _LIBCPP_INLINE_VISIBILITY constexpr explicit span(pointer __ptr, size_type __count) : __data{__ptr} 210 { (void)__count; _LIBCPP_ASSERT(_Extent == __count, "size mismatch in span's constructor (ptr, len)"); } 211 _LIBCPP_INLINE_VISIBILITY constexpr explicit span(pointer __f, pointer __l) : __data{__f} 212 { (void)__l; _LIBCPP_ASSERT(_Extent == distance(__f, __l), "size mismatch in span's constructor (ptr, ptr)"); } 213 214 _LIBCPP_INLINE_VISIBILITY constexpr span(element_type (&__arr)[_Extent]) noexcept : __data{__arr} {} 215 216 template <class _OtherElementType, 217 enable_if_t<is_convertible_v<_OtherElementType(*)[], element_type (*)[]>, nullptr_t> = nullptr> 218 _LIBCPP_INLINE_VISIBILITY 219 constexpr span(array<_OtherElementType, _Extent>& __arr) noexcept : __data{__arr.data()} {} 220 221 template <class _OtherElementType, 222 enable_if_t<is_convertible_v<const _OtherElementType(*)[], element_type (*)[]>, nullptr_t> = nullptr> 223 _LIBCPP_INLINE_VISIBILITY 224 constexpr span(const array<_OtherElementType, _Extent>& __arr) noexcept : __data{__arr.data()} {} 225 226 template <class _Container> 227 _LIBCPP_INLINE_VISIBILITY 228 constexpr explicit span( _Container& __c, 229 enable_if_t<__is_span_compatible_container<_Container, _Tp>::value, nullptr_t> = nullptr) 230 : __data{_VSTD::data(__c)} { 231 _LIBCPP_ASSERT(_Extent == _VSTD::size(__c), "size mismatch in span's constructor (range)"); 232 } 233 234 template <class _Container> 235 _LIBCPP_INLINE_VISIBILITY 236 constexpr explicit span(const _Container& __c, 237 enable_if_t<__is_span_compatible_container<const _Container, _Tp>::value, nullptr_t> = nullptr) 238 : __data{_VSTD::data(__c)} { 239 _LIBCPP_ASSERT(_Extent == _VSTD::size(__c), "size mismatch in span's constructor (range)"); 240 } 241 242 template <class _OtherElementType> 243 _LIBCPP_INLINE_VISIBILITY 244 constexpr span(const span<_OtherElementType, _Extent>& __other, 245 enable_if_t< 246 is_convertible_v<_OtherElementType(*)[], element_type (*)[]>, 247 nullptr_t> = nullptr) 248 : __data{__other.data()} {} 249 250 template <class _OtherElementType> 251 _LIBCPP_INLINE_VISIBILITY 252 constexpr explicit span(const span<_OtherElementType, dynamic_extent>& __other, 253 enable_if_t< 254 is_convertible_v<_OtherElementType(*)[], element_type (*)[]>, 255 nullptr_t> = nullptr) noexcept 256 : __data{__other.data()} { _LIBCPP_ASSERT(_Extent == __other.size(), "size mismatch in span's constructor (other span)"); } 257 258 259// ~span() noexcept = default; 260 261 template <size_t _Count> 262 _LIBCPP_INLINE_VISIBILITY 263 constexpr span<element_type, _Count> first() const noexcept 264 { 265 static_assert(_Count <= _Extent, "Count out of range in span::first()"); 266 return span<element_type, _Count>{data(), _Count}; 267 } 268 269 template <size_t _Count> 270 _LIBCPP_INLINE_VISIBILITY 271 constexpr span<element_type, _Count> last() const noexcept 272 { 273 static_assert(_Count <= _Extent, "Count out of range in span::last()"); 274 return span<element_type, _Count>{data() + size() - _Count, _Count}; 275 } 276 277 _LIBCPP_INLINE_VISIBILITY 278 constexpr span<element_type, dynamic_extent> first(size_type __count) const noexcept 279 { 280 _LIBCPP_ASSERT(__count <= size(), "Count out of range in span::first(count)"); 281 return {data(), __count}; 282 } 283 284 _LIBCPP_INLINE_VISIBILITY 285 constexpr span<element_type, dynamic_extent> last(size_type __count) const noexcept 286 { 287 _LIBCPP_ASSERT(__count <= size(), "Count out of range in span::last(count)"); 288 return {data() + size() - __count, __count}; 289 } 290 291 template <size_t _Offset, size_t _Count = dynamic_extent> 292 _LIBCPP_INLINE_VISIBILITY 293 constexpr auto subspan() const noexcept 294 -> span<element_type, _Count != dynamic_extent ? _Count : _Extent - _Offset> 295 { 296 static_assert(_Offset <= _Extent, "Offset out of range in span::subspan()"); 297 static_assert(_Count == dynamic_extent || _Count <= _Extent - _Offset, "Offset + count out of range in span::subspan()"); 298 299 using _ReturnType = span<element_type, _Count != dynamic_extent ? _Count : _Extent - _Offset>; 300 return _ReturnType{data() + _Offset, _Count == dynamic_extent ? size() - _Offset : _Count}; 301 } 302 303 304 _LIBCPP_INLINE_VISIBILITY 305 constexpr span<element_type, dynamic_extent> 306 subspan(size_type __offset, size_type __count = dynamic_extent) const noexcept 307 { 308 _LIBCPP_ASSERT(__offset <= size(), "Offset out of range in span::subspan(offset, count)"); 309 _LIBCPP_ASSERT(__count <= size() || __count == dynamic_extent, "Count out of range in span::subspan(offset, count)"); 310 if (__count == dynamic_extent) 311 return {data() + __offset, size() - __offset}; 312 _LIBCPP_ASSERT(__count <= size() - __offset, "Offset + count out of range in span::subspan(offset, count)"); 313 return {data() + __offset, __count}; 314 } 315 316 _LIBCPP_INLINE_VISIBILITY constexpr size_type size() const noexcept { return _Extent; } 317 _LIBCPP_INLINE_VISIBILITY constexpr size_type size_bytes() const noexcept { return _Extent * sizeof(element_type); } 318 _LIBCPP_INLINE_VISIBILITY constexpr bool empty() const noexcept { return _Extent == 0; } 319 320 _LIBCPP_INLINE_VISIBILITY constexpr reference operator[](size_type __idx) const noexcept 321 { 322 _LIBCPP_ASSERT(__idx < size(), "span<T,N>[] index out of bounds"); 323 return __data[__idx]; 324 } 325 326 _LIBCPP_INLINE_VISIBILITY constexpr reference front() const noexcept 327 { 328 _LIBCPP_ASSERT(!empty(), "span<T, N>::front() on empty span"); 329 return __data[0]; 330 } 331 332 _LIBCPP_INLINE_VISIBILITY constexpr reference back() const noexcept 333 { 334 _LIBCPP_ASSERT(!empty(), "span<T, N>::back() on empty span"); 335 return __data[size()-1]; 336 } 337 338 _LIBCPP_INLINE_VISIBILITY constexpr pointer data() const noexcept { return __data; } 339 340// [span.iter], span iterator support 341 _LIBCPP_INLINE_VISIBILITY constexpr iterator begin() const noexcept { return iterator(data()); } 342 _LIBCPP_INLINE_VISIBILITY constexpr iterator end() const noexcept { return iterator(data() + size()); } 343 _LIBCPP_INLINE_VISIBILITY constexpr reverse_iterator rbegin() const noexcept { return reverse_iterator(end()); } 344 _LIBCPP_INLINE_VISIBILITY constexpr reverse_iterator rend() const noexcept { return reverse_iterator(begin()); } 345 346 _LIBCPP_INLINE_VISIBILITY constexpr void swap(span &__other) noexcept 347 { 348 pointer __p = __data; 349 __data = __other.__data; 350 __other.__data = __p; 351 } 352 353 _LIBCPP_INLINE_VISIBILITY span<const byte, _Extent * sizeof(element_type)> __as_bytes() const noexcept 354 { return span<const byte, _Extent * sizeof(element_type)>{reinterpret_cast<const byte *>(data()), size_bytes()}; } 355 356 _LIBCPP_INLINE_VISIBILITY span<byte, _Extent * sizeof(element_type)> __as_writable_bytes() const noexcept 357 { return span<byte, _Extent * sizeof(element_type)>{reinterpret_cast<byte *>(data()), size_bytes()}; } 358 359private: 360 pointer __data; 361 362}; 363 364 365template <typename _Tp> 366class _LIBCPP_TEMPLATE_VIS span<_Tp, dynamic_extent> { 367private: 368 369public: 370// constants and types 371 using element_type = _Tp; 372 using value_type = remove_cv_t<_Tp>; 373 using size_type = size_t; 374 using difference_type = ptrdiff_t; 375 using pointer = _Tp *; 376 using const_pointer = const _Tp *; 377 using reference = _Tp &; 378 using const_reference = const _Tp &; 379 using iterator = __wrap_iter<pointer>; 380 using reverse_iterator = _VSTD::reverse_iterator<iterator>; 381 382 static constexpr size_type extent = dynamic_extent; 383 384// [span.cons], span constructors, copy, assignment, and destructor 385 _LIBCPP_INLINE_VISIBILITY constexpr span() noexcept : __data{nullptr}, __size{0} {} 386 387 constexpr span (const span&) noexcept = default; 388 constexpr span& operator=(const span&) noexcept = default; 389 390 _LIBCPP_INLINE_VISIBILITY constexpr span(pointer __ptr, size_type __count) : __data{__ptr}, __size{__count} {} 391 _LIBCPP_INLINE_VISIBILITY constexpr span(pointer __f, pointer __l) : __data{__f}, __size{static_cast<size_t>(distance(__f, __l))} {} 392 393 template <size_t _Sz> 394 _LIBCPP_INLINE_VISIBILITY 395 constexpr span(element_type (&__arr)[_Sz]) noexcept : __data{__arr}, __size{_Sz} {} 396 397 template <class _OtherElementType, size_t _Sz, 398 enable_if_t<is_convertible_v<_OtherElementType(*)[], element_type (*)[]>, nullptr_t> = nullptr> 399 _LIBCPP_INLINE_VISIBILITY 400 constexpr span(array<_OtherElementType, _Sz>& __arr) noexcept : __data{__arr.data()}, __size{_Sz} {} 401 402 template <class _OtherElementType, size_t _Sz, 403 enable_if_t<is_convertible_v<const _OtherElementType(*)[], element_type (*)[]>, nullptr_t> = nullptr> 404 _LIBCPP_INLINE_VISIBILITY 405 constexpr span(const array<_OtherElementType, _Sz>& __arr) noexcept : __data{__arr.data()}, __size{_Sz} {} 406 407 template <class _Container> 408 _LIBCPP_INLINE_VISIBILITY 409 constexpr span( _Container& __c, 410 enable_if_t<__is_span_compatible_container<_Container, _Tp>::value, nullptr_t> = nullptr) 411 : __data{_VSTD::data(__c)}, __size{(size_type) _VSTD::size(__c)} {} 412 413 template <class _Container> 414 _LIBCPP_INLINE_VISIBILITY 415 constexpr span(const _Container& __c, 416 enable_if_t<__is_span_compatible_container<const _Container, _Tp>::value, nullptr_t> = nullptr) 417 : __data{_VSTD::data(__c)}, __size{(size_type) _VSTD::size(__c)} {} 418 419 420 template <class _OtherElementType, size_t _OtherExtent> 421 _LIBCPP_INLINE_VISIBILITY 422 constexpr span(const span<_OtherElementType, _OtherExtent>& __other, 423 enable_if_t< 424 is_convertible_v<_OtherElementType(*)[], element_type (*)[]>, 425 nullptr_t> = nullptr) noexcept 426 : __data{__other.data()}, __size{__other.size()} {} 427 428// ~span() noexcept = default; 429 430 template <size_t _Count> 431 _LIBCPP_INLINE_VISIBILITY 432 constexpr span<element_type, _Count> first() const noexcept 433 { 434 _LIBCPP_ASSERT(_Count <= size(), "Count out of range in span::first()"); 435 return span<element_type, _Count>{data(), _Count}; 436 } 437 438 template <size_t _Count> 439 _LIBCPP_INLINE_VISIBILITY 440 constexpr span<element_type, _Count> last() const noexcept 441 { 442 _LIBCPP_ASSERT(_Count <= size(), "Count out of range in span::last()"); 443 return span<element_type, _Count>{data() + size() - _Count, _Count}; 444 } 445 446 _LIBCPP_INLINE_VISIBILITY 447 constexpr span<element_type, dynamic_extent> first(size_type __count) const noexcept 448 { 449 _LIBCPP_ASSERT(__count <= size(), "Count out of range in span::first(count)"); 450 return {data(), __count}; 451 } 452 453 _LIBCPP_INLINE_VISIBILITY 454 constexpr span<element_type, dynamic_extent> last (size_type __count) const noexcept 455 { 456 _LIBCPP_ASSERT(__count <= size(), "Count out of range in span::last(count)"); 457 return {data() + size() - __count, __count}; 458 } 459 460 template <size_t _Offset, size_t _Count = dynamic_extent> 461 _LIBCPP_INLINE_VISIBILITY 462 constexpr span<element_type, _Count> subspan() const noexcept 463 { 464 _LIBCPP_ASSERT(_Offset <= size(), "Offset out of range in span::subspan()"); 465 _LIBCPP_ASSERT(_Count == dynamic_extent || _Count <= size() - _Offset, "Offset + count out of range in span::subspan()"); 466 return span<element_type, _Count>{data() + _Offset, _Count == dynamic_extent ? size() - _Offset : _Count}; 467 } 468 469 constexpr span<element_type, dynamic_extent> 470 _LIBCPP_INLINE_VISIBILITY 471 subspan(size_type __offset, size_type __count = dynamic_extent) const noexcept 472 { 473 _LIBCPP_ASSERT(__offset <= size(), "Offset out of range in span::subspan(offset, count)"); 474 _LIBCPP_ASSERT(__count <= size() || __count == dynamic_extent, "count out of range in span::subspan(offset, count)"); 475 if (__count == dynamic_extent) 476 return {data() + __offset, size() - __offset}; 477 _LIBCPP_ASSERT(__count <= size() - __offset, "Offset + count out of range in span::subspan(offset, count)"); 478 return {data() + __offset, __count}; 479 } 480 481 _LIBCPP_INLINE_VISIBILITY constexpr size_type size() const noexcept { return __size; } 482 _LIBCPP_INLINE_VISIBILITY constexpr size_type size_bytes() const noexcept { return __size * sizeof(element_type); } 483 _LIBCPP_INLINE_VISIBILITY constexpr bool empty() const noexcept { return __size == 0; } 484 485 _LIBCPP_INLINE_VISIBILITY constexpr reference operator[](size_type __idx) const noexcept 486 { 487 _LIBCPP_ASSERT(__idx < size(), "span<T>[] index out of bounds"); 488 return __data[__idx]; 489 } 490 491 _LIBCPP_INLINE_VISIBILITY constexpr reference front() const noexcept 492 { 493 _LIBCPP_ASSERT(!empty(), "span<T>[].front() on empty span"); 494 return __data[0]; 495 } 496 497 _LIBCPP_INLINE_VISIBILITY constexpr reference back() const noexcept 498 { 499 _LIBCPP_ASSERT(!empty(), "span<T>[].back() on empty span"); 500 return __data[size()-1]; 501 } 502 503 504 _LIBCPP_INLINE_VISIBILITY constexpr pointer data() const noexcept { return __data; } 505 506// [span.iter], span iterator support 507 _LIBCPP_INLINE_VISIBILITY constexpr iterator begin() const noexcept { return iterator(data()); } 508 _LIBCPP_INLINE_VISIBILITY constexpr iterator end() const noexcept { return iterator(data() + size()); } 509 _LIBCPP_INLINE_VISIBILITY constexpr reverse_iterator rbegin() const noexcept { return reverse_iterator(end()); } 510 _LIBCPP_INLINE_VISIBILITY constexpr reverse_iterator rend() const noexcept { return reverse_iterator(begin()); } 511 512 _LIBCPP_INLINE_VISIBILITY constexpr void swap(span &__other) noexcept 513 { 514 pointer __p = __data; 515 __data = __other.__data; 516 __other.__data = __p; 517 518 size_type __sz = __size; 519 __size = __other.__size; 520 __other.__size = __sz; 521 } 522 523 _LIBCPP_INLINE_VISIBILITY span<const byte, dynamic_extent> __as_bytes() const noexcept 524 { return {reinterpret_cast<const byte *>(data()), size_bytes()}; } 525 526 _LIBCPP_INLINE_VISIBILITY span<byte, dynamic_extent> __as_writable_bytes() const noexcept 527 { return {reinterpret_cast<byte *>(data()), size_bytes()}; } 528 529private: 530 pointer __data; 531 size_type __size; 532}; 533 534// as_bytes & as_writable_bytes 535template <class _Tp, size_t _Extent> 536_LIBCPP_INLINE_VISIBILITY 537auto as_bytes(span<_Tp, _Extent> __s) noexcept 538-> decltype(__s.__as_bytes()) 539{ return __s.__as_bytes(); } 540 541template <class _Tp, size_t _Extent> 542_LIBCPP_INLINE_VISIBILITY 543auto as_writable_bytes(span<_Tp, _Extent> __s) noexcept 544-> enable_if_t<!is_const_v<_Tp>, decltype(__s.__as_writable_bytes())> 545{ return __s.__as_writable_bytes(); } 546 547template <class _Tp, size_t _Extent> 548_LIBCPP_INLINE_VISIBILITY 549constexpr void swap(span<_Tp, _Extent> &__lhs, span<_Tp, _Extent> &__rhs) noexcept 550{ __lhs.swap(__rhs); } 551 552 553// Deduction guides 554template<class _Tp, size_t _Sz> 555 span(_Tp (&)[_Sz]) -> span<_Tp, _Sz>; 556 557template<class _Tp, size_t _Sz> 558 span(array<_Tp, _Sz>&) -> span<_Tp, _Sz>; 559 560template<class _Tp, size_t _Sz> 561 span(const array<_Tp, _Sz>&) -> span<const _Tp, _Sz>; 562 563template<class _Container> 564 span(_Container&) -> span<typename _Container::value_type>; 565 566template<class _Container> 567 span(const _Container&) -> span<const typename _Container::value_type>; 568 569#endif // _LIBCPP_STD_VER > 17 570 571_LIBCPP_END_NAMESPACE_STD 572 573#endif // _LIBCPP_SPAN 574