diff options
author | Anna Henningsen <anna@addaleax.net> | 2020-06-06 16:57:12 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2020-06-14 15:53:39 +0300 |
commit | 8ead0211d7ee534015a10cc99c01a14cc38cbd3a (patch) | |
tree | 1e5bc7b4016d9bd3603f63f79631e4d9ceee4677 | |
parent | 57e7c63f74255e3287a11393bb4c18d0ab4e7b1d (diff) |
src: add equality operators for BaseObjectPtr
PR-URL: https://github.com/nodejs/node/pull/33772
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
-rw-r--r-- | src/base_object-inl.h | 14 | ||||
-rw-r--r-- | src/base_object.h | 5 |
2 files changed, 19 insertions, 0 deletions
diff --git a/src/base_object-inl.h b/src/base_object-inl.h index b3fb1562707..555063f4e23 100644 --- a/src/base_object-inl.h +++ b/src/base_object-inl.h @@ -338,6 +338,20 @@ BaseObjectPtrImpl<T, kIsWeak>::operator bool() const { return get() != nullptr; } +template <typename T, bool kIsWeak> +template <typename U, bool kW> +bool BaseObjectPtrImpl<T, kIsWeak>::operator ==( + const BaseObjectPtrImpl<U, kW>& other) const { + return get() == other.get(); +} + +template <typename T, bool kIsWeak> +template <typename U, bool kW> +bool BaseObjectPtrImpl<T, kIsWeak>::operator !=( + const BaseObjectPtrImpl<U, kW>& other) const { + return get() != other.get(); +} + template <typename T, typename... Args> BaseObjectPtr<T> MakeBaseObject(Args&&... args) { return BaseObjectPtr<T>(new T(std::forward<Args>(args)...)); diff --git a/src/base_object.h b/src/base_object.h index 39450540323..79ef76b236f 100644 --- a/src/base_object.h +++ b/src/base_object.h @@ -236,6 +236,11 @@ class BaseObjectPtrImpl final { inline T* operator->() const; inline operator bool() const; + template <typename U, bool kW> + inline bool operator ==(const BaseObjectPtrImpl<U, kW>& other) const; + template <typename U, bool kW> + inline bool operator !=(const BaseObjectPtrImpl<U, kW>& other) const; + private: union { BaseObject* target; // Used for strong pointers. |