#include <arg_auto_ptr.h>
Public Members | |||
![]() | ![]() | typedef my_element_type | element_type |
![]() | ![]() | explicit | auto_ptr (my_element_type* ptr = 0) throw () |
![]() | ![]() | constructor. | |
![]() | ![]() | template<class rhs_element_type> | auto_ptr<rhs_element_type> (auto_ptr<rhs_element_type>& rhs) throw () |
![]() | ![]() | copy constructor - reseats ownership from rhs (which changes). More... | |
![]() | ![]() | auto_ptr (auto_ptr& rhs) throw () | |
![]() | ![]() | copy constructor - reseats ownership from rhs (which changes). More... | |
![]() | ![]() | template<class rhs_element_type> auto_ptr& | operator=<rhs_element_type> (auto_ptr<rhs_element_type>& rhs) throw () |
![]() | ![]() | assignment - reseats ownership from rhs (which changes). More... | |
![]() | ![]() | auto_ptr& | operator= (auto_ptr& rhs) throw () |
![]() | ![]() | assignment - reseats ownership from rhs (which changes). More... | |
![]() | ![]() | ~auto_ptr () throw () | |
![]() | ![]() | destructor - deletes the owned object. | |
![]() | ![]() | my_element_type* | get () const throw () |
![]() | ![]() | access raw ptr. | |
![]() | ![]() | my_element_type& | operator * () const throw () |
![]() | ![]() | dereference. | |
![]() | ![]() | my_element_type* | operator-> () const throw () |
![]() | ![]() | gets the pointer. | |
![]() | ![]() | my_element_type* | release () throw () |
![]() | ![]() | release ownership to caller - returns pointer to referenced object. | |
![]() | ![]() | void | reset (my_element_type* ptr=0) throw () |
![]() | ![]() | reset pointer - deletes the owned object. | |
![]() | ![]() | auto_ptr (auto_ptr_ref<my_element_type> rhs) throw () | |
![]() | ![]() | Implementation "magic". More... | |
![]() | ![]() | template<class an_element_type> | operator auto_ptr_ref<an_element_type> () throw () |
![]() | ![]() | Implementation "magic". More... | |
![]() | ![]() | template<class an_element_type> | operator auto_ptr<an_element_type> () throw () |
![]() | ![]() | Implementation "magic". More... |
Written both as an exercise and because the one in VC++ is badly broken (i.e. a buggy implementation of the wrong spec [CD2].) Also useful as some distributions of gcc have auto_ptr commented out.
All methods support the strong exception safety guarantee with the proviso that the referenced type must have a non-throwing destructor.
Note:
By historical accident the standard library provides only this single smart pointer template. auto_ptr<> has what I will politely describe as "interesting" copy semantics. Specifically, if one auto_ptr<> is assigned (or copy constructed) from another then they are both changed - the auto_ptr<> that originally owned the object loses ownership and becomes 0. This is a trap for the unwary!
There are situations that call for this behaviour, but on most occasions that require a smart pointer the copy semantics cause a problem. (For examples of situation that do not suit auto_ptr see: Uncounted Pointers in C++ and Ending with the grin)
template<class my_element_type> typedef my_element_type arg::auto_ptr<my_element_type>::element_type |
template<class my_element_type> explicit arg::auto_ptr<my_element_type>::auto_ptr<my_element_type> (my_element_type * ptr = 0) throw () |
constructor.
template<class my_element_type> template<class rhs_element_type> arg::auto_ptr<my_element_type>::auto_ptr<my_element_type> (auto_ptr<rhs_element_type>& rhs) throw () |
copy constructor - reseats ownership from rhs (which changes).
For this to work there must be an accessible conversion between rhs_element_type*
and my_element_type*
.
template<class my_element_type> arg::auto_ptr<my_element_type>::auto_ptr<my_element_type> (auto_ptr<my_element_type> & rhs) throw () |
copy constructor - reseats ownership from rhs (which changes).
For this to work there must be an accessible conversion between rhs_element_type*
and my_element_type*
.
template<class my_element_type> template<class rhs_element_type> auto_ptr<my_element_type> & arg::auto_ptr<my_element_type>::operator= (auto_ptr<rhs_element_type>& rhs) throw () [inline]
|
assignment - reseats ownership from rhs (which changes).
For this to work there must be an accessible conversion between rhs_element_type*
and my_element_type*
.
template<class my_element_type> auto_ptr<my_element_type> & arg::auto_ptr<my_element_type>::operator= (auto_ptr<my_element_type> & rhs) throw () [inline]
|
assignment - reseats ownership from rhs (which changes).
For this to work there must be an accessible conversion between rhs_element_type*
and my_element_type*
.
template<class my_element_type> arg::auto_ptr<my_element_type>::~auto_ptr<my_element_type> () throw () [inline]
|
destructor - deletes the owned object.
template<class my_element_type> my_element_type * arg::auto_ptr<my_element_type>::get () const throw () [inline]
|
access raw ptr.
template<class my_element_type> my_element_type & arg::auto_ptr<my_element_type>::operator * () const throw () [inline]
|
dereference.
template<class my_element_type> my_element_type * arg::auto_ptr<my_element_type>::operator-> () const throw () [inline]
|
gets the pointer.
template<class my_element_type> my_element_type * arg::auto_ptr<my_element_type>::release () throw () [inline]
|
release ownership to caller - returns pointer to referenced object.
template<class my_element_type> void arg::auto_ptr<my_element_type>::reset (my_element_type * ptr = 0) throw () [inline]
|
reset pointer - deletes the owned object.
template<class my_element_type> arg::auto_ptr<my_element_type>::auto_ptr<my_element_type> (auto_ptr_ref<my_element_type> rhs) throw () |
Implementation "magic".
Create an auto_ptr from a wrapper around a reference to an auto_ptr. This is part of the mechanism for allowing auto_ptr<>s to be returned as temporaries.
template<class my_element_type> template<class an_element_type> arg::auto_ptr<my_element_type>::operator auto_ptr_ref<an_element_type> () throw () [inline]
|
Implementation "magic".
Create a wrapper around a reference to an auto_ptr. This is part of the mechanism for allowing auto_ptr<>s to be returned as temporaries.
(I don't think this mechanism has the intended effect because auto_ptr_ref<foo> is private within an auto_ptr<bar>, but I'm just following the spec. - alan)
template<class my_element_type> template<class an_element_type> arg::auto_ptr<my_element_type>::operator auto_ptr<an_element_type> () throw () [inline]
|
Implementation "magic".
Conversion to an auto_ptr of supertype. Ownership is passed to the returned temporary.