template<typename T>
class OFunique_ptr< T >
OFunique_ptr is a smart pointer that retains sole ownership of an object through a pointer and destroys that object when the unique_ptr goes out of scope.
No two unique_ptr instances can manage the same object.
The object is destroyed and its memory deallocated when either of the following happens:
- unique_ptr managing the object is destroyed
- unique_ptr managing the object is assigned another pointer via reset().
A unique_ptr may also own no objects, in which case it is called empty.
OFunique_ptr is NOT CopyConstructible or CopyAssignable.
- Template Parameters
-
| T | the type of the managed object, e.g. int for an OFunique_ptr behaving like an int*. |
- Note
- this implementation is meant to be a subset of the c++11's std::unique_ptr that lacks the following features: swap support, custom deleters, specialized handling of pointers to arrays and some functions like comparing OFunique_ptrs or creating a hash key. see http://en.cppreference.com/w/cpp/memory/unique_ptr to compare OFunique_ptr against std::unique_ptr.
Move constructor.
The move constructor moves the ownership of the managed object from its parameter to the newly created OFunique_ptr object, effectively emptying the former OFunique_ptr object.
- Parameters
-
| rhs | an rvalue reference to another OFunique_ptr object, e.g. obtained via OFmove. |
Example
This example shows how to move the ownership of a managed object from one OFunique_ptr to another. Note that the ownership always remains unique in this example, even if an error occurred while reading the Dataset. Therefore no memory leaks are possible!
. . .
if( pDataset && pDataset->read( ... ).good() )
{
consumeDataset(
OFmove( pDataset ) );
}
a class handling the DICOM dataset format (files without meta header)
Definition dcdatset.h:42
OFunique_ptr()
Constructs an empty OFunique_ptr.
Definition ofmem.h:296
OFconstexpr xvalue OFmove(T< unspecified > t)
Obtains an rvalue reference to its argument and converts it to an xvalue.
References OFunique_ptr(), m_pData, OFrvalue_access(), and OFrvalue_ref.