diff --git a/include/gsl/span b/include/gsl/span index 5f66c6c..ef7580c 100644 --- a/include/gsl/span +++ b/include/gsl/span @@ -333,7 +333,7 @@ namespace details public: using index_type = std::size_t; - static_assert(Ext >= 0, "A fixed-size span must be >= 0 in size."); + static_assert(Ext != dynamic_extent, "A fixed-size span must be >= 0 in size."); constexpr extent_type() noexcept {} @@ -417,7 +417,7 @@ public: constexpr span(pointer ptr, index_type count) noexcept : storage_(ptr, count) {} constexpr span(pointer firstElem, pointer lastElem) noexcept - : storage_(firstElem, std::distance(firstElem, lastElem)) + : storage_(firstElem, static_cast(std::distance(firstElem, lastElem))) {} template @@ -536,7 +536,7 @@ public: GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute constexpr reference operator[](index_type idx) const noexcept { - Expects(CheckRange(idx, storage_.size())); + Expects(idx < size()); return data()[idx]; } @@ -594,32 +594,6 @@ public: #endif // _MSC_VER private: - static constexpr bool CheckRange(index_type idx, index_type size) noexcept - { - // Optimization: - // - // idx >= 0 && idx < size - // => - // static_cast(idx) < static_cast(size) - // - // because size >=0 by span construction, and negative idx will - // wrap around to a value always greater than size when casted. - - // check if we have enough space to wrap around -#if defined(__cpp_if_constexpr) - if constexpr (sizeof(index_type) <= sizeof(size_t)) -#else - if (sizeof(index_type) <= sizeof(size_t)) -#endif - { - return narrow_cast(idx) < narrow_cast(size); - } - else - { - return idx < size; - } - } - // Needed to remove unnecessary null check in subspans struct KnownNotNull {