Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

std_memory.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 1997-1999
00003  * Silicon Graphics Computer Systems, Inc.
00004  *
00005  * Permission to use, copy, modify, distribute and sell this software
00006  * and its documentation for any purpose is hereby granted without fee,
00007  * provided that the above copyright notice appear in all copies and
00008  * that both that copyright notice and this permission notice appear
00009  * in supporting documentation.  Silicon Graphics makes no
00010  * representations about the suitability of this software for any
00011  * purpose.  It is provided "as is" without express or implied warranty.
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> //for iterator_traits
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   // Note: The C++ standard says there is supposed to be an empty throw
00061   // specification here, but omitting it is standard conforming.  Its 
00062   // presence can be detected only if _Tp::~_Tp() throws, but (17.4.3.6/2)
00063   // this is prohibited.
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   // According to the C++ standard, these conversions are required.  Most
00088   // present-day compilers, however, do not enforce that requirement---and, 
00089   // in fact, most present-day compilers do not support the language 
00090   // features that these conversions rely on.
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 } // namespace std
00110 
00111 #endif /* _CPP_MEMORY */
00112 
00113 
00114 // Local Variables:
00115 // mode:C++
00116 // End:

Generated at Tue May 1 16:28:38 2001 for libstdc++-v3 by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001