1 /**************************************************************************
2 * auto_ptr.hxx -- A simple auto_ptr definition.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 **************************************************************************/
24 #include "fg_stl_config.h"
26 //-----------------------------------------------------------------------------
28 // auto_ptr is initialised with a pointer obtained via new and deletes that
29 // object when it itself is destroyed (such as when leaving block scope).
30 // auto_ptr can be used in any way that a normal pointer can be.
32 // This class is only required when the STL doesn't supply one.
34 template <class X> class auto_ptr {
40 typedef X element_type;
42 explicit auto_ptr(X* p = 0) : ptr(p), owns(p) {}
44 auto_ptr(const auto_ptr& a) : ptr(a.ptr), owns(a.owns) {
48 #ifdef _SG_MEMBER_TEMPLATES
49 template <class T> auto_ptr(const auto_ptr<T>& a)
50 : ptr(a.ptr), owns(a.owns) {
55 auto_ptr& operator = (const auto_ptr& a) {
65 #ifdef _SG_MEMBER_TEMPLATES
66 template <class T> auto_ptr& operator = (const auto_ptr<T>& a) {
82 X& operator*() const { return *ptr; }
83 X* operator->() const { return ptr; }
84 X* get() const { return ptr; }
85 X* release() const { owns = false; return ptr; }
88 #endif /* _AUTO_PTR_HXX */