1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:37:34 +00:00

AK+Everywhere: Make StdLibExtras templates less wrapper-y

This commit makes the user-facing StdLibExtras templates and utilities
arguably more nice-looking by removing the need to reach into the
wrapper structs generated by them to get the value/type needed.
The C++ standard library had to invent `_v` and `_t` variants (likely
because of backwards compat), but we don't need to cater to any codebase
except our own, so might as well have good things for free. :^)
This commit is contained in:
AnotherTest 2021-04-10 18:29:06 +04:30 committed by Andreas Kling
parent d8d16dea95
commit a6e4482080
41 changed files with 650 additions and 662 deletions

View file

@ -38,26 +38,26 @@ class WeakPtr {
public:
WeakPtr() = default;
template<typename U, typename EnableIf<IsBaseOf<T, U>::value>::Type* = nullptr>
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
WeakPtr(const WeakPtr<U>& other)
: m_link(other.m_link)
{
}
template<typename U, typename EnableIf<IsBaseOf<T, U>::value>::Type* = nullptr>
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
WeakPtr(WeakPtr<U>&& other)
: m_link(other.take_link())
{
}
template<typename U, typename EnableIf<IsBaseOf<T, U>::value>::Type* = nullptr>
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
WeakPtr& operator=(WeakPtr<U>&& other)
{
m_link = other.take_link();
return *this;
}
template<typename U, typename EnableIf<IsBaseOf<T, U>::value>::Type* = nullptr>
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
WeakPtr& operator=(const WeakPtr<U>& other)
{
if ((const void*)this != (const void*)&other)
@ -71,20 +71,20 @@ public:
return *this;
}
template<typename U, typename EnableIf<IsBaseOf<T, U>::value>::Type* = nullptr>
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
WeakPtr(const U& object)
: m_link(object.template make_weak_ptr<U>().take_link())
{
}
template<typename U, typename EnableIf<IsBaseOf<T, U>::value>::Type* = nullptr>
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
WeakPtr(const U* object)
{
if (object)
m_link = object->template make_weak_ptr<U>().take_link();
}
template<typename U, typename EnableIf<IsBaseOf<T, U>::value>::Type* = nullptr>
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
WeakPtr(const RefPtr<U>& object)
{
object.do_while_locked([&](U* obj) {
@ -93,7 +93,7 @@ public:
});
}
template<typename U, typename EnableIf<IsBaseOf<T, U>::value>::Type* = nullptr>
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
WeakPtr(const NonnullRefPtr<U>& object)
{
object.do_while_locked([&](U* obj) {
@ -102,14 +102,14 @@ public:
});
}
template<typename U, typename EnableIf<IsBaseOf<T, U>::value>::Type* = nullptr>
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
WeakPtr& operator=(const U& object)
{
m_link = object.template make_weak_ptr<U>().take_link();
return *this;
}
template<typename U, typename EnableIf<IsBaseOf<T, U>::value>::Type* = nullptr>
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
WeakPtr& operator=(const U* object)
{
if (object)
@ -119,7 +119,7 @@ public:
return *this;
}
template<typename U, typename EnableIf<IsBaseOf<T, U>::value>::Type* = nullptr>
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
WeakPtr& operator=(const RefPtr<U>& object)
{
object.do_while_locked([&](U* obj) {
@ -131,7 +131,7 @@ public:
return *this;
}
template<typename U, typename EnableIf<IsBaseOf<T, U>::value>::Type* = nullptr>
template<typename U, typename EnableIf<IsBaseOf<T, U>>::Type* = nullptr>
WeakPtr& operator=(const NonnullRefPtr<U>& object)
{
object.do_while_locked([&](U* obj) {
@ -199,7 +199,7 @@ template<typename T>
template<typename U>
inline WeakPtr<U> Weakable<T>::make_weak_ptr() const
{
if constexpr (IsBaseOf<RefCountedBase, T>::value) {
if constexpr (IsBaseOf<RefCountedBase, T>) {
// Checking m_being_destroyed isn't sufficient when dealing with
// a RefCounted type.The reference count will drop to 0 before the
// destructor is invoked and revoke_weak_ptrs is called. So, try
@ -223,7 +223,7 @@ inline WeakPtr<U> Weakable<T>::make_weak_ptr() const
WeakPtr<U> weak_ptr(m_link);
if constexpr (IsBaseOf<RefCountedBase, T>::value) {
if constexpr (IsBaseOf<RefCountedBase, T>) {
// Now drop the reference we temporarily added
if (static_cast<const T*>(this)->unref()) {
// We just dropped the last reference, which should have called