In VC2012, I want to create a mutex in a constructor using a unique pointer and a deleter, so that I don\'t need to create a destructor just to call CloseHandle.
I w
Others have pointed out how the whole HANDLE
/HANDLE*
issue works. Here's a much cleverer way to deal with it, using interesting features of std::unique_pointer
.
struct WndHandleDeleter
{
typedef HANDLE pointer;
void operator()(HANDLE h) {::CloseHandle(h);}
};
typedef std::unique_ptr unique_handle;
This allows unique_handle::get
to return HANDLE
instead of HANDLE*
, without any fancy std::remove_pointer
or other such things.
This works because HANDLE
is a pointer and therefore satisfies NullablePointer.