CRTP mixin to enable objects to create strong_ptr instances to themselves. More...
#include <memory.hpp>
Public Member Functions | |
| strong_ptr< T > | strong_from_this () |
| Get a strong_ptr to this object. | |
| strong_ptr< T const > | strong_from_this () const |
| Get a strong_ptr to this object (const version) | |
| weak_ptr< T > | weak_from_this () noexcept |
| Get a weak_ptr to this object. | |
| weak_ptr< T const > | weak_from_this () const noexcept |
| Get a weak_ptr to this object (const version) | |
Protected Member Functions | |
| enable_strong_from_this ()=default | |
| Protected constructor to prevent direct instantiation. | |
| enable_strong_from_this (enable_strong_from_this const &) noexcept | |
| Protected copy constructor. | |
| enable_strong_from_this & | operator= (enable_strong_from_this const &) noexcept |
| Protected assignment operator. | |
| ~enable_strong_from_this ()=default | |
| Protected destructor. | |
Friends | |
| template<class U , typename... Args> | |
| strong_ptr< U > | make_strong_ptr (std::pmr::polymorphic_allocator<>, Args &&...) |
CRTP mixin to enable objects to create strong_ptr instances to themselves.
Similar to std::enable_shared_from_this, this class allows an object to safely obtain a strong_ptr to itself. The object must inherit from this class and be managed by a strong_ptr created via make_strong_ptr.
Example usage:
| T | The derived class type |
|
inlineprotectednoexcept |
Protected copy constructor.
Note: The weak_ptr is not copied - each object gets its own weak reference
|
inlineprotectednoexcept |
Protected assignment operator.
Note: The weak_ptr is not assigned - each object keeps its own weak reference
|
inline |
Get a strong_ptr to this object.
| hal::bad_weak_ptr | if this object is not managed by a strong_ptr |
|
inline |
Get a strong_ptr to this object (const version)
| hal::bad_weak_ptr | if this object is not managed by a strong_ptr |
|
inlinenoexcept |
Get a weak_ptr to this object (const version)
|
inlinenoexcept |
Get a weak_ptr to this object.