mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
AK: Add IntrusiveList::take_first()
This commit is contained in:
parent
4b8851bd01
commit
96cfddb3ac
Notes:
sideshowbarker
2024-07-19 10:46:23 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/96cfddb3acf
1 changed files with 12 additions and 0 deletions
|
@ -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
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue