From 41c0312921f85de90f3114907cf1c0cf8ff903aa Mon Sep 17 00:00:00 2001 From: elasota Date: Thu, 17 Mar 2022 01:48:16 -0400 Subject: [PATCH] Add more nullptr_t operators --- PortabilityLayer/PLHandle.h | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/PortabilityLayer/PLHandle.h b/PortabilityLayer/PLHandle.h index 8ad1563..f2ff795 100644 --- a/PortabilityLayer/PLHandle.h +++ b/PortabilityLayer/PLHandle.h @@ -1,5 +1,7 @@ #pragma once +#include + namespace PortabilityLayer { struct MMHandleBlock; @@ -47,6 +49,9 @@ public: bool operator==(T** other) const; bool operator!=(T** other) const; + bool operator==(std::nullptr_t) const; + bool operator!=(std::nullptr_t) const; + static THandle NullPtr(); }; @@ -114,17 +119,33 @@ inline bool THandle::operator!=(const THandle &other) const template inline bool THandle::operator==(T** other) const { + if (other == nullptr) + return m_hdl == nullptr; return static_cast(&m_hdl->m_contents) == static_cast(other); } template inline bool THandle::operator!=(T** other) const { + if (other == nullptr) + return m_hdl != nullptr; return static_cast(&m_hdl->m_contents) != static_cast(other); } template -THandle THandle::NullPtr() +inline bool THandle::operator==(std::nullptr_t) const +{ + return m_hdl == nullptr; +} + +template +inline bool THandle::operator!=(std::nullptr_t) const +{ + return m_hdl != nullptr; +} + +template +inline THandle THandle::NullPtr() { return THandle(static_cast(nullptr)); }