|
Boost Users : |
From: Jason Cipriani (jason.cipriani_at_[hidden])
Date: 2008-03-26 22:40:03
The boost shared_ptr lets me specify my own destructor function, but
shared_ptr does more than I want -- I do not need thread-safety or
reference counting, and would like to avoid the associated overhead.
What I really want is an std::auto_ptr that lets me specify a
destructor function. Does boost have something light-weight like this?
Right now I implement my own, sort of like this (with extra conversion stuff):
template <class T> class auto_ptr_ex {
public:
typedef void (* D) (T *);
// object + destructor
auto_ptr_ex (T *t, D d)
: t_(t), d_(d) { }
// copied auto_ptr_ex's don't destroy t_
auto_ptr_ex (const auto_ptr_ex &a)
: t_(a.t_), d_(NULL) { }
~auto_ptr_ex () {
if (d_) d_(t_);
}
private:
T *t_;
D d_;
};
It's simple enough but I try not to reinvent wheels, so I was
wondering if it existed already.
Thanks,
Jason
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net