Nullable RAII data pointer with exclusive ownership of an array 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 array.
|
| constexpr | UniquePointer (std::nullptr_t pointer) noexcept |
| | Construct a null pointer without an associated array.
|
| constexpr | UniquePointer (pointer pointer, Deleter deleter=Deleter()) noexcept |
| | Construct a pointer that takes ownership of an existing array.
|
| constexpr | operator bool () const noexcept |
| | Check if this pointer has an associated array, 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 array.
|
| constexpr void | reset (pointer newPointer=nullptr) noexcept |
| | Destroy the array associated with this pointer, if any, and take ownership of a new array, which may be null.
|
| constexpr pointer | release () noexcept |
| | Relinquish ownership of the associated array.
|
| constexpr pointer | get () const noexcept |
| | Get the underlying array pointer.
|
| constexpr Deleter & | get_deleter () noexcept |
| | Get the current deleter.
|
| constexpr const Deleter & | get_deleter () const noexcept |
| | Get the current deleter.
|
| constexpr decltype(auto) | operator[] (std::size_t index) const noexcept |
| | Access an element of the associated array.
|
| constexpr pointer | operator-> () const noexcept |
| | Access the associated object by pointer.
|
| constexpr decltype(auto) | operator* () const noexcept |
| | Access the associated object.
|
|
| static constexpr UniquePointer | create (std::size_t size) |
| | Allocate an array of default-initialized elements of the associated type and wrap it in a pointer with unique ownership.
|
template<typename T, typename Deleter>
class grem::UniquePointer< T[], Deleter >
Nullable RAII data pointer with exclusive ownership of an array that is automatically destroyed on pointer destruction.
- Template Parameters
-
| T | the element type of the associated array. |
| Deleter | function object type that destroys the associated array when called with a non-null pointer. Passing nullptr must be a no-op. |
◆ pointer
template<typename T, typename Deleter>
| 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>
◆ deleter_type
template<typename T, typename Deleter>
◆ UniquePointer() [1/3]
template<typename T, typename Deleter>
Construct a null pointer without an associated array.
◆ UniquePointer() [2/3]
template<typename T, typename Deleter>
Construct a null pointer without an associated array.
- Parameters
-
◆ UniquePointer() [3/3]
template<typename T, typename Deleter>
|
|
inlineexplicitconstexprnoexcept |
Construct a pointer that takes ownership of an existing array.
- Parameters
-
| pointer | the underlying array pointer to take ownership of, or nullptr to construct a null pointer without an associated array. |
| deleter | the deleter to use to destroy the array on destruction. |
◆ create()
template<typename T, typename Deleter>
|
|
inlinestaticnodiscardconstexpr |
Allocate an array of default-initialized elements of the associated type and wrap it in a pointer with unique ownership.
- Parameters
-
| size | number of elements to allocate. |
- Returns
- a non-null pointer that owns the allocated array.
- Exceptions
-
| std::bad_alloc | on allocation failure. |
| std::bad_array_new_length | if the given size is invalid. |
| any | exception thrown by the element's default constructor. |
◆ operator bool()
template<typename T, typename Deleter>
|
|
inlineexplicitconstexprnoexcept |
Check if this pointer has an associated array, i.e. if it is not null.
- Returns
- true if the pointer has an associated array, false if the pointer is null.
◆ operator==() [1/2]
template<typename T, typename Deleter>
|
|
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 arrays. It only compares the values of the pointers themselves.
◆ operator==() [2/2]
template<typename T, typename Deleter>
|
|
inlinenodiscardconstexprnoexcept |
Check if this pointer is null and has no associated array.
- 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>
Destroy the array associated with this pointer, if any, and take ownership of a new array, which may be null.
- Parameters
-
| newPointer | the new underlying array pointer to take ownership of, or nullptr to reset to a null pointer without an associated array. |
- See also
- release()
-
get()
◆ release()
template<typename T, typename Deleter>
Relinquish ownership of the associated array.
This pointer will be reset to null, without destroying the associated array.
- Returns
- the pointer to the associated array that was released, or nullptr if the pointer did not have an associated array.
- Warning
- After calling this function, the associated array will no longer be destroyed automatically along with the pointer. It instead becomes the responsibility of the caller to ensure that the array is properly destroyed. If the intent is to reset the pointer to null while destroying the associated array in the process, use reset() instead.
- See also
- reset()
-
get()
◆ get()
template<typename T, typename Deleter>
|
|
inlinenodiscardconstexprnoexcept |
◆ get_deleter() [1/2]
template<typename T, typename Deleter>
|
|
inlinenodiscardconstexprnoexcept |
Get the current deleter.
- Returns
- a reference to the current deleter.
◆ get_deleter() [2/2]
template<typename T, typename Deleter>
|
|
inlinenodiscardconstexprnoexcept |
Get the current deleter.
- Returns
- a read-only reference to the current deleter.
◆ operator[]()
template<typename T, typename Deleter>
|
|
inlinenodiscardconstexprnoexcept |
Access an element of the associated array.
- Parameters
-
| index | index of the array element to access. |
- Returns
- a reference to the given element of the associated array.
- Warning
- If the pointer is null and has no associated array, the behavior is undefined.
- See also
- get()
◆ operator->()
|
|
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*()
|
|
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: