Merge amd64 NDK from amd64 branch:
[reactos.git] / irc / ArchBlackmann / auto_ptr.h
1 // auto_ptr.h
2 // This file is (C) 2002-2003 Royce Mitchell III
3 // and released under the LGPL & BSD licenses
4
5 #ifndef AUTO_PTR_H
6 #define AUTO_PTR_H
7
8 template<class T>
9 class auto_ptr
10 {
11 public:
12 typedef T element_type;
13
14 explicit auto_ptr(T *p = 0) : _p(p)
15 {
16 }
17
18 auto_ptr(auto_ptr<T>& rhs) : _p(rhs.release())
19 {
20 }
21
22 auto_ptr<T>& operator=(auto_ptr<T>& rhs)
23 {
24 if ( &rhs != this )
25 {
26 dispose();
27 _p = rhs.release();
28 }
29 return *this;
30 }
31
32 auto_ptr<T>& set ( auto_ptr<T>& rhs )
33 {
34 if ( &rhs != this )
35 {
36 dispose();
37 _p = rhs.release();
38 }
39 return *this;
40 }
41
42 ~auto_ptr()
43 {
44 dispose();
45 }
46
47 void dispose()
48 {
49 if ( _p )
50 {
51 delete _p;
52 _p = 0;
53 }
54 }
55
56 T& operator[] ( int i )
57 {
58 return _p[i];
59 }
60
61 T& operator*() const
62 {
63 return *_p;
64 }
65
66 T* operator->() const
67 {
68 return _p;
69 }
70
71 T* get() const
72 {
73 return _p;
74 }
75
76 T* release()
77 {
78 T* p = _p;
79 _p = 0;
80 return p;
81 }
82
83 private:
84 T* _p;
85 };
86
87 #endif//AUTO_PTR_H