00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef _CPP_MEMORY
00016 #define _CPP_MEMORY 1
00017
00018 #pragma GCC system_header
00019
00020 #include <bits/stl_algobase.h>
00021 #include <bits/stl_alloc.h>
00022 #include <bits/stl_construct.h>
00023 #include <bits/stl_iterator_base_types.h>
00024 #include <bits/stl_tempbuf.h>
00025 #include <bits/stl_uninitialized.h>
00026 #include <bits/stl_raw_storage_iter.h>
00027
00028 namespace std
00029 {
00030
00031 template<class _Tp1> struct auto_ptr_ref {
00032 _Tp1* _M_ptr;
00033 auto_ptr_ref(_Tp1* __p) : _M_ptr(__p) {}
00034 };
00035
00036 template <class _Tp> class auto_ptr {
00037 private:
00038 _Tp* _M_ptr;
00039
00040 public:
00041 typedef _Tp element_type;
00042
00043 explicit auto_ptr(_Tp* __p = 0) __STL_NOTHROW : _M_ptr(__p) {}
00044 auto_ptr(auto_ptr& __a) __STL_NOTHROW : _M_ptr(__a.release()) {}
00045
00046 template <class _Tp1> auto_ptr(auto_ptr<_Tp1>& __a) __STL_NOTHROW
00047 : _M_ptr(__a.release()) {}
00048
00049 auto_ptr& operator=(auto_ptr& __a) __STL_NOTHROW {
00050 reset(__a.release());
00051 return *this;
00052 }
00053
00054 template <class _Tp1>
00055 auto_ptr& operator=(auto_ptr<_Tp1>& __a) __STL_NOTHROW {
00056 reset(__a.release());
00057 return *this;
00058 }
00059
00060
00061
00062
00063
00064 ~auto_ptr() { delete _M_ptr; }
00065
00066 _Tp& operator*() const __STL_NOTHROW {
00067 return *_M_ptr;
00068 }
00069 _Tp* operator->() const __STL_NOTHROW {
00070 return _M_ptr;
00071 }
00072 _Tp* get() const __STL_NOTHROW {
00073 return _M_ptr;
00074 }
00075 _Tp* release() __STL_NOTHROW {
00076 _Tp* __tmp = _M_ptr;
00077 _M_ptr = 0;
00078 return __tmp;
00079 }
00080 void reset(_Tp* __p = 0) __STL_NOTHROW {
00081 if (__p != _M_ptr) {
00082 delete _M_ptr;
00083 _M_ptr = __p;
00084 }
00085 }
00086
00087
00088
00089
00090
00091 public:
00092 auto_ptr(auto_ptr_ref<_Tp> __ref) __STL_NOTHROW
00093 : _M_ptr(__ref._M_ptr) {}
00094
00095 auto_ptr& operator=(auto_ptr_ref<_Tp> __ref) __STL_NOTHROW {
00096 if (__ref._M_ptr != this->get()) {
00097 delete _M_ptr;
00098 _M_ptr = __ref._M_ptr;
00099 }
00100 return *this;
00101 }
00102
00103 template <class _Tp1> operator auto_ptr_ref<_Tp1>() __STL_NOTHROW
00104 { return auto_ptr_ref<_Tp>(this->release()); }
00105 template <class _Tp1> operator auto_ptr<_Tp1>() __STL_NOTHROW
00106 { return auto_ptr<_Tp1>(this->release()); }
00107 };
00108
00109 }
00110
00111 #endif
00112
00113
00114
00115
00116