[span] Tell MSVC how to avoid range-checking (#664)

* [span] implement non-member + as a hidden friend

Drive-by: remove garbage `operator-(difference_type, span_iterator)`.

* [span] Use pointers for range-based-for on MSVC
This commit is contained in:
Casey Carter 2018-05-09 14:01:22 -07:00 committed by Anna Gringauze
parent 5cbde3008a
commit d6a2242d97

View File

@ -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 <class Span, bool IsConst>
constexpr span_iterator<Span, IsConst>
operator+(typename span_iterator<Span, IsConst>::difference_type n,
span_iterator<Span, IsConst> rhs)
{
return rhs + n;
}
template <class Span, bool IsConst>
constexpr span_iterator<Span, IsConst>
operator-(typename span_iterator<Span, IsConst>::difference_type n,
span_iterator<Span, IsConst> rhs)
{
return rhs - n;
}
template <std::ptrdiff_t Ext>
class extent_type
{
@ -493,6 +482,12 @@ 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