AutoPtr< T, Destroy > Class Template Reference

#include <Pt/SmartPtr.h>

Policy based Auto pointer. More...

Inherits Destroy.

Public Member Functions

 AutoPtr (T *ptr=0)
 Default constructor.
 
 AutoPtr (AutoPtrRef< T > rhs)
 Copy constructor.
 
 ~AutoPtr ()
 Destructor.
 
T * get () const
 Access value.
 
template<class Y >
 operator AutoPtrRef< Y > ()
 Conversion operator used for assignments.
 
 operator bool () const
 Bool conversion operator. More...
 
bool operator! () const
 Returns true if nullptr.
 
T & operator* () const
 Access value.
 
T * operator-> () const
 Access value.
 
AutoPtroperator= (AutoPtrRef< T > rhs)
 Assignment operator.
 
T * release ()
 Release ownership.
 
void reset (T *ptr=0)
 Reset value.
 

Related Functions

template<typename T , typename D , typename T2 , typename D2 >
bool operator!= (const AutoPtr< T, D > &a, const AutoPtr< T2, D2 > &b)
 Equality comparison operator.
 
template<typename T , typename D , typename T2 >
bool operator!= (const AutoPtr< T, D > &a, const T2 *b)
 Equality comparison operator.
 
template<typename T , typename D , typename T2 , typename D2 >
bool operator< (const AutoPtr< T, D > &a, const AutoPtr< T2, D2 > &b)
 Less-than comparison operator.
 
template<typename T , typename D , typename T2 >
bool operator< (const AutoPtr< T, D > &a, const T2 *b)
 Less-than comparison operator.
 
template<typename T , typename D , typename T2 , typename D2 >
bool operator== (const AutoPtr< T, D > &a, const AutoPtr< T2, D2 > &b)
 Equality comparison operator.
 
template<typename T , typename D , typename T2 >
bool operator== (const AutoPtr< T, D > &a, const T2 *b)
 Equality comparison operator.
 

Detailed Description

template<typename T, typename Destroy = DeletePolicy<T>>
class Pt::AutoPtr< T, Destroy >

The DestroyPolicy implements the method for destroying the managed object once the auto pointer runs out of scope. By default, the object is destroyed by deleting it, but this can be overridden by using a different DestroyPolicy. The DestroyPolicy needs to implement a method destroy(T*), which releases the underlying pointer.

Parameters
TManaged type.
DestroyPolicyDestroys the managed type.

Member Function Documentation

operator bool ( ) const

An AutoPtr can be implicitly converted to bool. True is returned when the raw pointer is not null, false if it is null

Returns
false if the raw pointer is null.