diff --git a/AK/IntrusiveList.h b/AK/IntrusiveList.h index 6382a503b9..2fdc5291e2 100644 --- a/AK/IntrusiveList.h +++ b/AK/IntrusiveList.h @@ -27,6 +27,8 @@ public: T* first() const; T* last() const; + T* take_first(); + class Iterator { public: Iterator(); @@ -193,6 +195,16 @@ inline T* IntrusiveList::first() const return m_storage.m_first ? node_to_value(*m_storage.m_first) : nullptr; } +template +inline T* IntrusiveList::take_first() +{ + if (auto* ptr = first()) { + remove(*ptr); + return ptr; + } + return nullptr; +} + template inline T* IntrusiveList::last() const {