Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mstd::span rename index_type to size_type according to spec #15176

Merged
merged 2 commits into from
Dec 9, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions platform/cxxsupport/mstd_span
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ class span {
public:
using element_type = ElementType;
using value_type = typename mstd::remove_cv_t<element_type>;
using index_type = size_t;
using size_type = size_t;
// Typedef because IAR does not allow [[deprecated]] with using
[[deprecated("Use size_type instead.")]] typedef size_t index_type;
using difference_type = ptrdiff_t;
using pointer = element_type *;
using const_pointer = const element_type *;
Expand All @@ -148,7 +150,7 @@ public:
using iterator = pointer;
using reverse_iterator = std::reverse_iterator<iterator>;

static constexpr index_type extent = Extent;
static constexpr size_type extent = Extent;

// Constructors, copy and assignment
template<size_t E = Extent,
Expand All @@ -160,7 +162,7 @@ public:
typename mstd::enable_if_t<mstd::is_convertible<
remove_reference_t<mstd::iter_reference_t<It>>(*)[],
ElementType(*)[]>::value, int> = 0>
constexpr span(It ptr, index_type count) :
constexpr span(It ptr, size_type count) :
_storage(ptr, count)
{
MBED_ASSERT(extent == dynamic_extent || extent == count);
Expand Down Expand Up @@ -251,32 +253,32 @@ public:
return {data() + Offset, Count != dynamic_extent ? Count : size() - Offset};
}

constexpr span<element_type, dynamic_extent> first(index_type count) const
constexpr span<element_type, dynamic_extent> first(size_type count) const
{
MBED_ASSERT(count <= size());
return {data(), count};
}

constexpr span<element_type, dynamic_extent> last(index_type count) const
constexpr span<element_type, dynamic_extent> last(size_type count) const
{
MBED_ASSERT(count <= size());
return {data() + (size() - count), count};
}

constexpr span<element_type, dynamic_extent>
subspan(index_type offset, index_type count = dynamic_extent) const
subspan(size_type offset, size_type count = dynamic_extent) const
{
MBED_ASSERT(offset <= size() && (count == dynamic_extent || count <= size() - offset));
return {data() + offset, count == dynamic_extent ? size() - offset : count };
}

// Observers
constexpr index_type size() const noexcept
constexpr size_type size() const noexcept
{
return _storage._size;
}

constexpr index_type size_bytes() const noexcept
constexpr size_type size_bytes() const noexcept
{
return size() * sizeof(element_type);
}
Expand All @@ -287,7 +289,7 @@ public:
}

// Element access
constexpr reference operator[](index_type idx) const
constexpr reference operator[](size_type idx) const
{
MBED_ASSERT(idx < size());
return *(data() + idx);
Expand Down Expand Up @@ -336,7 +338,7 @@ private:
};

template<typename ElementType, size_t Extent>
constexpr span<ElementType, Extent>::index_type span<ElementType, Extent>::extent;
constexpr span<ElementType, Extent>::size_type span<ElementType, Extent>::extent;

#if __cplusplus >= 201703L || __cpp_deduction_guides >= 201703L
// Deduction guides
Expand Down