From 19b55be03bc5ed7f85d4093c27ef038320725c39 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sat, 6 Jun 2020 15:57:12 +0200 Subject: [PATCH] src: add equality operators for BaseObjectPtr PR-URL: https://github.com/nodejs/node/pull/33772 Backport-PR-URL: https://github.com/nodejs/node/pull/33965 Reviewed-By: Benjamin Gruenbaum --- src/base_object-inl.h | 14 ++++++++++++++ src/base_object.h | 5 +++++ 2 files changed, 19 insertions(+) diff --git a/src/base_object-inl.h b/src/base_object-inl.h index 5dad438d1f55bf..cee7976c37e004 100644 --- a/src/base_object-inl.h +++ b/src/base_object-inl.h @@ -336,6 +336,20 @@ BaseObjectPtrImpl::operator bool() const { return get() != nullptr; } +template +template +bool BaseObjectPtrImpl::operator ==( + const BaseObjectPtrImpl& other) const { + return get() == other.get(); +} + +template +template +bool BaseObjectPtrImpl::operator !=( + const BaseObjectPtrImpl& other) const { + return get() != other.get(); +} + template BaseObjectPtr MakeBaseObject(Args&&... args) { return BaseObjectPtr(new T(std::forward(args)...)); diff --git a/src/base_object.h b/src/base_object.h index cc7a220d078552..24965a9879825d 100644 --- a/src/base_object.h +++ b/src/base_object.h @@ -195,6 +195,11 @@ class BaseObjectPtrImpl final { inline T* operator->() const; inline operator bool() const; + template + inline bool operator ==(const BaseObjectPtrImpl& other) const; + template + inline bool operator !=(const BaseObjectPtrImpl& other) const; + private: union { BaseObject* target; // Used for strong pointers.