From: Joe Swatosh (joe-swatosh_at_[hidden])
Date: 2002-06-05 20:17:24
Petru Marginean and Andrei Alexandrescu wrote a handy group of classes that will call a function when a "guard" object goes out of scope (unless the "guard" has been "dismissed"), that they documented in a CUJ "C++ Experts Forum" column. The article is available online:
With their permission, I've attempted to "boostify" this group of classes. I have uploaded these files to the "vault" (together they are fewer than 200 lines so I hope not compressing them isn't too big a deal). The code has been tested with VC6SP5, VC7, and Borland 5.5.
I realized that much of the code in the original was for binding arguments to the function to be called and so could be replaced by boost::bind. Other than that I renamed things to be more like the naming conventions on the boost website, and simplified where possible.
I recognize that this is basically a primitive "smart resource" and that smart resources have been discussed a lot lately especially in the context of smart pointers. These classes are just so simple and useful that I want to propose something _now_ to fill the gap. This much too small to be a boost library by itself and I'm not sure where it might fit, so here it is to talk about.
Joe Swatosh [mailto:joe-swatosh_at_[hidden]]
3305 Main St. Suite 201
Vancouver, WA 98663
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk