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_PUSH_MACROS 136#include <__undef_macros> 137 138_LIBCPP_BEGIN_NAMESPACE_STD 139 140#if _LIBCPP_STD_VER > 17 141 142inline constexpr size_t dynamic_extent = numeric_limits<size_t>::max(); 143template <typename _Tp, size_t _Extent = dynamic_extent> class span; 144 145 146template <class _Tp> 147struct __is_span_impl : public false_type {}; 148 149template <class _Tp, size_t _Extent> 150struct __is_span_impl<span<_Tp, _Extent>> : public true_type {}; 151 152template <class _Tp> 153struct __is_span : public __is_span_impl<remove_cv_t<_Tp>> {}; 154 155template <class _Tp> 156struct __is_std_array_impl : public false_type {}; 157 158template <class _Tp, size_t _Sz> 159struct __is_std_array_impl<array<_Tp, _Sz>> : public true_type {}; 160 161template <class _Tp> 162struct __is_std_array : public __is_std_array_impl<remove_cv_t<_Tp>> {}; 163 164template <class _Tp, class _ElementType, class = void> 165struct __is_span_compatible_container : public false_type {}; 166 167template <class _Tp, class _ElementType> 168struct __is_span_compatible_container<_Tp, _ElementType, 169 void_t< 170 // is not a specialization of span 171 typename enable_if<!__is_span<_Tp>::value, nullptr_t>::type, 172 // is not a specialization of array 173 typename enable_if<!__is_std_array<_Tp>::value, nullptr_t>::type, 174 // is_array_v<Container> is false, 175 typename enable_if<!is_array_v<_Tp>, nullptr_t>::type, 176 // data(cont) and size(cont) are well formed 177 decltype(data(declval<_Tp>())), 178 decltype(size(declval<_Tp>())), 179 // remove_pointer_t<decltype(data(cont))>(*)[] is convertible to ElementType(*)[] 180 typename enable_if< 181 is_convertible_v<remove_pointer_t<decltype(data(declval<_Tp &>()))>(*)[], 182 _ElementType(*)[]>, 183 nullptr_t>::type 184 >> 185 : public true_type {}; 186 187 188template <typename _Tp, size_t _Extent> 189class _LIBCPP_TEMPLATE_VIS span { 190public: 191// constants and types 192 using element_type = _Tp; 193 using value_type = remove_cv_t<_Tp>; 194 using size_type = size_t; 195 using difference_type = ptrdiff_t; 196 using pointer = _Tp *; 197 using const_pointer = const _Tp *; 198 using reference = _Tp &; 199 using const_reference = const _Tp &; 200 using iterator = __wrap_iter<pointer>; 201 using reverse_iterator = _VSTD::reverse_iterator<iterator>; 202 203 static constexpr size_type extent = _Extent; 204 205// [span.cons], span constructors, copy, assignment, and destructor 206 template <size_t _Sz = _Extent, enable_if_t<_Sz == 0, nullptr_t> = nullptr> 207 _LIBCPP_INLINE_VISIBILITY constexpr span() noexcept : __data{nullptr} {} 208 209 constexpr span (const span&) noexcept = default; 210 constexpr span& operator=(const span&) noexcept = default; 211 212 _LIBCPP_INLINE_VISIBILITY constexpr explicit span(pointer __ptr, size_type __count) : __data{__ptr} 213 { (void)__count; _LIBCPP_ASSERT(_Extent == __count, "size mismatch in span's constructor (ptr, len)"); } 214 _LIBCPP_INLINE_VISIBILITY constexpr explicit span(pointer __f, pointer __l) : __data{__f} 215 { (void)__l; _LIBCPP_ASSERT(_Extent == distance(__f, __l), "size mismatch in span's constructor (ptr, ptr)"); } 216 217 _LIBCPP_INLINE_VISIBILITY constexpr span(element_type (&__arr)[_Extent]) noexcept : __data{__arr} {} 218 219 template <class _OtherElementType, 220 enable_if_t<is_convertible_v<_OtherElementType(*)[], element_type (*)[]>, nullptr_t> = nullptr> 221 _LIBCPP_INLINE_VISIBILITY 222 constexpr span(array<_OtherElementType, _Extent>& __arr) noexcept : __data{__arr.data()} {} 223 224 template <class _OtherElementType, 225 enable_if_t<is_convertible_v<const _OtherElementType(*)[], element_type (*)[]>, nullptr_t> = nullptr> 226 _LIBCPP_INLINE_VISIBILITY 227 constexpr span(const array<_OtherElementType, _Extent>& __arr) noexcept : __data{__arr.data()} {} 228 229 template <class _Container> 230 _LIBCPP_INLINE_VISIBILITY 231 constexpr explicit span( _Container& __c, 232 enable_if_t<__is_span_compatible_container<_Container, _Tp>::value, nullptr_t> = nullptr) 233 : __data{_VSTD::data(__c)} { 234 _LIBCPP_ASSERT(_Extent == _VSTD::size(__c), "size mismatch in span's constructor (range)"); 235 } 236 237 template <class _Container> 238 _LIBCPP_INLINE_VISIBILITY 239 constexpr explicit span(const _Container& __c, 240 enable_if_t<__is_span_compatible_container<const _Container, _Tp>::value, nullptr_t> = nullptr) 241 : __data{_VSTD::data(__c)} { 242 _LIBCPP_ASSERT(_Extent == _VSTD::size(__c), "size mismatch in span's constructor (range)"); 243 } 244 245 template <class _OtherElementType> 246 _LIBCPP_INLINE_VISIBILITY 247 constexpr span(const span<_OtherElementType, _Extent>& __other, 248 enable_if_t< 249 is_convertible_v<_OtherElementType(*)[], element_type (*)[]>, 250 nullptr_t> = nullptr) 251 : __data{__other.data()} {} 252 253 template <class _OtherElementType> 254 _LIBCPP_INLINE_VISIBILITY 255 constexpr explicit span(const span<_OtherElementType, dynamic_extent>& __other, 256 enable_if_t< 257 is_convertible_v<_OtherElementType(*)[], element_type (*)[]>, 258 nullptr_t> = nullptr) noexcept 259 : __data{__other.data()} { _LIBCPP_ASSERT(_Extent == __other.size(), "size mismatch in span's constructor (other span)"); } 260 261 262// ~span() noexcept = default; 263 264 template <size_t _Count> 265 _LIBCPP_INLINE_VISIBILITY 266 constexpr span<element_type, _Count> first() const noexcept 267 { 268 static_assert(_Count <= _Extent, "Count out of range in span::first()"); 269 return span<element_type, _Count>{data(), _Count}; 270 } 271 272 template <size_t _Count> 273 _LIBCPP_INLINE_VISIBILITY 274 constexpr span<element_type, _Count> last() const noexcept 275 { 276 static_assert(_Count <= _Extent, "Count out of range in span::last()"); 277 return span<element_type, _Count>{data() + size() - _Count, _Count}; 278 } 279 280 _LIBCPP_INLINE_VISIBILITY 281 constexpr span<element_type, dynamic_extent> first(size_type __count) const noexcept 282 { 283 _LIBCPP_ASSERT(__count <= size(), "Count out of range in span::first(count)"); 284 return {data(), __count}; 285 } 286 287 _LIBCPP_INLINE_VISIBILITY 288 constexpr span<element_type, dynamic_extent> last(size_type __count) const noexcept 289 { 290 _LIBCPP_ASSERT(__count <= size(), "Count out of range in span::last(count)"); 291 return {data() + size() - __count, __count}; 292 } 293 294 template <size_t _Offset, size_t _Count = dynamic_extent> 295 _LIBCPP_INLINE_VISIBILITY 296 constexpr auto subspan() const noexcept 297 -> span<element_type, _Count != dynamic_extent ? _Count : _Extent - _Offset> 298 { 299 static_assert(_Offset <= _Extent, "Offset out of range in span::subspan()"); 300 static_assert(_Count == dynamic_extent || _Count <= _Extent - _Offset, "Offset + count out of range in span::subspan()"); 301 302 using _ReturnType = span<element_type, _Count != dynamic_extent ? _Count : _Extent - _Offset>; 303 return _ReturnType{data() + _Offset, _Count == dynamic_extent ? size() - _Offset : _Count}; 304 } 305 306 307 _LIBCPP_INLINE_VISIBILITY 308 constexpr span<element_type, dynamic_extent> 309 subspan(size_type __offset, size_type __count = dynamic_extent) const noexcept 310 { 311 _LIBCPP_ASSERT(__offset <= size(), "Offset out of range in span::subspan(offset, count)"); 312 _LIBCPP_ASSERT(__count <= size() || __count == dynamic_extent, "Count out of range in span::subspan(offset, count)"); 313 if (__count == dynamic_extent) 314 return {data() + __offset, size() - __offset}; 315 _LIBCPP_ASSERT(__count <= size() - __offset, "Offset + count out of range in span::subspan(offset, count)"); 316 return {data() + __offset, __count}; 317 } 318 319 _LIBCPP_INLINE_VISIBILITY constexpr size_type size() const noexcept { return _Extent; } 320 _LIBCPP_INLINE_VISIBILITY constexpr size_type size_bytes() const noexcept { return _Extent * sizeof(element_type); } 321 _LIBCPP_INLINE_VISIBILITY constexpr bool empty() const noexcept { return _Extent == 0; } 322 323 _LIBCPP_INLINE_VISIBILITY constexpr reference operator[](size_type __idx) const noexcept 324 { 325 _LIBCPP_ASSERT(__idx < size(), "span<T,N>[] index out of bounds"); 326 return __data[__idx]; 327 } 328 329 _LIBCPP_INLINE_VISIBILITY constexpr reference front() const noexcept 330 { 331 _LIBCPP_ASSERT(!empty(), "span<T, N>::front() on empty span"); 332 return __data[0]; 333 } 334 335 _LIBCPP_INLINE_VISIBILITY constexpr reference back() const noexcept 336 { 337 _LIBCPP_ASSERT(!empty(), "span<T, N>::back() on empty span"); 338 return __data[size()-1]; 339 } 340 341 _LIBCPP_INLINE_VISIBILITY constexpr pointer data() const noexcept { return __data; } 342 343// [span.iter], span iterator support 344 _LIBCPP_INLINE_VISIBILITY constexpr iterator begin() const noexcept { return iterator(data()); } 345 _LIBCPP_INLINE_VISIBILITY constexpr iterator end() const noexcept { return iterator(data() + size()); } 346 _LIBCPP_INLINE_VISIBILITY constexpr reverse_iterator rbegin() const noexcept { return reverse_iterator(end()); } 347 _LIBCPP_INLINE_VISIBILITY constexpr reverse_iterator rend() const noexcept { return reverse_iterator(begin()); } 348 349 _LIBCPP_INLINE_VISIBILITY span<const byte, _Extent * sizeof(element_type)> __as_bytes() const noexcept 350 { return span<const byte, _Extent * sizeof(element_type)>{reinterpret_cast<const byte *>(data()), size_bytes()}; } 351 352 _LIBCPP_INLINE_VISIBILITY span<byte, _Extent * sizeof(element_type)> __as_writable_bytes() const noexcept 353 { return span<byte, _Extent * sizeof(element_type)>{reinterpret_cast<byte *>(data()), size_bytes()}; } 354 355private: 356 pointer __data; 357 358}; 359 360 361template <typename _Tp> 362class _LIBCPP_TEMPLATE_VIS span<_Tp, dynamic_extent> { 363private: 364 365public: 366// constants and types 367 using element_type = _Tp; 368 using value_type = remove_cv_t<_Tp>; 369 using size_type = size_t; 370 using difference_type = ptrdiff_t; 371 using pointer = _Tp *; 372 using const_pointer = const _Tp *; 373 using reference = _Tp &; 374 using const_reference = const _Tp &; 375 using iterator = __wrap_iter<pointer>; 376 using reverse_iterator = _VSTD::reverse_iterator<iterator>; 377 378 static constexpr size_type extent = dynamic_extent; 379 380// [span.cons], span constructors, copy, assignment, and destructor 381 _LIBCPP_INLINE_VISIBILITY constexpr span() noexcept : __data{nullptr}, __size{0} {} 382 383 constexpr span (const span&) noexcept = default; 384 constexpr span& operator=(const span&) noexcept = default; 385 386 _LIBCPP_INLINE_VISIBILITY constexpr span(pointer __ptr, size_type __count) : __data{__ptr}, __size{__count} {} 387 _LIBCPP_INLINE_VISIBILITY constexpr span(pointer __f, pointer __l) : __data{__f}, __size{static_cast<size_t>(distance(__f, __l))} {} 388 389 template <size_t _Sz> 390 _LIBCPP_INLINE_VISIBILITY 391 constexpr span(element_type (&__arr)[_Sz]) noexcept : __data{__arr}, __size{_Sz} {} 392 393 template <class _OtherElementType, size_t _Sz, 394 enable_if_t<is_convertible_v<_OtherElementType(*)[], element_type (*)[]>, nullptr_t> = nullptr> 395 _LIBCPP_INLINE_VISIBILITY 396 constexpr span(array<_OtherElementType, _Sz>& __arr) noexcept : __data{__arr.data()}, __size{_Sz} {} 397 398 template <class _OtherElementType, size_t _Sz, 399 enable_if_t<is_convertible_v<const _OtherElementType(*)[], element_type (*)[]>, nullptr_t> = nullptr> 400 _LIBCPP_INLINE_VISIBILITY 401 constexpr span(const array<_OtherElementType, _Sz>& __arr) noexcept : __data{__arr.data()}, __size{_Sz} {} 402 403 template <class _Container> 404 _LIBCPP_INLINE_VISIBILITY 405 constexpr span( _Container& __c, 406 enable_if_t<__is_span_compatible_container<_Container, _Tp>::value, nullptr_t> = nullptr) 407 : __data{_VSTD::data(__c)}, __size{(size_type) _VSTD::size(__c)} {} 408 409 template <class _Container> 410 _LIBCPP_INLINE_VISIBILITY 411 constexpr span(const _Container& __c, 412 enable_if_t<__is_span_compatible_container<const _Container, _Tp>::value, nullptr_t> = nullptr) 413 : __data{_VSTD::data(__c)}, __size{(size_type) _VSTD::size(__c)} {} 414 415 416 template <class _OtherElementType, size_t _OtherExtent> 417 _LIBCPP_INLINE_VISIBILITY 418 constexpr span(const span<_OtherElementType, _OtherExtent>& __other, 419 enable_if_t< 420 is_convertible_v<_OtherElementType(*)[], element_type (*)[]>, 421 nullptr_t> = nullptr) noexcept 422 : __data{__other.data()}, __size{__other.size()} {} 423 424// ~span() noexcept = default; 425 426 template <size_t _Count> 427 _LIBCPP_INLINE_VISIBILITY 428 constexpr span<element_type, _Count> first() const noexcept 429 { 430 _LIBCPP_ASSERT(_Count <= size(), "Count out of range in span::first()"); 431 return span<element_type, _Count>{data(), _Count}; 432 } 433 434 template <size_t _Count> 435 _LIBCPP_INLINE_VISIBILITY 436 constexpr span<element_type, _Count> last() const noexcept 437 { 438 _LIBCPP_ASSERT(_Count <= size(), "Count out of range in span::last()"); 439 return span<element_type, _Count>{data() + size() - _Count, _Count}; 440 } 441 442 _LIBCPP_INLINE_VISIBILITY 443 constexpr span<element_type, dynamic_extent> first(size_type __count) const noexcept 444 { 445 _LIBCPP_ASSERT(__count <= size(), "Count out of range in span::first(count)"); 446 return {data(), __count}; 447 } 448 449 _LIBCPP_INLINE_VISIBILITY 450 constexpr span<element_type, dynamic_extent> last (size_type __count) const noexcept 451 { 452 _LIBCPP_ASSERT(__count <= size(), "Count out of range in span::last(count)"); 453 return {data() + size() - __count, __count}; 454 } 455 456 template <size_t _Offset, size_t _Count = dynamic_extent> 457 _LIBCPP_INLINE_VISIBILITY 458 constexpr span<element_type, _Count> subspan() const noexcept 459 { 460 _LIBCPP_ASSERT(_Offset <= size(), "Offset out of range in span::subspan()"); 461 _LIBCPP_ASSERT(_Count == dynamic_extent || _Count <= size() - _Offset, "Offset + count out of range in span::subspan()"); 462 return span<element_type, _Count>{data() + _Offset, _Count == dynamic_extent ? size() - _Offset : _Count}; 463 } 464 465 constexpr span<element_type, dynamic_extent> 466 _LIBCPP_INLINE_VISIBILITY 467 subspan(size_type __offset, size_type __count = dynamic_extent) const noexcept 468 { 469 _LIBCPP_ASSERT(__offset <= size(), "Offset out of range in span::subspan(offset, count)"); 470 _LIBCPP_ASSERT(__count <= size() || __count == dynamic_extent, "count out of range in span::subspan(offset, count)"); 471 if (__count == dynamic_extent) 472 return {data() + __offset, size() - __offset}; 473 _LIBCPP_ASSERT(__count <= size() - __offset, "Offset + count out of range in span::subspan(offset, count)"); 474 return {data() + __offset, __count}; 475 } 476 477 _LIBCPP_INLINE_VISIBILITY constexpr size_type size() const noexcept { return __size; } 478 _LIBCPP_INLINE_VISIBILITY constexpr size_type size_bytes() const noexcept { return __size * sizeof(element_type); } 479 _LIBCPP_INLINE_VISIBILITY constexpr bool empty() const noexcept { return __size == 0; } 480 481 _LIBCPP_INLINE_VISIBILITY constexpr reference operator[](size_type __idx) const noexcept 482 { 483 _LIBCPP_ASSERT(__idx < size(), "span<T>[] index out of bounds"); 484 return __data[__idx]; 485 } 486 487 _LIBCPP_INLINE_VISIBILITY constexpr reference front() const noexcept 488 { 489 _LIBCPP_ASSERT(!empty(), "span<T>[].front() on empty span"); 490 return __data[0]; 491 } 492 493 _LIBCPP_INLINE_VISIBILITY constexpr reference back() const noexcept 494 { 495 _LIBCPP_ASSERT(!empty(), "span<T>[].back() on empty span"); 496 return __data[size()-1]; 497 } 498 499 500 _LIBCPP_INLINE_VISIBILITY constexpr pointer data() const noexcept { return __data; } 501 502// [span.iter], span iterator support 503 _LIBCPP_INLINE_VISIBILITY constexpr iterator begin() const noexcept { return iterator(data()); } 504 _LIBCPP_INLINE_VISIBILITY constexpr iterator end() const noexcept { return iterator(data() + size()); } 505 _LIBCPP_INLINE_VISIBILITY constexpr reverse_iterator rbegin() const noexcept { return reverse_iterator(end()); } 506 _LIBCPP_INLINE_VISIBILITY constexpr reverse_iterator rend() const noexcept { return reverse_iterator(begin()); } 507 508 _LIBCPP_INLINE_VISIBILITY span<const byte, dynamic_extent> __as_bytes() const noexcept 509 { return {reinterpret_cast<const byte *>(data()), size_bytes()}; } 510 511 _LIBCPP_INLINE_VISIBILITY span<byte, dynamic_extent> __as_writable_bytes() const noexcept 512 { return {reinterpret_cast<byte *>(data()), size_bytes()}; } 513 514private: 515 pointer __data; 516 size_type __size; 517}; 518 519// as_bytes & as_writable_bytes 520template <class _Tp, size_t _Extent> 521_LIBCPP_INLINE_VISIBILITY 522auto as_bytes(span<_Tp, _Extent> __s) noexcept 523-> decltype(__s.__as_bytes()) 524{ return __s.__as_bytes(); } 525 526template <class _Tp, size_t _Extent> 527_LIBCPP_INLINE_VISIBILITY 528auto as_writable_bytes(span<_Tp, _Extent> __s) noexcept 529-> enable_if_t<!is_const_v<_Tp>, decltype(__s.__as_writable_bytes())> 530{ return __s.__as_writable_bytes(); } 531 532// Deduction guides 533template<class _Tp, size_t _Sz> 534 span(_Tp (&)[_Sz]) -> span<_Tp, _Sz>; 535 536template<class _Tp, size_t _Sz> 537 span(array<_Tp, _Sz>&) -> span<_Tp, _Sz>; 538 539template<class _Tp, size_t _Sz> 540 span(const array<_Tp, _Sz>&) -> span<const _Tp, _Sz>; 541 542template<class _Container> 543 span(_Container&) -> span<typename _Container::value_type>; 544 545template<class _Container> 546 span(const _Container&) -> span<const typename _Container::value_type>; 547 548#endif // _LIBCPP_STD_VER > 17 549 550_LIBCPP_END_NAMESPACE_STD 551 552_LIBCPP_POP_MACROS 553 554#endif // _LIBCPP_SPAN 555