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