C++11智能指针(二)
107 shared_ptr(_Myt&& _Right) _NOEXCEPT
108 : _Mybase(_STD forward<_Myt>(_Right))
109 { // construct shared_ptr object that takes resource from _Right
110 }
111
112 template
113 shared_ptr(shared_ptr<_Ty2>&& _Right,
114 typename enable_if::value,
115 void>::type ** = 0) _NOEXCEPT
116 : _Mybase(_STD forward >(_Right))
117 { // construct shared_ptr object that takes resource from _Right
118 }
119
120 #if _HAS_CPP0X
121 template
122 class _Dx>
123 shared_ptr(unique_ptr<_Ux, _Dx>&& _Right)
124 { // construct from unique_ptr
125 _Resetp(_Right.release(), _Right.get_deleter());
126 }
127
128 template
129 class _Dx>
130 _Myt& operator=(unique_ptr<_Ux, _Dx>&& _Right)
131 { // move from unique_ptr
132 shared_ptr(_STD move(_Right)).swap(*this);
133 return (*this);
134 }
135 #endif /* _HAS_CPP0X */
136
137 _Myt& operator=(_Myt&& _Right) _NOEXCEPT
138 { // construct shared_ptr object that takes resource from _Right
139 shared_ptr(_STD move(_Right)).swap(*this);
140 return (*this);
141 }
142
143 template
144 _Myt& operator=(shared_ptr<_Ty2>&& _Right) _NOEXCEPT
145 { // construct shared_ptr object that takes resource from _Right
146 shared_ptr(_STD move(_Right)).swap(*this);
147 return (*this);
148 }
149
150 ~shared_ptr() _NOEXCEPT
151 { // release resource
152 this->_Decref();
153 }
154
155 _Myt& operator=(const _Myt& _Right) _NOEXCEPT
156 { // assign shared ownership of resource owned by _Right
157 shared_ptr(_Right).swap(*this);
158 return (*this);
159 }
160
161 template
162 _Myt& operator=(const shared_ptr<_Ty2>& _Right) _NOEXCEPT
163 { // assign shared ownership of resource owned by _Right
164 shared_ptr(_Right).swap(*this);
165 return (*this);
166 }
167
168 template
169 _Myt& operator=(auto_ptr<_Ty2>&& _Right)
170 { // assign ownership of resource pointed to by _Right
171 shared_ptr(_STD move(_Right)).swap(*this);
172 return (*this);
173 }
174
175 void reset() _NOEXCEPT
176 { // release resource and convert to empty shared_ptr object
177 shared_ptr().swap(*this);
178 }
179
180 template
181 void reset(_Ux *_Px)
182 { // release, take ownership of _Px
183 shared_ptr(_Px).swap(*this);
184 }
185
186 template
187 class _Dx>
188 void reset(_Ux *_Px, _Dx _Dt)
189 { // release, take ownership of _Px, with deleter _Dt
190 shared_ptr(_Px, _Dt).swap(*this);
191 }
192
193 //#if _HAS_CPP0X
194 template
195 class _Dx,
196 class _Alloc>
197 void reset(_Ux *_Px, _Dx _Dt, _Alloc _Ax)
198 { // release, take ownership of _Px, with deleter _Dt, allocator _Ax
199 shared_ptr(_Px, _Dt, _Ax).swap(*this);
200 }
201 //#endif /* _HAS_CPP0X */
202
203 void swap(_Myt& _Other) _NOEXCEPT
204 { // swap pointers
205 this->_Swap(_Other);
206 }
207
208 _Ty *get() const _NOEXCEPT
209 { // return pointer to resource
210 return (this->_Get());
211 }
212
213