Skip to content

Commit

Permalink
Merge pull request #15176 from marcemmers/rename_mstd_span_size_type
Browse files Browse the repository at this point in the history
mstd::span rename index_type to size_type according to spec
  • Loading branch information
0xc0170 authored Dec 9, 2021
2 parents 1c5813b + 0fb88f8 commit 810662b
Showing 1 changed file with 12 additions and 10 deletions.
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

0 comments on commit 810662b

Please sign in to comment.