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