express: Allow WeakPointer comparisons to nullptr

This saves us from having to do casts like:
if (foo == (const FooType *)nullptr) {
  ...
}
This commit is contained in:
Sam Edwards 2018-05-27 17:31:49 -06:00
parent 57602d750f
commit ebe1b0763f
2 changed files with 61 additions and 0 deletions

View File

@ -292,6 +292,51 @@ operator >= (To *other) const {
return (To *)_void_ptr >= other;
}
/**
*
*/
template<class T>
INLINE bool WeakPointerToBase<T>::
operator == (nullptr_t) const {
return _void_ptr == nullptr;
}
/**
*
*/
template<class T>
INLINE bool WeakPointerToBase<T>::
operator != (nullptr_t) const {
return _void_ptr != nullptr;
}
/**
*
*/
template<class T>
INLINE bool WeakPointerToBase<T>::
operator > (nullptr_t) const {
return _void_ptr != nullptr;
}
/**
*
*/
template<class T>
INLINE bool WeakPointerToBase<T>::
operator <= (nullptr_t) const {
return _void_ptr == nullptr;
}
/**
*
*/
template<class T>
INLINE bool WeakPointerToBase<T>::
operator >= (nullptr_t) const {
return true;
}
/**
*
*/
@ -392,6 +437,15 @@ operator < (const To *other) const {
return (To *)_void_ptr < other;
}
/**
*
*/
template<class T>
INLINE bool WeakPointerToBase<T>::
operator < (nullptr_t) const {
return false;
}
/**
*
*/

View File

@ -60,6 +60,12 @@ public:
INLINE bool operator <= (To *other) const;
INLINE bool operator >= (To *other) const;
INLINE bool operator == (nullptr_t) const;
INLINE bool operator != (nullptr_t) const;
INLINE bool operator > (nullptr_t) const;
INLINE bool operator <= (nullptr_t) const;
INLINE bool operator >= (nullptr_t) const;
INLINE bool operator == (const WeakPointerToBase<To> &other) const;
INLINE bool operator != (const WeakPointerToBase<To> &other) const;
INLINE bool operator > (const WeakPointerToBase<To> &other) const;
@ -73,6 +79,7 @@ public:
INLINE bool operator >= (const PointerToBase<To> &other) const;
#endif // WIN32_VC
INLINE bool operator < (const To *other) const;
INLINE bool operator < (nullptr_t) const;
INLINE bool operator < (const WeakPointerToBase<To> &other) const;
INLINE bool operator < (const PointerToBase<To> &other) const;
#endif // CPPPARSER