/*========================================================================= Program: KWSys - Kitware System Library Module: $RCSfile$ Copyright (c) Kitware, Inc., Insight Consortium. All rights reserved. See Copyright.txt or http://www.kitware.com/Copyright.htm for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef @KWSYS_NAMESPACE@_auto_ptr_hxx #define @KWSYS_NAMESPACE@_auto_ptr_hxx namespace @KWSYS_NAMESPACE@ { // C++98 Standard Section 20.4.5 - Template class auto_ptr. template class auto_ptr { template struct auto_ptr_ref { auto_ptr& p_; explicit auto_ptr_ref(auto_ptr& p): p_(p) {} }; X* x_; public: typedef X element_type; template auto_ptr(auto_ptr& a) throw(): x_(a.release()) {} template auto_ptr& operator=(auto_ptr& a) throw() { reset(a.release()); return *this; } explicit auto_ptr(X* p=0) throw(): x_(p) {} auto_ptr(auto_ptr& a) throw(): x_(a.release()) {} auto_ptr& operator=(auto_ptr& a) throw() { reset(a.release()); return *this; } ~auto_ptr() throw() { delete get(); } X& operator*() const throw() { return *get(); } X* operator->() const throw() { return get(); } X* get() const throw() { return x_; } X* release() throw() { X* x = x_; x_ = 0; return x; } void reset(X* p=0) throw() { if(get() != p) { delete get(); x_ = p; } } auto_ptr(auto_ptr_ref r) throw(): x_(r.p_.release()) {} template operator auto_ptr_ref() throw() { return *this; } template operator auto_ptr() throw() { return release(); } auto_ptr& operator=(auto_ptr_ref r) throw() { x_ = r.p_.release(); return *this; } }; } // namespace @KWSYS_NAMESPACE@ #endif