remove index_type from string_span, update comments

This commit is contained in:
Jordan Maples [MSFT] 2020-02-04 13:30:03 -08:00
parent db2134485a
commit 61c6ef8d42
2 changed files with 19 additions and 22 deletions

View File

@ -185,7 +185,7 @@ namespace details
constexpr span_iterator& operator+=(const difference_type n) noexcept constexpr span_iterator& operator+=(const difference_type n) noexcept
{ {
Expects(begin_ && current_ && end_); if (n != 0) Expects(begin_ && current_ && end_);
if (n > 0) Expects(end_ - current_ >= n); if (n > 0) Expects(end_ - current_ >= n);
if (n < 0) Expects(current_ - begin_ >= -n); if (n < 0) Expects(current_ - begin_ >= -n);
current_ += n; current_ += n;
@ -206,7 +206,7 @@ namespace details
constexpr span_iterator& operator-=(const difference_type n) noexcept constexpr span_iterator& operator-=(const difference_type n) noexcept
{ {
Expects(begin_ && end_ && current_); if (n != 0) Expects(begin_ && current_ && end_);
if (n > 0) Expects(current_ - begin_ >= n); if (n > 0) Expects(current_ - begin_ >= n);
if (n < 0) Expects(end_ - current_ >= -n); if (n < 0) Expects(end_ - current_ >= -n);
current_ -= n; current_ -= n;
@ -294,8 +294,7 @@ namespace details
} }
constexpr void _Verify_offset(const difference_type n) const noexcept constexpr void _Verify_offset(const difference_type n) const noexcept
{ // test that *this + n is within the span of this iterator STL { // test that *this + n is within the range of this call
// algorithm call
Expects( n <= (current_ - begin_) && n <= (end_ - current_)); Expects( n <= (current_ - begin_) && n <= (end_ - current_));
} }
@ -408,8 +407,8 @@ public:
// [span.cons], span constructors, copy, assignment, and destructor // [span.cons], span constructors, copy, assignment, and destructor
template <bool Dependent = false, template <bool Dependent = false,
// "Dependent" is needed to make "std::enable_if_t<Dependent || Extent <= 0>" SFINAE, // "Dependent" is needed to make "std::enable_if_t<Dependent || Extent == 0 || Extent == dynamic_extent>" SFINAE,
// since "std::enable_if_t<Extent <= 0>" is ill-formed when Extent is greater than 0. // since "std::enable_if_t<Extent == 0 || Extent == dynamic_extent>" is ill-formed when Extent is greater than 0.
class = std::enable_if_t<(Dependent || Extent == 0 || Extent == dynamic_extent)>> class = std::enable_if_t<(Dependent || Extent == 0 || Extent == dynamic_extent)>>
constexpr span() noexcept : storage_(nullptr, details::extent_type<0>()) constexpr span() noexcept : storage_(nullptr, details::extent_type<0>())
{} {}

View File

@ -184,14 +184,12 @@ public:
using const_reference = std::add_lvalue_reference_t<std::add_const_t<element_type>>; using const_reference = std::add_lvalue_reference_t<std::add_const_t<element_type>>;
using impl_type = span<element_type, Extent>; using impl_type = span<element_type, Extent>;
using index_type = typename impl_type::index_type; using size_type = typename impl_type::size_type;
using iterator = typename impl_type::iterator; using iterator = typename impl_type::iterator;
using const_iterator = typename impl_type::const_iterator; using const_iterator = typename impl_type::const_iterator;
using reverse_iterator = typename impl_type::reverse_iterator; using reverse_iterator = typename impl_type::reverse_iterator;
using const_reverse_iterator = typename impl_type::const_reverse_iterator; using const_reverse_iterator = typename impl_type::const_reverse_iterator;
using size_type = index_type;
// default (empty) // default (empty)
constexpr basic_string_span() noexcept = default; constexpr basic_string_span() noexcept = default;
@ -201,7 +199,7 @@ public:
// assign // assign
constexpr basic_string_span& operator=(const basic_string_span& other) noexcept = default; constexpr basic_string_span& operator=(const basic_string_span& other) noexcept = default;
constexpr basic_string_span(pointer ptr, index_type length) : span_(ptr, length) {} constexpr basic_string_span(pointer ptr, size_type length) : span_(ptr, length) {}
constexpr basic_string_span(pointer firstElem, pointer lastElem) : span_(firstElem, lastElem) {} constexpr basic_string_span(pointer firstElem, pointer lastElem) : span_(firstElem, lastElem) {}
// From static arrays - if 0-terminated, remove 0 from the view // From static arrays - if 0-terminated, remove 0 from the view
@ -258,49 +256,49 @@ public:
: span_(other.data(), other.length()) : span_(other.data(), other.length())
{} {}
template <index_type Count> template <size_type Count>
constexpr basic_string_span<element_type, Count> first() const constexpr basic_string_span<element_type, Count> first() const
{ {
return {span_.template first<Count>()}; return {span_.template first<Count>()};
} }
constexpr basic_string_span<element_type, dynamic_extent> first(index_type count) const constexpr basic_string_span<element_type, dynamic_extent> first(size_type count) const
{ {
return {span_.first(count)}; return {span_.first(count)};
} }
template <index_type Count> template <size_type Count>
constexpr basic_string_span<element_type, Count> last() const constexpr basic_string_span<element_type, Count> last() const
{ {
return {span_.template last<Count>()}; return {span_.template last<Count>()};
} }
constexpr basic_string_span<element_type, dynamic_extent> last(index_type count) const constexpr basic_string_span<element_type, dynamic_extent> last(size_type count) const
{ {
return {span_.last(count)}; return {span_.last(count)};
} }
template <index_type Offset, index_type Count> template <size_type Offset, size_type Count>
constexpr basic_string_span<element_type, Count> subspan() const constexpr basic_string_span<element_type, Count> subspan() const
{ {
return {span_.template subspan<Offset, Count>()}; return {span_.template subspan<Offset, Count>()};
} }
constexpr basic_string_span<element_type, dynamic_extent> constexpr basic_string_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
{ {
return {span_.subspan(offset, count)}; return {span_.subspan(offset, count)};
} }
constexpr reference operator[](index_type idx) const { return span_[idx]; } constexpr reference operator[](size_type idx) const { return span_[idx]; }
constexpr reference operator()(index_type idx) const { return span_[idx]; } constexpr reference operator()(size_type idx) const { return span_[idx]; }
constexpr pointer data() const { return span_.data(); } constexpr pointer data() const { return span_.data(); }
constexpr index_type length() const noexcept { return span_.size(); } constexpr size_type length() const noexcept { return span_.size(); }
constexpr index_type size() const noexcept { return span_.size(); } constexpr size_type size() const noexcept { return span_.size(); }
constexpr index_type size_bytes() const noexcept { return span_.size_bytes(); } constexpr size_type size_bytes() const noexcept { return span_.size_bytes(); }
constexpr index_type length_bytes() const noexcept { return span_.length_bytes(); } constexpr size_type length_bytes() const noexcept { return span_.length_bytes(); }
constexpr bool empty() const noexcept { return size() == 0; } constexpr bool empty() const noexcept { return size() == 0; }
constexpr iterator begin() const noexcept { return span_.begin(); } constexpr iterator begin() const noexcept { return span_.begin(); }