From 61c6ef8d426dd4869789be9b8432c6cb4454a8bb Mon Sep 17 00:00:00 2001 From: "Jordan Maples [MSFT]" <49793787+JordanMaples@users.noreply.github.com> Date: Tue, 4 Feb 2020 13:30:03 -0800 Subject: [PATCH] remove index_type from string_span, update comments --- include/gsl/span | 11 +++++------ include/gsl/string_span | 30 ++++++++++++++---------------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/include/gsl/span b/include/gsl/span index c919f38..737ef80 100644 --- a/include/gsl/span +++ b/include/gsl/span @@ -185,7 +185,7 @@ namespace details 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(current_ - begin_ >= -n); current_ += n; @@ -206,7 +206,7 @@ namespace details 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(end_ - current_ >= -n); current_ -= n; @@ -294,8 +294,7 @@ namespace details } constexpr void _Verify_offset(const difference_type n) const noexcept - { // test that *this + n is within the span of this iterator STL - // algorithm call + { // test that *this + n is within the range of this call Expects( n <= (current_ - begin_) && n <= (end_ - current_)); } @@ -408,8 +407,8 @@ public: // [span.cons], span constructors, copy, assignment, and destructor template " SFINAE, - // since "std::enable_if_t" is ill-formed when Extent is greater than 0. + // "Dependent" is needed to make "std::enable_if_t" SFINAE, + // since "std::enable_if_t" is ill-formed when Extent is greater than 0. class = std::enable_if_t<(Dependent || Extent == 0 || Extent == dynamic_extent)>> constexpr span() noexcept : storage_(nullptr, details::extent_type<0>()) {} diff --git a/include/gsl/string_span b/include/gsl/string_span index c4752db..27b8977 100644 --- a/include/gsl/string_span +++ b/include/gsl/string_span @@ -184,14 +184,12 @@ public: using const_reference = std::add_lvalue_reference_t>; using impl_type = span; - using index_type = typename impl_type::index_type; + using size_type = typename impl_type::size_type; using iterator = typename impl_type::iterator; using const_iterator = typename impl_type::const_iterator; using reverse_iterator = typename impl_type::reverse_iterator; using const_reverse_iterator = typename impl_type::const_reverse_iterator; - using size_type = index_type; - // default (empty) constexpr basic_string_span() noexcept = default; @@ -201,7 +199,7 @@ public: // assign 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) {} // From static arrays - if 0-terminated, remove 0 from the view @@ -258,49 +256,49 @@ public: : span_(other.data(), other.length()) {} - template + template constexpr basic_string_span first() const { return {span_.template first()}; } - constexpr basic_string_span first(index_type count) const + constexpr basic_string_span first(size_type count) const { return {span_.first(count)}; } - template + template constexpr basic_string_span last() const { return {span_.template last()}; } - constexpr basic_string_span last(index_type count) const + constexpr basic_string_span last(size_type count) const { return {span_.last(count)}; } - template + template constexpr basic_string_span subspan() const { return {span_.template subspan()}; } constexpr basic_string_span - 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)}; } - constexpr reference operator[](index_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 reference operator()(size_type idx) const { return span_[idx]; } constexpr pointer data() const { return span_.data(); } - constexpr index_type length() const noexcept { return span_.size(); } - constexpr index_type size() const noexcept { return span_.size(); } - constexpr index_type size_bytes() const noexcept { return span_.size_bytes(); } - constexpr index_type length_bytes() const noexcept { return span_.length_bytes(); } + constexpr size_type length() const noexcept { return span_.size(); } + constexpr size_type size() const noexcept { return span_.size(); } + constexpr size_type size_bytes() const noexcept { return span_.size_bytes(); } + constexpr size_type length_bytes() const noexcept { return span_.length_bytes(); } constexpr bool empty() const noexcept { return size() == 0; } constexpr iterator begin() const noexcept { return span_.begin(); }