Boost logo

Boost :

From: scleary_at_[hidden]
Date: 2002-01-26 17:59:48


If you (or the user) don't want to create a separate policy plugin for each
type of releasable resource, we might want to consider providing (as part of
Boost, I mean) a shared/scoped_ptr<> that calls a function<void> on
destruction. This would also be helpful in other situations.

I already use a simple object of this type in my code -- it just derives
from noncopyable and runs the function in its destructor. As such, it acts
as a scoped_ptr<function<void> > that "frees" its "resource" by executing
it.

I also use a copyable object that runs a function in its destructor -- but
only if the destructor is called during stack unwinding. This replaces
"do_stuff(); try { more_stuff(); } catch (...) { undo_stuff(); throw; }"
with "do_stuff(); run_on_error guard(&undo_stuff); more_stuff();".

Just some thoughts for future directions! :)
        -Steve


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk