Skip to content

Commit a3d0b0e

Browse files
addaleaxcodebytere
authored andcommitted
src: add equality operators for BaseObjectPtr
PR-URL: #33772 Backport-PR-URL: #33965 Reviewed-By: Benjamin Gruenbaum <[email protected]>
1 parent eaccf84 commit a3d0b0e

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/base_object-inl.h

+14
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,20 @@ BaseObjectPtrImpl<T, kIsWeak>::operator bool() const {
338338
return get() != nullptr;
339339
}
340340

341+
template <typename T, bool kIsWeak>
342+
template <typename U, bool kW>
343+
bool BaseObjectPtrImpl<T, kIsWeak>::operator ==(
344+
const BaseObjectPtrImpl<U, kW>& other) const {
345+
return get() == other.get();
346+
}
347+
348+
template <typename T, bool kIsWeak>
349+
template <typename U, bool kW>
350+
bool BaseObjectPtrImpl<T, kIsWeak>::operator !=(
351+
const BaseObjectPtrImpl<U, kW>& other) const {
352+
return get() != other.get();
353+
}
354+
341355
template <typename T, typename... Args>
342356
BaseObjectPtr<T> MakeBaseObject(Args&&... args) {
343357
return BaseObjectPtr<T>(new T(std::forward<Args>(args)...));

src/base_object.h

+5
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,11 @@ class BaseObjectPtrImpl final {
236236
inline T* operator->() const;
237237
inline operator bool() const;
238238

239+
template <typename U, bool kW>
240+
inline bool operator ==(const BaseObjectPtrImpl<U, kW>& other) const;
241+
template <typename U, bool kW>
242+
inline bool operator !=(const BaseObjectPtrImpl<U, kW>& other) const;
243+
239244
private:
240245
union {
241246
BaseObject* target; // Used for strong pointers.

0 commit comments

Comments
 (0)