## Monday, September 27, 2010

### Abusing shared_ptr custom deleters to store data.

So you can associate a custom deleter with a boost::shared_ptr object. That deleter will get called when the last reference to the underlying object is destroyed and is responsible for cleaning up the object. You might use this to use a boost::shared_ptr to hold a mysql handle.
boost::shared_ptr mysql( mysq_init(), mysql_close );


(or something like that .. can't remember the exact function names)
But you can also "hide" objects with the shared_ptr that will get destroyed with it... I'm not sure quite why you might want to do it, but someone was asking how to do somethign similar in StackOverflow.

Here's how you do it.