Your coding a wrapper/aggregator for std::unique_ptr is a good choice.
Some types are same, but with different default values and different cleanup APIs.
For OpenProcess()/OpenThreadToken() etc., the type is HANDLE, the default value is NULL, the cleanup API is CloseHandle().
For CreateFile()/FindFirstFile()/CreateToolhelp32Snapshot() etc., the type is also HANDLE, but the default value is INVALID_HANDLE_VALUE, and the cleanup API for FindFirstFile() is FindClose(), instead of CloseHandle().
So that's why I use traits/adapter to describe the difference.
And, I need the operator&() override to auto reset to the default value when reusing the same UniqueResource variable.
Quote:
Originally Posted by atom0s
Using templates can remove the need to manually define the delete function. It can also be used to further extend into a custom wrapper to deal with the other parts you mentioned as well such as:
|