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 #pragma GCC system_header
20 #include <bits/stl_algobase.h>
21 #include <bits/stl_alloc.h>
22 #include <bits/stl_construct.h>
23 #include <bits/stl_iterator_base_types.h> //for iterator_traits
24 #include <bits/stl_tempbuf.h>
25 #include <bits/stl_uninitialized.h>
26 #include <bits/stl_raw_storage_iter.h>
31 template<class _Tp1> struct auto_ptr_ref {
33 auto_ptr_ref(_Tp1* __p) : _M_ptr(__p) {}
36 template <class _Tp> class auto_ptr {
41 typedef _Tp element_type;
43 explicit auto_ptr(_Tp* __p = 0) __STL_NOTHROW : _M_ptr(__p) {}
44 auto_ptr(auto_ptr& __a) __STL_NOTHROW : _M_ptr(__a.release()) {}
46 template <class _Tp1> auto_ptr(auto_ptr<_Tp1>& __a) __STL_NOTHROW
47 : _M_ptr(__a.release()) {}
49 auto_ptr& operator=(auto_ptr& __a) __STL_NOTHROW {
55 auto_ptr& operator=(auto_ptr<_Tp1>& __a) __STL_NOTHROW {
60 // Note: The C++ standard says there is supposed to be an empty throw
61 // specification here, but omitting it is standard conforming. Its
62 // presence can be detected only if _Tp::~_Tp() throws, but (17.4.3.6/2)
63 // this is prohibited.
64 ~auto_ptr() { delete _M_ptr; }
66 _Tp& operator*() const __STL_NOTHROW {
69 _Tp* operator->() const __STL_NOTHROW {
72 _Tp* get() const __STL_NOTHROW {
75 _Tp* release() __STL_NOTHROW {
80 void reset(_Tp* __p = 0) __STL_NOTHROW {
87 // According to the C++ standard, these conversions are required. Most
88 // present-day compilers, however, do not enforce that requirement---and,
89 // in fact, most present-day compilers do not support the language
90 // features that these conversions rely on.
92 auto_ptr(auto_ptr_ref<_Tp> __ref) __STL_NOTHROW
93 : _M_ptr(__ref._M_ptr) {}
95 auto_ptr& operator=(auto_ptr_ref<_Tp> __ref) __STL_NOTHROW {
96 if (__ref._M_ptr != this->get()) {
98 _M_ptr = __ref._M_ptr;
103 template <class _Tp1> operator auto_ptr_ref<_Tp1>() __STL_NOTHROW
104 { return auto_ptr_ref<_Tp>(this->release()); }
105 template <class _Tp1> operator auto_ptr<_Tp1>() __STL_NOTHROW
106 { return auto_ptr<_Tp1>(this->release()); }
111 #endif /* _CPP_MEMORY */