1/*
2 * Copyright (c) 1997
3 * Silicon Graphics Computer Systems, Inc.
4 *
5 * Permission to use, copy, modify, distribute and sell this software
6 * and its documentation for any purpose is hereby granted without fee,
7 * provided that the above copyright notice appear in all copies and
8 * that both that copyright notice and this permission notice appear
9 * in supporting documentation.  Silicon Graphics makes no
10 * representations about the suitability of this software for any
11 * purpose.  It is provided "as is" without express or implied warranty.
12 *
13 */
14
15#ifndef __SGI_STL_MEMORY
16#define __SGI_STL_MEMORY
17
18#include <stl_algobase.h>
19#include <stl_alloc.h>
20#include <stl_construct.h>
21#include <stl_tempbuf.h>
22#include <stl_uninitialized.h>
23#include <stl_raw_storage_iter.h>
24
25
26#if defined(__STL_MEMBER_TEMPLATES)
27
28__STL_BEGIN_NAMESPACE
29
30template <class _Tp> class auto_ptr {
31private:
32  _Tp* _M_ptr;
33
34public:
35  typedef _Tp element_type;
36  explicit auto_ptr(_Tp* __p = 0) __STL_NOTHROW : _M_ptr(__p) {}
37  auto_ptr(auto_ptr& __a) __STL_NOTHROW : _M_ptr(__a.release()) {}
38  template <class _Tp1> auto_ptr(auto_ptr<_Tp1>& __a) __STL_NOTHROW
39    : _M_ptr(__a.release()) {}
40  auto_ptr& operator=(auto_ptr& __a) __STL_NOTHROW {
41    if (&__a != this) {
42      delete _M_ptr;
43      _M_ptr = __a.release();
44    }
45    return *this;
46  }
47  template <class _Tp1>
48  auto_ptr& operator=(auto_ptr<_Tp1>& __a) __STL_NOTHROW {
49    if (__a.get() != this->get()) {
50      delete _M_ptr;
51      _M_ptr = __a.release();
52    }
53    return *this;
54  }
55  ~auto_ptr() __STL_NOTHROW { delete _M_ptr; }
56
57  _Tp& operator*() const __STL_NOTHROW {
58    return *_M_ptr;
59  }
60  _Tp* operator->() const __STL_NOTHROW {
61    return _M_ptr;
62  }
63  _Tp* get() const __STL_NOTHROW {
64    return _M_ptr;
65  }
66  _Tp* release() __STL_NOTHROW {
67    _Tp* __tmp = _M_ptr;
68    _M_ptr = 0;
69    return __tmp;
70  }
71  void reset(_Tp* __p = 0) __STL_NOTHROW {
72    delete _M_ptr;
73    _M_ptr = __p;
74  }
75
76  // According to the C++ standard, these conversions are required.  Most
77  // present-day compilers, however, do not enforce that requirement---and,
78  // in fact, most present-day compilers do not support the language
79  // features that these conversions rely on.
80
81#ifdef __SGI_STL_USE_AUTO_PTR_CONVERSIONS
82
83private:
84  template<class _Tp1> struct auto_ptr_ref {
85    _Tp1* _M_ptr;
86    auto_ptr_ref(_Tp1* __p) : _M_ptr(__p) {}
87  };
88
89public:
90  auto_ptr(auto_ptr_ref<_Tp> __ref) __STL_NOTHROW
91    : _M_ptr(__ref._M_ptr) {}
92  template <class _Tp1> operator auto_ptr_ref<_Tp1>() __STL_NOTHROW
93    { return auto_ptr_ref<_Tp>(this->release()); }
94  template <class _Tp1> operator auto_ptr<_Tp1>() __STL_NOTHROW
95    { return auto_ptr<_Tp1>(this->release()); }
96
97#endif /* __SGI_STL_USE_AUTO_PTR_CONVERSIONS */
98};
99
100__STL_END_NAMESPACE
101#endif /* member templates */
102
103#endif /* __SGI_STL_MEMORY */
104
105
106// Local Variables:
107// mode:C++
108// End:
109