diff --git a/AK/Span.h b/AK/Span.h index de72faf0c9a..544e8c0ce4a 100644 --- a/AK/Span.h +++ b/AK/Span.h @@ -296,6 +296,12 @@ public: return TypedTransfer::compare(data(), other.data(), size()); } + constexpr bool operator==(Span const& other) const + requires(!IsConst) + { + return Span(*this) == other; + } + ALWAYS_INLINE constexpr operator ReadonlySpan() const { return { data(), size() }; diff --git a/Tests/AK/TestSpan.cpp b/Tests/AK/TestSpan.cpp index f9518d7706e..407f8ca407a 100644 --- a/Tests/AK/TestSpan.cpp +++ b/Tests/AK/TestSpan.cpp @@ -159,3 +159,11 @@ TEST_CASE(contains_slow) EXPECT(!span.contains_slow(String {})); EXPECT(!span.contains_slow(StringView {})); } + +TEST_CASE(compare_different_constness) +{ + constexpr Array array { 4, 5, 6 }; + Vector vector { 4, 5, 6 }; + + EXPECT_EQ(array, vector.span()); +}