diff --git a/include/gsl/span b/include/gsl/span index b3e5349..1b06fb3 100644 --- a/include/gsl/span +++ b/include/gsl/span @@ -26,16 +26,18 @@ #include // for ptrdiff_t, size_t, nullptr_t #include // for reverse_iterator, distance, random_access_... #include +#include // for std::addressof #include #include // for enable_if_t, declval, is_convertible, inte... #include -#include // for std::addressof #if defined(_MSC_VER) && !defined(__clang__) #pragma warning(push) // turn off some warnings that are noisy about our Expects statements #pragma warning(disable : 4127) // conditional expression is constant +#pragma warning( \ + disable : 4146) // unary minus operator applied to unsigned type, result still unsigned #pragma warning(disable : 4702) // unreachable code // Turn MSVC /analyze rules that generate too much noise. TODO: fix in the tool. @@ -70,9 +72,9 @@ namespace gsl { // [views.constants], constants -constexpr const std::ptrdiff_t dynamic_extent = -1; +constexpr const std::size_t dynamic_extent = std::numeric_limits::max(); -template +template class span; // implementation details @@ -83,7 +85,7 @@ namespace details { }; - template + template struct is_span_oracle> : std::true_type { }; @@ -108,7 +110,7 @@ namespace details { }; - template + template struct is_allowed_extent_conversion : public std::integral_constant @@ -151,10 +153,10 @@ namespace details : span_iterator(other.span_, other.index_) {} - GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute + GSL_SUPPRESS(bounds .1) // NO-FORMAT: attribute constexpr reference operator*() const { - Expects(index_ != span_->size()); + Expects(static_cast(index_) != span_->size()); return *(span_->data() + index_); } @@ -166,7 +168,7 @@ namespace details constexpr span_iterator& operator++() noexcept { - Expects(0 <= index_ && index_ != span_->size()); + Expects(0 <= index_ && static_cast(index_) != span_->size()); ++index_; return *this; } @@ -180,7 +182,7 @@ namespace details constexpr span_iterator& operator--() noexcept { - Expects(index_ != 0 && index_ <= span_->size()); + Expects(index_ != 0 && static_cast(index_) <= span_->size()); --index_; return *this; } @@ -198,7 +200,8 @@ namespace details return ret += n; } - friend constexpr span_iterator operator+(difference_type n, span_iterator const& rhs) noexcept + friend constexpr span_iterator operator+(difference_type n, + span_iterator const& rhs) noexcept { return rhs + n; } @@ -272,7 +275,7 @@ namespace details Expects((index_ + n) >= 0 && (index_ + n) <= span_->size()); } - GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute + GSL_SUPPRESS(bounds .1) // NO-FORMAT: attribute constexpr pointer _Unwrapped() const noexcept { // after seeking *this to a high water mark, or using one of the // _Verify_xxx functions above, unwrap this span_iterator to a raw @@ -287,7 +290,7 @@ namespace details #else static constexpr bool _Unwrap_when_unverified = false; #endif - GSL_SUPPRESS(con.3) // NO-FORMAT: attribute // TODO: false positive + GSL_SUPPRESS(con .3) // NO-FORMAT: attribute // TODO: false positive constexpr void _Seek_to(const pointer p) noexcept { // adjust the position of *this to previously verified location p // after _Unwrapped @@ -300,11 +303,11 @@ namespace details std::ptrdiff_t index_ = 0; }; - template + template class extent_type { public: - using index_type = std::ptrdiff_t; + using index_type = std::size_t; static_assert(Ext >= 0, "A fixed-size span must be >= 0 in size."); @@ -327,13 +330,16 @@ namespace details class extent_type { public: - using index_type = std::ptrdiff_t; + using index_type = std::size_t; template explicit constexpr extent_type(extent_type ext) : size_(ext.size()) {} - explicit constexpr extent_type(index_type size) : size_(size) { Expects(size >= 0); } + explicit constexpr extent_type(index_type size) : size_(size) + { + Expects(size != dynamic_extent); + } constexpr index_type size() const noexcept { return size_; } @@ -341,7 +347,7 @@ namespace details index_type size_; }; - template + template struct calculate_subspan_type { using type = span +template class span { public: // constants and types using element_type = ElementType; using value_type = std::remove_cv_t; - using index_type = std::ptrdiff_t; + using index_type = std::size_t; using pointer = element_type*; using reference = element_type&; + using difference_type = std::ptrdiff_t; using iterator = details::span_iterator, false>; using const_iterator = details::span_iterator, true>; @@ -379,11 +386,11 @@ public: template " SFINAE, // since "std::enable_if_t" is ill-formed when Extent is greater than 0. - class = std::enable_if_t<(Dependent || Extent <= 0)>> + class = std::enable_if_t<(Dependent || Extent == 0 || Extent == dynamic_extent)>> constexpr span() noexcept : storage_(nullptr, details::extent_type<0>()) {} - constexpr span(pointer ptr, index_type count) noexcept: storage_(ptr, count) {} + constexpr span(pointer ptr, index_type count) noexcept : storage_(ptr, count) {} constexpr span(pointer firstElem, pointer lastElem) noexcept : storage_(firstElem, std::distance(firstElem, lastElem)) @@ -397,24 +404,20 @@ public: template 0)>> constexpr span(std::array, N>& arr) noexcept : storage_(KnownNotNull{arr.data()}, details::extent_type()) - { - } + {} constexpr span(std::array, 0>&) noexcept : storage_(static_cast(nullptr), details::extent_type<0>()) - { - } + {} template 0)>> constexpr span(const std::array, N>& arr) noexcept : storage_(KnownNotNull{arr.data()}, details::extent_type()) - { - } + {} constexpr span(const std::array, 0>&) noexcept : storage_(static_cast(nullptr), details::extent_type<0>()) - { - } + {} // NB: the SFINAE here uses .data() as a incomplete/imperfect proxy for the requirement // on Container to be a contiguous sequence container. @@ -433,13 +436,14 @@ public: std::is_convertible::value && std::is_convertible().data())>::value>> - constexpr span(const Container& cont) noexcept : span(cont.data(), narrow(cont.size())) + constexpr span(const Container& cont) noexcept + : span(cont.data(), narrow(cont.size())) {} constexpr span(const span& other) noexcept = default; template < - class OtherElementType, std::ptrdiff_t OtherExtent, + class OtherElementType, std::size_t OtherExtent, class = std::enable_if_t< details::is_allowed_extent_conversion::value && details::is_allowed_element_type_conversion::value>> @@ -451,27 +455,27 @@ public: constexpr span& operator=(const span& other) noexcept = default; // [span.sub], span subviews - template + template constexpr span first() const noexcept { - Expects(Count >= 0 && Count <= size()); + Expects(Count <= size()); return {data(), Count}; } - template - GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute + template + GSL_SUPPRESS(bounds .1) // NO-FORMAT: attribute constexpr span last() const noexcept { - Expects(Count >= 0 && size() - Count >= 0); + Expects(size() >= Count); return {data() + (size() - Count), Count}; } - template - GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute + template + GSL_SUPPRESS(bounds .1) // NO-FORMAT: attribute constexpr auto subspan() const noexcept -> typename details::calculate_subspan_type::type { - Expects((Offset >= 0 && size() - Offset >= 0) && + Expects((size() >= Offset) && (Count == dynamic_extent || (Count >= 0 && Offset + Count <= size()))); return {data() + Offset, Count == dynamic_extent ? size() - Offset : Count}; @@ -479,17 +483,19 @@ public: constexpr span first(index_type count) const noexcept { - Expects(count >= 0 && count <= size()); + Expects(count <= size()); return {data(), count}; } constexpr span last(index_type count) const noexcept { + Expects(count <= size()); return make_subspan(size() - count, dynamic_extent, subspan_selector{}); } constexpr span subspan(index_type offset, - index_type count = dynamic_extent) const noexcept + index_type count = dynamic_extent) const + noexcept { return make_subspan(offset, count, subspan_selector{}); } @@ -503,7 +509,7 @@ public: constexpr bool empty() const noexcept { return size() == 0; } // [span.elem], span element access - GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute + GSL_SUPPRESS(bounds .1) // NO-FORMAT: attribute constexpr reference operator[](index_type idx) const noexcept { Expects(CheckRange(idx, storage_.size())); @@ -512,23 +518,25 @@ public: constexpr reference front() const noexcept { - Expects(size() > 0); + Expects(size() != dynamic_extent && size() > 0); return data()[0]; } constexpr reference back() const noexcept { - Expects(size() > 0); + Expects(size() != dynamic_extent && size() > 0); return data()[size() - 1]; } - + // at and operator() are deprecated to align to the public member functions of std::span - [[deprecated("Use operator[]")]] - constexpr reference at(index_type idx) const noexcept{ return this->operator[](idx); } - [[deprecated("Use operator[]")]] - constexpr reference operator()(index_type idx) const noexcept{ return this->operator[](idx); } - - + [[deprecated("Use operator[]")]] constexpr reference at(index_type idx) const noexcept + { + return this->operator[](idx); + } + [[deprecated("Use operator[]")]] constexpr reference operator()(index_type idx) const noexcept + { + return this->operator[](idx); + } constexpr pointer data() const noexcept { return storage_.data(); } @@ -556,7 +564,7 @@ public: constexpr pointer _Unchecked_begin() const noexcept { return data(); } constexpr pointer _Unchecked_end() const noexcept { - GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute + GSL_SUPPRESS(bounds .1) // NO-FORMAT: attribute return data() + size(); } #endif // _MSC_VER @@ -607,13 +615,13 @@ private: constexpr storage_type(KnownNotNull data, OtherExtentType ext) : ExtentType(ext), data_(data.p) { - Expects(ExtentType::size() >= 0); + Expects(ExtentType::size() != dynamic_extent); } template constexpr storage_type(pointer data, OtherExtentType ext) : ExtentType(ext), data_(data) { - Expects(ExtentType::size() >= 0); + Expects(ExtentType::size() != dynamic_extent); Expects(data || ExtentType::size() == 0); } @@ -629,12 +637,12 @@ private: // in subspans and constructors from arrays constexpr span(KnownNotNull ptr, index_type count) : storage_(ptr, count) {} - template + template class subspan_selector { }; - template + template span make_subspan(index_type offset, index_type count, subspan_selector) const { @@ -642,56 +650,56 @@ private: return tmp.subspan(offset, count); } - GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute + GSL_SUPPRESS(bounds .1) // NO-FORMAT: attribute span make_subspan(index_type offset, index_type count, subspan_selector) const { - Expects(offset >= 0 && size() - offset >= 0); + Expects(offset >= 0 && size() >= offset && size() != dynamic_extent); if (count == dynamic_extent) { return {KnownNotNull{data() + offset}, size() - offset}; } - Expects(count >= 0 && size() - offset >= count); + Expects(size() - offset >= count); return {KnownNotNull{data() + offset}, count}; } }; #if defined(GSL_USE_STATIC_CONSTEXPR_WORKAROUND) -template +template constexpr const typename span::index_type span::extent; #endif // [span.comparison], span comparison operators -template +template constexpr bool operator==(span l, span r) { return std::equal(l.begin(), l.end(), r.begin(), r.end()); } -template +template constexpr bool operator!=(span l, span r) { return !(l == r); } -template +template constexpr bool operator<(span l, span r) { return std::lexicographical_compare(l.begin(), l.end(), r.begin(), r.end()); } -template +template constexpr bool operator<=(span l, span r) { return !(l > r); } -template +template constexpr bool operator>(span l, span r) { return r < l; } -template +template constexpr bool operator>=(span l, span r) { return !(l < r); @@ -705,36 +713,33 @@ namespace details // we should use a narrow_cast<> to go to std::size_t, but older compilers may not see it as // constexpr // and so will fail compilation of the template - template - struct calculate_byte_size - : std::integral_constant(sizeof(ElementType) * - static_cast(Extent))> + template + struct calculate_byte_size : std::integral_constant { }; template struct calculate_byte_size - : std::integral_constant + : std::integral_constant { }; } // namespace details // [span.objectrep], views of object representation -template +template span::value> as_bytes(span s) noexcept { - GSL_SUPPRESS(type.1) // NO-FORMAT: attribute + GSL_SUPPRESS(type .1) // NO-FORMAT: attribute return {reinterpret_cast(s.data()), s.size_bytes()}; } -template ::value>> span::value> as_writeable_bytes(span s) noexcept { - GSL_SUPPRESS(type.1) // NO-FORMAT: attribute + GSL_SUPPRESS(type .1) // NO-FORMAT: attribute return {reinterpret_cast(s.data()), s.size_bytes()}; } @@ -773,7 +778,7 @@ constexpr span make_span(const Container& } template -constexpr span make_span(Ptr& cont, std::ptrdiff_t count) +constexpr span make_span(Ptr& cont, std::size_t count) { return span(cont, count); } @@ -785,7 +790,7 @@ constexpr span make_span(Ptr& cont) } // Specialization of gsl::at for span -template +template constexpr ElementType& at(span s, index i) { // No bounds checking here because it is done in span::operator[] called below @@ -793,57 +798,66 @@ constexpr ElementType& at(span s, index i) } // [span.obs] Free observer functions -template -constexpr typename span::index_type ssize(const span &span) noexcept +template +constexpr typename span::index_type +ssize(const span& span) noexcept { return span.size(); } // [span.iter] Free functions for begin/end functions -template -constexpr typename span::iterator begin(const span &span) noexcept +template +constexpr typename span::iterator +begin(const span& span) noexcept { return span.begin(); } -template -constexpr typename span::iterator end(const span &span) noexcept +template +constexpr typename span::iterator +end(const span& span) noexcept { return span.end(); } -template -constexpr typename span::const_iterator cbegin(const span &span) noexcept +template +constexpr typename span::const_iterator +cbegin(const span& span) noexcept { return span.cbegin(); } -template -constexpr typename span::const_iterator cend(const span &span) noexcept +template +constexpr typename span::const_iterator +cend(const span& span) noexcept { return span.cend(); } -template -constexpr typename span::reverse_iterator rbegin(const span &span) noexcept +template +constexpr typename span::reverse_iterator +rbegin(const span& span) noexcept { return span.rbegin(); } -template -constexpr typename span::reverse_iterator rend(const span &span) noexcept +template +constexpr typename span::reverse_iterator +rend(const span& span) noexcept { return span.rend(); } -template -constexpr typename span::const_reverse_iterator crbegin(const span &span) noexcept +template +constexpr typename span::const_reverse_iterator +crbegin(const span& span) noexcept { return span.crbegin(); } -template -constexpr typename span::const_reverse_iterator crend(const span &span) noexcept +template +constexpr typename span::const_reverse_iterator +crend(const span& span) noexcept { return span.crend(); } diff --git a/include/gsl/string_span b/include/gsl/string_span index 37cbe15..a1d2bb2 100644 --- a/include/gsl/string_span +++ b/include/gsl/string_span @@ -23,7 +23,7 @@ #include // for equal, lexicographical_compare #include // for array -#include // for ptrdiff_t, size_t, nullptr_t +#include // for size_t, nullptr_t #include // for PTRDIFF_MAX #include #include // for basic_string, allocator, char_traits @@ -56,43 +56,43 @@ namespace gsl // (sometimes needlessly) break existing programs when introduced. // -template +template using basic_zstring = CharT*; -template +template using czstring = basic_zstring; -template +template using cwzstring = basic_zstring; -template +template using cu16zstring = basic_zstring; -template +template using cu32zstring = basic_zstring; -template +template using zstring = basic_zstring; -template +template using wzstring = basic_zstring; -template +template using u16zstring = basic_zstring; -template +template using u32zstring = basic_zstring; namespace details { template - std::ptrdiff_t string_length(const CharT* str, std::ptrdiff_t n) + std::size_t string_length(const CharT* str, std::size_t n) { - if (str == nullptr || n <= 0) return 0; + if (str == nullptr || n == dynamic_extent) return 0; const span str_span{str, n}; - std::ptrdiff_t len = 0; + std::size_t len = 0; while (len < n && str_span[len]) len++; return len; @@ -108,18 +108,20 @@ namespace details // Will fail-fast if sentinel cannot be found before max elements are examined. // template -span ensure_sentinel(T* seq, std::ptrdiff_t max = PTRDIFF_MAX) +span ensure_sentinel(T* seq, + std::size_t max = std::numeric_limits::max()) { Ensures(seq != nullptr); - GSL_SUPPRESS(f.23) // NO-FORMAT: attribute // TODO: false positive // TODO: suppress does not work + GSL_SUPPRESS( + f .23) // NO-FORMAT: attribute // TODO: false positive // TODO: suppress does not work auto cur = seq; Ensures(cur != nullptr); // workaround for removing the warning - GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute // TODO: suppress does not work - while ((cur - seq) < max && *cur != Sentinel) ++cur; + GSL_SUPPRESS(bounds .1) // NO-FORMAT: attribute // TODO: suppress does not work + while (static_cast(cur - seq) < max && *cur != Sentinel) ++cur; Ensures(*cur == Sentinel); - return {seq, cur - seq}; + return {seq, static_cast(cur - seq)}; } // @@ -128,7 +130,8 @@ span ensure_sentinel(T* seq, std::ptrdiff_t max = PTRDIFF_MAX // the limit of size_type. // template -span ensure_z(CharT* const& sz, std::ptrdiff_t max = PTRDIFF_MAX) +span ensure_z(CharT* const& sz, + std::size_t max = std::numeric_limits::max()) { return ensure_sentinel(sz, max); } @@ -136,26 +139,27 @@ span ensure_z(CharT* const& sz, std::ptrdiff_t max = PTRD template span ensure_z(CharT (&sz)[N]) { - return ensure_z(&sz[0], narrow_cast(N)); + return ensure_z(&sz[0], N); } template span::type, dynamic_extent> ensure_z(Cont& cont) { - return ensure_z(cont.data(), narrow_cast(cont.size())); + return ensure_z(cont.data(), cont.size()); } -template +template class basic_string_span; -namespace details { +namespace details +{ template struct is_basic_string_span_oracle : std::false_type { }; - template + template struct is_basic_string_span_oracle> : std::true_type { }; @@ -169,7 +173,7 @@ namespace details { // // string_span and relatives // -template +template class basic_string_span { public: @@ -218,7 +222,7 @@ public: template // GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute // TODO: parser bug constexpr basic_string_span(std::basic_string& str) - : span_(&str[0], narrow_cast(str.length())) + : span_(&str[0], str.length()) {} template @@ -247,7 +251,7 @@ public: // from string_span template < - class OtherValueType, std::ptrdiff_t OtherExtent, + class OtherValueType, std::size_t OtherExtent, class = std::enable_if_t::impl_type, impl_type>::value>> constexpr basic_string_span(basic_string_span other) @@ -312,7 +316,7 @@ public: constexpr const_reverse_iterator crend() const noexcept { return span_.crend(); } private: - static impl_type remove_z(pointer const& sz, std::ptrdiff_t max) + static impl_type remove_z(pointer const& sz, std::size_t max) { return {sz, details::string_length(sz, max)}; } @@ -320,41 +324,41 @@ private: template static impl_type remove_z(element_type (&sz)[N]) { - return remove_z(&sz[0], narrow_cast(N)); + return remove_z(&sz[0], N); } impl_type span_; }; -template +template using string_span = basic_string_span; -template +template using cstring_span = basic_string_span; -template +template using wstring_span = basic_string_span; -template +template using cwstring_span = basic_string_span; -template +template using u16string_span = basic_string_span; -template +template using cu16string_span = basic_string_span; -template +template using u32string_span = basic_string_span; -template +template using cu32string_span = basic_string_span; // // to_string() allow (explicit) conversions from string_span to string // -template +template std::basic_string::type> to_string(basic_string_span view) { @@ -362,33 +366,34 @@ to_string(basic_string_span view) } template , - typename Allocator = std::allocator, typename gCharT, std::ptrdiff_t Extent> + typename Allocator = std::allocator, typename gCharT, std::size_t Extent> std::basic_string to_basic_string(basic_string_span view) { return {view.data(), narrow_cast(view.length())}; } -template +template basic_string_span::value> as_bytes(basic_string_span s) noexcept { - GSL_SUPPRESS(type.1) // NO-FORMAT: attribute + GSL_SUPPRESS(type .1) // NO-FORMAT: attribute return {reinterpret_cast(s.data()), s.size_bytes()}; } -template ::value>> basic_string_span::value> as_writeable_bytes(basic_string_span s) noexcept { - GSL_SUPPRESS(type.1) // NO-FORMAT: attribute + GSL_SUPPRESS(type .1) // NO-FORMAT: attribute return {reinterpret_cast(s.data()), s.size_bytes()}; } // zero-terminated string span, used to convert // zero-terminated spans to legacy strings -template -class basic_zstring_span { +template +class basic_zstring_span +{ public: using value_type = CharT; using const_value_type = std::add_const_t; @@ -435,32 +440,32 @@ private: impl_type span_; }; -template +template using zstring_span = basic_zstring_span; -template +template using wzstring_span = basic_zstring_span; -template +template using u16zstring_span = basic_zstring_span; -template +template using u32zstring_span = basic_zstring_span; -template +template using czstring_span = basic_zstring_span; -template +template using cwzstring_span = basic_zstring_span; -template +template using cu16zstring_span = basic_zstring_span; -template +template using cu32zstring_span = basic_zstring_span; // operator == -template ::value || std::is_convertible>>::value>> @@ -470,7 +475,7 @@ bool operator==(const gsl::basic_string_span& one, const T& other return std::equal(one.begin(), one.end(), tmp.begin(), tmp.end()); } -template ::value && std::is_convertible>>::value>> @@ -481,7 +486,7 @@ bool operator==(const T& one, const gsl::basic_string_span& other } // operator != -template , Extent>>::value>> bool operator!=(gsl::basic_string_span one, const T& other) @@ -490,7 +495,7 @@ bool operator!=(gsl::basic_string_span one, const T& other) } template < - typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T, + typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T, typename = std::enable_if_t< std::is_convertible, Extent>>::value && !gsl::details::is_basic_string_span::value>> @@ -500,7 +505,7 @@ bool operator!=(const T& one, gsl::basic_string_span other) } // operator< -template , Extent>>::value>> bool operator<(gsl::basic_string_span one, const T& other) @@ -510,7 +515,7 @@ bool operator<(gsl::basic_string_span one, const T& other) } template < - typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T, + typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T, typename = std::enable_if_t< std::is_convertible, Extent>>::value && !gsl::details::is_basic_string_span::value>> @@ -526,7 +531,7 @@ bool operator<(const T& one, gsl::basic_string_span other) // so the cases below are already covered by the previous operators template < - typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T, + typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T, typename DataType = typename T::value_type, typename = std::enable_if_t< !gsl::details::is_span::value && !gsl::details::is_basic_string_span::value && @@ -540,7 +545,7 @@ bool operator<(gsl::basic_string_span one, const T& other) } template < - typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T, + typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T, typename DataType = typename T::value_type, typename = std::enable_if_t< !gsl::details::is_span::value && !gsl::details::is_basic_string_span::value && @@ -555,7 +560,7 @@ bool operator<(const T& one, gsl::basic_string_span other) #endif // operator <= -template , Extent>>::value>> bool operator<=(gsl::basic_string_span one, const T& other) @@ -564,7 +569,7 @@ bool operator<=(gsl::basic_string_span one, const T& other) } template < - typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T, + typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T, typename = std::enable_if_t< std::is_convertible, Extent>>::value && !gsl::details::is_basic_string_span::value>> @@ -579,7 +584,7 @@ bool operator<=(const T& one, gsl::basic_string_span other) // so the cases below are already covered by the previous operators template < - typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T, + typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T, typename DataType = typename T::value_type, typename = std::enable_if_t< !gsl::details::is_span::value && !gsl::details::is_basic_string_span::value && @@ -592,7 +597,7 @@ bool operator<=(gsl::basic_string_span one, const T& other) } template < - typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T, + typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T, typename DataType = typename T::value_type, typename = std::enable_if_t< !gsl::details::is_span::value && !gsl::details::is_basic_string_span::value && @@ -606,7 +611,7 @@ bool operator<=(const T& one, gsl::basic_string_span other) #endif // operator> -template , Extent>>::value>> bool operator>(gsl::basic_string_span one, const T& other) @@ -615,7 +620,7 @@ bool operator>(gsl::basic_string_span one, const T& other) } template < - typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T, + typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T, typename = std::enable_if_t< std::is_convertible, Extent>>::value && !gsl::details::is_basic_string_span::value>> @@ -630,7 +635,7 @@ bool operator>(const T& one, gsl::basic_string_span other) // so the cases below are already covered by the previous operators template < - typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T, + typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T, typename DataType = typename T::value_type, typename = std::enable_if_t< !gsl::details::is_span::value && !gsl::details::is_basic_string_span::value && @@ -643,7 +648,7 @@ bool operator>(gsl::basic_string_span one, const T& other) } template < - typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T, + typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T, typename DataType = typename T::value_type, typename = std::enable_if_t< !gsl::details::is_span::value && !gsl::details::is_basic_string_span::value && @@ -657,7 +662,7 @@ bool operator>(const T& one, gsl::basic_string_span other) #endif // operator >= -template , Extent>>::value>> bool operator>=(gsl::basic_string_span one, const T& other) @@ -666,7 +671,7 @@ bool operator>=(gsl::basic_string_span one, const T& other) } template < - typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T, + typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T, typename = std::enable_if_t< std::is_convertible, Extent>>::value && !gsl::details::is_basic_string_span::value>> @@ -681,7 +686,7 @@ bool operator>=(const T& one, gsl::basic_string_span other) // so the cases below are already covered by the previous operators template < - typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T, + typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T, typename DataType = typename T::value_type, typename = std::enable_if_t< !gsl::details::is_span::value && !gsl::details::is_basic_string_span::value && @@ -694,7 +699,7 @@ bool operator>=(gsl::basic_string_span one, const T& other) } template < - typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T, + typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T, typename DataType = typename T::value_type, typename = std::enable_if_t< !gsl::details::is_span::value && !gsl::details::is_basic_string_span::value && diff --git a/tests/span_tests.cpp b/tests/span_tests.cpp index c41e013..166d64f 100644 --- a/tests/span_tests.cpp +++ b/tests/span_tests.cpp @@ -158,14 +158,14 @@ TEST(span_test, from_pointer_length_constructor) int arr[4] = {1, 2, 3, 4}; { - for (int i = 0; i < 4; ++i) + for (std::size_t i = 0; i < 4; ++i) { { span s = {&arr[0], i}; EXPECT_TRUE(s.size() == i); EXPECT_TRUE(s.data() == &arr[0]); EXPECT_TRUE(s.empty() == (i == 0)); - for (int j = 0; j < i; ++j) + for (std::size_t j = 0; j < i; ++j) { EXPECT_TRUE(arr[j] == s[j]); EXPECT_TRUE(arr[j] == s.at(j)); @@ -173,12 +173,12 @@ TEST(span_test, from_pointer_length_constructor) } } { - span s = {&arr[i], 4 - narrow_cast(i)}; + span s = {&arr[i], 4 - i}; EXPECT_TRUE(s.size() == 4 - i); EXPECT_TRUE(s.data() == &arr[i]); EXPECT_TRUE(s.empty() == ((4 - i) == 0)); - for (int j = 0; j < 4 - i; ++j) + for (std::size_t j = 0; j < 4 - i; ++j) { EXPECT_TRUE(arr[j + i] == s[j]); EXPECT_TRUE(arr[j + i] == s.at(j)); @@ -457,21 +457,21 @@ TEST(span_test, from_array_constructor) { span s{arr}; - EXPECT_TRUE(s.size() == narrow_cast(arr.size())); + EXPECT_TRUE(s.size() == arr.size()); EXPECT_TRUE(s.data() == arr.data()); span cs{arr}; - EXPECT_TRUE(cs.size() == narrow_cast(arr.size())); + EXPECT_TRUE(cs.size() == arr.size()); EXPECT_TRUE(cs.data() == arr.data()); } { span s{arr}; - EXPECT_TRUE(s.size() == narrow_cast(arr.size())); + EXPECT_TRUE(s.size() == arr.size()); EXPECT_TRUE(s.data() == arr.data()); span cs{arr}; - EXPECT_TRUE(cs.size() == narrow_cast(arr.size())); + EXPECT_TRUE(cs.size() == arr.size()); EXPECT_TRUE(cs.data() == arr.data()); } @@ -486,7 +486,7 @@ TEST(span_test, from_array_constructor) { span fs{ao_arr}; - EXPECT_TRUE(fs.size() == narrow_cast(ao_arr.size())); + EXPECT_TRUE(fs.size() == ao_arr.size()); EXPECT_TRUE(ao_arr.data() == fs.data()); } @@ -532,7 +532,7 @@ TEST(span_test, from_array_constructor) { auto s = make_span(arr); - EXPECT_TRUE(s.size() == narrow_cast(arr.size())); + EXPECT_TRUE(s.size() == arr.size()); EXPECT_TRUE(s.data() == arr.data()); } @@ -561,13 +561,13 @@ TEST(span_test, from_array_constructor) { span s{arr}; - EXPECT_TRUE(s.size() == narrow_cast(arr.size())); + EXPECT_TRUE(s.size() == arr.size()); EXPECT_TRUE(s.data() == arr.data()); } { span s{arr}; - EXPECT_TRUE(s.size() == narrow_cast(arr.size())); + EXPECT_TRUE(s.size() == arr.size()); EXPECT_TRUE(s.data() == arr.data()); } @@ -575,7 +575,7 @@ TEST(span_test, from_array_constructor) { span s{ao_arr}; - EXPECT_TRUE(s.size() == narrow_cast(ao_arr.size())); + EXPECT_TRUE(s.size() == ao_arr.size()); EXPECT_TRUE(s.data() == ao_arr.data()); } @@ -606,7 +606,7 @@ TEST(span_test, from_array_constructor) { auto s = make_span(arr); - EXPECT_TRUE(s.size() == narrow_cast(arr.size())); + EXPECT_TRUE(s.size() == arr.size()); EXPECT_TRUE(s.data() == arr.data()); } } @@ -617,13 +617,13 @@ TEST(span_test, from_array_constructor) { span s{arr}; - EXPECT_TRUE(s.size() == narrow_cast(arr.size())); + EXPECT_TRUE(s.size() == arr.size()); EXPECT_TRUE(s.data() == arr.data()); } { span s{arr}; - EXPECT_TRUE(s.size() == narrow_cast(arr.size())); + EXPECT_TRUE(s.size() == arr.size()); EXPECT_TRUE(s.data() == arr.data()); } @@ -651,7 +651,7 @@ TEST(span_test, from_array_constructor) { auto s = make_span(arr); - EXPECT_TRUE(s.size() == narrow_cast(arr.size())); + EXPECT_TRUE(s.size() == arr.size()); EXPECT_TRUE(s.data() == arr.data()); } } @@ -663,11 +663,11 @@ TEST(span_test, from_array_constructor) { span s{v}; - EXPECT_TRUE(s.size() == narrow_cast(v.size())); + EXPECT_TRUE(s.size() == v.size()); EXPECT_TRUE(s.data() == v.data()); span cs{v}; - EXPECT_TRUE(cs.size() == narrow_cast(v.size())); + EXPECT_TRUE(cs.size() == v.size()); EXPECT_TRUE(cs.data() == v.data()); } @@ -677,11 +677,11 @@ TEST(span_test, from_array_constructor) { #ifdef CONFIRM_COMPILATION_ERRORS span s{str}; - EXPECT_TRUE(s.size() == narrow_cast(str.size())); + EXPECT_TRUE(s.size() == str.size()); EXPECT_TRUE(s.data() == str.data())); #endif span cs{str}; - EXPECT_TRUE(cs.size() == narrow_cast(str.size())); + EXPECT_TRUE(cs.size() == str.size()); EXPECT_TRUE(cs.data() == str.data()); } @@ -690,7 +690,7 @@ TEST(span_test, from_array_constructor) span s{cstr}; #endif span cs{cstr}; - EXPECT_TRUE(cs.size() == narrow_cast(cstr.size())); + EXPECT_TRUE(cs.size() == cstr.size()); EXPECT_TRUE(cs.data() == cstr.data()); } @@ -745,11 +745,11 @@ TEST(span_test, from_array_constructor) { auto s = make_span(v); - EXPECT_TRUE(s.size() == narrow_cast(v.size())); + EXPECT_TRUE(s.size() == v.size()); EXPECT_TRUE(s.data() == v.data()); auto cs = make_span(cv); - EXPECT_TRUE(cs.size() == narrow_cast(cv.size())); + EXPECT_TRUE(cs.size() == cv.size()); EXPECT_TRUE(cs.data() == cv.data()); } }