Pointer types that let me specify destructor functions.

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

Jason Cipriani wrote:
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?
You're asking for the upcoming std::unique_ptr, but AFAIK boost currently does not provide it (I like to be corrected here). There exists a public domain implementation provided by Howard Hinnant, which comes quite next to its final interface (which has yet not been decided, but personally I'm quite sure that further changes are only marginal), http://home.twcny.rr.com/hinnant/cpp_extensions/unique_ptr.html (This link has been provided via issue http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html#673 ) If you replace some used tr1 utilities (static_assert, tr1::is_reference, ...) by currently existing boost analoga, it should work for you, I guess, hmmmh, aeeh, if you have a compiler that understands the new rvalue references.... Greetings from Bremen, Daniel Krügler
participants (2)
-
Daniel Krügler
-
Jason Cipriani