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