diff --git a/include/gsl/span b/include/gsl/span index 6dd1c1f..f5f1332 100644 --- a/include/gsl/span +++ b/include/gsl/span @@ -191,6 +191,11 @@ namespace details return ret += n; } + friend constexpr span_iterator operator+(difference_type n, span_iterator const& rhs) + { + return rhs + n; + } + constexpr span_iterator& operator+=(difference_type n) { Expects((index_ + n) >= 0 && (index_ + n) <= span_->size()); @@ -258,22 +263,6 @@ namespace details std::ptrdiff_t index_ = 0; }; - template - constexpr span_iterator - operator+(typename span_iterator::difference_type n, - span_iterator rhs) - { - return rhs + n; - } - - template - constexpr span_iterator - operator-(typename span_iterator::difference_type n, - span_iterator rhs) - { - return rhs - n; - } - template class extent_type { @@ -418,7 +407,7 @@ public: ~span() noexcept = default; constexpr span& operator=(const span& other) noexcept = default; - + // [span.sub], span subviews template constexpr span first() const @@ -493,10 +482,16 @@ public: constexpr const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator{cend()}; } constexpr const_reverse_iterator crend() const noexcept { return const_reverse_iterator{cbegin()}; } +#ifdef _MSC_VER + // Tell MSVC how to unwrap spans in range-based-for + constexpr pointer _Unchecked_begin() const noexcept { return data(); } + constexpr pointer _Unchecked_end() const noexcept { return data() + size(); } +#endif // _MSC_VER + private: // Needed to remove unnecessary null check in subspans - struct KnownNotNull + struct KnownNotNull { pointer p; }; @@ -508,7 +503,7 @@ private: class storage_type : public ExtentType { public: - // KnownNotNull parameter is needed to remove unnecessary null check + // KnownNotNull parameter is needed to remove unnecessary null check // in subspans and constructors from arrays template constexpr storage_type(KnownNotNull data, OtherExtentType ext) : ExtentType(ext), data_(data.p)