Skip to content

Commit

Permalink
src: add equality operators for BaseObjectPtr
Browse files Browse the repository at this point in the history
PR-URL: #33772
Backport-PR-URL: #33965
Reviewed-By: Benjamin Gruenbaum <[email protected]>
  • Loading branch information
addaleax committed Sep 22, 2020
1 parent fb68487 commit 19b55be
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/base_object-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,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)...));
Expand Down
5 changes: 5 additions & 0 deletions src/base_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,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.
Expand Down

0 comments on commit 19b55be

Please sign in to comment.