Boost logo

Boost :

From: svanechel_at_[hidden]
Date: 2001-06-11 13:34:33


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



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