mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-15 04:13:11 +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
|
@ -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…
Reference in a new issue