
Kevin Martin wrote:
I have just discovered to my delight that you can use shared_ptr with a null deleter to pass around stack based objects. This is great because a function shouldn't care whether a parameter passed to it is on the heap or stack. So I can write general functions to accept a shared_ptr and if I have to pass a stack based object I can just pass a null deleter.
You can do a lot more than that! Consider the case of a handle of some sort that you need to return to a service when you are done. Case in point, in order to get rid of an sqlite database connection pointer you call db_close(), NOT delete. No big deal, just use db_close as your deleter! The fact that you can use anything as a deleter for a shared_ptr turns it into a hammer with a driver head. So then everything IS effectively a nail.