C++ API Reference RNBO: RNBO::UniquePtr< T, Deleter > Class Template Reference

RNBO: RNBO::UniquePtr< T, Deleter > Class Template Reference

An smart pointer like std::unique_ptr. More...

#include <RNBO_UniquePtr.h>

Public Member Functions

 UniquePtr (T *ptr=nullptr)
 Construct a UniquePtr.
 
UniquePtr< T > & operator= (T *ptr)
 Assign the UniquePtr. More...
 
 UniquePtr (UniquePtr< T > &&other)
 Copy constructor. More...
 
UniquePtr< T > & operator= (UniquePtr< T > &&other)
 Move assignment operator. More...
 
 ~UniquePtr ()
 Destruct the managed object if one exists.
 
void reset (T *ptr=nullptr)
 Replace the managed object.
 
T * get () const
 Get a pointer to the managed object. More...
 
T * release ()
 Release ownership of the managed object. More...
 
T * operator-> () const
 Dereference the pointer to the managed object.
 
T & operator* () const
 Dereference the pointer to the managed object.
 
 operator bool () const
 Check if there is an associated managed object. More...
 
 UniquePtr (const UniquePtr< T > &other)=delete
 
UniquePtr< T > & operator= (const UniquePtr< T > &other)=delete
 

Detailed Description

template<class T, class Deleter = default_delete<T>>
class RNBO::UniquePtr< T, Deleter >

An smart pointer like std::unique_ptr.

A unique pointer is a smart pointer that owns and manages another object through a pointer and disposes of that object when the UniquePtr goes out of scope. Ownership is enforced by deletion of copy construction and copy assignment.

Template Parameters
Tthe type of object to point to
Deletera callable delete for object destruction
See also
default_delete
{
auto myPtr = UniquePtr<int>(new int(74));
} // myPtr is out of scope and the memory allocated is now freed

{}

Constructor & Destructor Documentation

◆ UniquePtr()

template<class T , class Deleter = default_delete<T>>
RNBO::UniquePtr< T, Deleter >::UniquePtr ( UniquePtr< T > &&  other)
inline

Copy constructor.

Construct a UniquePtr by transfering ownership from u to *this and making other's pointer nullptr

Member Function Documentation

◆ get()

template<class T , class Deleter = default_delete<T>>
T* RNBO::UniquePtr< T, Deleter >::get ( ) const
inline

Get a pointer to the managed object.

Returns
a pointer to the managed object if one exists, otherwise nullptr

◆ operator bool()

template<class T , class Deleter = default_delete<T>>
RNBO::UniquePtr< T, Deleter >::operator bool ( ) const
inline

Check if there is an associated managed object.

Returns
true if *this owns an object, false otherwise

◆ operator=() [1/2]

template<class T , class Deleter = default_delete<T>>
UniquePtr<T>& RNBO::UniquePtr< T, Deleter >::operator= ( T *  ptr)
inline

Assign the UniquePtr.

Effectively the same as calling reset()

◆ operator=() [2/2]

template<class T , class Deleter = default_delete<T>>
UniquePtr<T>& RNBO::UniquePtr< T, Deleter >::operator= ( UniquePtr< T > &&  other)
inline

Move assignment operator.

Transfers ownership from other to *this

◆ release()

template<class T , class Deleter = default_delete<T>>
T* RNBO::UniquePtr< T, Deleter >::release ( )
inline

Release ownership of the managed object.

Returns
a pointer to the managed object

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