Boost logo

Boost :

From: Mat Marcus (mmarcus_at_[hidden])
Date: 2001-06-11 14:12:56

Have you looked at Andrei Alexandrescu and Petru Marginean's ScopeGuard
class? I believe it has the same intent. See the article:


Quote from the article:

"...ScopeGuard uses several generic programming techniques to let you
prescribe function and member function calls to be performed when a
ScopeGuard variable exits a scope. Optionally, you can dismiss the
ScopeGuard object.

ScopeGuard is useful when you need to perform automatic cleanup of resources
and can rely on failure-proof undo operations..."

-- Mat

-----Original Message-----
From: svanechel_at_[hidden] [mailto:svanechel_at_[hidden]]
Sent: Monday, June 11, 2001 11:35 AM
To: boost_at_[hidden]
Subject: [boost] Resource managment


Recently I grew tired always having to write the same boiler plate
code when I wanted to manage a resource using the "resource
acquisition is initialization" technique. Looking for a more
solution I browsed through the posted message and noticed that I
wasn't the first one who encountered this problem (yeah duh). At
first glance I couldn't find any acceptable solution (browsed
a large subset of the 13000+ postings), so I went on and tried it
myself. The solution I came up with uses a traits class to handle
both resource destruction and a suitable nul-value. I've uploaded
results in the files section (

Basically the RAII-harness (apparently that's the terminology for
does most of the work and only those aspects that of resource
management that are dependent on the resource type are moved out into
a traits class. To test my idea I went on and (naively) re-
implemented the boost smart pointer classes <boost/smart_ptr.hpp>
using the classes I just created. I discern three different types:

* the non-copyable resources (boost::scoped_ptr and
* the shared resources (boost::shared_ptr and boost::shared_array)
* resources that aren't shared but can be copied (E.g. Win32

Three base classes handle these three cases.

I would very much appreciate some input on the issue (is this
approach OK? Is the solution useful enough to be turned into a



To unsubscribe, send email to: <mailto:boost-unsubscribe_at_[hidden]>

Your use of Yahoo! Groups is subject to

Boost list run by bdawes at, gregod at, cpdaniel at, john at