more reliable op phandle

This commit is contained in:
Akash Mozumdar 2019-01-23 14:47:42 -05:00
parent 632139dce2
commit 7fcf994a00

View File

@ -39,11 +39,11 @@ class AutoHandle
public: public:
AutoHandle(HANDLE h) : h(h) {} AutoHandle(HANDLE h) : h(h) {}
operator HANDLE() { return h.get(); } operator HANDLE() { return h.get(); }
PHANDLE operator&() { return &h._Myptr(); } PHANDLE operator&() { static_assert(sizeof(*this) == sizeof(HANDLE)); return (PHANDLE)this; }
operator bool() { return h.get() != NULL && h.get() != INVALID_HANDLE_VALUE; } operator bool() { return h.get() != NULL && h.get() != INVALID_HANDLE_VALUE; }
private: private:
struct HandleCleaner : HandleCloser { void operator()(void* h) { if (h != INVALID_HANDLE_VALUE) HandleCloser::operator()(h); } }; struct HandleCleaner { void operator()(void* h) { if (h != INVALID_HANDLE_VALUE) HandleCloser()(h); } };
std::unique_ptr<void, HandleCleaner> h; std::unique_ptr<void, HandleCleaner> h;
}; };