From f46e88153e8779077377e4e975d9e17046016eac Mon Sep 17 00:00:00 2001 From: "Billy O'Neal (VC LIBS)" Date: Tue, 15 May 2018 19:13:12 -0700 Subject: [PATCH] Teach GSL::span::iterator how to talk to the new iterator debugging machinery that works in release builds. --- include/gsl/span | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/include/gsl/span b/include/gsl/span index f5f1332..035f64c 100644 --- a/include/gsl/span +++ b/include/gsl/span @@ -258,6 +258,41 @@ namespace details return !(rhs > lhs); } +#ifdef _MSC_VER + // MSVC++ iterator debugging support; allows STL algorithms in 15.8+ + // to unwrap span_iterator to a pointer type after a range check in STL + // algorithm calls + friend constexpr void _Verify_range(span_iterator lhs, + span_iterator rhs) noexcept + { // test that [lhs, rhs) forms a valid range inside an STL algorithm + Expects(lhs.span_ == rhs.span_ // range spans have to match + && lhs.index_ < rhs.index_); // range must not be transposed + } + + cosntexpr void _Verify_offset(const difference_type n) const noexcpt + { // test that the iterator *this + n is a valid range in an STL + // algorithm call + Expects((index_ + n) >= 0 && (index_ + n) <= span_->size()); + } + + 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 + // pointer + return span_->data() + index_; + } + + // Tell the STL that span_iterator should not be unwrapped if it can't + // validate in advance, even in release / optimized builds: + static constexpr bool _Unwrap_when_unverified = false; + + constexpr void _Seek_to(const pointer p) noexcept + { // adjust the position of *this to previously verified location p + // after _Unwrap + index_ = p - span_->data(); + } +#endif + protected: const Span* span_ = nullptr; std::ptrdiff_t index_ = 0;