annotate libcxx/include/span @ 173:0572611fdcc8 llvm10 llvm12

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