Index: libcxx/include/iterator =================================================================== --- libcxx/include/iterator +++ libcxx/include/iterator @@ -1442,7 +1442,7 @@ template friend class __wrap_iter; template friend class basic_string; template friend class _LIBCPP_TEMPLATE_VIS vector; - template friend class _LIBCPP_TEMPLATE_VIS span; + template friend class _LIBCPP_TEMPLATE_VIS span; template _LIBCPP_CONSTEXPR_IF_NODEBUG friend Index: libcxx/include/span =================================================================== --- libcxx/include/span +++ libcxx/include/span @@ -16,36 +16,36 @@ namespace std { // constants -inline constexpr ptrdiff_t dynamic_extent = -1; +inline constexpr size_t dynamic_extent = numeric_limits::max(); // [views.span], class template span -template +template class span; // [span.objectrep], views of object representation -template +template span(sizeof(ElementType)) * Extent))> as_bytes(span s) noexcept; -template +template span< byte, ((Extent == dynamic_extent) ? dynamic_extent : (static_cast(sizeof(ElementType)) * Extent))> as_writable_bytes(span s) noexcept; namespace std { -template +template class span { public: // constants and types using element_type = ElementType; using value_type = remove_cv_t; - using index_type = ptrdiff_t; + using index_type = size_t; using difference_type = ptrdiff_t; using pointer = element_type*; using const_pointer = const element_type*; using reference = element_type&; - using iterator = implementation-defined; using const_reference = const element_type&; + using iterator = implementation-defined; using const_iterator = implementation-defined; using reverse_iterator = std::reverse_iterator; using const_reverse_iterator = std::reverse_iterator; @@ -66,17 +66,17 @@ template constexpr span(const Container& cont); constexpr span(const span& other) noexcept = default; - template + template constexpr span(const span& s) noexcept; ~span() noexcept = default; constexpr span& operator=(const span& other) noexcept = default; // [span.sub], span subviews - template + template constexpr span first() const; - template + template constexpr span last() const; - template + template constexpr span subspan() const; constexpr span first(index_type count) const; @@ -143,14 +143,14 @@ #if _LIBCPP_STD_VER > 17 -inline constexpr ptrdiff_t dynamic_extent = -1; -template class span; +inline constexpr size_t dynamic_extent = numeric_limits::max(); +template class span; template struct __is_span_impl : public false_type {}; -template +template struct __is_span_impl> : public true_type {}; template @@ -189,18 +189,18 @@ : public true_type {}; -template +template class _LIBCPP_TEMPLATE_VIS span { public: // constants and types using element_type = _Tp; using value_type = remove_cv_t<_Tp>; - using index_type = ptrdiff_t; + using index_type = size_t; using difference_type = ptrdiff_t; using pointer = _Tp *; - using const_pointer = const _Tp *; + using const_pointer = const _Tp *; // not in standard using reference = _Tp &; - using const_reference = const _Tp &; + using const_reference = const _Tp &; // not in standard using iterator = __wrap_iter; using const_iterator = __wrap_iter; using reverse_iterator = _VSTD::reverse_iterator; @@ -244,20 +244,18 @@ // ~span() noexcept = default; - template + template inline _LIBCPP_INLINE_VISIBILITY constexpr span first() const noexcept { - static_assert(_Count >= 0, "Count must be >= 0 in span::first()"); static_assert(_Count <= _Extent, "Count out of range in span::first()"); return {data(), _Count}; } - template + template inline _LIBCPP_INLINE_VISIBILITY constexpr span last() const noexcept { - static_assert(_Count >= 0, "Count must be >= 0 in span::last()"); static_assert(_Count <= _Extent, "Count out of range in span::last()"); return {data() + size() - _Count, _Count}; } @@ -276,7 +274,7 @@ return {data() + size() - __count, __count}; } - template + template inline _LIBCPP_INLINE_VISIBILITY constexpr auto subspan() const noexcept -> span @@ -359,12 +357,12 @@ // constants and types using element_type = _Tp; using value_type = remove_cv_t<_Tp>; - using index_type = ptrdiff_t; + using index_type = size_t; using difference_type = ptrdiff_t; using pointer = _Tp *; - using const_pointer = const _Tp *; + using const_pointer = const _Tp *; // not in standard using reference = _Tp &; - using const_reference = const _Tp &; + using const_reference = const _Tp &; // not in standard using iterator = __wrap_iter; using const_iterator = __wrap_iter; using reverse_iterator = _VSTD::reverse_iterator; @@ -379,7 +377,7 @@ constexpr span& operator=(const span&) noexcept = default; _LIBCPP_INLINE_VISIBILITY constexpr span(pointer __ptr, index_type __count) : __data{__ptr}, __size{__count} {} - _LIBCPP_INLINE_VISIBILITY constexpr span(pointer __f, pointer __l) : __data{__f}, __size{distance(__f, __l)} {} + _LIBCPP_INLINE_VISIBILITY constexpr span(pointer __f, pointer __l) : __data{__f}, __size{static_cast(distance(__f, __l))} {} template inline _LIBCPP_INLINE_VISIBILITY @@ -406,7 +404,7 @@ : __data{_VSTD::data(__c)}, __size{(index_type) _VSTD::size(__c)} {} - template + template inline _LIBCPP_INLINE_VISIBILITY constexpr span(const span<_OtherElementType, _OtherExtent>& __other, enable_if_t< @@ -416,20 +414,18 @@ // ~span() noexcept = default; - template + template inline _LIBCPP_INLINE_VISIBILITY constexpr span first() const noexcept { - static_assert(_Count >= 0, "Count must be >= 0 in span::first()"); _LIBCPP_ASSERT(_Count <= size(), "Count out of range in span::first()"); return {data(), _Count}; } - template + template inline _LIBCPP_INLINE_VISIBILITY constexpr span last() const noexcept { - static_assert(_Count >= 0, "Count must be >= 0 in span::last()"); _LIBCPP_ASSERT(_Count <= size(), "Count out of range in span::last()"); return {data() + size() - _Count, _Count}; } @@ -448,7 +444,7 @@ return {data() + size() - __count, __count}; } - template + template inline _LIBCPP_INLINE_VISIBILITY constexpr span<_Tp, dynamic_extent> subspan() const noexcept { @@ -527,17 +523,17 @@ }; // as_bytes & as_writeable_bytes -template +template auto as_bytes(span<_Tp, _Extent> __s) noexcept -> decltype(__s.__as_bytes()) { return __s.__as_bytes(); } -template +template auto as_writeable_bytes(span<_Tp, _Extent> __s) noexcept -> typename enable_if, decltype(__s.__as_writeable_bytes())>::type { return __s.__as_writeable_bytes(); } -template +template constexpr void swap(span<_Tp, _Extent> &__lhs, span<_Tp, _Extent> &__rhs) noexcept { __lhs.swap(__rhs); } Index: libcxx/test/std/containers/views/span.cons/default.fail.cpp =================================================================== --- libcxx/test/std/containers/views/span.cons/default.fail.cpp +++ libcxx/test/std/containers/views/span.cons/default.fail.cpp @@ -24,7 +24,7 @@ int main(int, char**) { - std::span s; // expected-error-re@span:* {{static_assert failed{{( due to requirement '2[LL]{0,2} == 0')?}} "Can't default construct a statically sized span with size > 0"}} + std::span s; // expected-error-re@span:* {{static_assert failed{{( due to requirement '.*')?}} "Can't default construct a statically sized span with size > 0"}} // TODO: This is what I want: // eXpected-error {{no matching constructor for initialization of 'std::span'}} Index: libcxx/test/std/containers/views/span.iterators/end.pass.cpp =================================================================== --- libcxx/test/std/containers/views/span.iterators/end.pass.cpp +++ libcxx/test/std/containers/views/span.iterators/end.pass.cpp @@ -38,8 +38,8 @@ ret = ret && (&*(ce-1) == last); } - ret = ret && (( e - s.begin()) == s.size()); - ret = ret && ((ce - s.cbegin()) == s.size()); + ret = ret && (static_cast( e - s.begin()) == s.size()); + ret = ret && (static_cast(ce - s.cbegin()) == s.size()); ret = ret && (e == ce); return ret; @@ -64,8 +64,8 @@ assert( &*(ce-1) == last); } - assert(( e - s.begin()) == s.size()); - assert((ce - s.cbegin()) == s.size()); + assert(static_cast( e - s.begin()) == s.size()); + assert(static_cast(ce - s.cbegin()) == s.size()); assert(e == ce); } Index: libcxx/test/std/containers/views/span.iterators/rend.pass.cpp =================================================================== --- libcxx/test/std/containers/views/span.iterators/rend.pass.cpp +++ libcxx/test/std/containers/views/span.iterators/rend.pass.cpp @@ -35,8 +35,8 @@ ret = ret && (ce != s.crbegin()); } - ret = ret && (( e - s.rbegin()) == s.size()); - ret = ret && ((ce - s.crbegin()) == s.size()); + ret = ret && (static_cast( e - s.rbegin()) == s.size()); + ret = ret && (static_cast(ce - s.crbegin()) == s.size()); ret = ret && (e == ce); return ret; @@ -58,8 +58,8 @@ assert(ce != s.crbegin()); } - assert(( e - s.rbegin()) == s.size()); - assert((ce - s.crbegin()) == s.size()); + assert(static_cast( e - s.rbegin()) == s.size()); + assert(static_cast(ce - s.crbegin()) == s.size()); assert(e == ce); } Index: libcxx/test/std/containers/views/span.obs/size.pass.cpp =================================================================== --- libcxx/test/std/containers/views/span.obs/size.pass.cpp +++ libcxx/test/std/containers/views/span.obs/size.pass.cpp @@ -22,7 +22,7 @@ template -constexpr bool testConstexprSpan(Span sp, ptrdiff_t sz) +constexpr bool testConstexprSpan(Span sp, size_t sz) { ASSERT_NOEXCEPT(sp.size()); return sp.size() == sz; @@ -30,7 +30,7 @@ template -void testRuntimeSpan(Span sp, ptrdiff_t sz) +void testRuntimeSpan(Span sp, size_t sz) { ASSERT_NOEXCEPT(sp.size()); assert(sp.size() == sz); Index: libcxx/test/std/containers/views/types.pass.cpp =================================================================== --- libcxx/test/std/containers/views/types.pass.cpp +++ libcxx/test/std/containers/views/types.pass.cpp @@ -16,7 +16,7 @@ // // constants and types // using element_type = ElementType; // using value_type = remove_cv_t; -// using index_type = ptrdiff_t; +// using index_type = size_t; // using difference_type = ptrdiff_t; // using pointer = element_type *; // using reference = element_type &; @@ -63,12 +63,12 @@ ASSERT_SAME_TYPE(typename ItT::difference_type, typename S::difference_type); } -template +template void testSpan() { ASSERT_SAME_TYPE(typename S::element_type, ElementType); ASSERT_SAME_TYPE(typename S::value_type, std::remove_cv_t); - ASSERT_SAME_TYPE(typename S::index_type, std::ptrdiff_t); + ASSERT_SAME_TYPE(typename S::index_type, size_t); ASSERT_SAME_TYPE(typename S::difference_type, std::ptrdiff_t); ASSERT_SAME_TYPE(typename S::pointer, ElementType *); ASSERT_SAME_TYPE(typename S::const_pointer, const ElementType *); @@ -87,10 +87,10 @@ template void test() { - testSpan, T, -1>(); - testSpan, const T, -1>(); - testSpan, volatile T, -1>(); - testSpan, const volatile T, -1>(); + testSpan, T, std::dynamic_extent>(); + testSpan, const T, std::dynamic_extent>(); + testSpan, volatile T, std::dynamic_extent>(); + testSpan, const volatile T, std::dynamic_extent>(); testSpan, T, 5>(); testSpan, const T, 5>();