Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
src: add equality operators for BaseObjectPtr
  • Loading branch information
addaleax committed Jun 11, 2020
commit b1aad92c98d8c909c93971b47c2b12c32f2a0a6f
14 changes: 14 additions & 0 deletions src/base_object-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)...));
Expand Down
5 changes: 5 additions & 0 deletions src/base_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down