mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50:22 +00:00
AK: Introduce IntrusiveListRelaxedConst
This container is the same as IntrusiveList, except that it allows modifications to the elements even if the reference to the IntrusiveList itself is const, by returning mutable iterators. This represents a use-case where we want to allow modifications to the elements while keeping the list itself immutable. This behavior is explicitely opt-in by using IntrusiveListRelaxedConst instead of IntrusiveList. It will be useful later on when we model shared/exclusive locks with the help of const and mutable references.
This commit is contained in:
parent
bb609cee7f
commit
786036820b
Notes:
sideshowbarker
2024-07-18 07:21:07 +09:00
Author: https://github.com/boricj Commit: https://github.com/SerenityOS/serenity/commit/786036820b4 Pull-request: https://github.com/SerenityOS/serenity/pull/8851 Reviewed-by: https://github.com/awesomekling ✅ Reviewed-by: https://github.com/bgianfo
1 changed files with 29 additions and 0 deletions
29
AK/IntrusiveListRelaxedConst.h
Normal file
29
AK/IntrusiveListRelaxedConst.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Copyright (c) 2021, the SerenityOS developers.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/IntrusiveList.h>
|
||||
|
||||
namespace AK {
|
||||
|
||||
template<class T, typename Container, IntrusiveListNode<T, Container> T::*member>
|
||||
class IntrusiveListRelaxedConst : public IntrusiveList<T, Container, member> {
|
||||
AK_MAKE_NONCOPYABLE(IntrusiveListRelaxedConst);
|
||||
AK_MAKE_NONMOVABLE(IntrusiveListRelaxedConst);
|
||||
|
||||
public:
|
||||
using IntrusiveList<T, Container, member>::IntrusiveList;
|
||||
|
||||
using Iterator = IntrusiveList<T, Container, member>::Iterator;
|
||||
|
||||
Iterator begin() const { return const_cast<IntrusiveListRelaxedConst*>(this)->IntrusiveList<T, Container, member>::begin(); }
|
||||
Iterator end() const { return Iterator {}; }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
using AK::IntrusiveListRelaxedConst;
|
Loading…
Reference in a new issue