mirror of
https://github.com/microsoft/GSL.git
synced 2024-11-03 17:56:43 -05:00
Merge pull request #616 from neilmacintosh/tidy-comparison-ops
Tidy up span comparison ops
This commit is contained in:
commit
3a12c55cb6
@ -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;
|
||||||
}
|
}
|
||||||
@ -535,43 +535,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);
|
||||||
}
|
}
|
||||||
@ -662,7 +662,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];
|
||||||
|
Loading…
Reference in New Issue
Block a user