diff options
Diffstat (limited to 'libcxx')
12 files changed, 66 insertions, 67 deletions
diff --git a/libcxx/include/span b/libcxx/include/span index 1cb1a1835c3..c2ed8b17664 100644 --- a/libcxx/include/span +++ b/libcxx/include/span @@ -25,11 +25,11 @@ template <class ElementType, size_t Extent = dynamic_extent> // [span.objectrep], views of object representation template <class ElementType, size_t Extent> span<const byte, ((Extent == dynamic_extent) ? dynamic_extent : - (static_cast<ptrdiff_t>(sizeof(ElementType)) * Extent))> as_bytes(span<ElementType, Extent> s) noexcept; + (sizeof(ElementType) * Extent))> as_bytes(span<ElementType, Extent> s) noexcept; template <class ElementType, size_t Extent> span< byte, ((Extent == dynamic_extent) ? dynamic_extent : - (static_cast<ptrdiff_t>(sizeof(ElementType)) * Extent))> as_writable_bytes(span<ElementType, Extent> s) noexcept; + (sizeof(ElementType) * Extent))> as_writable_bytes(span<ElementType, Extent> s) noexcept; namespace std { @@ -207,7 +207,6 @@ public: using const_reverse_iterator = _VSTD::reverse_iterator<const_iterator>; static constexpr index_type extent = _Extent; - static_assert (_Extent >= 0, "Can't have a span with an extent < 0"); // [span.cons], span constructors, copy, assignment, and destructor _LIBCPP_INLINE_VISIBILITY constexpr span() noexcept : __data{nullptr} @@ -226,7 +225,7 @@ public: _LIBCPP_INLINE_VISIBILITY constexpr span(const array<value_type, _Extent>& __arr) noexcept : __data{__arr.data()} {} template <class _OtherElementType> - inline _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY constexpr span(const span<_OtherElementType, _Extent>& __other, enable_if_t< is_convertible_v<_OtherElementType(*)[], element_type (*)[]>, @@ -234,7 +233,7 @@ public: : __data{__other.data()} {} template <class _OtherElementType> - inline _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY constexpr span(const span<_OtherElementType, dynamic_extent>& __other, enable_if_t< is_convertible_v<_OtherElementType(*)[], element_type (*)[]>, @@ -245,16 +244,16 @@ public: // ~span() noexcept = default; template <size_t _Count> - inline _LIBCPP_INLINE_VISIBILITY - constexpr span<element_type, _Count> first() const noexcept + _LIBCPP_INLINE_VISIBILITY + constexpr span<element_type, _Count> first() const noexcept { static_assert(_Count <= _Extent, "Count out of range in span::first()"); return {data(), _Count}; } template <size_t _Count> - inline _LIBCPP_INLINE_VISIBILITY - constexpr span<element_type, _Count> last() const noexcept + _LIBCPP_INLINE_VISIBILITY + constexpr span<element_type, _Count> last() const noexcept { static_assert(_Count <= _Extent, "Count out of range in span::last()"); return {data() + size() - _Count, _Count}; @@ -263,36 +262,36 @@ public: _LIBCPP_INLINE_VISIBILITY constexpr span<element_type, dynamic_extent> first(index_type __count) const noexcept { - _LIBCPP_ASSERT(__count >= 0 && __count <= size(), "Count out of range in span::first(count)"); + _LIBCPP_ASSERT(__count <= size(), "Count out of range in span::first(count)"); return {data(), __count}; } _LIBCPP_INLINE_VISIBILITY constexpr span<element_type, dynamic_extent> last(index_type __count) const noexcept { - _LIBCPP_ASSERT(__count >= 0 && __count <= size(), "Count out of range in span::last(count)"); + _LIBCPP_ASSERT(__count <= size(), "Count out of range in span::last(count)"); return {data() + size() - __count, __count}; } template <size_t _Offset, size_t _Count = dynamic_extent> - inline _LIBCPP_INLINE_VISIBILITY - constexpr auto subspan() const noexcept + _LIBCPP_INLINE_VISIBILITY + constexpr auto subspan() const noexcept -> span<element_type, _Count != dynamic_extent ? _Count : _Extent - _Offset> { - _LIBCPP_ASSERT(_Offset >= 0 && _Offset <= size(), "Offset out of range in span::subspan()"); + static_assert(_Offset <= _Extent, "Offset out of range in span::subspan()"); return {data() + _Offset, _Count == dynamic_extent ? size() - _Offset : _Count}; } - inline _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY constexpr span<element_type, dynamic_extent> subspan(index_type __offset, index_type __count = dynamic_extent) const noexcept { - _LIBCPP_ASSERT( __offset >= 0 && __offset <= size(), "Offset out of range in span::subspan(offset, count)"); - _LIBCPP_ASSERT((__count >= 0 && __count <= size()) || __count == dynamic_extent, "Count out of range in span::subspan(offset, count)"); + _LIBCPP_ASSERT(__offset <= size(), "Offset out of range in span::subspan(offset, count)"); + _LIBCPP_ASSERT(__count <= size() || __count == dynamic_extent, "Count out of range in span::subspan(offset, count)"); if (__count == dynamic_extent) return {data() + __offset, size() - __offset}; - _LIBCPP_ASSERT(__offset + __count <= size(), "count + offset out of range in span::subspan(offset, count)"); + _LIBCPP_ASSERT(__offset <= size() - __count, "count + offset out of range in span::subspan(offset, count)"); return {data() + __offset, __count}; } @@ -380,32 +379,32 @@ public: _LIBCPP_INLINE_VISIBILITY constexpr span(pointer __f, pointer __l) : __data{__f}, __size{static_cast<size_t>(distance(__f, __l))} {} template <size_t _Sz> - inline _LIBCPP_INLINE_VISIBILITY - constexpr span(element_type (&__arr)[_Sz]) noexcept : __data{__arr}, __size{_Sz} {} + _LIBCPP_INLINE_VISIBILITY + constexpr span(element_type (&__arr)[_Sz]) noexcept : __data{__arr}, __size{_Sz} {} template <size_t _Sz> - inline _LIBCPP_INLINE_VISIBILITY - constexpr span(array<value_type, _Sz>& __arr) noexcept : __data{__arr.data()}, __size{_Sz} {} + _LIBCPP_INLINE_VISIBILITY + constexpr span(array<value_type, _Sz>& __arr) noexcept : __data{__arr.data()}, __size{_Sz} {} template <size_t _Sz> - inline _LIBCPP_INLINE_VISIBILITY - constexpr span(const array<value_type, _Sz>& __arr) noexcept : __data{__arr.data()}, __size{_Sz} {} + _LIBCPP_INLINE_VISIBILITY + constexpr span(const array<value_type, _Sz>& __arr) noexcept : __data{__arr.data()}, __size{_Sz} {} template <class _Container> - inline _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY constexpr span( _Container& __c, enable_if_t<__is_span_compatible_container<_Container, _Tp>::value, nullptr_t> = nullptr) : __data{_VSTD::data(__c)}, __size{(index_type) _VSTD::size(__c)} {} template <class _Container> - inline _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY constexpr span(const _Container& __c, enable_if_t<__is_span_compatible_container<const _Container, _Tp>::value, nullptr_t> = nullptr) : __data{_VSTD::data(__c)}, __size{(index_type) _VSTD::size(__c)} {} template <class _OtherElementType, size_t _OtherExtent> - inline _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY constexpr span(const span<_OtherElementType, _OtherExtent>& __other, enable_if_t< is_convertible_v<_OtherElementType(*)[], element_type (*)[]>, @@ -415,16 +414,16 @@ public: // ~span() noexcept = default; template <size_t _Count> - inline _LIBCPP_INLINE_VISIBILITY - constexpr span<element_type, _Count> first() const noexcept + _LIBCPP_INLINE_VISIBILITY + constexpr span<element_type, _Count> first() const noexcept { _LIBCPP_ASSERT(_Count <= size(), "Count out of range in span::first()"); return {data(), _Count}; } template <size_t _Count> - inline _LIBCPP_INLINE_VISIBILITY - constexpr span<element_type, _Count> last() const noexcept + _LIBCPP_INLINE_VISIBILITY + constexpr span<element_type, _Count> last() const noexcept { _LIBCPP_ASSERT(_Count <= size(), "Count out of range in span::last()"); return {data() + size() - _Count, _Count}; @@ -433,35 +432,35 @@ public: _LIBCPP_INLINE_VISIBILITY constexpr span<element_type, dynamic_extent> first(index_type __count) const noexcept { - _LIBCPP_ASSERT(__count >= 0 && __count <= size(), "Count out of range in span::first(count)"); + _LIBCPP_ASSERT(__count <= size(), "Count out of range in span::first(count)"); return {data(), __count}; } _LIBCPP_INLINE_VISIBILITY constexpr span<element_type, dynamic_extent> last (index_type __count) const noexcept { - _LIBCPP_ASSERT(__count >= 0 && __count <= size(), "Count out of range in span::last(count)"); + _LIBCPP_ASSERT(__count <= size(), "Count out of range in span::last(count)"); return {data() + size() - __count, __count}; } template <size_t _Offset, size_t _Count = dynamic_extent> - inline _LIBCPP_INLINE_VISIBILITY - constexpr span<_Tp, dynamic_extent> subspan() const noexcept + _LIBCPP_INLINE_VISIBILITY + constexpr span<_Tp, dynamic_extent> subspan() const noexcept { - _LIBCPP_ASSERT(_Offset >= 0 && _Offset <= size(), "Offset out of range in span::subspan()"); + _LIBCPP_ASSERT(_Offset <= size(), "Offset out of range in span::subspan()"); _LIBCPP_ASSERT(_Count == dynamic_extent || _Offset + _Count <= size(), "Count out of range in span::subspan()"); return {data() + _Offset, _Count == dynamic_extent ? size() - _Offset : _Count}; } constexpr span<element_type, dynamic_extent> - inline _LIBCPP_INLINE_VISIBILITY - subspan(index_type __offset, index_type __count = dynamic_extent) const noexcept + _LIBCPP_INLINE_VISIBILITY + subspan(index_type __offset, index_type __count = dynamic_extent) const noexcept { - _LIBCPP_ASSERT( __offset >= 0 && __offset <= size(), "Offset out of range in span::subspan(offset, count)"); - _LIBCPP_ASSERT((__count >= 0 && __count <= size()) || __count == dynamic_extent, "count out of range in span::subspan(offset, count)"); + _LIBCPP_ASSERT(__offset <= size(), "Offset out of range in span::subspan(offset, count)"); + _LIBCPP_ASSERT(__count <= size() || __count == dynamic_extent, "count out of range in span::subspan(offset, count)"); if (__count == dynamic_extent) return {data() + __offset, size() - __offset}; - _LIBCPP_ASSERT(__offset + __count <= size(), "Offset + count out of range in span::subspan(offset, count)"); + _LIBCPP_ASSERT(__offset <= size() - __count, "Offset + count out of range in span::subspan(offset, count)"); return {data() + __offset, __count}; } diff --git a/libcxx/test/std/containers/views/span.cons/span.fail.cpp b/libcxx/test/std/containers/views/span.cons/span.fail.cpp index f559b1fb0c2..c303719fd01 100644 --- a/libcxx/test/std/containers/views/span.cons/span.fail.cpp +++ b/libcxx/test/std/containers/views/span.cons/span.fail.cpp @@ -10,7 +10,7 @@ // <span> -// template<class OtherElementType, ptrdiff_t OtherExtent> +// template<class OtherElementType, size_t OtherExtent> // constexpr span(const span<OtherElementType, OtherExtent>& s) noexcept; // // Remarks: This constructor shall not participate in overload resolution unless: diff --git a/libcxx/test/std/containers/views/span.cons/span.pass.cpp b/libcxx/test/std/containers/views/span.cons/span.pass.cpp index 74da3fce894..62f8b9da11b 100644 --- a/libcxx/test/std/containers/views/span.cons/span.pass.cpp +++ b/libcxx/test/std/containers/views/span.cons/span.pass.cpp @@ -10,7 +10,7 @@ // <span> -// template<class OtherElementType, ptrdiff_t OtherExtent> +// template<class OtherElementType, size_t OtherExtent> // constexpr span(const span<OtherElementType, OtherExtent>& s) noexcept; // // Remarks: This constructor shall not participate in overload resolution unless: diff --git a/libcxx/test/std/containers/views/span.elem/op_idx.pass.cpp b/libcxx/test/std/containers/views/span.elem/op_idx.pass.cpp index cb63ec9d17b..893331ad8f1 100644 --- a/libcxx/test/std/containers/views/span.elem/op_idx.pass.cpp +++ b/libcxx/test/std/containers/views/span.elem/op_idx.pass.cpp @@ -23,7 +23,7 @@ template <typename Span> -constexpr bool testConstexprSpan(Span sp, ptrdiff_t idx) +constexpr bool testConstexprSpan(Span sp, size_t idx) { _LIBCPP_ASSERT(noexcept(sp[idx]), ""); @@ -34,7 +34,7 @@ constexpr bool testConstexprSpan(Span sp, ptrdiff_t idx) template <typename Span> -void testRuntimeSpan(Span sp, ptrdiff_t idx) +void testRuntimeSpan(Span sp, size_t idx) { _LIBCPP_ASSERT(noexcept(sp[idx]), ""); diff --git a/libcxx/test/std/containers/views/span.objectrep/as_bytes.pass.cpp b/libcxx/test/std/containers/views/span.objectrep/as_bytes.pass.cpp index 12772c42f16..ff1038e0b11 100644 --- a/libcxx/test/std/containers/views/span.objectrep/as_bytes.pass.cpp +++ b/libcxx/test/std/containers/views/span.objectrep/as_bytes.pass.cpp @@ -10,11 +10,11 @@ // <span> -// template <class ElementType, ptrdiff_t Extent> +// template <class ElementType, size_t Extent> // span<const byte, // Extent == dynamic_extent // ? dynamic_extent -// : static_cast<ptrdiff_t>(sizeof(ElementType)) * Extent> +// : sizeof(ElementType) * Extent> // as_bytes(span<ElementType, Extent> s) noexcept; @@ -36,7 +36,7 @@ void testRuntimeSpan(Span sp) if (sp.extent == std::dynamic_extent) assert(spBytes.extent == std::dynamic_extent); else - assert(spBytes.extent == static_cast<std::ptrdiff_t>(sizeof(typename Span::element_type)) * sp.extent); + assert(spBytes.extent == sizeof(typename Span::element_type) * sp.extent); assert((void *) spBytes.data() == (void *) sp.data()); assert(spBytes.size() == sp.size_bytes()); diff --git a/libcxx/test/std/containers/views/span.objectrep/as_writeable_bytes.fail.cpp b/libcxx/test/std/containers/views/span.objectrep/as_writeable_bytes.fail.cpp index 9dadedd7523..388da084ae0 100644 --- a/libcxx/test/std/containers/views/span.objectrep/as_writeable_bytes.fail.cpp +++ b/libcxx/test/std/containers/views/span.objectrep/as_writeable_bytes.fail.cpp @@ -10,11 +10,11 @@ // <span> -// template <class ElementType, ptrdiff_t Extent> +// template <class ElementType, size_t Extent> // span<byte, // Extent == dynamic_extent // ? dynamic_extent -// : static_cast<ptrdiff_t>(sizeof(ElementType)) * Extent> +// : sizeof(ElementType) * Extent> // as_writeable_bytes(span<ElementType, Extent> s) noexcept; diff --git a/libcxx/test/std/containers/views/span.objectrep/as_writeable_bytes.pass.cpp b/libcxx/test/std/containers/views/span.objectrep/as_writeable_bytes.pass.cpp index b12500d4ffb..409f6fa7cd6 100644 --- a/libcxx/test/std/containers/views/span.objectrep/as_writeable_bytes.pass.cpp +++ b/libcxx/test/std/containers/views/span.objectrep/as_writeable_bytes.pass.cpp @@ -10,11 +10,11 @@ // <span> -// template <class ElementType, ptrdiff_t Extent> +// template <class ElementType, size_t Extent> // span<byte, // Extent == dynamic_extent // ? dynamic_extent -// : static_cast<ptrdiff_t>(sizeof(ElementType)) * Extent> +// : sizeof(ElementType) * Extent> // as_writeable_bytes(span<ElementType, Extent> s) noexcept; @@ -36,7 +36,7 @@ void testRuntimeSpan(Span sp) if (sp.extent == std::dynamic_extent) assert(spBytes.extent == std::dynamic_extent); else - assert(spBytes.extent == static_cast<std::ptrdiff_t>(sizeof(typename Span::element_type)) * sp.extent); + assert(spBytes.extent == sizeof(typename Span::element_type) * sp.extent); assert(static_cast<void*>(spBytes.data()) == static_cast<void*>(sp.data())); assert(spBytes.size() == sp.size_bytes()); diff --git a/libcxx/test/std/containers/views/span.obs/size_bytes.pass.cpp b/libcxx/test/std/containers/views/span.obs/size_bytes.pass.cpp index 447829d516e..257956684ea 100644 --- a/libcxx/test/std/containers/views/span.obs/size_bytes.pass.cpp +++ b/libcxx/test/std/containers/views/span.obs/size_bytes.pass.cpp @@ -23,7 +23,7 @@ template <typename Span> -constexpr bool testConstexprSpan(Span sp, ptrdiff_t sz) +constexpr bool testConstexprSpan(Span sp, size_t sz) { ASSERT_NOEXCEPT(sp.size_bytes()); return (size_t) sp.size_bytes() == sz * sizeof(typename Span::element_type); @@ -31,7 +31,7 @@ constexpr bool testConstexprSpan(Span sp, ptrdiff_t sz) template <typename Span> -void testRuntimeSpan(Span sp, ptrdiff_t sz) +void testRuntimeSpan(Span sp, size_t sz) { ASSERT_NOEXCEPT(sp.size_bytes()); assert((size_t) sp.size_bytes() == sz * sizeof(typename Span::element_type)); diff --git a/libcxx/test/std/containers/views/span.sub/first.pass.cpp b/libcxx/test/std/containers/views/span.sub/first.pass.cpp index f9da9fdc233..30ab130381c 100644 --- a/libcxx/test/std/containers/views/span.sub/first.pass.cpp +++ b/libcxx/test/std/containers/views/span.sub/first.pass.cpp @@ -10,7 +10,7 @@ // <span> -// template<ptrdiff_t Count> +// template<size_t Count> // constexpr span<element_type, Count> first() const; // // constexpr span<element_type, dynamic_extent> first(index_type count) const; @@ -25,7 +25,7 @@ #include "test_macros.h" -template <typename Span, ptrdiff_t Count> +template <typename Span, size_t Count> constexpr bool testConstexprSpan(Span sp) { LIBCPP_ASSERT((noexcept(sp.template first<Count>()))); @@ -45,7 +45,7 @@ constexpr bool testConstexprSpan(Span sp) } -template <typename Span, ptrdiff_t Count> +template <typename Span, size_t Count> void testRuntimeSpan(Span sp) { LIBCPP_ASSERT((noexcept(sp.template first<Count>()))); diff --git a/libcxx/test/std/containers/views/span.sub/last.pass.cpp b/libcxx/test/std/containers/views/span.sub/last.pass.cpp index e0a399ff9cd..2864a7f65e5 100644 --- a/libcxx/test/std/containers/views/span.sub/last.pass.cpp +++ b/libcxx/test/std/containers/views/span.sub/last.pass.cpp @@ -10,7 +10,7 @@ // <span> -// template<ptrdiff_t Count> +// template<size_t Count> // constexpr span<element_type, Count> last() const; // // constexpr span<element_type, dynamic_extent> last(index_type count) const; @@ -25,7 +25,7 @@ #include "test_macros.h" -template <typename Span, ptrdiff_t Count> +template <typename Span, size_t Count> constexpr bool testConstexprSpan(Span sp) { LIBCPP_ASSERT((noexcept(sp.template last<Count>()))); @@ -45,7 +45,7 @@ constexpr bool testConstexprSpan(Span sp) } -template <typename Span, ptrdiff_t Count> +template <typename Span, size_t Count> void testRuntimeSpan(Span sp) { LIBCPP_ASSERT((noexcept(sp.template last<Count>()))); diff --git a/libcxx/test/std/containers/views/span.sub/subspan.pass.cpp b/libcxx/test/std/containers/views/span.sub/subspan.pass.cpp index 9cb73109347..f2dbe8408dd 100644 --- a/libcxx/test/std/containers/views/span.sub/subspan.pass.cpp +++ b/libcxx/test/std/containers/views/span.sub/subspan.pass.cpp @@ -10,7 +10,7 @@ // <span> -// template<ptrdiff_t Offset, ptrdiff_t Count = dynamic_extent> +// template<size_t Offset, size_t Count = dynamic_extent> // constexpr span<element_type, see below> subspan() const; // // constexpr span<element_type, dynamic_extent> subspan( @@ -26,7 +26,7 @@ #include "test_macros.h" -template <typename Span, ptrdiff_t Offset, ptrdiff_t Count> +template <typename Span, size_t Offset, size_t Count> constexpr bool testConstexprSpan(Span sp) { LIBCPP_ASSERT((noexcept(sp.template subspan<Offset, Count>()))); @@ -45,7 +45,7 @@ constexpr bool testConstexprSpan(Span sp) && std::equal(s1.begin(), s1.end(), sp.begin() + Offset); } -template <typename Span, ptrdiff_t Offset> +template <typename Span, size_t Offset> constexpr bool testConstexprSpan(Span sp) { LIBCPP_ASSERT((noexcept(sp.template subspan<Offset>()))); @@ -65,7 +65,7 @@ constexpr bool testConstexprSpan(Span sp) } -template <typename Span, ptrdiff_t Offset, ptrdiff_t Count> +template <typename Span, size_t Offset, size_t Count> void testRuntimeSpan(Span sp) { LIBCPP_ASSERT((noexcept(sp.template subspan<Offset, Count>()))); @@ -84,7 +84,7 @@ void testRuntimeSpan(Span sp) } -template <typename Span, ptrdiff_t Offset> +template <typename Span, size_t Offset> void testRuntimeSpan(Span sp) { LIBCPP_ASSERT((noexcept(sp.template subspan<Offset>()))); diff --git a/libcxx/test/std/containers/views/types.pass.cpp b/libcxx/test/std/containers/views/types.pass.cpp index 60c365b8938..787cfdd4e0c 100644 --- a/libcxx/test/std/containers/views/types.pass.cpp +++ b/libcxx/test/std/containers/views/types.pass.cpp @@ -10,7 +10,7 @@ // <span> -// template<class ElementType, ptrdiff_t Extent = dynamic_extent> +// template<class ElementType, size_t Extent = dynamic_extent> // class span { // public: // // constants and types |