span (d56accc7c3dcc897489b6a07834763a03b9f3d68) span (fb03ea46eb853b2d128828e9d82882125bcc1657)
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===---------------------------------------------------------------------===//

--- 156 unchanged lines hidden (view full) ---

165struct __is_std_array<array<_Tp, _Sz>> : true_type {};
166
167template <class _Tp>
168struct __is_std_span : false_type {};
169
170template <class _Tp, size_t _Sz>
171struct __is_std_span<span<_Tp, _Sz>> : true_type {};
172
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===---------------------------------------------------------------------===//

--- 156 unchanged lines hidden (view full) ---

165struct __is_std_array<array<_Tp, _Sz>> : true_type {};
166
167template <class _Tp>
168struct __is_std_span : false_type {};
169
170template <class _Tp, size_t _Sz>
171struct __is_std_span<span<_Tp, _Sz>> : true_type {};
172
173#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
173#if defined(_LIBCPP_HAS_NO_CONCEPTS) || defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
174// This is a temporary workaround until we ship <ranges> -- we've unfortunately been
175// shipping <span> before its API was finalized, and we used to provide a constructor
176// from container types that had the requirements below. To avoid breaking code that
177// has started relying on the range-based constructor until we ship all of <ranges>,
178// we emulate the constructor requirements like this.
179template <class _Range, class _ElementType, class = void>
180struct __span_compatible_range : false_type { };
181
174template <class _Range, class _ElementType>
182template <class _Range, class _ElementType>
183struct __span_compatible_range<_Range, _ElementType, void_t<
184 enable_if_t<!__is_std_span<remove_cvref_t<_Range>>::value>,
185 enable_if_t<!__is_std_array<remove_cvref_t<_Range>>::value>,
186 enable_if_t<!is_array_v<remove_cvref_t<_Range>>>,
187 decltype(data(declval<_Range>())),
188 decltype(size(declval<_Range>())),
189 enable_if_t<is_convertible_v<remove_pointer_t<decltype(data(declval<_Range&>()))>(*)[], _ElementType(*)[]>>
190>> : true_type { };
191#else
192template <class _Range, class _ElementType>
175concept __span_compatible_range =
176 ranges::contiguous_range<_Range> &&
177 ranges::sized_range<_Range> &&
178 (ranges::borrowed_range<_Range> || is_const_v<_ElementType>) &&
179 !__is_std_span<remove_cvref_t<_Range>>::value &&
180 !__is_std_array<remove_cvref_t<_Range>>::value &&
181 !is_array_v<remove_cvref_t<_Range>> &&
182 is_convertible_v<remove_reference_t<ranges::range_reference_t<_Range>>(*)[], _ElementType(*)[]>;

--- 60 unchanged lines hidden (view full) ---

243 _LIBCPP_INLINE_VISIBILITY
244 constexpr span(array<_OtherElementType, _Extent>& __arr) noexcept : __data{__arr.data()} {}
245
246 template <class _OtherElementType,
247 enable_if_t<is_convertible_v<const _OtherElementType(*)[], element_type (*)[]>, nullptr_t> = nullptr>
248 _LIBCPP_INLINE_VISIBILITY
249 constexpr span(const array<_OtherElementType, _Extent>& __arr) noexcept : __data{__arr.data()} {}
250
193concept __span_compatible_range =
194 ranges::contiguous_range<_Range> &&
195 ranges::sized_range<_Range> &&
196 (ranges::borrowed_range<_Range> || is_const_v<_ElementType>) &&
197 !__is_std_span<remove_cvref_t<_Range>>::value &&
198 !__is_std_array<remove_cvref_t<_Range>>::value &&
199 !is_array_v<remove_cvref_t<_Range>> &&
200 is_convertible_v<remove_reference_t<ranges::range_reference_t<_Range>>(*)[], _ElementType(*)[]>;

--- 60 unchanged lines hidden (view full) ---

