![]() |
Scope-limited management of dynamically allocated arrays.The UniqueArray class implements a scope-restricted, lightweight smart pointer that manages a dynamically allocated array. In contrast to other smart pointer implementations, UniqueArray is non-copyable and therefore restricted to manage arrays within a single scope, but does so so with a minimum of runtime overhead. The following example demonstrates the application of UniqueArray: More...
#include <UniqueArray.h>
Inherits blaze::NonCopyable.
Public Types | |
typedef RemoveReference< T > ::Type * | Pointer |
Pointer type of the managed array elements. | |
typedef RemoveReference< T > ::Type & | Reference |
Reference type of the managed array elements. | |
typedef D | Deleter |
Type of the resource deleter. | |
Public Member Functions | |
Constructors | |
UniqueArray (Pointer ptr=NULL) | |
The default constructor for the UniqueArray specialization. More... | |
Destructor | |
~UniqueArray () | |
The destructor for the UniqueArray specialization. | |
Access operators | |
Reference | operator[] (size_t index) const |
Direct access to the array elements. More... | |
Utility functions | |
Pointer | get () const |
Returns a pointer to the managed array. More... | |
Pointer | release () |
Releases the ownership of the managed array to the caller. More... | |
void | reset (Pointer ptr=NULL) |
Resets the unique array and replaces the managed array with the given array. More... | |
void | swap (UniqueArray &up) |
Swapping the contents of two unique arrays. More... | |
Private Attributes | |
Member variables | |
Pointer | ptr_ |
Pointer to the managed array. | |
Deleter | deleter_ |
Resource deleter. | |
Scope-limited management of dynamically allocated arrays.
The UniqueArray class implements a scope-restricted, lightweight smart pointer that manages a dynamically allocated array. In contrast to other smart pointer implementations, UniqueArray is non-copyable and therefore restricted to manage arrays within a single scope, but does so so with a minimum of runtime overhead. The following example demonstrates the application of UniqueArray:
Note that UniqueArray's interface is optimized for arrays and that by default ArrayDelete is used. For the management of single objects, UniquePtr can be used:
Note that the template argument T must not have any array extent (similar to the unique_ptr implementation of the C++11 standard, where the array extent differentiates between single objects and arrays). Providing a type with array extent will result in a compile time error!
|
inline |
The default constructor for the UniqueArray specialization.
ptr | The array to be managed by the unique array |
|
inline |
Returns a pointer to the managed array.
This function returns a pointer to the managed array (or NULL in case no array is currently managed). Note however that the ownership remains with the unqiue pointer.
|
inline |
Direct access to the array elements.
|
inline |
Releases the ownership of the managed array to the caller.
This function returns a pointer to the managed array (or NULL in case no array is currently managed). The ownership of the array is released and passed to the caller.
|
inline |
Resets the unique array and replaces the managed array with the given array.
ptr | The new array to be managed by the unique array. |
|
inline |
Swapping the contents of two unique arrays.
ptr | The unique array to be swapped. |
no-throw | guarantee. |