[libc++][P1872] span should have size_type, not index_type.

Thanks to Marek Kurdej for the patch.

Differential Revision: https://reviews.llvm.org/D70206
This commit is contained in:
Louis Dionne 2019-11-14 09:07:05 -05:00
parent 8b77a3a0f4
commit 1466335cf4
13 changed files with 53 additions and 53 deletions

View File

@ -39,7 +39,7 @@ public:
// constants and types
using element_type = ElementType;
using value_type = remove_cv_t<ElementType>;
using index_type = size_t;
using size_type = size_t;
using difference_type = ptrdiff_t;
using pointer = element_type*;
using const_pointer = const element_type*;
@ -49,11 +49,11 @@ public:
using const_iterator = implementation-defined;
using reverse_iterator = std::reverse_iterator<iterator>;
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
static constexpr index_type extent = Extent;
static constexpr size_type extent = Extent;
// [span.cons], span constructors, copy, assignment, and destructor
constexpr span() noexcept;
constexpr span(pointer ptr, index_type count);
constexpr span(pointer ptr, size_type count);
constexpr span(pointer firstElem, pointer lastElem);
template <size_t N>
constexpr span(element_type (&arr)[N]) noexcept;
@ -79,17 +79,17 @@ public:
template <size_t Offset, size_t Count = dynamic_extent>
constexpr span<element_type, see below> subspan() const;
constexpr span<element_type, dynamic_extent> first(index_type count) const;
constexpr span<element_type, dynamic_extent> last(index_type count) const;
constexpr span<element_type, dynamic_extent> subspan(index_type offset, index_type count = dynamic_extent) const;
constexpr span<element_type, dynamic_extent> first(size_type count) const;
constexpr span<element_type, dynamic_extent> last(size_type count) const;
constexpr span<element_type, dynamic_extent> subspan(size_type offset, size_type count = dynamic_extent) const;
// [span.obs], span observers
constexpr index_type size() const noexcept;
constexpr index_type size_bytes() const noexcept;
constexpr size_type size() const noexcept;
constexpr size_type size_bytes() const noexcept;
constexpr bool empty() const noexcept;
// [span.elem], span element access
constexpr reference operator[](index_type idx) const;
constexpr reference operator[](size_type idx) const;
constexpr reference front() const;
constexpr reference back() const;
constexpr pointer data() const noexcept;
@ -105,8 +105,8 @@ public:
constexpr const_reverse_iterator crend() const noexcept;
private:
pointer data_; // exposition only
index_type size_; // exposition only
pointer data_; // exposition only
size_type size_; // exposition only
};
template<class T, size_t N>
@ -195,7 +195,7 @@ public:
// constants and types
using element_type = _Tp;
using value_type = remove_cv_t<_Tp>;
using index_type = size_t;
using size_type = size_t;
using difference_type = ptrdiff_t;
using pointer = _Tp *;
using const_pointer = const _Tp *;
@ -206,7 +206,7 @@ public:
using reverse_iterator = _VSTD::reverse_iterator<iterator>;
using const_reverse_iterator = _VSTD::reverse_iterator<const_iterator>;
static constexpr index_type extent = _Extent;
static constexpr size_type extent = _Extent;
// [span.cons], span constructors, copy, assignment, and destructor
_LIBCPP_INLINE_VISIBILITY constexpr span() noexcept : __data{nullptr}
@ -215,7 +215,7 @@ public:
constexpr span (const span&) noexcept = default;
constexpr span& operator=(const span&) noexcept = default;
_LIBCPP_INLINE_VISIBILITY constexpr span(pointer __ptr, index_type __count) : __data{__ptr}
_LIBCPP_INLINE_VISIBILITY constexpr span(pointer __ptr, size_type __count) : __data{__ptr}
{ (void)__count; _LIBCPP_ASSERT(_Extent == __count, "size mismatch in span's constructor (ptr, len)"); }
_LIBCPP_INLINE_VISIBILITY constexpr span(pointer __f, pointer __l) : __data{__f}
{ (void)__l; _LIBCPP_ASSERT(_Extent == distance(__f, __l), "size mismatch in span's constructor (ptr, ptr)"); }
@ -260,14 +260,14 @@ public:
}
_LIBCPP_INLINE_VISIBILITY
constexpr span<element_type, dynamic_extent> first(index_type __count) const noexcept
constexpr span<element_type, dynamic_extent> first(size_type __count) const noexcept
{
_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
constexpr span<element_type, dynamic_extent> last(size_type __count) const noexcept
{
_LIBCPP_ASSERT(__count <= size(), "Count out of range in span::last(count)");
return {data() + size() - __count, __count};
@ -285,7 +285,7 @@ public:
_LIBCPP_INLINE_VISIBILITY
constexpr span<element_type, dynamic_extent>
subspan(index_type __offset, index_type __count = dynamic_extent) const noexcept
subspan(size_type __offset, size_type __count = dynamic_extent) const noexcept
{
_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)");
@ -295,11 +295,11 @@ public:
return {data() + __offset, __count};
}
_LIBCPP_INLINE_VISIBILITY constexpr index_type size() const noexcept { return _Extent; }
_LIBCPP_INLINE_VISIBILITY constexpr index_type size_bytes() const noexcept { return _Extent * sizeof(element_type); }
_LIBCPP_INLINE_VISIBILITY constexpr bool empty() const noexcept { return _Extent == 0; }
_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); }
_LIBCPP_INLINE_VISIBILITY constexpr bool empty() const noexcept { return _Extent == 0; }
_LIBCPP_INLINE_VISIBILITY constexpr reference operator[](index_type __idx) const noexcept
_LIBCPP_INLINE_VISIBILITY constexpr reference operator[](size_type __idx) const noexcept
{
_LIBCPP_ASSERT(__idx >= 0 && __idx < size(), "span<T,N>[] index out of bounds");
return __data[__idx];
@ -356,7 +356,7 @@ public:
// constants and types
using element_type = _Tp;
using value_type = remove_cv_t<_Tp>;
using index_type = size_t;
using size_type = size_t;
using difference_type = ptrdiff_t;
using pointer = _Tp *;
using const_pointer = const _Tp *;
@ -367,7 +367,7 @@ public:
using reverse_iterator = _VSTD::reverse_iterator<iterator>;
using const_reverse_iterator = _VSTD::reverse_iterator<const_iterator>;
static constexpr index_type extent = dynamic_extent;
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} {}
@ -375,7 +375,7 @@ public:
constexpr span (const span&) noexcept = default;
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 __ptr, size_type __count) : __data{__ptr}, __size{__count} {}
_LIBCPP_INLINE_VISIBILITY constexpr span(pointer __f, pointer __l) : __data{__f}, __size{static_cast<size_t>(distance(__f, __l))} {}
template <size_t _Sz>
@ -394,13 +394,13 @@ public:
_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)} {}
: __data{_VSTD::data(__c)}, __size{(size_type) _VSTD::size(__c)} {}
template <class _Container>
_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)} {}
: __data{_VSTD::data(__c)}, __size{(size_type) _VSTD::size(__c)} {}
template <class _OtherElementType, size_t _OtherExtent>
@ -430,14 +430,14 @@ public:
}
_LIBCPP_INLINE_VISIBILITY
constexpr span<element_type, dynamic_extent> first(index_type __count) const noexcept
constexpr span<element_type, dynamic_extent> first(size_type __count) const noexcept
{
_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
constexpr span<element_type, dynamic_extent> last (size_type __count) const noexcept
{
_LIBCPP_ASSERT(__count <= size(), "Count out of range in span::last(count)");
return {data() + size() - __count, __count};
@ -454,7 +454,7 @@ public:
constexpr span<element_type, dynamic_extent>
_LIBCPP_INLINE_VISIBILITY
subspan(index_type __offset, index_type __count = dynamic_extent) const noexcept
subspan(size_type __offset, size_type __count = dynamic_extent) const noexcept
{
_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)");
@ -464,11 +464,11 @@ public:
return {data() + __offset, __count};
}
_LIBCPP_INLINE_VISIBILITY constexpr index_type size() const noexcept { return __size; }
_LIBCPP_INLINE_VISIBILITY constexpr index_type size_bytes() const noexcept { return __size * sizeof(element_type); }
_LIBCPP_INLINE_VISIBILITY constexpr bool empty() const noexcept { return __size == 0; }
_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); }
_LIBCPP_INLINE_VISIBILITY constexpr bool empty() const noexcept { return __size == 0; }
_LIBCPP_INLINE_VISIBILITY constexpr reference operator[](index_type __idx) const noexcept
_LIBCPP_INLINE_VISIBILITY constexpr reference operator[](size_type __idx) const noexcept
{
_LIBCPP_ASSERT(__idx >= 0 && __idx < size(), "span<T>[] index out of bounds");
return __data[__idx];
@ -505,7 +505,7 @@ public:
__data = __other.__data;
__other.__data = __p;
index_type __sz = __size;
size_type __sz = __size;
__size = __other.__size;
__other.__size = __sz;
}
@ -517,8 +517,8 @@ public:
{ return {reinterpret_cast<byte *>(data()), size_bytes()}; }
private:
pointer __data;
index_type __size;
pointer __data;
size_type __size;
};
// tuple interface

