1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 19:27:36 +00:00

AK: Generalize Span::contains_slow to use the Traits infrastructure

This allows, for example, checking if a Span<String> contains a value
without having to allocate a String.
This commit is contained in:
Timothy Flynn 2024-03-14 12:48:09 -04:00 committed by Andreas Kling
parent faf4ba63c2
commit e4213f5767
2 changed files with 24 additions and 2 deletions

View file

@ -210,10 +210,11 @@ public:
return size();
}
[[nodiscard]] constexpr bool contains_slow(T const& value) const
template<typename V>
[[nodiscard]] constexpr bool contains_slow(V const& value) const
{
for (size_t i = 0; i < size(); ++i) {
if (at(i) == value)
if (Traits<RemoveReference<T>>::equals(at(i), value))
return true;
}
return false;