mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +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:
parent
c9caa4262e
commit
831e5ed4e2
Notes:
github-actions[bot]
2024-08-13 12:14:06 +00:00
Author: https://github.com/trflynn89 Commit: https://github.com/LadybirdBrowser/ladybird/commit/831e5ed4e22 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1041
2 changed files with 14 additions and 0 deletions
|
@ -296,6 +296,12 @@ public:
|
||||||
return TypedTransfer<T>::compare(data(), other.data(), size());
|
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
|
ALWAYS_INLINE constexpr operator ReadonlySpan<T>() const
|
||||||
{
|
{
|
||||||
return { data(), size() };
|
return { data(), size() };
|
||||||
|
|
|
@ -159,3 +159,11 @@ TEST_CASE(contains_slow)
|
||||||
EXPECT(!span.contains_slow(String {}));
|
EXPECT(!span.contains_slow(String {}));
|
||||||
EXPECT(!span.contains_slow(StringView {}));
|
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());
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue