xref: /llvm-project-15.0.7/libcxx/include/span (revision 643df8fa)
18a0794b7SMarshall Clow// -*- C++ -*-
2eb8650a7SLouis Dionne//===----------------------------------------------------------------------===//
38a0794b7SMarshall Clow//
457b08b09SChandler Carruth// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
557b08b09SChandler Carruth// See https://llvm.org/LICENSE.txt for license information.
657b08b09SChandler Carruth// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
78a0794b7SMarshall Clow//
88a0794b7SMarshall Clow//===---------------------------------------------------------------------===//
98a0794b7SMarshall Clow
108a0794b7SMarshall Clow#ifndef _LIBCPP_SPAN
118a0794b7SMarshall Clow#define _LIBCPP_SPAN
128a0794b7SMarshall Clow
138a0794b7SMarshall Clow/*
148a0794b7SMarshall Clow    span synopsis
158a0794b7SMarshall Clow
168a0794b7SMarshall Clownamespace std {
178a0794b7SMarshall Clow
188a0794b7SMarshall Clow// constants
197ad06a93SMarshall Clowinline constexpr size_t dynamic_extent = numeric_limits<size_t>::max();
208a0794b7SMarshall Clow
218a0794b7SMarshall Clow// [views.span], class template span
227ad06a93SMarshall Clowtemplate <class ElementType, size_t Extent = dynamic_extent>
238a0794b7SMarshall Clow    class span;
248a0794b7SMarshall Clow
2501ace074SMark de Wevertemplate<class ElementType, size_t Extent>
26462f8f06SChristopher Di Bella  inline constexpr bool ranges::enable_view<span<ElementType, Extent>> = true;
27462f8f06SChristopher Di Bella
28462f8f06SChristopher Di Bellatemplate<class ElementType, size_t Extent>
2901ace074SMark de Wever    inline constexpr bool ranges::enable_borrowed_range<span<ElementType, Extent>> = true;
3001ace074SMark de Wever
318a0794b7SMarshall Clow// [span.objectrep], views of object representation
327ad06a93SMarshall Clowtemplate <class ElementType, size_t Extent>
338a0794b7SMarshall Clow    span<const byte, ((Extent == dynamic_extent) ? dynamic_extent :
348eda3ad2SMarshall Clow        (sizeof(ElementType) * Extent))> as_bytes(span<ElementType, Extent> s) noexcept;
358a0794b7SMarshall Clow
367ad06a93SMarshall Clowtemplate <class ElementType, size_t Extent>
378a0794b7SMarshall Clow    span<      byte, ((Extent == dynamic_extent) ? dynamic_extent :
388eda3ad2SMarshall Clow        (sizeof(ElementType) * Extent))> as_writable_bytes(span<ElementType, Extent> s) noexcept;
398a0794b7SMarshall Clow
408a0794b7SMarshall Clow
417ad06a93SMarshall Clowtemplate <class ElementType, size_t Extent = dynamic_extent>
428a0794b7SMarshall Clowclass span {
438a0794b7SMarshall Clowpublic:
448a0794b7SMarshall Clow    // constants and types
458a0794b7SMarshall Clow    using element_type = ElementType;
468a0794b7SMarshall Clow    using value_type = remove_cv_t<ElementType>;
471466335cSLouis Dionne    using size_type = size_t;
488a0794b7SMarshall Clow    using difference_type = ptrdiff_t;
498a0794b7SMarshall Clow    using pointer = element_type*;
504fd03954SMarshall Clow    using const_pointer = const element_type*;
518a0794b7SMarshall Clow    using reference = element_type&;
524fd03954SMarshall Clow    using const_reference = const element_type&;
537ad06a93SMarshall Clow    using iterator = implementation-defined;
548a0794b7SMarshall Clow    using reverse_iterator = std::reverse_iterator<iterator>;
551466335cSLouis Dionne    static constexpr size_type extent = Extent;
568a0794b7SMarshall Clow
578a0794b7SMarshall Clow    // [span.cons], span constructors, copy, assignment, and destructor
588a0794b7SMarshall Clow    constexpr span() noexcept;
593a208c68SJoe Loser    template <class It>
603a208c68SJoe Loser    constexpr explicit(Extent != dynamic_extent) span(It first, size_type count);
613a208c68SJoe Loser    template <class It, class End>
623a208c68SJoe Loser    constexpr explicit(Extent != dynamic_extent) span(It first, End last);
638a0794b7SMarshall Clow    template <size_t N>
640412c007SArthur O'Dwyer        constexpr span(type_identity_t<element_type> (&arr)[N]) noexcept;
658a0794b7SMarshall Clow    template <size_t N>
668a0794b7SMarshall Clow        constexpr span(array<value_type, N>& arr) noexcept;
678a0794b7SMarshall Clow    template <size_t N>
688a0794b7SMarshall Clow        constexpr span(const array<value_type, N>& arr) noexcept;
693a208c68SJoe Loser    template<class R>
703a208c68SJoe Loser      constexpr explicit(Extent != dynamic_extent) span(R&& r);
718a0794b7SMarshall Clow    constexpr span(const span& other) noexcept = default;
727ad06a93SMarshall Clow    template <class OtherElementType, size_t OtherExtent>
736d2599e4SMichael Schellenberger Costa        constexpr explicit(Extent != dynamic_extent) span(const span<OtherElementType, OtherExtent>& s) noexcept;
748a0794b7SMarshall Clow    ~span() noexcept = default;
758a0794b7SMarshall Clow    constexpr span& operator=(const span& other) noexcept = default;
768a0794b7SMarshall Clow
778a0794b7SMarshall Clow    // [span.sub], span subviews
787ad06a93SMarshall Clow    template <size_t Count>
798a0794b7SMarshall Clow        constexpr span<element_type, Count> first() const;
807ad06a93SMarshall Clow    template <size_t Count>
818a0794b7SMarshall Clow        constexpr span<element_type, Count> last() const;
827ad06a93SMarshall Clow    template <size_t Offset, size_t Count = dynamic_extent>
838a0794b7SMarshall Clow        constexpr span<element_type, see below> subspan() const;
848a0794b7SMarshall Clow
851466335cSLouis Dionne    constexpr span<element_type, dynamic_extent> first(size_type count) const;
861466335cSLouis Dionne    constexpr span<element_type, dynamic_extent> last(size_type count) const;
871466335cSLouis Dionne    constexpr span<element_type, dynamic_extent> subspan(size_type offset, size_type count = dynamic_extent) const;
888a0794b7SMarshall Clow
898a0794b7SMarshall Clow    // [span.obs], span observers
901466335cSLouis Dionne    constexpr size_type size() const noexcept;
911466335cSLouis Dionne    constexpr size_type size_bytes() const noexcept;
928e92410eSJoe Loser    [[nodiscard]] constexpr bool empty() const noexcept;
938a0794b7SMarshall Clow
948a0794b7SMarshall Clow    // [span.elem], span element access
951466335cSLouis Dionne    constexpr reference operator[](size_type idx) const;
969ab85a69SMarshall Clow    constexpr reference front() const;
979ab85a69SMarshall Clow    constexpr reference back() const;
988a0794b7SMarshall Clow    constexpr pointer data() const noexcept;
998a0794b7SMarshall Clow
1008a0794b7SMarshall Clow    // [span.iterators], span iterator support
1018a0794b7SMarshall Clow    constexpr iterator begin() const noexcept;
1028a0794b7SMarshall Clow    constexpr iterator end() const noexcept;
1038a0794b7SMarshall Clow    constexpr reverse_iterator rbegin() const noexcept;
1048a0794b7SMarshall Clow    constexpr reverse_iterator rend() const noexcept;
1058a0794b7SMarshall Clow
1068a0794b7SMarshall Clowprivate:
1078a0794b7SMarshall Clow    pointer data_;    // exposition only
1081466335cSLouis Dionne    size_type size_;  // exposition only
1098a0794b7SMarshall Clow};
1108a0794b7SMarshall Clow
1113a208c68SJoe Losertemplate<class It, class EndOrSize>
1123a208c68SJoe Loser    span(It, EndOrSize) -> span<remove_reference_t<iter_reference_t<_It>>>;
1133a208c68SJoe Loser
1148a0794b7SMarshall Clowtemplate<class T, size_t N>
1158a0794b7SMarshall Clow    span(T (&)[N]) -> span<T, N>;
1168a0794b7SMarshall Clow
1178a0794b7SMarshall Clowtemplate<class T, size_t N>
1188a0794b7SMarshall Clow    span(array<T, N>&) -> span<T, N>;
1198a0794b7SMarshall Clow
1208a0794b7SMarshall Clowtemplate<class T, size_t N>
1218a0794b7SMarshall Clow    span(const array<T, N>&) -> span<const T, N>;
1228a0794b7SMarshall Clow
1233a208c68SJoe Losertemplate<class R>
1243a208c68SJoe Loser    span(R&&) -> span<remove_reference_t<ranges::range_reference_t<R>>>;
1258a0794b7SMarshall Clow
1268a0794b7SMarshall Clow} // namespace std
1278a0794b7SMarshall Clow
1288a0794b7SMarshall Clow*/
1298a0794b7SMarshall Clow
130385cc25aSLouis Dionne#include <__assert> // all public C++ headers provide the assertion handler
13135773f55SMarshall Clow#include <__config>
13206b40e80SArthur O'Dwyer#include <__debug>
1339924d8d6SKonstantin Varlamov#include <__fwd/span.h>
1343a208c68SJoe Loser#include <__iterator/concepts.h>
135f32f3db9SLouis Dionne#include <__iterator/wrap_iter.h>
1363a208c68SJoe Loser#include <__ranges/concepts.h>
1373a208c68SJoe Loser#include <__ranges/data.h>
13801ace074SMark de Wever#include <__ranges/enable_borrowed_range.h>
139462f8f06SChristopher Di Bella#include <__ranges/enable_view.h>
1403a208c68SJoe Loser#include <__ranges/size.h>
141*643df8faSLouis Dionne#include <__utility/forward.h>
1428a0794b7SMarshall Clow#include <array>        // for array
1438a0794b7SMarshall Clow#include <cstddef>      // for byte
144edbaa7fcSLouis Dionne#include <iterator>     // for iterators
14569d5a666SChristopher Di Bella#include <limits>
146edbaa7fcSLouis Dionne#include <type_traits>  // for remove_cv, etc
147e37bbfe5SChristopher Di Bella#include <version>
1488a0794b7SMarshall Clow
1498a0794b7SMarshall Clow#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1508a0794b7SMarshall Clow#  pragma GCC system_header
1518a0794b7SMarshall Clow#endif
1528a0794b7SMarshall Clow
15303ee4612SArthur O'Dwyer_LIBCPP_PUSH_MACROS
15403ee4612SArthur O'Dwyer#include <__undef_macros>
15503ee4612SArthur O'Dwyer
1568a0794b7SMarshall Clow_LIBCPP_BEGIN_NAMESPACE_STD
1578a0794b7SMarshall Clow
1588a0794b7SMarshall Clow#if _LIBCPP_STD_VER > 17
1598a0794b7SMarshall Clow
1608a0794b7SMarshall Clowtemplate <class _Tp>
1613a208c68SJoe Loserstruct __is_std_array : false_type {};
1628a0794b7SMarshall Clow
1638a0794b7SMarshall Clowtemplate <class _Tp, size_t _Sz>
1643a208c68SJoe Loserstruct __is_std_array<array<_Tp, _Sz>> : true_type {};
1658a0794b7SMarshall Clow
1668a0794b7SMarshall Clowtemplate <class _Tp>
1673a208c68SJoe Loserstruct __is_std_span : false_type {};
1688a0794b7SMarshall Clow
1693a208c68SJoe Losertemplate <class _Tp, size_t _Sz>
1703a208c68SJoe Loserstruct __is_std_span<span<_Tp, _Sz>> : true_type {};
1718a0794b7SMarshall Clow
172d4c39f1aSLouis Dionne#if defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
173d4c39f1aSLouis Dionne// This is a temporary workaround until we ship <ranges> -- we've unfortunately been
174d4c39f1aSLouis Dionne// shipping <span> before its API was finalized, and we used to provide a constructor
175d4c39f1aSLouis Dionne// from container types that had the requirements below. To avoid breaking code that
176d4c39f1aSLouis Dionne// has started relying on the range-based constructor until we ship all of <ranges>,
177d4c39f1aSLouis Dionne// we emulate the constructor requirements like this.
178d4c39f1aSLouis Dionnetemplate <class _Range, class _ElementType>
179d4c39f1aSLouis Dionneconcept __span_compatible_range =
180d4c39f1aSLouis Dionne  !__is_std_span<remove_cvref_t<_Range>>::value  &&
181d4c39f1aSLouis Dionne  !__is_std_array<remove_cvref_t<_Range>>::value &&
182d4c39f1aSLouis Dionne  !is_array_v<remove_cvref_t<_Range>> &&
183d4c39f1aSLouis Dionne  requires (_Range&& __r) {
184d4c39f1aSLouis Dionne      data(std::forward<_Range>(__r));
185d4c39f1aSLouis Dionne      size(std::forward<_Range>(__r));
186d4c39f1aSLouis Dionne  } &&
187d4c39f1aSLouis Dionne  is_convertible_v<remove_reference_t<ranges::range_reference_t<_Range>>(*)[], _ElementType(*)[]>;
188d4c39f1aSLouis Dionne#else
1893a208c68SJoe Losertemplate <class _Range, class _ElementType>
1903a208c68SJoe Loserconcept __span_compatible_range =
1913a208c68SJoe Loser  ranges::contiguous_range<_Range> &&
1923a208c68SJoe Loser  ranges::sized_range<_Range> &&
1933a208c68SJoe Loser  (ranges::borrowed_range<_Range> || is_const_v<_ElementType>) &&
1943a208c68SJoe Loser  !__is_std_span<remove_cvref_t<_Range>>::value  &&
1953a208c68SJoe Loser  !__is_std_array<remove_cvref_t<_Range>>::value &&
1963a208c68SJoe Loser  !is_array_v<remove_cvref_t<_Range>> &&
1973a208c68SJoe Loser  is_convertible_v<remove_reference_t<ranges::range_reference_t<_Range>>(*)[], _ElementType(*)[]>;
198849e749dSLouis Dionne#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
1998a0794b7SMarshall Clow
2007ad06a93SMarshall Clowtemplate <typename _Tp, size_t _Extent>
2018a0794b7SMarshall Clowclass _LIBCPP_TEMPLATE_VIS span {
2028a0794b7SMarshall Clowpublic:
2038a0794b7SMarshall Clow//  constants and types
2048a0794b7SMarshall Clow    using element_type           = _Tp;
2058a0794b7SMarshall Clow    using value_type             = remove_cv_t<_Tp>;
2061466335cSLouis Dionne    using size_type              = size_t;
2078a0794b7SMarshall Clow    using difference_type        = ptrdiff_t;
2088a0794b7SMarshall Clow    using pointer                = _Tp *;
2094fd03954SMarshall Clow    using const_pointer          = const _Tp *;
2108a0794b7SMarshall Clow    using reference              = _Tp &;
2114fd03954SMarshall Clow    using const_reference        = const _Tp &;
2126946f0ecSArthur O'Dwyer#if (_LIBCPP_DEBUG_LEVEL == 2) || defined(_LIBCPP_ABI_SPAN_POINTER_ITERATORS)
2136946f0ecSArthur O'Dwyer    using iterator               = pointer;
2146946f0ecSArthur O'Dwyer#else
2158a0794b7SMarshall Clow    using iterator               = __wrap_iter<pointer>;
2166946f0ecSArthur O'Dwyer#endif
2178a0794b7SMarshall Clow    using reverse_iterator       = _VSTD::reverse_iterator<iterator>;
2188a0794b7SMarshall Clow
2191466335cSLouis Dionne    static constexpr size_type extent = _Extent;
2208a0794b7SMarshall Clow
2218a0794b7SMarshall Clow// [span.cons], span constructors, copy, assignment, and destructor
22279941086SMichael Schellenberger Costa    template <size_t _Sz = _Extent, enable_if_t<_Sz == 0, nullptr_t> = nullptr>
22379941086SMichael Schellenberger Costa    _LIBCPP_INLINE_VISIBILITY constexpr span() noexcept : __data{nullptr} {}
2248a0794b7SMarshall Clow
2258a0794b7SMarshall Clow    constexpr span           (const span&) noexcept = default;
2268a0794b7SMarshall Clow    constexpr span& operator=(const span&) noexcept = default;
2278a0794b7SMarshall Clow
2283a208c68SJoe Loser    template <class _It,
2293a208c68SJoe Loser              enable_if_t<contiguous_iterator<_It> &&
2303a208c68SJoe Loser                              is_convertible_v<remove_reference_t<iter_reference_t<_It>>(*)[], element_type (*)[]>,
2313a208c68SJoe Loser                          nullptr_t> = nullptr>
2323a208c68SJoe Loser    _LIBCPP_INLINE_VISIBILITY
2333a208c68SJoe Loser    constexpr explicit span(_It __first, size_type __count)
2343a208c68SJoe Loser        : __data{_VSTD::to_address(__first)} {
2353a208c68SJoe Loser      (void)__count;
2363a208c68SJoe Loser      _LIBCPP_ASSERT(_Extent == __count, "size mismatch in span's constructor (iterator, len)");
2373a208c68SJoe Loser    }
2383a208c68SJoe Loser
2393a208c68SJoe Loser    template <
2403a208c68SJoe Loser        class _It, class _End,
2413a208c68SJoe Loser        enable_if_t<is_convertible_v<remove_reference_t<iter_reference_t<_It> > (*)[], element_type (*)[]> &&
2423a208c68SJoe Loser                        contiguous_iterator<_It> && sized_sentinel_for<_End, _It> && !is_convertible_v<_End, size_t>,
2433a208c68SJoe Loser                    nullptr_t> = nullptr>
2443a208c68SJoe Loser    _LIBCPP_INLINE_VISIBILITY
2453a208c68SJoe Loser    constexpr explicit span(_It __first, _End __last) : __data{_VSTD::to_address(__first)} {
2463a208c68SJoe Loser      (void)__last;
2473a208c68SJoe Loser      _LIBCPP_ASSERT((__last - __first >= 0), "invalid range in span's constructor (iterator, sentinel)");
2483a208c68SJoe Loser      _LIBCPP_ASSERT(__last - __first == _Extent,
2493a208c68SJoe Loser                     "invalid range in span's constructor (iterator, sentinel): last - first != extent");
2503a208c68SJoe Loser    }
2518a0794b7SMarshall Clow
2520412c007SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY constexpr span(type_identity_t<element_type> (&__arr)[_Extent]) noexcept : __data{__arr} {}
253ab9f1116SMichael Schellenberger Costa
254ab9f1116SMichael Schellenberger Costa    template <class _OtherElementType,
255ab9f1116SMichael Schellenberger Costa              enable_if_t<is_convertible_v<_OtherElementType(*)[], element_type (*)[]>, nullptr_t> = nullptr>
256ab9f1116SMichael Schellenberger Costa    _LIBCPP_INLINE_VISIBILITY
257ab9f1116SMichael Schellenberger Costa    constexpr span(array<_OtherElementType, _Extent>& __arr) noexcept : __data{__arr.data()} {}
258ab9f1116SMichael Schellenberger Costa
259ab9f1116SMichael Schellenberger Costa    template <class _OtherElementType,
260ab9f1116SMichael Schellenberger Costa              enable_if_t<is_convertible_v<const _OtherElementType(*)[], element_type (*)[]>, nullptr_t> = nullptr>
261ab9f1116SMichael Schellenberger Costa    _LIBCPP_INLINE_VISIBILITY
262ab9f1116SMichael Schellenberger Costa    constexpr span(const array<_OtherElementType, _Extent>& __arr) noexcept : __data{__arr.data()} {}
2638a0794b7SMarshall Clow
264d4c39f1aSLouis Dionne#if defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
265d4c39f1aSLouis Dionne    template <class _Container>
266d4c39f1aSLouis Dionne        requires __span_compatible_range<_Container, element_type>
267d4c39f1aSLouis Dionne    _LIBCPP_INLINE_VISIBILITY
268d4c39f1aSLouis Dionne    constexpr explicit span(_Container& __c) : __data{std::data(__c)} {
269d4c39f1aSLouis Dionne      _LIBCPP_ASSERT(std::size(__c) == _Extent, "size mismatch in span's constructor (range)");
270d4c39f1aSLouis Dionne    }
271d4c39f1aSLouis Dionne    template <class _Container>
272d4c39f1aSLouis Dionne        requires __span_compatible_range<const _Container, element_type>
273d4c39f1aSLouis Dionne    _LIBCPP_INLINE_VISIBILITY
274d4c39f1aSLouis Dionne    constexpr explicit span(const _Container& __c) : __data{std::data(__c)} {
275d4c39f1aSLouis Dionne      _LIBCPP_ASSERT(std::size(__c) == _Extent, "size mismatch in span's constructor (range)");
276d4c39f1aSLouis Dionne    }
277d4c39f1aSLouis Dionne#else
2783a208c68SJoe Loser    template <__span_compatible_range<element_type> _Range>
2796d2599e4SMichael Schellenberger Costa    _LIBCPP_INLINE_VISIBILITY
2803a208c68SJoe Loser    constexpr explicit span(_Range&& __r) : __data{ranges::data(__r)} {
2813a208c68SJoe Loser      _LIBCPP_ASSERT(ranges::size(__r) == _Extent, "size mismatch in span's constructor (range)");
2826d2599e4SMichael Schellenberger Costa    }
283849e749dSLouis Dionne#endif
2846d2599e4SMichael Schellenberger Costa
2858a0794b7SMarshall Clow    template <class _OtherElementType>
2868eda3ad2SMarshall Clow    _LIBCPP_INLINE_VISIBILITY
2878a0794b7SMarshall Clow        constexpr span(const span<_OtherElementType, _Extent>& __other,
2888a0794b7SMarshall Clow                       enable_if_t<
2898a0794b7SMarshall Clow                          is_convertible_v<_OtherElementType(*)[], element_type (*)[]>,
2908a0794b7SMarshall Clow                          nullptr_t> = nullptr)
2918a0794b7SMarshall Clow        : __data{__other.data()} {}
2928a0794b7SMarshall Clow
2938a0794b7SMarshall Clow    template <class _OtherElementType>
2948eda3ad2SMarshall Clow    _LIBCPP_INLINE_VISIBILITY
2956d2599e4SMichael Schellenberger Costa        constexpr explicit span(const span<_OtherElementType, dynamic_extent>& __other,
2968a0794b7SMarshall Clow                       enable_if_t<
2978a0794b7SMarshall Clow                          is_convertible_v<_OtherElementType(*)[], element_type (*)[]>,
2988a0794b7SMarshall Clow                          nullptr_t> = nullptr) noexcept
2998a0794b7SMarshall Clow        : __data{__other.data()} { _LIBCPP_ASSERT(_Extent == __other.size(), "size mismatch in span's constructor (other span)"); }
3008a0794b7SMarshall Clow
3018a0794b7SMarshall Clow
3028a0794b7SMarshall Clow//  ~span() noexcept = default;
3038a0794b7SMarshall Clow
3047ad06a93SMarshall Clow    template <size_t _Count>
3058eda3ad2SMarshall Clow    _LIBCPP_INLINE_VISIBILITY
3068a0794b7SMarshall Clow    constexpr span<element_type, _Count> first() const noexcept
3078a0794b7SMarshall Clow    {
3088a0794b7SMarshall Clow        static_assert(_Count <= _Extent, "Count out of range in span::first()");
3096d2599e4SMichael Schellenberger Costa        return span<element_type, _Count>{data(), _Count};
3108a0794b7SMarshall Clow    }
3118a0794b7SMarshall Clow
3127ad06a93SMarshall Clow    template <size_t _Count>
3138eda3ad2SMarshall Clow    _LIBCPP_INLINE_VISIBILITY
3148a0794b7SMarshall Clow    constexpr span<element_type, _Count> last() const noexcept
3158a0794b7SMarshall Clow    {
3168a0794b7SMarshall Clow        static_assert(_Count <= _Extent, "Count out of range in span::last()");
3176d2599e4SMichael Schellenberger Costa        return span<element_type, _Count>{data() + size() - _Count, _Count};
3188a0794b7SMarshall Clow    }
3198a0794b7SMarshall Clow
3208a0794b7SMarshall Clow    _LIBCPP_INLINE_VISIBILITY
3211466335cSLouis Dionne    constexpr span<element_type, dynamic_extent> first(size_type __count) const noexcept
3228a0794b7SMarshall Clow    {
3238eda3ad2SMarshall Clow        _LIBCPP_ASSERT(__count <= size(), "Count out of range in span::first(count)");
3248a0794b7SMarshall Clow        return {data(), __count};
3258a0794b7SMarshall Clow    }
3268a0794b7SMarshall Clow
3278a0794b7SMarshall Clow    _LIBCPP_INLINE_VISIBILITY
3281466335cSLouis Dionne    constexpr span<element_type, dynamic_extent> last(size_type __count) const noexcept
3298a0794b7SMarshall Clow    {
3308eda3ad2SMarshall Clow        _LIBCPP_ASSERT(__count <= size(), "Count out of range in span::last(count)");
3318a0794b7SMarshall Clow        return {data() + size() - __count, __count};
3328a0794b7SMarshall Clow    }
3338a0794b7SMarshall Clow
3347ad06a93SMarshall Clow    template <size_t _Offset, size_t _Count = dynamic_extent>
3358eda3ad2SMarshall Clow    _LIBCPP_INLINE_VISIBILITY
3368a0794b7SMarshall Clow    constexpr auto subspan() const noexcept
3378a0794b7SMarshall Clow        -> span<element_type, _Count != dynamic_extent ? _Count : _Extent - _Offset>
3388a0794b7SMarshall Clow    {
3398eda3ad2SMarshall Clow        static_assert(_Offset <= _Extent, "Offset out of range in span::subspan()");
340b5abd50fSLouis Dionne        static_assert(_Count == dynamic_extent || _Count <= _Extent - _Offset, "Offset + count out of range in span::subspan()");
3416d2599e4SMichael Schellenberger Costa
3426d2599e4SMichael Schellenberger Costa        using _ReturnType = span<element_type, _Count != dynamic_extent ? _Count : _Extent - _Offset>;
3436d2599e4SMichael Schellenberger Costa        return _ReturnType{data() + _Offset, _Count == dynamic_extent ? size() - _Offset : _Count};
3448a0794b7SMarshall Clow    }
3458a0794b7SMarshall Clow
3468a0794b7SMarshall Clow
3478eda3ad2SMarshall Clow    _LIBCPP_INLINE_VISIBILITY
3488a0794b7SMarshall Clow    constexpr span<element_type, dynamic_extent>
3491466335cSLouis Dionne       subspan(size_type __offset, size_type __count = dynamic_extent) const noexcept
3508a0794b7SMarshall Clow    {
3518eda3ad2SMarshall Clow        _LIBCPP_ASSERT(__offset <= size(), "Offset out of range in span::subspan(offset, count)");
3528eda3ad2SMarshall Clow        _LIBCPP_ASSERT(__count  <= size() || __count == dynamic_extent, "Count out of range in span::subspan(offset, count)");
3538a0794b7SMarshall Clow        if (__count == dynamic_extent)
3548a0794b7SMarshall Clow            return {data() + __offset, size() - __offset};
355b5abd50fSLouis Dionne        _LIBCPP_ASSERT(__count <= size() - __offset, "Offset + count out of range in span::subspan(offset, count)");
3568a0794b7SMarshall Clow        return {data() + __offset, __count};
3578a0794b7SMarshall Clow    }
3588a0794b7SMarshall Clow
3591466335cSLouis Dionne    _LIBCPP_INLINE_VISIBILITY constexpr size_type size()           const noexcept { return _Extent; }
3601466335cSLouis Dionne    _LIBCPP_INLINE_VISIBILITY constexpr size_type size_bytes()     const noexcept { return _Extent * sizeof(element_type); }
3618e92410eSJoe Loser    [[nodiscard]] _LIBCPP_INLINE_VISIBILITY constexpr bool empty() const noexcept { return _Extent == 0; }
3628a0794b7SMarshall Clow
3631466335cSLouis Dionne    _LIBCPP_INLINE_VISIBILITY constexpr reference operator[](size_type __idx) const noexcept
3648a0794b7SMarshall Clow    {
365b4a3e6b6SLouis Dionne        _LIBCPP_ASSERT(__idx < size(), "span<T,N>[] index out of bounds");
3668a0794b7SMarshall Clow        return __data[__idx];
3678a0794b7SMarshall Clow    }
3688a0794b7SMarshall Clow
3699ab85a69SMarshall Clow    _LIBCPP_INLINE_VISIBILITY constexpr reference front() const noexcept
3708a0794b7SMarshall Clow    {
3710a0e0afaSLouis Dionne        _LIBCPP_ASSERT(!empty(), "span<T, N>::front() on empty span");
3729ab85a69SMarshall Clow        return __data[0];
3739ab85a69SMarshall Clow    }
3749ab85a69SMarshall Clow
3759ab85a69SMarshall Clow    _LIBCPP_INLINE_VISIBILITY constexpr reference back() const noexcept
3769ab85a69SMarshall Clow    {
3770a0e0afaSLouis Dionne        _LIBCPP_ASSERT(!empty(), "span<T, N>::back() on empty span");
3789ab85a69SMarshall Clow        return __data[size()-1];
3798a0794b7SMarshall Clow    }
3808a0794b7SMarshall Clow
3818a0794b7SMarshall Clow    _LIBCPP_INLINE_VISIBILITY constexpr pointer data()                         const noexcept { return __data; }
3828a0794b7SMarshall Clow
3838a0794b7SMarshall Clow// [span.iter], span iterator support
3848a0794b7SMarshall Clow    _LIBCPP_INLINE_VISIBILITY constexpr iterator                 begin() const noexcept { return iterator(data()); }
3858a0794b7SMarshall Clow    _LIBCPP_INLINE_VISIBILITY constexpr iterator                   end() const noexcept { return iterator(data() + size()); }
3868a0794b7SMarshall Clow    _LIBCPP_INLINE_VISIBILITY constexpr reverse_iterator        rbegin() const noexcept { return reverse_iterator(end()); }
3878a0794b7SMarshall Clow    _LIBCPP_INLINE_VISIBILITY constexpr reverse_iterator          rend() const noexcept { return reverse_iterator(begin()); }
3888a0794b7SMarshall Clow
3898a0794b7SMarshall Clow    _LIBCPP_INLINE_VISIBILITY span<const byte, _Extent * sizeof(element_type)> __as_bytes() const noexcept
3906d2599e4SMichael Schellenberger Costa    { return span<const byte, _Extent * sizeof(element_type)>{reinterpret_cast<const byte *>(data()), size_bytes()}; }
3918a0794b7SMarshall Clow
3927cd0dad8SLouis Dionne    _LIBCPP_INLINE_VISIBILITY span<byte, _Extent * sizeof(element_type)> __as_writable_bytes() const noexcept
3936d2599e4SMichael Schellenberger Costa    { return span<byte, _Extent * sizeof(element_type)>{reinterpret_cast<byte *>(data()), size_bytes()}; }
3948a0794b7SMarshall Clow
3958a0794b7SMarshall Clowprivate:
3968a0794b7SMarshall Clow    pointer    __data;
3978a0794b7SMarshall Clow
3988a0794b7SMarshall Clow};
3998a0794b7SMarshall Clow
4008a0794b7SMarshall Clow
4018a0794b7SMarshall Clowtemplate <typename _Tp>
4028a0794b7SMarshall Clowclass _LIBCPP_TEMPLATE_VIS span<_Tp, dynamic_extent> {
4038a0794b7SMarshall Clowprivate:
4048a0794b7SMarshall Clow
4058a0794b7SMarshall Clowpublic:
4068a0794b7SMarshall Clow//  constants and types
4078a0794b7SMarshall Clow    using element_type           = _Tp;
4088a0794b7SMarshall Clow    using value_type             = remove_cv_t<_Tp>;
4091466335cSLouis Dionne    using size_type              = size_t;
4108a0794b7SMarshall Clow    using difference_type        = ptrdiff_t;
4118a0794b7SMarshall Clow    using pointer                = _Tp *;
4124fd03954SMarshall Clow    using const_pointer          = const _Tp *;
4138a0794b7SMarshall Clow    using reference              = _Tp &;
4144fd03954SMarshall Clow    using const_reference        = const _Tp &;
4156946f0ecSArthur O'Dwyer#if (_LIBCPP_DEBUG_LEVEL == 2) || defined(_LIBCPP_ABI_SPAN_POINTER_ITERATORS)
4166946f0ecSArthur O'Dwyer    using iterator               = pointer;
4176946f0ecSArthur O'Dwyer#else
4188a0794b7SMarshall Clow    using iterator               = __wrap_iter<pointer>;
4196946f0ecSArthur O'Dwyer#endif
4208a0794b7SMarshall Clow    using reverse_iterator       = _VSTD::reverse_iterator<iterator>;
4218a0794b7SMarshall Clow
4221466335cSLouis Dionne    static constexpr size_type extent = dynamic_extent;
4238a0794b7SMarshall Clow
4248a0794b7SMarshall Clow// [span.cons], span constructors, copy, assignment, and destructor
4258a0794b7SMarshall Clow    _LIBCPP_INLINE_VISIBILITY constexpr span() noexcept : __data{nullptr}, __size{0} {}
4268a0794b7SMarshall Clow
4278a0794b7SMarshall Clow    constexpr span           (const span&) noexcept = default;
4288a0794b7SMarshall Clow    constexpr span& operator=(const span&) noexcept = default;
4298a0794b7SMarshall Clow
4303a208c68SJoe Loser    template <class _It,
4313a208c68SJoe Loser              enable_if_t<contiguous_iterator<_It> &&
4323a208c68SJoe Loser                              is_convertible_v<remove_reference_t<iter_reference_t<_It> > (*)[], element_type (*)[]>,
4333a208c68SJoe Loser                          nullptr_t> = nullptr>
4343a208c68SJoe Loser    _LIBCPP_INLINE_VISIBILITY
4353a208c68SJoe Loser    constexpr span(_It __first, size_type __count)
4363a208c68SJoe Loser        : __data{_VSTD::to_address(__first)}, __size{__count} {}
4373a208c68SJoe Loser
4383a208c68SJoe Loser    template <
4393a208c68SJoe Loser        class _It, class _End,
4403a208c68SJoe Loser        enable_if_t<is_convertible_v<remove_reference_t<iter_reference_t<_It> > (*)[], element_type (*)[]> &&
4413a208c68SJoe Loser                        contiguous_iterator<_It> && sized_sentinel_for<_End, _It> && !is_convertible_v<_End, size_t>,
4423a208c68SJoe Loser                    nullptr_t> = nullptr>
4433a208c68SJoe Loser    _LIBCPP_INLINE_VISIBILITY
4443a208c68SJoe Loser    constexpr span(_It __first, _End __last)
4453a208c68SJoe Loser        : __data(_VSTD::to_address(__first)), __size(__last - __first) {}
4468a0794b7SMarshall Clow
4478a0794b7SMarshall Clow    template <size_t _Sz>
4488eda3ad2SMarshall Clow    _LIBCPP_INLINE_VISIBILITY
4490412c007SArthur O'Dwyer    constexpr span(type_identity_t<element_type> (&__arr)[_Sz]) noexcept : __data{__arr}, __size{_Sz} {}
4508a0794b7SMarshall Clow
451ab9f1116SMichael Schellenberger Costa    template <class _OtherElementType, size_t _Sz,
452ab9f1116SMichael Schellenberger Costa              enable_if_t<is_convertible_v<_OtherElementType(*)[], element_type (*)[]>, nullptr_t> = nullptr>
4538eda3ad2SMarshall Clow    _LIBCPP_INLINE_VISIBILITY
454ab9f1116SMichael Schellenberger Costa    constexpr span(array<_OtherElementType, _Sz>& __arr) noexcept : __data{__arr.data()}, __size{_Sz} {}
4558a0794b7SMarshall Clow
456ab9f1116SMichael Schellenberger Costa    template <class _OtherElementType, size_t _Sz,
457ab9f1116SMichael Schellenberger Costa              enable_if_t<is_convertible_v<const _OtherElementType(*)[], element_type (*)[]>, nullptr_t> = nullptr>
4588eda3ad2SMarshall Clow    _LIBCPP_INLINE_VISIBILITY
459ab9f1116SMichael Schellenberger Costa    constexpr span(const array<_OtherElementType, _Sz>& __arr) noexcept : __data{__arr.data()}, __size{_Sz} {}
4608a0794b7SMarshall Clow
461d4c39f1aSLouis Dionne#if defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
462d4c39f1aSLouis Dionne    template <class _Container>
463d4c39f1aSLouis Dionne        requires __span_compatible_range<_Container, element_type>
464d4c39f1aSLouis Dionne    _LIBCPP_INLINE_VISIBILITY
465d4c39f1aSLouis Dionne    constexpr span(_Container& __c) : __data(std::data(__c)), __size{std::size(__c)} {}
466d4c39f1aSLouis Dionne    template <class _Container>
467d4c39f1aSLouis Dionne        requires __span_compatible_range<const _Container, element_type>
468d4c39f1aSLouis Dionne    _LIBCPP_INLINE_VISIBILITY
469d4c39f1aSLouis Dionne    constexpr span(const _Container& __c) : __data(std::data(__c)), __size{std::size(__c)} {}
470d4c39f1aSLouis Dionne#else
4713a208c68SJoe Loser    template <__span_compatible_range<element_type> _Range>
4728eda3ad2SMarshall Clow    _LIBCPP_INLINE_VISIBILITY
4733a208c68SJoe Loser    constexpr span(_Range&& __r) : __data(ranges::data(__r)), __size{ranges::size(__r)} {}
474849e749dSLouis Dionne#endif
4758a0794b7SMarshall Clow
4767ad06a93SMarshall Clow    template <class _OtherElementType, size_t _OtherExtent>
4778eda3ad2SMarshall Clow    _LIBCPP_INLINE_VISIBILITY
4788a0794b7SMarshall Clow        constexpr span(const span<_OtherElementType, _OtherExtent>& __other,
4798a0794b7SMarshall Clow                       enable_if_t<
4808a0794b7SMarshall Clow                          is_convertible_v<_OtherElementType(*)[], element_type (*)[]>,
4818a0794b7SMarshall Clow                          nullptr_t> = nullptr) noexcept
4828a0794b7SMarshall Clow        : __data{__other.data()}, __size{__other.size()} {}
4838a0794b7SMarshall Clow
4848a0794b7SMarshall Clow//    ~span() noexcept = default;
4858a0794b7SMarshall Clow
4867ad06a93SMarshall Clow    template <size_t _Count>
4878eda3ad2SMarshall Clow    _LIBCPP_INLINE_VISIBILITY
4888a0794b7SMarshall Clow    constexpr span<element_type, _Count> first() const noexcept
4898a0794b7SMarshall Clow    {
4908a0794b7SMarshall Clow        _LIBCPP_ASSERT(_Count <= size(), "Count out of range in span::first()");
4916d2599e4SMichael Schellenberger Costa        return span<element_type, _Count>{data(), _Count};
4928a0794b7SMarshall Clow    }
4938a0794b7SMarshall Clow
4947ad06a93SMarshall Clow    template <size_t _Count>
4958eda3ad2SMarshall Clow    _LIBCPP_INLINE_VISIBILITY
4968a0794b7SMarshall Clow    constexpr span<element_type, _Count> last() const noexcept
4978a0794b7SMarshall Clow    {
4988a0794b7SMarshall Clow        _LIBCPP_ASSERT(_Count <= size(), "Count out of range in span::last()");
4996d2599e4SMichael Schellenberger Costa        return span<element_type, _Count>{data() + size() - _Count, _Count};
5008a0794b7SMarshall Clow    }
5018a0794b7SMarshall Clow
5028a0794b7SMarshall Clow    _LIBCPP_INLINE_VISIBILITY
5031466335cSLouis Dionne    constexpr span<element_type, dynamic_extent> first(size_type __count) const noexcept
5048a0794b7SMarshall Clow    {
5058eda3ad2SMarshall Clow        _LIBCPP_ASSERT(__count <= size(), "Count out of range in span::first(count)");
5068a0794b7SMarshall Clow        return {data(), __count};
5078a0794b7SMarshall Clow    }
5088a0794b7SMarshall Clow
5098a0794b7SMarshall Clow    _LIBCPP_INLINE_VISIBILITY
5101466335cSLouis Dionne    constexpr span<element_type, dynamic_extent> last (size_type __count) const noexcept
5118a0794b7SMarshall Clow    {
5128eda3ad2SMarshall Clow        _LIBCPP_ASSERT(__count <= size(), "Count out of range in span::last(count)");
5138a0794b7SMarshall Clow        return {data() + size() - __count, __count};
5148a0794b7SMarshall Clow    }
5158a0794b7SMarshall Clow
5167ad06a93SMarshall Clow    template <size_t _Offset, size_t _Count = dynamic_extent>
5178eda3ad2SMarshall Clow    _LIBCPP_INLINE_VISIBILITY
51892a1f65fSLouis Dionne    constexpr span<element_type, _Count> subspan() const noexcept
5198a0794b7SMarshall Clow    {
5208eda3ad2SMarshall Clow        _LIBCPP_ASSERT(_Offset <= size(), "Offset out of range in span::subspan()");
521b5abd50fSLouis Dionne        _LIBCPP_ASSERT(_Count == dynamic_extent || _Count <= size() - _Offset, "Offset + count out of range in span::subspan()");
5226d2599e4SMichael Schellenberger Costa        return span<element_type, _Count>{data() + _Offset, _Count == dynamic_extent ? size() - _Offset : _Count};
5238a0794b7SMarshall Clow    }
5248a0794b7SMarshall Clow
5258a0794b7SMarshall Clow    constexpr span<element_type, dynamic_extent>
5268eda3ad2SMarshall Clow    _LIBCPP_INLINE_VISIBILITY
5271466335cSLouis Dionne    subspan(size_type __offset, size_type __count = dynamic_extent) const noexcept
5288a0794b7SMarshall Clow    {
5298eda3ad2SMarshall Clow        _LIBCPP_ASSERT(__offset <= size(), "Offset out of range in span::subspan(offset, count)");
5308eda3ad2SMarshall Clow        _LIBCPP_ASSERT(__count  <= size() || __count == dynamic_extent, "count out of range in span::subspan(offset, count)");
5318a0794b7SMarshall Clow        if (__count == dynamic_extent)
5328a0794b7SMarshall Clow            return {data() + __offset, size() - __offset};
533b5abd50fSLouis Dionne        _LIBCPP_ASSERT(__count <= size() - __offset, "Offset + count out of range in span::subspan(offset, count)");
5348a0794b7SMarshall Clow        return {data() + __offset, __count};
5358a0794b7SMarshall Clow    }
5368a0794b7SMarshall Clow
5371466335cSLouis Dionne    _LIBCPP_INLINE_VISIBILITY constexpr size_type size()           const noexcept { return __size; }
5381466335cSLouis Dionne    _LIBCPP_INLINE_VISIBILITY constexpr size_type size_bytes()     const noexcept { return __size * sizeof(element_type); }
5398e92410eSJoe Loser    [[nodiscard]] _LIBCPP_INLINE_VISIBILITY constexpr bool empty() const noexcept { return __size == 0; }
5408a0794b7SMarshall Clow
5411466335cSLouis Dionne    _LIBCPP_INLINE_VISIBILITY constexpr reference operator[](size_type __idx) const noexcept
5428a0794b7SMarshall Clow    {
543b4a3e6b6SLouis Dionne        _LIBCPP_ASSERT(__idx < size(), "span<T>[] index out of bounds");
5448a0794b7SMarshall Clow        return __data[__idx];
5458a0794b7SMarshall Clow    }
5468a0794b7SMarshall Clow
5479ab85a69SMarshall Clow    _LIBCPP_INLINE_VISIBILITY constexpr reference front() const noexcept
5488a0794b7SMarshall Clow    {
5499ab85a69SMarshall Clow        _LIBCPP_ASSERT(!empty(), "span<T>[].front() on empty span");
5509ab85a69SMarshall Clow        return __data[0];
5518a0794b7SMarshall Clow    }
5528a0794b7SMarshall Clow
5539ab85a69SMarshall Clow    _LIBCPP_INLINE_VISIBILITY constexpr reference back() const noexcept
5549ab85a69SMarshall Clow    {
5559ab85a69SMarshall Clow        _LIBCPP_ASSERT(!empty(), "span<T>[].back() on empty span");
5569ab85a69SMarshall Clow        return __data[size()-1];
5579ab85a69SMarshall Clow    }
5589ab85a69SMarshall Clow
5599ab85a69SMarshall Clow
5608a0794b7SMarshall Clow    _LIBCPP_INLINE_VISIBILITY constexpr pointer data()                         const noexcept { return __data; }
5618a0794b7SMarshall Clow
5628a0794b7SMarshall Clow// [span.iter], span iterator support
5638a0794b7SMarshall Clow    _LIBCPP_INLINE_VISIBILITY constexpr iterator                 begin() const noexcept { return iterator(data()); }
5648a0794b7SMarshall Clow    _LIBCPP_INLINE_VISIBILITY constexpr iterator                   end() const noexcept { return iterator(data() + size()); }
5658a0794b7SMarshall Clow    _LIBCPP_INLINE_VISIBILITY constexpr reverse_iterator        rbegin() const noexcept { return reverse_iterator(end()); }
5668a0794b7SMarshall Clow    _LIBCPP_INLINE_VISIBILITY constexpr reverse_iterator          rend() const noexcept { return reverse_iterator(begin()); }
5678a0794b7SMarshall Clow
5688a0794b7SMarshall Clow    _LIBCPP_INLINE_VISIBILITY span<const byte, dynamic_extent> __as_bytes() const noexcept
5698a0794b7SMarshall Clow    { return {reinterpret_cast<const byte *>(data()), size_bytes()}; }
5708a0794b7SMarshall Clow
5717cd0dad8SLouis Dionne    _LIBCPP_INLINE_VISIBILITY span<byte, dynamic_extent> __as_writable_bytes() const noexcept
5728a0794b7SMarshall Clow    { return {reinterpret_cast<byte *>(data()), size_bytes()}; }
5738a0794b7SMarshall Clow
5748a0794b7SMarshall Clowprivate:
5758a0794b7SMarshall Clow    pointer   __data;
5761466335cSLouis Dionne    size_type __size;
5778a0794b7SMarshall Clow};
5788a0794b7SMarshall Clow
57901ace074SMark de Wevertemplate <class _Tp, size_t _Extent>
58001ace074SMark de Weverinline constexpr bool ranges::enable_borrowed_range<span<_Tp, _Extent> > = true;
581462f8f06SChristopher Di Bella
582462f8f06SChristopher Di Bellatemplate <class _ElementType, size_t _Extent>
583462f8f06SChristopher Di Bellainline constexpr bool ranges::enable_view<span<_ElementType, _Extent>> = true;
58401ace074SMark de Wever
5857cd0dad8SLouis Dionne//  as_bytes & as_writable_bytes
5867ad06a93SMarshall Clowtemplate <class _Tp, size_t _Extent>
58702e1651cSMarshall Clow_LIBCPP_INLINE_VISIBILITY
5888a0794b7SMarshall Clowauto as_bytes(span<_Tp, _Extent> __s) noexcept
5898a0794b7SMarshall Clow-> decltype(__s.__as_bytes())
5908a0794b7SMarshall Clow{ return    __s.__as_bytes(); }
5918a0794b7SMarshall Clow
5927ad06a93SMarshall Clowtemplate <class _Tp, size_t _Extent>
59302e1651cSMarshall Clow_LIBCPP_INLINE_VISIBILITY
5947cd0dad8SLouis Dionneauto as_writable_bytes(span<_Tp, _Extent> __s) noexcept
5957cd0dad8SLouis Dionne-> enable_if_t<!is_const_v<_Tp>, decltype(__s.__as_writable_bytes())>
5967cd0dad8SLouis Dionne{ return __s.__as_writable_bytes(); }
5978a0794b7SMarshall Clow
598d2baefaeSJoe Loser#if _LIBCPP_STD_VER > 17
5993a208c68SJoe Losertemplate<contiguous_iterator _It, class _EndOrSize>
6003a208c68SJoe Loser    span(_It, _EndOrSize) -> span<remove_reference_t<iter_reference_t<_It>>>;
601d2baefaeSJoe Loser#endif // _LIBCPP_STD_VER > 17
6023a208c68SJoe Loser
6038a0794b7SMarshall Clowtemplate<class _Tp, size_t _Sz>
6048a0794b7SMarshall Clow    span(_Tp (&)[_Sz]) -> span<_Tp, _Sz>;
6058a0794b7SMarshall Clow
6068a0794b7SMarshall Clowtemplate<class _Tp, size_t _Sz>
6078a0794b7SMarshall Clow    span(array<_Tp, _Sz>&) -> span<_Tp, _Sz>;
6088a0794b7SMarshall Clow
6098a0794b7SMarshall Clowtemplate<class _Tp, size_t _Sz>
6108a0794b7SMarshall Clow    span(const array<_Tp, _Sz>&) -> span<const _Tp, _Sz>;
6118a0794b7SMarshall Clow
6126a7f0551SLouis Dionne#if defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
6136a7f0551SLouis Dionnetemplate<class _Container>
6146a7f0551SLouis Dionne    span(_Container&) -> span<typename _Container::value_type>;
6156a7f0551SLouis Dionne
6166a7f0551SLouis Dionnetemplate<class _Container>
6176a7f0551SLouis Dionne    span(const _Container&) -> span<const typename _Container::value_type>;
6186a7f0551SLouis Dionne#else
6193a208c68SJoe Losertemplate<ranges::contiguous_range _Range>
6203a208c68SJoe Loser    span(_Range&&) -> span<remove_reference_t<ranges::range_reference_t<_Range>>>;
6213a208c68SJoe Loser#endif
6228a0794b7SMarshall Clow
62335773f55SMarshall Clow#endif // _LIBCPP_STD_VER > 17
62435773f55SMarshall Clow
6258a0794b7SMarshall Clow_LIBCPP_END_NAMESPACE_STD
6268a0794b7SMarshall Clow
62703ee4612SArthur O'Dwyer_LIBCPP_POP_MACROS
62803ee4612SArthur O'Dwyer
6298a0794b7SMarshall Clow#endif // _LIBCPP_SPAN
630