1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-09 17:44:56 +09:00

AK: Add Vector::get(index) convenience function

This is similar to HashMap::get(key), which returns an Optional, empty
if the index is out of bounds for the vector.
This commit is contained in:
Ali Mohammad Pur 2024-12-10 23:33:38 +01:00 committed by Ali Mohammad Pur
parent f8092455e2
commit 44798f44ef
Notes: github-actions[bot] 2024-12-13 09:01:34 +00:00

View file

@ -155,6 +155,20 @@ public:
ALWAYS_INLINE VisibleType const& operator[](size_t i) const { return at(i); }
ALWAYS_INLINE VisibleType& operator[](size_t i) { return at(i); }
Optional<VisibleType&> get(size_t i)
{
if (i >= size())
return {};
return at(i);
}
Optional<VisibleType const&> get(size_t i) const
{
if (i >= size())
return {};
return at(i);
}
VisibleType const& first() const { return at(0); }
VisibleType& first() { return at(0); }