Good point, I just didn't bother writing a handle class given I knew I could
use shared_ptr and the space/time overhead wasn't important.
Anyway, I'll take a shot at writing an auto_handle class.
"Ben Hutchings"
Pablo Aguilar wrote:
Thanks for your reply...
You're right, "reset" would delete the pointer... but when you're getting rid of a pointer obtained from a factory, like I was in my case, pointers don't always get disposed of using delete, but rather another function (like p->release())
And rather than writing special purpose smart pointers for each type of deleting function (p->dispose(), p->release(), api_function_free(p), etc..) you can use shared_ptr with a custom deleter (here: mem_fn(&pointer_type::dispose) or bind(&api_function_free, _1))
In some cases you can avoid the space and time overhead of shared_ptr by using a smart pointer template for which the custom deleter is a template argument. In fact you can get even more general than that quite easily; I have a class template called auto_handle which with minimal work can be used to encapsulate all kinds of things with custom deleters, including Windows handles and POSIX file descriptors.
Ben.