2 * Copyright (c) 1997-1999
3 * Silicon Graphics Computer Systems, Inc.
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.
18 #include <bits/stl_algobase.h>
19 #include <bits/stl_alloc.h>
20 #include <bits/stl_construct.h>
21 #include <bits/stl_iterator_base.h> //for iterator_traits
22 #include <bits/stl_tempbuf.h>
23 #include <bits/stl_uninitialized.h>
24 #include <bits/stl_raw_storage_iter.h>
28 #if defined(__SGI_STL_USE_AUTO_PTR_CONVERSIONS) && \
29 defined(__STL_MEMBER_TEMPLATES)
31 template<class _Tp1> struct auto_ptr_ref {
33 auto_ptr_ref(_Tp1* __p) : _M_ptr(__p) {}
38 template <class _Tp> class auto_ptr {
43 typedef _Tp element_type;
45 explicit auto_ptr(_Tp* __p = 0) __STL_NOTHROW : _M_ptr(__p) {}
46 auto_ptr(auto_ptr& __a) __STL_NOTHROW : _M_ptr(__a.release()) {}
48 #ifdef __STL_MEMBER_TEMPLATES
49 template <class _Tp1> auto_ptr(auto_ptr<_Tp1>& __a) __STL_NOTHROW
50 : _M_ptr(__a.release()) {}
51 #endif /* __STL_MEMBER_TEMPLATES */
53 auto_ptr& operator=(auto_ptr& __a) __STL_NOTHROW {
58 #ifdef __STL_MEMBER_TEMPLATES
60 auto_ptr& operator=(auto_ptr<_Tp1>& __a) __STL_NOTHROW {
64 #endif /* __STL_MEMBER_TEMPLATES */
66 ~auto_ptr() __STL_NOTHROW { delete _M_ptr; }
68 _Tp& operator*() const __STL_NOTHROW {
71 _Tp* operator->() const __STL_NOTHROW {
74 _Tp* get() const __STL_NOTHROW {
77 _Tp* release() __STL_NOTHROW {
82 void reset(_Tp* __p = 0) __STL_NOTHROW {
89 // According to the C++ standard, these conversions are required. Most
90 // present-day compilers, however, do not enforce that requirement---and,
91 // in fact, most present-day compilers do not support the language
92 // features that these conversions rely on.
94 #if defined(__SGI_STL_USE_AUTO_PTR_CONVERSIONS) && \
95 defined(__STL_MEMBER_TEMPLATES)
98 auto_ptr(auto_ptr_ref<_Tp> __ref) __STL_NOTHROW
99 : _M_ptr(__ref._M_ptr) {}
101 auto_ptr& operator=(auto_ptr_ref<_Tp> __ref) __STL_NOTHROW {
102 if (__ref._M_ptr != this->get()) {
104 _M_ptr = __ref._M_ptr;
109 template <class _Tp1> operator auto_ptr_ref<_Tp1>() __STL_NOTHROW
110 { return auto_ptr_ref<_Tp>(this->release()); }
111 template <class _Tp1> operator auto_ptr<_Tp1>() __STL_NOTHROW
112 { return auto_ptr<_Tp1>(this->release()); }
114 #endif /* auto ptr conversions && member templates */
119 #endif /* _CPP_MEMORY */