diff --git a/include/span.h b/include/span.h index 187f948..2760121 100644 --- a/include/span.h +++ b/include/span.h @@ -481,26 +481,30 @@ private: }; -#if 0 // TODO // [span.comparison], span comparison operators template -constexpr bool operator==(const span& l, const span& r) const noexcept; +constexpr bool operator==(const span& l, const span& r) noexcept +{ return std::equal(l.begin(), l.end(), r.begin(), r.end()); } template -constexpr bool operator!=(const span& l, const span& r) const noexcept; +constexpr bool operator!=(const span& l, const span& r) noexcept +{ return !(l == r); } template -constexpr bool operator<(const span& l, const span& r) const noexcept; +constexpr bool operator<(const span& l, const span& r) noexcept +{ return std::lexicographical_compare(l.begin(), l.end(), r.begin(), r.end()); } template -constexpr bool operator<=(const span& l, const span& r) const noexcept; +constexpr bool operator<=(const span& l, const span& r) noexcept +{ return !(l > r); } template -constexpr bool operator>(const span& l, const span& r) const noexcept; +constexpr bool operator>(const span& l, const span& r) noexcept +{ return r < l; } template -constexpr bool operator>=(const span& l, const span& r) const noexcept; -#endif +constexpr bool operator>=(const span& l, const span& r) noexcept +{ return !(l < r); } #if 0 // TODO diff --git a/tests/span_tests.cpp b/tests/span_tests.cpp index 74182de..694d9a2 100644 --- a/tests/span_tests.cpp +++ b/tests/span_tests.cpp @@ -801,23 +801,30 @@ SUITE(span_tests) } } -#if 0 TEST(comparison_operators) { { - int arr[10][2]; - auto s1 = as_span(arr); - span s2 = s1; - + span s1 = nullptr; + span s2 = nullptr; CHECK(s1 == s2); - - span s3 = as_span(s1, dim<>(20)); - CHECK(s3 == s2 && s3 == s1); + CHECK(!(s1 != s2)); + CHECK(!(s1 < s2)); + CHECK(s1 <= s2); + CHECK(!(s1 > s2)); + CHECK(s1 >= s2); + CHECK(s2 == s1); + CHECK(!(s2 != s1)); + CHECK(!(s2 < s1)); + CHECK(s2 <= s1); + CHECK(!(s2 > s1)); + CHECK(s2 >= s1); } { - auto s1 = nullptr; - auto s2 = nullptr; + int arr[] = {2, 1}; + span s1 = arr; + span s2 = arr; + CHECK(s1 == s2); CHECK(!(s1 != s2)); CHECK(!(s1 < s2)); @@ -914,6 +921,7 @@ SUITE(span_tests) } } +#if 0 TEST(fixed_size_conversions) { int arr[] = {1, 2, 3, 4};