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
-
T the type of object to point to Deleter a 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>>
|
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>>
|
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>>
|
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>>
|
inline |
◆ operator=() [2/2]
template<class T , class Deleter = default_delete<T>>
|
inline |
Move assignment operator.
Transfers ownership from other
to *this
◆ release()
template<class T , class Deleter = default_delete<T>>
|
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:
- common/RNBO_UniquePtr.h