iox::cxx::unique_ptr🔗
The unique_ptr class is a heap-less unique ptr implementation, unlike the STL. More...
#include <iceoryx_hoofs/cxx/unique_ptr.hpp>
Public Functions🔗
Name | |
---|---|
unique_ptr() | |
unique_ptr(function_ref< void(T *)> && deleter) unique_ptr Creates an empty unique ptr that owns nothing. Can be passed ownership later via reset. |
|
unique_ptr(T const ptr, function_ref< void(T )> && deleter) unique_ptr Creates a unique pointer that takes ownership of an object. |
|
unique_ptr(const unique_ptr & other) | |
unique_ptr & | operator=(const unique_ptr & ) |
unique_ptr(unique_ptr && rhs) | |
unique_ptr & | operator=(unique_ptr && rhs) |
~unique_ptr() | |
unique_ptr< T > & | operator=(std::nullptr_t ) |
T * | operator->() operator -> Transparent access to the managed object. |
const T * | operator->() const operator -> Transparent access to the managed object. |
operator bool() const operator bool Returns true if it points to something. |
|
T * | get() get Retrieve the underlying raw pointer. |
const T * | get() const get Retrieve the underlying raw pointer. |
T * | release() release Release ownership of the underlying pointer. |
void | reset(T *const ptr =nullptr) reset Reset the unique pointer to take ownership of the given pointer. |
void | swap(unique_ptr & other) swap Swaps object ownership with another unique_ptr (incl. deleters) |
Detailed Description🔗
template <typename T >
class iox::cxx::unique_ptr;
The unique_ptr class is a heap-less unique ptr implementation, unlike the STL.
To avoid using the heap, deleters are not managed by the pointer itself, and instead must be provided as function references ('cxx:function_ref'). The functions must exist at least as long as the pointers that use them.
Also unlike the STL implementation, the deleters are not encoded in the unique_ptr type, allowing unique_ptr instances with different deleters to be stored in the same containers.
Public Functions Documentation🔗
function unique_ptr🔗
unique_ptr()
function unique_ptr🔗
unique_ptr(
function_ref< void(T *)> && deleter
)
unique_ptr Creates an empty unique ptr that owns nothing. Can be passed ownership later via reset.
function unique_ptr🔗
unique_ptr(
T *const ptr,
function_ref< void(T *)> && deleter
)
unique_ptr Creates a unique pointer that takes ownership of an object.
Parameters:
- ptr The raw pointer to the object to be managed.
- deleter The deleter function for cleaning up the managed object. As cxx:function_ref used for the deleter is non-owning the user needs to care about the lifetime of the callable!
A deleter must always be provided as no default can be provided given that no heap is used. The unique_ptr must know how to delete the managed object when the pointer goes out of scope.
function unique_ptr🔗
unique_ptr(
const unique_ptr & other
)
function operator=🔗
unique_ptr & operator=(
const unique_ptr &
)
function unique_ptr🔗
unique_ptr(
unique_ptr && rhs
)
function operator=🔗
unique_ptr & operator=(
unique_ptr && rhs
)
function ~unique_ptr🔗
~unique_ptr()
Automatically deletes the managed object on destruction.
function operator=🔗
unique_ptr< T > & operator=(
std::nullptr_t
)
function operator->🔗
T * operator->()
operator -> Transparent access to the managed object.
Return:
function operator->🔗
const T * operator->() const
operator -> Transparent access to the managed object.
Return:
function operator bool🔗
explicit operator bool() const
operator bool Returns true if it points to something.
function get🔗
T * get()
get Retrieve the underlying raw pointer.
Return: Pointer to managed object or nullptr if none owned.
The unique_ptr retains ownership, therefore the "borrowed" pointer must not be deleted.
function get🔗
const T * get() const
get Retrieve the underlying raw pointer.
Return: Pointer to managed object or nullptr if none owned.
The unique_ptr retains ownership, therefore the "borrowed" pointer must not be deleted.
function release🔗
T * release()
release Release ownership of the underlying pointer.
Return: Pointer to the managed object or nullptr if none owned.
function reset🔗
void reset(
T *const ptr =nullptr
)
reset Reset the unique pointer to take ownership of the given pointer.
Parameters:
- ptr Pointer to object to take ownership on.
Any previously owned objects will be deleted. If no pointer given then points to nullptr.
function swap🔗
void swap(
unique_ptr & other
)
swap Swaps object ownership with another unique_ptr (incl. deleters)
Parameters:
- other The unique_ptr with which to swap owned objects.
Updated on 2 April 2022 at 16:37:47 CEST