mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 20:45:14 +00:00
AK: Add find_first_index to NonnullPtrVector that strips smart pointer
When we want to use the find_first_index that base Vector provides, we need to provide an element of the real contained type. That's impossible for OwnPtr, however, and even with RefPtr there might be instances where we have a raw reference to the object we want to find, but no smart pointer. Therefore, overloading this function (with an identical body, the magic is done by the find_index templatization) with `T const&` as a parameter allows there use cases.
This commit is contained in:
parent
67b5aea2f9
commit
ff8ca811c7
Notes:
sideshowbarker
2024-07-17 14:22:07 +09:00
Author: https://github.com/kleinesfilmroellchen Commit: https://github.com/SerenityOS/serenity/commit/ff8ca811c7 Pull-request: https://github.com/SerenityOS/serenity/pull/13516 Issue: https://github.com/SerenityOS/serenity/issues/65
1 changed files with 9 additions and 0 deletions
|
@ -47,6 +47,15 @@ public:
|
|||
ALWAYS_INLINE constexpr auto in_reverse() { return ReverseWrapper::in_reverse(*this); }
|
||||
ALWAYS_INLINE constexpr auto in_reverse() const { return ReverseWrapper::in_reverse(*this); }
|
||||
|
||||
Optional<size_t> find_first_index(T const& value) const
|
||||
{
|
||||
if (auto const index = AK::find_index(begin(), end(), value);
|
||||
index < size()) {
|
||||
return index;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
ALWAYS_INLINE PtrType& ptr_at(size_t index) { return Base::at(index); }
|
||||
ALWAYS_INLINE PtrType const& ptr_at(size_t index) const { return Base::at(index); }
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue