ezEngine  Release 25.03
ezUniquePtr< T > Class Template Reference

A Unique ptr manages an object and destroys that object when it goes out of scope. It is ensure that only one unique ptr can manage the same object. More...

#include <UniquePtr.h>

Public Member Functions

 EZ_DECLARE_MEM_RELOCATABLE_TYPE ()
 
 ezUniquePtr ()
 Creates an empty unique ptr.
 
template<typename U >
 ezUniquePtr (const ezInternal::NewInstance< U > &instance)
 Creates a unique ptr from a freshly created instance through EZ_NEW or EZ_DEFAULT_NEW.
 
template<typename U >
 ezUniquePtr (U *pInstance, ezAllocator *pAllocator)
 Creates a unique ptr from a pointer and an allocator. The passed allocator will be used to destroy the instance when the unique ptr goes out of scope.
 
template<typename U >
 ezUniquePtr (ezUniquePtr< U > &&other)
 Move constructs a unique ptr from another. The other unique ptr will be empty afterwards to guarantee that there is only one unique ptr managing the same object.
 
 ezUniquePtr (std::nullptr_t)
 Initialization with nullptr to be able to return nullptr in functions that return unique ptr.
 
 ~ezUniquePtr ()
 Destroys the managed object using the stored allocator.
 
template<typename U >
ezUniquePtr< T > & operator= (const ezInternal::NewInstance< U > &instance)
 Sets the unique ptr from a freshly created instance through EZ_NEW or EZ_DEFAULT_NEW.
 
template<typename U >
ezUniquePtr< T > & operator= (ezUniquePtr< U > &&other)
 Move assigns a unique ptr from another. The other unique ptr will be empty afterwards to guarantee that there is only one unique ptr managing the same object.
 
ezUniquePtr< T > & operator= (std::nullptr_t)
 Same as calling 'Reset()'.
 
T * Release ()
 Releases the managed object without destroying it. The unique ptr will be empty afterwards.
 
T * Release (ezAllocator *&out_pAllocator)
 Releases the managed object without destroying it. The unique ptr will be empty afterwards. Also returns the allocator that should be used to destroy the object.
 
T * Borrow () const
 Borrows the managed object. The unique ptr stays unmodified.
 
void Clear ()
 Destroys the managed object and resets the unique ptr.
 
T & operator* () const
 Provides access to the managed object.
 
T * operator-> () const
 Provides access to the managed object.
 
 operator bool () const
 Returns true if there is managed object and false if the unique ptr is empty.
 
bool operator== (const ezUniquePtr< T > &rhs) const
 Compares the unique ptr against another unique ptr.
 
bool operator!= (const ezUniquePtr< T > &rhs) const
 
bool operator< (const ezUniquePtr< T > &rhs) const
 
bool operator<= (const ezUniquePtr< T > &rhs) const
 
bool operator> (const ezUniquePtr< T > &rhs) const
 
bool operator>= (const ezUniquePtr< T > &rhs) const
 
bool operator== (std::nullptr_t) const
 Compares the unique ptr against nullptr.
 
bool operator!= (std::nullptr_t) const
 
bool operator< (std::nullptr_t) const
 
bool operator<= (std::nullptr_t) const
 
bool operator> (std::nullptr_t) const
 
bool operator>= (std::nullptr_t) const
 
template<typename U >
EZ_ALWAYS_INLINE ezUniquePtr (const ezInternal::NewInstance< U > &instance)
 
template<typename U >
EZ_ALWAYS_INLINE ezUniquePtr (U *pInstance, ezAllocator *pAllocator)
 
template<typename U >
EZ_ALWAYS_INLINE ezUniquePtr (ezUniquePtr< U > &&other)
 
template<typename U >
EZ_ALWAYS_INLINE ezUniquePtr< T > & operator= (const ezInternal::NewInstance< U > &instance)
 
template<typename U >
EZ_ALWAYS_INLINE ezUniquePtr< T > & operator= (ezUniquePtr< U > &&other)
 

Detailed Description

template<typename T>
class ezUniquePtr< T >

A Unique ptr manages an object and destroys that object when it goes out of scope. It is ensure that only one unique ptr can manage the same object.


The documentation for this class was generated from the following files: