mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:07:35 +00:00
AK+Kernel: Use requires expression when invoking ref counting hooks
Replace some old-school template trickery with C++20 requires. :^)
This commit is contained in:
parent
ec74afdb8d
commit
c4a0f01b02
3 changed files with 22 additions and 62 deletions
|
@ -25,10 +25,12 @@ class ListedRefCounted : public RefCountedBase {
|
|||
public:
|
||||
bool unref() const
|
||||
{
|
||||
auto const* that = static_cast<T const*>(this);
|
||||
|
||||
auto callback = [&](auto& list) {
|
||||
auto new_ref_count = deref_base();
|
||||
if (new_ref_count == 0)
|
||||
list.remove(const_cast<T&>(static_cast<T const&>(*this)));
|
||||
list.remove(const_cast<T&>(*that));
|
||||
return new_ref_count;
|
||||
};
|
||||
|
||||
|
@ -38,10 +40,12 @@ public:
|
|||
else if constexpr (Lock == LockType::Mutex)
|
||||
new_ref_count = T::all_instances().with_exclusive(callback);
|
||||
if (new_ref_count == 0) {
|
||||
call_will_be_destroyed_if_present(static_cast<const T*>(this));
|
||||
delete const_cast<T*>(static_cast<T const*>(this));
|
||||
if constexpr (requires { that->will_be_destroyed(); })
|
||||
that->will_be_destroyed();
|
||||
delete that;
|
||||
} else if (new_ref_count == 1) {
|
||||
call_one_ref_left_if_present(static_cast<T const*>(this));
|
||||
if constexpr (requires { that->one_ref_left(); })
|
||||
that->one_ref_left();
|
||||
}
|
||||
return new_ref_count == 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue