C12Adapter Opensource C++ Interface
MUniqueArrayPtr< Type > Class Template Reference

Compiler version independent unique pointer to an array variable. More...

Inheritance diagram for MUniqueArrayPtr< Type >:

Public Member Functions

 MUniqueArrayPtr (Type *ptr=NULL)
 Explicit initialization constructor. More...
 
 ~MUniqueArrayPtr ()
 Destructor. More...
 
void reset (Type *ptr=NULL)
 Destroy the current object and assign a given pointer. More...
 
- Public Member Functions inherited from MGenericNoncopyablePtr< Type >
Type * operator-> () const
 Field dereference operator.
 
Type & operator* () const
 Pointer dereference operator.
 
Type * get () const
 Get the underlying pointer.
 
Type * release ()
 Return the the underlying pointer while nullifying the unique pointer object.
 

Additional Inherited Members

- Public Types inherited from MGenericNoncopyablePtr< Type >
typedef Type element_type
 Type of the unique pointer.
 
- Protected Member Functions inherited from MGenericNoncopyablePtr< Type >
 MGenericNoncopyablePtr (Type *ptr=NULL)
 Protected explicit initialization constructor.
 
 ~MGenericNoncopyablePtr ()
 Protected destructor. More...
 
- Protected Attributes inherited from MGenericNoncopyablePtr< Type >
Type * m_pointer
 Pointer to object.
 

Detailed Description

template<typename Type>
class MUniqueArrayPtr< Type >

Compiler version independent unique pointer to an array variable.

This is similar to unique_ptr with an array deleter, while it works with the older compilers. Otherwise, the class interface is a proper subset of classic auto_ptr, however it does not have a copy constructor at all, making it safe in the way unique_ptr is safe. The whole codebase can be moved to using unique_ptr with an array deleter once all the clients of the library upgrade their compilers from C++Builder 2007 and Visual C++ 2010.

One cannot give a non-array to unique array pointer, and there is a static check for explicit array type.

See also
MUniquePtr - unique pointer to a variable that is not an array

Constructor & Destructor Documentation

template<typename Type >
MUniqueArrayPtr< Type >::MUniqueArrayPtr ( Type *  ptr = NULL)
inlineexplicit

Explicit initialization constructor.

Usage is compatible with both std::auto_ptr and std::unique_ptr

template<typename Type >
MUniqueArrayPtr< Type >::~MUniqueArrayPtr ( )
inline

Destructor.

Same as std::auto_ptr, and different from std::unique_ptr as it cannot handle arrays correctly. There is a compile time check that verifies the pointer is not declared as array.

Member Function Documentation

template<typename Type >
void MUniqueArrayPtr< Type >::reset ( Type *  ptr = NULL)
inline

Destroy the current object and assign a given pointer.

Usage is compatible with both std::auto_ptr and std::unique_ptr