|
| owned_or_borrowed_ptr () noexcept=default |
| Initializes a new instance of the owned_or_borrowed_ptr class, which does not contain any pointer.
|
|
| owned_or_borrowed_ptr (const owned_or_borrowed_ptr &)=delete |
|
| owned_or_borrowed_ptr (owned_or_borrowed_ptr &&other) noexcept |
| Move constructor. More...
|
|
template<typename T2 , typename = std::enable_if_t<std::is_convertible_v<T2*, pointer>>> |
| owned_or_borrowed_ptr (owned_or_borrowed_ptr< T2 > &&other) noexcept |
| Move constructor from a different owned_or_borrowed_ptr if the pointer types can be implicitly converted. More...
|
|
| owned_or_borrowed_ptr (pointer ptr, bool owned=true) noexcept |
| Initializes a new instance of the owned_or_borrowed_ptr class, which contains the specified pointer. More...
|
|
| owned_or_borrowed_ptr (std::nullptr_t) noexcept |
| Initializes a new instance of the owned_or_borrowed_ptr class, which does not contain any pointer.
|
|
| ~owned_or_borrowed_ptr () |
| Deletes the contained pointer if it is not NULL and if it's owned.
|
|
owned_or_borrowed_ptr | as_borrowed () const noexcept |
| Creates a borrowed pointer that refers to the same pointer as this instance.
|
|
pointer | get () const noexcept |
| Gets the contained pointer.
|
|
bool | is_owned () const noexcept |
| Gets a value that indicates whether the contained pointer is owned. More...
|
|
| operator bool () const noexcept |
| Gets a value that indicates if the contained pointer is not NULL. More...
|
|
reference | operator* () const noexcept |
| Dererences the contained pointer. More...
|
|
pointer | operator-> () const noexcept |
| Member access operator.
|
|
owned_or_borrowed_ptr & | operator= (const owned_or_borrowed_ptr &)=delete |
|
owned_or_borrowed_ptr & | operator= (owned_or_borrowed_ptr &&other) noexcept |
| Move assignment operator. More...
|
|
template<typename T2 , typename = std::enable_if_t<std::is_convertible_v<T2*, pointer>>> |
owned_or_borrowed_ptr & | operator= (owned_or_borrowed_ptr< T2 > &&other) noexcept |
| Move assignment operator from a different owned_or_borrowed_ptr if the pointer types can be implicitly converted. More...
|
|
owned_or_borrowed_ptr & | operator= (std::nullptr_t) noexcept |
| Assigns a NULL value to this instance.
|
|
pointer | release () noexcept |
| Releases the contained pointer without deleting it, even if it was owned. More...
|
|
void | reset (pointer ptr=nullptr, bool owned=true) noexcept |
| Resets this instance with a new pointer value. More...
|
|
void | reset (std::nullptr_t) noexcept |
| Resets this instance with a NULL pointer value. More...
|
|
void | swap (owned_or_borrowed_ptr &other) noexcept |
| Swaps this owned_or_borrowed_ptr with another. More...
|
|
template<typename T>
class ookii::owned_or_borrowed_ptr< T >
Smart pointer that may or may not own the contained pointer.
This type is a smart pointer that will free the contained pointer on destruction if it's owned, or will do nothing if it's borrowed. Essentially, it acts like a std::unique_ptr<T>
if the pointer is owned, and like a raw pointer if not.
This type is used to store both owned and duplicate references to the same objects in a single list.
- Warning
- The borrowed pointers don't have any influence on the lifetime of their owned counterparts, so it's up to the user to assure that the borrowed pointer doesn't outlive the underlying pointer.
- Template Parameters
-
T | The type of object referred to by the pointer. Should not be an array type. |
Gets a value that indicates whether the contained pointer is owned.
If this method returns true
, the reset() method and the destructor will delete the contained pointer. If it's false
, they will do nothing to that pointer.
This method may return true
if the contained pointer is NULL, in which case it has no significance.
- Returns
true
if the contained pointer is owned; otherwise, false
.