Nullable RAII data pointer with exclusive ownership of an object that is automatically destroyed on pointer destruction.
More...
#include <GREM/core/data/UniquePointer.hpp>
|
| using | pointer = typename detail::deleter_pointer_type<T, std::remove_reference_t<Deleter>>::type |
| | Pointer type.
|
| using | element_type = T |
| | Object type.
|
| using | deleter_type = Deleter |
| | Deleter type.
|
|
| constexpr | UniquePointer () noexcept=default |
| | Construct a null pointer without an associated object.
|
| constexpr | UniquePointer (std::nullptr_t pointer) noexcept |
| | Construct a null pointer without an associated object.
|
template<typename U, typename OtherDeleter>
requires (!std::is_same_v<T, U> && std::is_convertible_v<typename UniquePointer<U, OtherDeleter>::pointer, pointer>) |
| constexpr | UniquePointer (UniquePointer< U, OtherDeleter > &&other) noexcept |
| | Construct a pointer from another pointer of a derived type, taking ownership of its underlying object.
|
| constexpr | UniquePointer (pointer pointer, Deleter deleter=Deleter()) noexcept |
| | Construct a pointer that takes ownership of an existing object pointer.
|
| constexpr | operator bool () const noexcept |
| | Check if this pointer has an associated object, i.e. if it is not null.
|
| constexpr bool | operator== (const UniquePointer &other) const noexcept |
| | Compare this pointer against another for equality of the underlying address.
|
| constexpr bool | operator== (std::nullptr_t other) const noexcept |
| | Check if this pointer is null and has no associated object.
|
| constexpr void | reset (pointer newPointer=nullptr) noexcept |
| | Destroy the object associated with this pointer, if any, and take ownership of a new object pointer, which may be null.
|
| constexpr pointer | release () noexcept |
| | Relinquish ownership of the associated object.
|
| constexpr pointer | get () const noexcept |
| | Get the underlying pointer.
|
| constexpr Deleter & | get_deleter () noexcept |
| | Get the current deleter.
|
| constexpr const Deleter & | get_deleter () const noexcept |
| | Get the current deleter.
|
| constexpr pointer | operator-> () const noexcept |
| | Access the associated object by pointer.
|
| constexpr decltype(auto) | operator* () const noexcept |
| | Access the associated object.
|
|
| template<typename... Args> |
| static constexpr UniquePointer | create (Args &&... args) |
| | Allocate and construct an object of the associated type and wrap it in a pointer with unique ownership.
|
template<typename T, typename Deleter = DefaultDelete<T>>
class grem::UniquePointer< T, Deleter >
Nullable RAII data pointer with exclusive ownership of an object that is automatically destroyed on pointer destruction.
- Template Parameters
-
| T | the associated object type. |
| Deleter | function object type that destroys the associated object when called with a non-null pointer. Passing nullptr must be a no-op. |
◆ pointer
template<typename T, typename Deleter = DefaultDelete<T>>
| using grem::UniquePointer< T, Deleter >::pointer = typename detail::deleter_pointer_type<T, std::remove_reference_t<Deleter>>::type |
◆ element_type
template<typename T, typename Deleter = DefaultDelete<T>>
◆ deleter_type
template<typename T, typename Deleter = DefaultDelete<T>>
◆ UniquePointer() [1/4]
template<typename T, typename Deleter = DefaultDelete<T>>
Construct a null pointer without an associated object.
◆ UniquePointer() [2/4]
template<typename T, typename Deleter = DefaultDelete<T>>
Construct a null pointer without an associated object.
- Parameters
-
◆ UniquePointer() [3/4]
template<typename T, typename Deleter = DefaultDelete<T>>
template<typename U, typename OtherDeleter>
requires (!std::is_same_v<T, U> && std::is_convertible_v<typename UniquePointer<U, OtherDeleter>
::pointer,
pointer>)
Construct a pointer from another pointer of a derived type, taking ownership of its underlying object.
- Parameters
-
| other | other pointer whose object to take owership of. |
◆ UniquePointer() [4/4]
template<typename T, typename Deleter = DefaultDelete<T>>
|
|
inlineexplicitconstexprnoexcept |
Construct a pointer that takes ownership of an existing object pointer.
- Parameters
-
| pointer | the underlying pointer to take ownership of, or nullptr to construct a null pointer without an associated object. |
| deleter | the deleter to use to destroy the object on destruction. |
◆ create()
template<typename T, typename Deleter = DefaultDelete<T>>
template<typename... Args>
|
|
inlinestaticnodiscardconstexpr |
Allocate and construct an object of the associated type and wrap it in a pointer with unique ownership.
- Parameters
-
| args | arguments to forward to the constructor of the underlying object. |
- Returns
- a non-null pointer that owns the constructed object.
- Exceptions
-
| std::bad_alloc | on allocation failure. |
| any | exception thrown by the object's constructor. |
◆ operator bool()
template<typename T, typename Deleter = DefaultDelete<T>>
|
|
inlineexplicitconstexprnoexcept |
Check if this pointer has an associated object, i.e. if it is not null.
- Returns
- true if the pointer has an associated object, false if the pointer is null.
◆ operator==() [1/2]
template<typename T, typename Deleter = DefaultDelete<T>>
|
|
inlinenodiscardconstexprnoexcept |
Compare this pointer against another for equality of the underlying address.
- Parameters
-
| other | the pointer to compare this pointer to. |
- Returns
- true if the pointers are equal, false otherwise.
- Note
- This does not compare the values of any associated objects. It only compares the values of the pointers themselves.
◆ operator==() [2/2]
template<typename T, typename Deleter = DefaultDelete<T>>
|
|
inlinenodiscardconstexprnoexcept |
Check if this pointer is null and has no associated object.
- Parameters
-
| other | the null pointer to compare this pointer to. |
- Returns
- true if the pointers are equal, false otherwise.
◆ reset()
template<typename T, typename Deleter = DefaultDelete<T>>
Destroy the object associated with this pointer, if any, and take ownership of a new object pointer, which may be null.
- Parameters
-
| newPointer | the new underlying pointer to take ownership of, or nullptr to reset to a null pointer without an associated object. |
- See also
- release()
-
get()
◆ release()
template<typename T, typename Deleter = DefaultDelete<T>>
Relinquish ownership of the associated object.
This pointer will be reset to null, without destroying the associated object.
- Returns
- the pointer to the associated object that was released, or nullptr if the pointer did not have an associated object.
- Warning
- After calling this function, the associated object will no longer be destroyed automatically along with the pointer. It instead becomes the responsibility of the caller to ensure that the object is properly destroyed. If the intent is to reset the pointer to null while destroying the associated object in the process, use reset() instead.
- See also
- reset()
-
get()
◆ get()
template<typename T, typename Deleter = DefaultDelete<T>>
|
|
inlinenodiscardconstexprnoexcept |
Get the underlying pointer.
- Returns
- a non-owning copy of the underlying pointer.
- See also
- reset()
-
release()
◆ get_deleter() [1/2]
template<typename T, typename Deleter = DefaultDelete<T>>
|
|
inlinenodiscardconstexprnoexcept |
Get the current deleter.
- Returns
- a reference to the current deleter.
◆ get_deleter() [2/2]
template<typename T, typename Deleter = DefaultDelete<T>>
|
|
inlinenodiscardconstexprnoexcept |
Get the current deleter.
- Returns
- a read-only reference to the current deleter.
◆ operator->()
template<typename T, typename Deleter = DefaultDelete<T>>
|
|
inlinenodiscardconstexprnoexcept |
Access the associated object by pointer.
- Returns
- a non-owning pointer to the associated object.
- Warning
- If the pointer is null and has no associated object, the behavior is undefined.
- See also
- get()
◆ operator*()
template<typename T, typename Deleter = DefaultDelete<T>>
|
|
inlinenodiscardconstexprnoexcept |
Access the associated object.
- Returns
- a reference to the associated object.
- Warning
- If the pointer is null and has no associated object, the behavior is undefined.
- See also
- get()
The documentation for this class was generated from the following file: