Skip to content

Commit

Permalink
AK: Simplify NonnullPtrVector template a bit.
Browse files Browse the repository at this point in the history
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. :^)
  • Loading branch information
awesomekling committed Jul 25, 2019
1 parent 10d120d commit 6a5446d
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 6 deletions.
2 changes: 2 additions & 0 deletions AK/NonnullOwnPtr.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class WeakPtr;
template<typename T>
class CONSUMABLE(unconsumed) NonnullOwnPtr {
public:
typedef T ElementType;

enum AdoptTag { Adopt };

RETURN_TYPESTATE(unconsumed)
Expand Down
2 changes: 1 addition & 1 deletion AK/NonnullOwnPtrVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace AK {

template<typename T, int inline_capacity = 0>
class NonnullOwnPtrVector : public NonnullPtrVector<NonnullOwnPtr<T>, T, inline_capacity>
class NonnullOwnPtrVector : public NonnullPtrVector<NonnullOwnPtr<T>, inline_capacity>
{
};

Expand Down
3 changes: 2 additions & 1 deletion AK/NonnullPtrVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

namespace AK {

template<typename PtrType, typename T, int inline_capacity = 0>
template<typename PtrType, int inline_capacity = 0>
class NonnullPtrVector : public Vector<PtrType, inline_capacity> {
typedef typename PtrType::ElementType T;
typedef Vector<PtrType, inline_capacity> Base;

public:
Expand Down
6 changes: 3 additions & 3 deletions AK/NonnullRefPtr.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ inline void deref_if_not_null(T* ptr)
template<typename T>
class CONSUMABLE(unconsumed) NonnullRefPtr {
public:
enum AdoptTag {
Adopt
};
typedef T ElementType;

enum AdoptTag { Adopt };

RETURN_TYPESTATE(unconsumed)
NonnullRefPtr(const T& object)
Expand Down
2 changes: 1 addition & 1 deletion AK/NonnullRefPtrVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace AK {

template<typename T, int inline_capacity = 0>
class NonnullRefPtrVector : public NonnullPtrVector<NonnullRefPtr<T>, T, inline_capacity>
class NonnullRefPtrVector : public NonnullPtrVector<NonnullRefPtr<T>, inline_capacity>
{
};

Expand Down

0 comments on commit 6a5446d

Please sign in to comment.