From 96cfddb3acfb1401160133550b2a6f70d9df52b3 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 22 Dec 2019 12:23:30 +0100 Subject: [PATCH] AK: Add IntrusiveList::take_first() --- AK/IntrusiveList.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 {