Fix span comparison ops to take arguments by-value rather than by-ref.

This commit is contained in:
Neil MacIntosh 2018-02-11 14:22:08 -08:00
parent f63fe12ba7
commit 314065b317

View File

@ -199,7 +199,7 @@ namespace details
constexpr span_iterator& operator-=(difference_type n) GSL_NOEXCEPT { return *this += -n; } 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_); Expects(span_ == rhs.span_);
return index_ - rhs.index_; return index_ - rhs.index_;
@ -210,39 +210,39 @@ namespace details
return *(*this + n); return *(*this + n);
} }
constexpr friend bool operator==(const span_iterator& lhs, constexpr friend bool operator==(span_iterator lhs,
const span_iterator& rhs) GSL_NOEXCEPT span_iterator rhs) GSL_NOEXCEPT
{ {
return lhs.span_ == rhs.span_ && lhs.index_ == rhs.index_; return lhs.span_ == rhs.span_ && lhs.index_ == rhs.index_;
} }
constexpr friend bool operator!=(const span_iterator& lhs, constexpr friend bool operator!=(span_iterator lhs,
const span_iterator& rhs) GSL_NOEXCEPT span_iterator rhs) GSL_NOEXCEPT
{ {
return !(lhs == rhs); return !(lhs == rhs);
} }
constexpr friend bool operator<(const span_iterator& lhs, constexpr friend bool operator<(span_iterator lhs,
const span_iterator& rhs) GSL_NOEXCEPT span_iterator rhs) GSL_NOEXCEPT
{ {
Expects(lhs.span_ == rhs.span_); Expects(lhs.span_ == rhs.span_);
return lhs.index_ < rhs.index_; return lhs.index_ < rhs.index_;
} }
constexpr friend bool operator<=(const span_iterator& lhs, constexpr friend bool operator<=(span_iterator lhs,
const span_iterator& rhs) GSL_NOEXCEPT span_iterator rhs) GSL_NOEXCEPT
{ {
return !(rhs < lhs); return !(rhs < lhs);
} }
constexpr friend bool operator>(const span_iterator& lhs, constexpr friend bool operator>(span_iterator lhs,
const span_iterator& rhs) GSL_NOEXCEPT span_iterator rhs) GSL_NOEXCEPT
{ {
return rhs < lhs; return rhs < lhs;
} }
constexpr friend bool operator>=(const span_iterator& lhs, constexpr friend bool operator>=(span_iterator lhs,
const span_iterator& rhs) GSL_NOEXCEPT span_iterator rhs) GSL_NOEXCEPT
{ {
return !(rhs > lhs); return !(rhs > lhs);
} }
@ -255,7 +255,7 @@ namespace details
template <class Span, bool IsConst> template <class Span, bool IsConst>
inline constexpr span_iterator<Span, IsConst> inline constexpr span_iterator<Span, IsConst>
operator+(typename span_iterator<Span, IsConst>::difference_type n, 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; return rhs + n;
} }
@ -263,7 +263,7 @@ namespace details
template <class Span, bool IsConst> template <class Span, bool IsConst>
inline constexpr span_iterator<Span, IsConst> inline constexpr span_iterator<Span, IsConst>
operator-(typename span_iterator<Span, IsConst>::difference_type n, 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; return rhs - n;
} }
@ -548,43 +548,43 @@ private:
// [span.comparison], span comparison operators // [span.comparison], span comparison operators
template <class ElementType, std::ptrdiff_t FirstExtent, std::ptrdiff_t SecondExtent> template <class ElementType, std::ptrdiff_t FirstExtent, std::ptrdiff_t SecondExtent>
inline constexpr bool operator==(const span<ElementType, FirstExtent>& l, inline constexpr bool operator==(span<ElementType, FirstExtent> l,
const span<ElementType, SecondExtent>& r) span<ElementType, SecondExtent> r)
{ {
return std::equal(l.begin(), l.end(), r.begin(), r.end()); return std::equal(l.begin(), l.end(), r.begin(), r.end());
} }
template <class ElementType, std::ptrdiff_t Extent> template <class ElementType, std::ptrdiff_t Extent>
inline constexpr bool operator!=(const span<ElementType, Extent>& l, inline constexpr bool operator!=(span<ElementType, Extent> l,
const span<ElementType, Extent>& r) span<ElementType, Extent> r)
{ {
return !(l == r); return !(l == r);
} }
template <class ElementType, std::ptrdiff_t Extent> template <class ElementType, std::ptrdiff_t Extent>
inline constexpr bool operator<(const span<ElementType, Extent>& l, inline constexpr bool operator<(span<ElementType, Extent> l,
const span<ElementType, Extent>& r) span<ElementType, Extent> r)
{ {
return std::lexicographical_compare(l.begin(), l.end(), r.begin(), r.end()); return std::lexicographical_compare(l.begin(), l.end(), r.begin(), r.end());
} }
template <class ElementType, std::ptrdiff_t Extent> template <class ElementType, std::ptrdiff_t Extent>
inline constexpr bool operator<=(const span<ElementType, Extent>& l, inline constexpr bool operator<=(span<ElementType, Extent> l,
const span<ElementType, Extent>& r) span<ElementType, Extent> r)
{ {
return !(l > r); return !(l > r);
} }
template <class ElementType, std::ptrdiff_t Extent> template <class ElementType, std::ptrdiff_t Extent>
inline constexpr bool operator>(const span<ElementType, Extent>& l, inline constexpr bool operator>(span<ElementType, Extent> l,
const span<ElementType, Extent>& r) span<ElementType, Extent> r)
{ {
return r < l; return r < l;
} }
template <class ElementType, std::ptrdiff_t Extent> template <class ElementType, std::ptrdiff_t Extent>
inline constexpr bool operator>=(const span<ElementType, Extent>& l, inline constexpr bool operator>=(span<ElementType, Extent> l,
const span<ElementType, Extent>& r) span<ElementType, Extent> r)
{ {
return !(l < r); return !(l < r);
} }
@ -675,7 +675,7 @@ span<typename Ptr::element_type> make_span(Ptr& cont)
// Specialization of gsl::at for span // Specialization of gsl::at for span
template <class ElementType, std::ptrdiff_t Extent> 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 // No bounds checking here because it is done in span::operator[] called below
return s[index]; return s[index];