View File

@ -43,11 +43,11 @@ int main(int, char**)
// constexpr dynamically sized assignment
{
// On systems where 'ptrdiff_t' is a synonym for 'int',
// the call span(ptr, 0) selects the (pointer, index_type) constructor.
// the call span(ptr, 0) selects the (pointer, size_type) constructor.
// On systems where 'ptrdiff_t' is NOT a synonym for 'int',
// it is ambiguous, because of 0 also being convertible to a null pointer
// and so the compiler can't choose between:
// span(pointer, index_type)
// span(pointer, size_type)
// and span(pointer, pointer)
// We cast zero to std::ptrdiff_t to remove that ambiguity.
// Example:

View File

@ -10,7 +10,7 @@
// <span>
// constexpr span(pointer ptr, index_type count);
// constexpr span(pointer ptr, size_type count);
// Requires: [ptr, ptr + count) shall be a valid range.
// If extent is not equal to dynamic_extent, then count shall be equal to extent.
//

View File

@ -10,7 +10,7 @@
// <span>
// constexpr span(pointer ptr, index_type count);
// constexpr span(pointer ptr, size_type count);
// Requires: [ptr, ptr + count) shall be a valid range.
// If extent is not equal to dynamic_extent, then count shall be equal to extent.
//

View File

@ -10,8 +10,8 @@
// <span>
// constexpr reference operator[](index_type idx) const;
// constexpr reference operator()(index_type idx) const;
// constexpr reference operator[](size_type idx) const;
// constexpr reference operator()(size_type idx) const;
//

View File

@ -31,7 +31,7 @@ constexpr bool testConstexprSpan(Span s)
}
else
{
const typename Span::index_type last = s.size() - 1;
const typename Span::size_type last = s.size() - 1;
ret = ret && ( *b == s[last]);
ret = ret && ( &*b == &s[last]);
ret = ret && ( *cb == s[last]);
@ -54,7 +54,7 @@ void testRuntimeSpan(Span s)
}
else
{
const typename Span::index_type last = s.size() - 1;
const typename Span::size_type last = s.size() - 1;
assert( *b == s[last]);
assert( &*b == &s[last]);
assert( *cb == s[last]);

View File

@ -10,7 +10,7 @@
// <span>
// constexpr index_type size() const noexcept;
// constexpr size_type size() const noexcept;
//

View File

@ -10,7 +10,7 @@
// <span>
// constexpr index_type size_bytes() const noexcept;
// constexpr size_type size_bytes() const noexcept;
//
// Effects: Equivalent to: return size() * sizeof(element_type);

View File

@ -13,7 +13,7 @@
// template<size_t Count>
// constexpr span<element_type, Count> first() const;
//
// constexpr span<element_type, dynamic_extent> first(index_type count) const;
// constexpr span<element_type, dynamic_extent> first(size_type count) const;
//
// Requires: 0 <= Count && Count <= size().

View File

@ -13,7 +13,7 @@
// template<size_t Count>
// constexpr span<element_type, Count> last() const;
//
// constexpr span<element_type, dynamic_extent> last(index_type count) const;
// constexpr span<element_type, dynamic_extent> last(size_type count) const;
//
// Requires: 0 <= Count && Count <= size().

View File

@ -14,7 +14,7 @@
// constexpr span<element_type, see below> subspan() const;
//
// constexpr span<element_type, dynamic_extent> subspan(
// index_type offset, index_type count = dynamic_extent) const;
// size_type offset, size_type count = dynamic_extent) const;
//
// Requires: (0 <= Offset && Offset <= size())
// && (Count == dynamic_extent || Count >= 0 && Offset + Count <= size())

View File

@ -16,7 +16,7 @@
// // constants and types
// using element_type = ElementType;
// using value_type = remove_cv_t<ElementType>;
// using index_type = size_t;
// using size_type = size_t;
// using difference_type = ptrdiff_t;
// using pointer = element_type *;
// using reference = element_type &;
@ -27,7 +27,7 @@
// using reverse_iterator = std::reverse_iterator<iterator>;
// using const_reverse_iterator = std::reverse_iterator<const_iterator>;
//
// static constexpr index_type extent = Extent;
// static constexpr size_type extent = Extent;
//
#include <span>
@ -68,7 +68,7 @@ void testSpan()
{
ASSERT_SAME_TYPE(typename S::element_type, ElementType);
ASSERT_SAME_TYPE(typename S::value_type, std::remove_cv_t<ElementType>);
ASSERT_SAME_TYPE(typename S::index_type, std::size_t);
ASSERT_SAME_TYPE(typename S::size_type, std::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 *);

View File

@ -215,7 +215,7 @@
<tr><td><a href="https://wg21.link/P1869">P1869</a></td><td>LWG</td><td>Rename 'condition_variable_any' interruptible wait methods </td><td>Belfast</td><td><i> </i></td><td></td></tr>
<tr><td><a href="https://wg21.link/P1870">P1870</a></td><td>LWG</td><td>forwarding-range is too subtle </td><td>Belfast</td><td><i> </i></td><td></td></tr>
<tr><td><a href="https://wg21.link/P1871">P1871</a></td><td>LWG</td><td>Should concepts be enabled or disabled? </td><td>Belfast</td><td><i> </i></td><td></td></tr>
<tr><td><a href="https://wg21.link/P1872">P1872</a></td><td>LWG</td><td>span should have size_type, not index_type </td><td>Belfast</td><td><i> </i></td><td></td></tr>
<tr><td><a href="https://wg21.link/P1872">P1872</a></td><td>LWG</td><td>span should have size_type, not index_type </td><td>Belfast</td><td>Complete</td><td>10.0</td></tr>
<tr><td><a href="https://wg21.link/P1878">P1878</a></td><td>LWG</td><td>Constraining Readable Types </td><td>Belfast</td><td><i> </i></td><td></td></tr>
<tr><td><a href="https://wg21.link/P1892">P1892</a></td><td>LWG</td><td>Extended locale-specific presentation specifiers for std::format </td><td>Belfast</td><td><i> </i></td><td></td></tr>
<tr><td><a href="https://wg21.link/P1902">P1902</a></td><td>LWG</td><td>Missing feature-test macros 2018-2019 </td><td>Belfast</td><td><i> </i></td><td></td></tr>