Skip to content

Commit

Permalink
Add nullptr comparison operator to parented_ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
jmigual committed Feb 27, 2017
1 parent 7b6370d commit b165107
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/util/parented_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define UTIL_PARENTED_PTR_H

#include <QPointer>
#include <cstddef>
#include "util/assert.h"

/**
Expand All @@ -22,7 +23,7 @@ class parented_ptr {
template <typename U>
parented_ptr(parented_ptr<U>&& u, typename std::enable_if<std::is_convertible<U*, T*>::value, void>::type * = 0)
: m_pObject(u.get()) {
if (u.m_pObject != nullptr) {
if (u != nullptr) {
DEBUG_ASSERT(u->parent() != nullptr);
}
}
Expand Down Expand Up @@ -108,6 +109,16 @@ inline bool operator== (const parented_ptr<T>& lhs, const parented_ptr<U>& rhs)
return lhs.get() == rhs.get();
}

template<typename T>
inline bool operator== (const parented_ptr<T>& p, std::nullptr_t) {
return p.get() == nullptr;
}

template<typename T>
inline bool operator== (std::nullptr_t, const parented_ptr<T>& p) {
return p.get() == nullptr;
}

template<typename T, typename U>
inline bool operator!= (const T* lhs, const parented_ptr<U>& rhs) {
return !(lhs == rhs.get());
Expand All @@ -123,6 +134,16 @@ inline bool operator!= (const parented_ptr<T>& lhs, const parented_ptr<U>& rhs)
return !(lhs.get() == rhs.get());
}

template<typename T>
inline bool operator!= (const parented_ptr<T>& p, std::nullptr_t) {
return !(p == nullptr);
}

template<typename T>
inline bool operator!= (std::nullptr_t, const parented_ptr<T>& p) {
return !(nullptr == p);
}

} // namespace

#endif // UTIL_PARENTED_PTR_H

0 comments on commit b165107

Please sign in to comment.