From 6a5446d6ddf009e5fe4970e8509e2b669222a7df Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 25 Jul 2019 11:10:28 +0200 Subject: [PATCH] AK: Simplify NonnullPtrVector template a bit. Add an "ElementType" typedef to NonnullOwnPtr and NonnullRefPtr to allow clients to easily find the pointee type. Then use this to remove a template argument from NonnullPtrVector. :^) --- AK/NonnullOwnPtr.h | 2 ++ AK/NonnullOwnPtrVector.h | 2 +- AK/NonnullPtrVector.h | 3 ++- AK/NonnullRefPtr.h | 6 +++--- AK/NonnullRefPtrVector.h | 2 +- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/AK/NonnullOwnPtr.h b/AK/NonnullOwnPtr.h index 7c8c7817f2..e9cc114be6 100644 --- a/AK/NonnullOwnPtr.h +++ b/AK/NonnullOwnPtr.h @@ -18,6 +18,8 @@ class WeakPtr; template class CONSUMABLE(unconsumed) NonnullOwnPtr { public: + typedef T ElementType; + enum AdoptTag { Adopt }; RETURN_TYPESTATE(unconsumed) diff --git a/AK/NonnullOwnPtrVector.h b/AK/NonnullOwnPtrVector.h index d1d7024b7b..d00644225c 100644 --- a/AK/NonnullOwnPtrVector.h +++ b/AK/NonnullOwnPtrVector.h @@ -6,7 +6,7 @@ namespace AK { template -class NonnullOwnPtrVector : public NonnullPtrVector, T, inline_capacity> +class NonnullOwnPtrVector : public NonnullPtrVector, inline_capacity> { }; diff --git a/AK/NonnullPtrVector.h b/AK/NonnullPtrVector.h index 345da11e08..2cc7147c4a 100644 --- a/AK/NonnullPtrVector.h +++ b/AK/NonnullPtrVector.h @@ -4,8 +4,9 @@ namespace AK { -template +template class NonnullPtrVector : public Vector { + typedef typename PtrType::ElementType T; typedef Vector Base; public: diff --git a/AK/NonnullRefPtr.h b/AK/NonnullRefPtr.h index 84719fd345..0cbb4ed8f9 100644 --- a/AK/NonnullRefPtr.h +++ b/AK/NonnullRefPtr.h @@ -26,9 +26,9 @@ inline void deref_if_not_null(T* ptr) template class CONSUMABLE(unconsumed) NonnullRefPtr { public: - enum AdoptTag { - Adopt - }; + typedef T ElementType; + + enum AdoptTag { Adopt }; RETURN_TYPESTATE(unconsumed) NonnullRefPtr(const T& object) diff --git a/AK/NonnullRefPtrVector.h b/AK/NonnullRefPtrVector.h index 1997e9fe45..38d137108b 100644 --- a/AK/NonnullRefPtrVector.h +++ b/AK/NonnullRefPtrVector.h @@ -6,7 +6,7 @@ namespace AK { template -class NonnullRefPtrVector : public NonnullPtrVector, T, inline_capacity> +class NonnullRefPtrVector : public NonnullPtrVector, inline_capacity> { };