I was wondering if there is a way to use unique_ptr with Windows HANDLEs?
unique_ptr
I was thinking to replace the std::default_delete with s
std::default_delete
You can typedef your unique_ptr with a custom deleter
struct handle_deleter { void operator()(void* handle) { if(handle != nullptr) CloseHandle(handle); } }; typedef std::unique_ptr UniqueHandle_t; UniqueHandle_t ptr(CreateFile(...));