Add more nullptr_t operators

This commit is contained in:
elasota
2022-03-17 01:48:16 -04:00
parent d470bb5eeb
commit 41c0312921

View File

@@ -1,5 +1,7 @@
#pragma once #pragma once
#include <cstddef>
namespace PortabilityLayer namespace PortabilityLayer
{ {
struct MMHandleBlock; struct MMHandleBlock;
@@ -47,6 +49,9 @@ public:
bool operator==(T** other) const; bool operator==(T** other) const;
bool operator!=(T** other) const; bool operator!=(T** other) const;
bool operator==(std::nullptr_t) const;
bool operator!=(std::nullptr_t) const;
static THandle<T> NullPtr(); static THandle<T> NullPtr();
}; };
@@ -114,17 +119,33 @@ inline bool THandle<T>::operator!=(const THandle<T> &other) const
template<class T> template<class T>
inline bool THandle<T>::operator==(T** other) const inline bool THandle<T>::operator==(T** other) const
{ {
if (other == nullptr)
return m_hdl == nullptr;
return static_cast<void*>(&m_hdl->m_contents) == static_cast<void*>(other); return static_cast<void*>(&m_hdl->m_contents) == static_cast<void*>(other);
} }
template<class T> template<class T>
inline bool THandle<T>::operator!=(T** other) const inline bool THandle<T>::operator!=(T** other) const
{ {
if (other == nullptr)
return m_hdl != nullptr;
return static_cast<void*>(&m_hdl->m_contents) != static_cast<void*>(other); return static_cast<void*>(&m_hdl->m_contents) != static_cast<void*>(other);
} }
template<class T> template<class T>
THandle<T> THandle<T>::NullPtr() inline bool THandle<T>::operator==(std::nullptr_t) const
{
return m_hdl == nullptr;
}
template<class T>
inline bool THandle<T>::operator!=(std::nullptr_t) const
{
return m_hdl != nullptr;
}
template<class T>
inline THandle<T> THandle<T>::NullPtr()
{ {
return THandle<T>(static_cast<PortabilityLayer::MMHandleBlock *>(nullptr)); return THandle<T>(static_cast<PortabilityLayer::MMHandleBlock *>(nullptr));
} }