// $Id$ // See http://cseng.aw.com/bookdetail.qry?ISBN=0-201-63371-X&ptype=634 // auto_ptr from More Effective C++ an earlier appendix (works w/ egcs) #ifndef CL_AUTO_PTR_H #define CL_AUTO_PTR_H #ifdef _MSC_VER #include template void ReinitializeAutoPtr(auto_ptr &apref, T *pt) { auto_ptr ap(pt); apref = ap; } #define cl_auto_ptr auto_ptr #else // FIXGJB: This implementation for egcs is buggy -- be careful // and replace ASAP template class cl_auto_ptr { public: explicit cl_auto_ptr(T *p = 0): pointee(p) {} template cl_auto_ptr(cl_auto_ptr& rhs): pointee(rhs.release()) {} ~cl_auto_ptr() { delete pointee; } template cl_auto_ptr& operator=(cl_auto_ptr& rhs) { if (this != &rhs) reset(rhs.release()); return *this; } T& operator*() const { return *pointee; } T* operator->() const { return pointee; } T* get() const { return pointee; } T* release() { T *oldPointee = pointee; pointee = 0; return oldPointee; } // protected: // This is non-standard void reset(T *p = 0) { delete pointee; pointee = p; } private: T *pointee; }; template void ReinitializeAutoPtr(cl_auto_ptr &apref, T *pt) { apref.reset(pt); } #endif #endif