AK: Add IntrusiveList::take_first()

This commit is contained in:
Andreas Kling 2019-12-22 12:23:30 +01:00
parent 4b8851bd01
commit 96cfddb3ac
Notes: sideshowbarker 2024-07-19 10:46:23 +09:00

View file

@ -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<T, member>::first() const
return m_storage.m_first ? node_to_value(*m_storage.m_first) : nullptr;
}
template<class T, IntrusiveListNode T::*member>
inline T* IntrusiveList<T, member>::take_first()
{
if (auto* ptr = first()) {
remove(*ptr);
return ptr;
}
return nullptr;
}
template<class T, IntrusiveListNode T::*member>
inline T* IntrusiveList<T, member>::last() const
{