I was wondering if there is a way to use unique_ptr with Windows HANDLEs?
I was thinking to replace the std::default_delete with s
The question can be extended for COM IUnknown pointers - can CComPtr be replaced by any of the standard smart pointers?
Yes. You don't specialize std::default_deleter, you simply replace the deleter type.
struct COMDeleter {
template void operator()(T* ptr) {
ptr->Release();
}
};
unique_ptr ptr; // Works fine
The same principle applies to shared_ptr and indeed, to HANDLE.