diff options
Diffstat (limited to 'libcxx/include/span')
| -rw-r--r-- | libcxx/include/span | 139 |
1 files changed, 69 insertions, 70 deletions
diff --git a/libcxx/include/span b/libcxx/include/span index b050dfe6e340..f94bda40fa73 100644 --- a/libcxx/include/span +++ b/libcxx/include/span @@ -146,7 +146,6 @@ template<class R> #include <__utility/forward.h> #include <array> // for array #include <cstddef> // for byte -#include <limits> #include <version> // standard-mandated includes @@ -183,12 +182,12 @@ struct __is_std_span<span<_Tp, _Sz>> : true_type {}; template <class _Range, class _ElementType> concept __span_compatible_range = - ranges::contiguous_range<_Range> && - ranges::sized_range<_Range> && - (ranges::borrowed_range<_Range> || is_const_v<_ElementType>) && - !__is_std_span<remove_cvref_t<_Range>>::value && - !__is_std_array<remove_cvref_t<_Range>>::value && - !is_array_v<remove_cvref_t<_Range>> && + ranges::contiguous_range<_Range> && // + ranges::sized_range<_Range> && // + (ranges::borrowed_range<_Range> || is_const_v<_ElementType>) && // + !__is_std_span<remove_cvref_t<_Range>>::value && // + !__is_std_array<remove_cvref_t<_Range>>::value && // + !is_array_v<remove_cvref_t<_Range>> && // is_convertible_v<remove_reference_t<ranges::range_reference_t<_Range>>(*)[], _ElementType(*)[]>; template <class _From, class _To> @@ -217,28 +216,28 @@ public: #else using iterator = __wrap_iter<pointer>; #endif - using reverse_iterator = _VSTD::reverse_iterator<iterator>; + using reverse_iterator = std::reverse_iterator<iterator>; static constexpr size_type extent = _Extent; // [span.cons], span constructors, copy, assignment, and destructor template <size_t _Sz = _Extent> requires(_Sz == 0) - _LIBCPP_INLINE_VISIBILITY constexpr span() noexcept : __data_{nullptr} {} + _LIBCPP_HIDE_FROM_ABI constexpr span() noexcept : __data_{nullptr} {} constexpr span (const span&) noexcept = default; constexpr span& operator=(const span&) noexcept = default; template <__span_compatible_iterator<element_type> _It> - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_HIDE_FROM_ABI constexpr explicit span(_It __first, size_type __count) - : __data_{_VSTD::to_address(__first)} { + : __data_{std::to_address(__first)} { (void)__count; _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(_Extent == __count, "size mismatch in span's constructor (iterator, len)"); } template <__span_compatible_iterator<element_type> _It, __span_compatible_sentinel_for<_It> _End> - _LIBCPP_INLINE_VISIBILITY - constexpr explicit span(_It __first, _End __last) : __data_{_VSTD::to_address(__first)} { + _LIBCPP_HIDE_FROM_ABI + constexpr explicit span(_It __first, _End __last) : __data_{std::to_address(__first)} { // [span.cons]/10 // Throws: When and what last - first throws. [[maybe_unused]] auto __dist = __last - __first; @@ -247,31 +246,31 @@ public: __dist == _Extent, "invalid range in span's constructor (iterator, sentinel): last - first != extent"); } - _LIBCPP_INLINE_VISIBILITY constexpr span(type_identity_t<element_type> (&__arr)[_Extent]) noexcept : __data_{__arr} {} + _LIBCPP_HIDE_FROM_ABI constexpr span(type_identity_t<element_type> (&__arr)[_Extent]) noexcept : __data_{__arr} {} template <__span_array_convertible<element_type> _OtherElementType> - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_HIDE_FROM_ABI constexpr span(array<_OtherElementType, _Extent>& __arr) noexcept : __data_{__arr.data()} {} template <class _OtherElementType> requires __span_array_convertible<const _OtherElementType, element_type> - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_HIDE_FROM_ABI constexpr span(const array<_OtherElementType, _Extent>& __arr) noexcept : __data_{__arr.data()} {} template <__span_compatible_range<element_type> _Range> - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_HIDE_FROM_ABI constexpr explicit span(_Range&& __r) : __data_{ranges::data(__r)} { _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( ranges::size(__r) == _Extent, "size mismatch in span's constructor (range)"); } template <__span_array_convertible<element_type> _OtherElementType> - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_HIDE_FROM_ABI constexpr span(const span<_OtherElementType, _Extent>& __other) : __data_{__other.data()} {} template <__span_array_convertible<element_type> _OtherElementType> - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_HIDE_FROM_ABI constexpr explicit span(const span<_OtherElementType, dynamic_extent>& __other) noexcept : __data_{__other.data()} { _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( @@ -279,7 +278,7 @@ public: } template <size_t _Count> - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_HIDE_FROM_ABI constexpr span<element_type, _Count> first() const noexcept { static_assert(_Count <= _Extent, "span<T, N>::first<Count>(): Count out of range"); @@ -287,21 +286,21 @@ public: } template <size_t _Count> - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_HIDE_FROM_ABI constexpr span<element_type, _Count> last() const noexcept { static_assert(_Count <= _Extent, "span<T, N>::last<Count>(): Count out of range"); return span<element_type, _Count>{data() + size() - _Count, _Count}; } - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_HIDE_FROM_ABI constexpr span<element_type, dynamic_extent> first(size_type __count) const noexcept { _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__count <= size(), "span<T, N>::first(count): count out of range"); return {data(), __count}; } - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_HIDE_FROM_ABI constexpr span<element_type, dynamic_extent> last(size_type __count) const noexcept { _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__count <= size(), "span<T, N>::last(count): count out of range"); @@ -309,7 +308,7 @@ public: } template <size_t _Offset, size_t _Count = dynamic_extent> - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_HIDE_FROM_ABI constexpr auto subspan() const noexcept -> span<element_type, _Count != dynamic_extent ? _Count : _Extent - _Offset> { @@ -321,7 +320,7 @@ public: } - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_HIDE_FROM_ABI constexpr span<element_type, dynamic_extent> subspan(size_type __offset, size_type __count = dynamic_extent) const noexcept { @@ -334,52 +333,52 @@ public: return {data() + __offset, __count}; } - _LIBCPP_INLINE_VISIBILITY constexpr size_type size() const noexcept { return _Extent; } - _LIBCPP_INLINE_VISIBILITY constexpr size_type size_bytes() const noexcept { return _Extent * sizeof(element_type); } - [[nodiscard]] _LIBCPP_INLINE_VISIBILITY constexpr bool empty() const noexcept { return _Extent == 0; } + _LIBCPP_HIDE_FROM_ABI constexpr size_type size() const noexcept { return _Extent; } + _LIBCPP_HIDE_FROM_ABI constexpr size_type size_bytes() const noexcept { return _Extent * sizeof(element_type); } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool empty() const noexcept { return _Extent == 0; } - _LIBCPP_INLINE_VISIBILITY constexpr reference operator[](size_type __idx) const noexcept + _LIBCPP_HIDE_FROM_ABI constexpr reference operator[](size_type __idx) const noexcept { _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__idx < size(), "span<T, N>::operator[](index): index out of range"); return __data_[__idx]; } - _LIBCPP_INLINE_VISIBILITY constexpr reference front() const noexcept + _LIBCPP_HIDE_FROM_ABI constexpr reference front() const noexcept { _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "span<T, N>::front() on empty span"); return __data_[0]; } - _LIBCPP_INLINE_VISIBILITY constexpr reference back() const noexcept + _LIBCPP_HIDE_FROM_ABI constexpr reference back() const noexcept { _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "span<T, N>::back() on empty span"); return __data_[size()-1]; } - _LIBCPP_INLINE_VISIBILITY constexpr pointer data() const noexcept { return __data_; } + _LIBCPP_HIDE_FROM_ABI constexpr pointer data() const noexcept { return __data_; } // [span.iter], span iterator support - _LIBCPP_INLINE_VISIBILITY constexpr iterator begin() const noexcept { + _LIBCPP_HIDE_FROM_ABI constexpr iterator begin() const noexcept { #ifdef _LIBCPP_ABI_BOUNDED_ITERATORS return std::__make_bounded_iter(data(), data(), data() + size()); #else return iterator(data()); #endif } - _LIBCPP_INLINE_VISIBILITY constexpr iterator end() const noexcept { + _LIBCPP_HIDE_FROM_ABI constexpr iterator end() const noexcept { #ifdef _LIBCPP_ABI_BOUNDED_ITERATORS return std::__make_bounded_iter(data() + size(), data(), data() + size()); #else return iterator(data() + size()); #endif } - _LIBCPP_INLINE_VISIBILITY constexpr reverse_iterator rbegin() const noexcept { return reverse_iterator(end()); } - _LIBCPP_INLINE_VISIBILITY constexpr reverse_iterator rend() const noexcept { return reverse_iterator(begin()); } + _LIBCPP_HIDE_FROM_ABI constexpr reverse_iterator rbegin() const noexcept { return reverse_iterator(end()); } + _LIBCPP_HIDE_FROM_ABI constexpr reverse_iterator rend() const noexcept { return reverse_iterator(begin()); } - _LIBCPP_INLINE_VISIBILITY span<const byte, _Extent * sizeof(element_type)> __as_bytes() const noexcept + _LIBCPP_HIDE_FROM_ABI span<const byte, _Extent * sizeof(element_type)> __as_bytes() const noexcept { return span<const byte, _Extent * sizeof(element_type)>{reinterpret_cast<const byte *>(data()), size_bytes()}; } - _LIBCPP_INLINE_VISIBILITY span<byte, _Extent * sizeof(element_type)> __as_writable_bytes() const noexcept + _LIBCPP_HIDE_FROM_ABI span<byte, _Extent * sizeof(element_type)> __as_writable_bytes() const noexcept { return span<byte, _Extent * sizeof(element_type)>{reinterpret_cast<byte *>(data()), size_bytes()}; } private: @@ -404,52 +403,52 @@ public: #else using iterator = __wrap_iter<pointer>; #endif - using reverse_iterator = _VSTD::reverse_iterator<iterator>; + using reverse_iterator = std::reverse_iterator<iterator>; static constexpr size_type extent = dynamic_extent; // [span.cons], span constructors, copy, assignment, and destructor - _LIBCPP_INLINE_VISIBILITY constexpr span() noexcept : __data_{nullptr}, __size_{0} {} + _LIBCPP_HIDE_FROM_ABI constexpr span() noexcept : __data_{nullptr}, __size_{0} {} constexpr span (const span&) noexcept = default; constexpr span& operator=(const span&) noexcept = default; template <__span_compatible_iterator<element_type> _It> - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_HIDE_FROM_ABI constexpr span(_It __first, size_type __count) - : __data_{_VSTD::to_address(__first)}, __size_{__count} {} + : __data_{std::to_address(__first)}, __size_{__count} {} template <__span_compatible_iterator<element_type> _It, __span_compatible_sentinel_for<_It> _End> - _LIBCPP_INLINE_VISIBILITY constexpr span(_It __first, _End __last) - : __data_(_VSTD::to_address(__first)), __size_(__last - __first) { + _LIBCPP_HIDE_FROM_ABI constexpr span(_It __first, _End __last) + : __data_(std::to_address(__first)), __size_(__last - __first) { _LIBCPP_ASSERT_VALID_INPUT_RANGE( __last - __first >= 0, "invalid range in span's constructor (iterator, sentinel)"); } template <size_t _Sz> - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_HIDE_FROM_ABI constexpr span(type_identity_t<element_type> (&__arr)[_Sz]) noexcept : __data_{__arr}, __size_{_Sz} {} template <__span_array_convertible<element_type> _OtherElementType, size_t _Sz> - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_HIDE_FROM_ABI constexpr span(array<_OtherElementType, _Sz>& __arr) noexcept : __data_{__arr.data()}, __size_{_Sz} {} template <class _OtherElementType, size_t _Sz> requires __span_array_convertible<const _OtherElementType, element_type> - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_HIDE_FROM_ABI constexpr span(const array<_OtherElementType, _Sz>& __arr) noexcept : __data_{__arr.data()}, __size_{_Sz} {} template <__span_compatible_range<element_type> _Range> - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_HIDE_FROM_ABI constexpr span(_Range&& __r) : __data_(ranges::data(__r)), __size_{ranges::size(__r)} {} template <__span_array_convertible<element_type> _OtherElementType, size_t _OtherExtent> - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_HIDE_FROM_ABI constexpr span(const span<_OtherElementType, _OtherExtent>& __other) noexcept : __data_{__other.data()}, __size_{__other.size()} {} template <size_t _Count> - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_HIDE_FROM_ABI constexpr span<element_type, _Count> first() const noexcept { _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(_Count <= size(), "span<T>::first<Count>(): Count out of range"); @@ -457,21 +456,21 @@ public: } template <size_t _Count> - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_HIDE_FROM_ABI constexpr span<element_type, _Count> last() const noexcept { _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(_Count <= size(), "span<T>::last<Count>(): Count out of range"); return span<element_type, _Count>{data() + size() - _Count, _Count}; } - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_HIDE_FROM_ABI constexpr span<element_type, dynamic_extent> first(size_type __count) const noexcept { _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__count <= size(), "span<T>::first(count): count out of range"); return {data(), __count}; } - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_HIDE_FROM_ABI constexpr span<element_type, dynamic_extent> last (size_type __count) const noexcept { _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__count <= size(), "span<T>::last(count): count out of range"); @@ -479,7 +478,7 @@ public: } template <size_t _Offset, size_t _Count = dynamic_extent> - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_HIDE_FROM_ABI constexpr span<element_type, _Count> subspan() const noexcept { _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( @@ -490,7 +489,7 @@ public: } constexpr span<element_type, dynamic_extent> - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_HIDE_FROM_ABI subspan(size_type __offset, size_type __count = dynamic_extent) const noexcept { _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__offset <= size(), "span<T>::subspan(offset, count): offset out of range"); @@ -501,53 +500,53 @@ public: return {data() + __offset, __count}; } - _LIBCPP_INLINE_VISIBILITY constexpr size_type size() const noexcept { return __size_; } - _LIBCPP_INLINE_VISIBILITY constexpr size_type size_bytes() const noexcept { return __size_ * sizeof(element_type); } - [[nodiscard]] _LIBCPP_INLINE_VISIBILITY constexpr bool empty() const noexcept { return __size_ == 0; } + _LIBCPP_HIDE_FROM_ABI constexpr size_type size() const noexcept { return __size_; } + _LIBCPP_HIDE_FROM_ABI constexpr size_type size_bytes() const noexcept { return __size_ * sizeof(element_type); } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool empty() const noexcept { return __size_ == 0; } - _LIBCPP_INLINE_VISIBILITY constexpr reference operator[](size_type __idx) const noexcept + _LIBCPP_HIDE_FROM_ABI constexpr reference operator[](size_type __idx) const noexcept { _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__idx < size(), "span<T>::operator[](index): index out of range"); return __data_[__idx]; } - _LIBCPP_INLINE_VISIBILITY constexpr reference front() const noexcept + _LIBCPP_HIDE_FROM_ABI constexpr reference front() const noexcept { _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "span<T>::front() on empty span"); return __data_[0]; } - _LIBCPP_INLINE_VISIBILITY constexpr reference back() const noexcept + _LIBCPP_HIDE_FROM_ABI constexpr reference back() const noexcept { _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "span<T>::back() on empty span"); return __data_[size()-1]; } - _LIBCPP_INLINE_VISIBILITY constexpr pointer data() const noexcept { return __data_; } + _LIBCPP_HIDE_FROM_ABI constexpr pointer data() const noexcept { return __data_; } // [span.iter], span iterator support - _LIBCPP_INLINE_VISIBILITY constexpr iterator begin() const noexcept { + _LIBCPP_HIDE_FROM_ABI constexpr iterator begin() const noexcept { #ifdef _LIBCPP_ABI_BOUNDED_ITERATORS return std::__make_bounded_iter(data(), data(), data() + size()); #else return iterator(data()); #endif } - _LIBCPP_INLINE_VISIBILITY constexpr iterator end() const noexcept { + _LIBCPP_HIDE_FROM_ABI constexpr iterator end() const noexcept { #ifdef _LIBCPP_ABI_BOUNDED_ITERATORS return std::__make_bounded_iter(data() + size(), data(), data() + size()); #else return iterator(data() + size()); #endif } - _LIBCPP_INLINE_VISIBILITY constexpr reverse_iterator rbegin() const noexcept { return reverse_iterator(end()); } - _LIBCPP_INLINE_VISIBILITY constexpr reverse_iterator rend() const noexcept { return reverse_iterator(begin()); } + _LIBCPP_HIDE_FROM_ABI constexpr reverse_iterator rbegin() const noexcept { return reverse_iterator(end()); } + _LIBCPP_HIDE_FROM_ABI constexpr reverse_iterator rend() const noexcept { return reverse_iterator(begin()); } - _LIBCPP_INLINE_VISIBILITY span<const byte, dynamic_extent> __as_bytes() const noexcept + _LIBCPP_HIDE_FROM_ABI span<const byte, dynamic_extent> __as_bytes() const noexcept { return {reinterpret_cast<const byte *>(data()), size_bytes()}; } - _LIBCPP_INLINE_VISIBILITY span<byte, dynamic_extent> __as_writable_bytes() const noexcept + _LIBCPP_HIDE_FROM_ABI span<byte, dynamic_extent> __as_writable_bytes() const noexcept { return {reinterpret_cast<byte *>(data()), size_bytes()}; } private: @@ -563,12 +562,12 @@ inline constexpr bool ranges::enable_view<span<_ElementType, _Extent>> = true; // as_bytes & as_writable_bytes template <class _Tp, size_t _Extent> -_LIBCPP_INLINE_VISIBILITY +_LIBCPP_HIDE_FROM_ABI auto as_bytes(span<_Tp, _Extent> __s) noexcept { return __s.__as_bytes(); } template <class _Tp, size_t _Extent> requires(!is_const_v<_Tp>) -_LIBCPP_INLINE_VISIBILITY +_LIBCPP_HIDE_FROM_ABI auto as_writable_bytes(span<_Tp, _Extent> __s) noexcept { return __s.__as_writable_bytes(); } |
