mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-22 01:09:25 +00:00
AK: Allow comparing spans of different constness
Otherwise, the following code would not compile:
constexpr Array<int, 3> array { 4, 5, 6 };
Vector<int> vector { 4, 5, 6 };
if (array == vector.span()) { }
We do such comparisons in tests quite a bit. But it currently doesn't
become an issue because of the way EXPECT_EQ copies its input parameters
to non-const locals. In a future patch, that copying will be removed,
and the compiler would otherwise complain about not finding a suitable
comparison operator.
This commit is contained in:
committed by
Andreas Kling
parent
c9caa4262e
commit
831e5ed4e2
@@ -296,6 +296,12 @@ public:
|
||||
return TypedTransfer<T>::compare(data(), other.data(), size());
|
||||
}
|
||||
|
||||
constexpr bool operator==(Span<T const> const& other) const
|
||||
requires(!IsConst<T>)
|
||||
{
|
||||
return Span<T const>(*this) == other;
|
||||
}
|
||||
|
||||
ALWAYS_INLINE constexpr operator ReadonlySpan<T>() const
|
||||
{
|
||||
return { data(), size() };
|
||||
|
||||
@@ -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<int, 3> array { 4, 5, 6 };
|
||||
Vector<int> vector { 4, 5, 6 };
|
||||
|
||||
EXPECT_EQ(array, vector.span());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user