mirror of
https://github.com/microsoft/GSL.git
synced 2024-11-03 17:56:43 -05:00
Fix span comparison ops to take arguments by-value rather than by-ref.
This commit is contained in:
parent
f63fe12ba7
commit
314065b317
@ -199,7 +199,7 @@ namespace details
|
||||
|
||||
constexpr span_iterator& operator-=(difference_type n) GSL_NOEXCEPT { return *this += -n; }
|
||||
|
||||
constexpr difference_type operator-(const span_iterator& rhs) const GSL_NOEXCEPT
|
||||
constexpr difference_type operator-(span_iterator rhs) const GSL_NOEXCEPT
|
||||
{
|
||||
Expects(span_ == rhs.span_);
|
||||
return index_ - rhs.index_;
|
||||
@ -210,39 +210,39 @@ namespace details
|
||||
return *(*this + n);
|
||||
}
|
||||
|
||||
constexpr friend bool operator==(const span_iterator& lhs,
|
||||
const span_iterator& rhs) GSL_NOEXCEPT
|
||||
constexpr friend bool operator==(span_iterator lhs,
|
||||
span_iterator rhs) GSL_NOEXCEPT
|
||||
{
|
||||
return lhs.span_ == rhs.span_ && lhs.index_ == rhs.index_;
|
||||
}
|
||||
|
||||
constexpr friend bool operator!=(const span_iterator& lhs,
|
||||
const span_iterator& rhs) GSL_NOEXCEPT
|
||||
constexpr friend bool operator!=(span_iterator lhs,
|
||||
span_iterator rhs) GSL_NOEXCEPT
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
constexpr friend bool operator<(const span_iterator& lhs,
|
||||
const span_iterator& rhs) GSL_NOEXCEPT
|
||||
constexpr friend bool operator<(span_iterator lhs,
|
||||
span_iterator rhs) GSL_NOEXCEPT
|
||||
{
|
||||
Expects(lhs.span_ == rhs.span_);
|
||||
return lhs.index_ < rhs.index_;
|
||||
}
|
||||
|
||||
constexpr friend bool operator<=(const span_iterator& lhs,
|
||||
const span_iterator& rhs) GSL_NOEXCEPT
|
||||
constexpr friend bool operator<=(span_iterator lhs,
|
||||
span_iterator rhs) GSL_NOEXCEPT
|
||||
{
|
||||
return !(rhs < lhs);
|
||||
}
|
||||
|
||||
constexpr friend bool operator>(const span_iterator& lhs,
|
||||
const span_iterator& rhs) GSL_NOEXCEPT
|
||||
constexpr friend bool operator>(span_iterator lhs,
|
||||
span_iterator rhs) GSL_NOEXCEPT
|
||||
{
|
||||
return rhs < lhs;
|
||||
}
|
||||
|
||||
constexpr friend bool operator>=(const span_iterator& lhs,
|
||||
const span_iterator& rhs) GSL_NOEXCEPT
|
||||
constexpr friend bool operator>=(span_iterator lhs,
|
||||
span_iterator rhs) GSL_NOEXCEPT
|
||||
{
|
||||
return !(rhs > lhs);
|
||||
}
|
||||
@ -255,7 +255,7 @@ namespace details
|
||||
template <class Span, bool IsConst>
|
||||
inline constexpr span_iterator<Span, IsConst>
|
||||
operator+(typename span_iterator<Span, IsConst>::difference_type n,
|
||||
const span_iterator<Span, IsConst>& rhs) GSL_NOEXCEPT
|
||||
span_iterator<Span, IsConst> rhs) GSL_NOEXCEPT
|
||||
{
|
||||
return rhs + n;
|
||||
}
|
||||
@ -263,7 +263,7 @@ namespace details
|
||||
template <class Span, bool IsConst>
|
||||
inline constexpr span_iterator<Span, IsConst>
|
||||
operator-(typename span_iterator<Span, IsConst>::difference_type n,
|
||||
const span_iterator<Span, IsConst>& rhs) GSL_NOEXCEPT
|
||||
span_iterator<Span, IsConst> rhs) GSL_NOEXCEPT
|
||||
{
|
||||
return rhs - n;
|
||||
}
|
||||
@ -548,43 +548,43 @@ private:
|
||||
|
||||
// [span.comparison], span comparison operators
|
||||
template <class ElementType, std::ptrdiff_t FirstExtent, std::ptrdiff_t SecondExtent>
|
||||
inline constexpr bool operator==(const span<ElementType, FirstExtent>& l,
|
||||
const span<ElementType, SecondExtent>& r)
|
||||
inline constexpr bool operator==(span<ElementType, FirstExtent> l,
|
||||
span<ElementType, SecondExtent> r)
|
||||
{
|
||||
return std::equal(l.begin(), l.end(), r.begin(), r.end());
|
||||
}
|
||||
|
||||
template <class ElementType, std::ptrdiff_t Extent>
|
||||
inline constexpr bool operator!=(const span<ElementType, Extent>& l,
|
||||
const span<ElementType, Extent>& r)
|
||||
inline constexpr bool operator!=(span<ElementType, Extent> l,
|
||||
span<ElementType, Extent> r)
|
||||
{
|
||||
return !(l == r);
|
||||
}
|
||||
|
||||
template <class ElementType, std::ptrdiff_t Extent>
|
||||
inline constexpr bool operator<(const span<ElementType, Extent>& l,
|
||||
const span<ElementType, Extent>& r)
|
||||
inline constexpr bool operator<(span<ElementType, Extent> l,
|
||||
span<ElementType, Extent> r)
|
||||
{
|
||||
return std::lexicographical_compare(l.begin(), l.end(), r.begin(), r.end());
|
||||
}
|
||||
|
||||
template <class ElementType, std::ptrdiff_t Extent>
|
||||
inline constexpr bool operator<=(const span<ElementType, Extent>& l,
|
||||
const span<ElementType, Extent>& r)
|
||||
inline constexpr bool operator<=(span<ElementType, Extent> l,
|
||||
span<ElementType, Extent> r)
|
||||
{
|
||||
return !(l > r);
|
||||
}
|
||||
|
||||
template <class ElementType, std::ptrdiff_t Extent>
|
||||
inline constexpr bool operator>(const span<ElementType, Extent>& l,
|
||||
const span<ElementType, Extent>& r)
|
||||
inline constexpr bool operator>(span<ElementType, Extent> l,
|
||||
span<ElementType, Extent> r)
|
||||
{
|
||||
return r < l;
|
||||
}
|
||||
|
||||
template <class ElementType, std::ptrdiff_t Extent>
|
||||
inline constexpr bool operator>=(const span<ElementType, Extent>& l,
|
||||
const span<ElementType, Extent>& r)
|
||||
inline constexpr bool operator>=(span<ElementType, Extent> l,
|
||||
span<ElementType, Extent> r)
|
||||
{
|
||||
return !(l < r);
|
||||
}
|
||||
@ -675,7 +675,7 @@ span<typename Ptr::element_type> make_span(Ptr& cont)
|
||||
|
||||
// Specialization of gsl::at for span
|
||||
template <class ElementType, std::ptrdiff_t Extent>
|
||||
inline constexpr ElementType& at(const span<ElementType, Extent>& s, std::ptrdiff_t index)
|
||||
inline constexpr ElementType& at(span<ElementType, Extent> s, std::ptrdiff_t index)
|
||||
{
|
||||
// No bounds checking here because it is done in span::operator[] called below
|
||||
return s[index];
|
||||
|
Loading…
Reference in New Issue
Block a user