261 _LIBCPP_INLINE_VISIBILITY
262 constexpr span(array<_OtherElementType, _Extent>& __arr) noexcept : __data{__arr.data()} {}
263
264 template <class _OtherElementType,
265 enable_if_t<is_convertible_v<const _OtherElementType(*)[], element_type (*)[]>, nullptr_t> = nullptr>
266 _LIBCPP_INLINE_VISIBILITY
267 constexpr span(const array<_OtherElementType, _Extent>& __arr) noexcept : __data{__arr.data()} {}
268
251#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
269#if defined(_LIBCPP_HAS_NO_CONCEPTS) || defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
270 template <class _Container, class = enable_if_t<
271 __span_compatible_range<_Container, element_type>::value
272 >>
273 _LIBCPP_INLINE_VISIBILITY
274 constexpr explicit span(_Container& __c) : __data{std::data(__c)} {
275 _LIBCPP_ASSERT(std::size(__c) == _Extent, "size mismatch in span's constructor (range)");
276 }
277 template <class _Container, class = enable_if_t<
278 __span_compatible_range<const _Container, element_type>::value
279 >>
280 _LIBCPP_INLINE_VISIBILITY
281 constexpr explicit span(const _Container& __c) : __data{std::data(__c)} {
282 _LIBCPP_ASSERT(std::size(__c) == _Extent, "size mismatch in span's constructor (range)");
283 }
284#else
252 template <__span_compatible_range<element_type> _Range>
253 _LIBCPP_INLINE_VISIBILITY
254 constexpr explicit span(_Range&& __r) : __data{ranges::data(__r)} {
255 _LIBCPP_ASSERT(ranges::size(__r) == _Extent, "size mismatch in span's constructor (range)");
256 }
257#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
258
259 template <class _OtherElementType>

--- 169 unchanged lines hidden (view full) ---

429 _LIBCPP_INLINE_VISIBILITY
430 constexpr span(array<_OtherElementType, _Sz>& __arr) noexcept : __data{__arr.data()}, __size{_Sz} {}
431
432 template <class _OtherElementType, size_t _Sz,
433 enable_if_t<is_convertible_v<const _OtherElementType(*)[], element_type (*)[]>, nullptr_t> = nullptr>
434 _LIBCPP_INLINE_VISIBILITY
435 constexpr span(const array<_OtherElementType, _Sz>& __arr) noexcept : __data{__arr.data()}, __size{_Sz} {}
436
285 template <__span_compatible_range<element_type> _Range>
286 _LIBCPP_INLINE_VISIBILITY
287 constexpr explicit span(_Range&& __r) : __data{ranges::data(__r)} {
288 _LIBCPP_ASSERT(ranges::size(__r) == _Extent, "size mismatch in span's constructor (range)");
289 }
290#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
291
292 template <class _OtherElementType>

--- 169 unchanged lines hidden (view full) ---

462 _LIBCPP_INLINE_VISIBILITY
463 constexpr span(array<_OtherElementType, _Sz>& __arr) noexcept : __data{__arr.data()}, __size{_Sz} {}
464
465 template <class _OtherElementType, size_t _Sz,
466 enable_if_t<is_convertible_v<const _OtherElementType(*)[], element_type (*)[]>, nullptr_t> = nullptr>
467 _LIBCPP_INLINE_VISIBILITY
468 constexpr span(const array<_OtherElementType, _Sz>& __arr) noexcept : __data{__arr.data()}, __size{_Sz} {}
469
437#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
470#if defined(_LIBCPP_HAS_NO_CONCEPTS) || defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
471 template <class _Container, class = enable_if_t<
472 __span_compatible_range<_Container, element_type>::value
473 >>
474 _LIBCPP_INLINE_VISIBILITY
475 constexpr span(_Container& __c) : __data(std::data(__c)), __size{std::size(__c)} {}
476 template <class _Container, class = enable_if_t<
477 __span_compatible_range<const _Container, element_type>::value
478 >>
479 _LIBCPP_INLINE_VISIBILITY
480 constexpr span(const _Container& __c) : __data(std::data(__c)), __size{std::size(__c)} {}
481#else
438 template <__span_compatible_range<element_type> _Range>
439 _LIBCPP_INLINE_VISIBILITY
440 constexpr span(_Range&& __r) : __data(ranges::data(__r)), __size{ranges::size(__r)} {}
441#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
442
443 template <class _OtherElementType, size_t _OtherExtent>
444 _LIBCPP_INLINE_VISIBILITY
445 constexpr span(const span<_OtherElementType, _OtherExtent>& __other,

--- 147 unchanged lines hidden ---
482 template <__span_compatible_range<element_type> _Range>
483 _LIBCPP_INLINE_VISIBILITY
484 constexpr span(_Range&& __r) : __data(ranges::data(__r)), __size{ranges::size(__r)} {}
485#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
486
487 template <class _OtherElementType, size_t _OtherExtent>
488 _LIBCPP_INLINE_VISIBILITY
489 constexpr span(const span<_OtherElementType, _OtherExtent>& __other,

--- 147 unchanged lines hidden ---