4.6.0
Freundlich's C++ toolkit
|
A weak reference to an object owned by a shared pointer.
A weak pointer contributes to the weak reference count of on object owned by shared pointers. The difference is that a weak pointer won't stop the object from being destructed. Such a weak pointer can be used to observe if there are any shared pointers left.
Type | The type the weak pointer points to |
Deleter | A deleter class that must be callable with a pointer to Type. |
Public Types | |
using | impl_type = std::weak_ptr<Type> |
The type if the std::weak_ptr used to implement this class. | |
using | shared_ptr = fcppt::shared_ptr<Type, Deleter> |
The corresponding shared pointer class. | |
using | element_type = Type |
The element type, which is Type. | |
using | count_type |
The reference count type. | |
Public Member Functions | |
weak_ptr () | |
Constructs an empty weak ptr. | |
template<typename Other > | |
weak_ptr (fcppt::weak_ptr< Other, Deleter > const &ref) | |
Constructs a weak_ptr from a compatible weak_ptr type. | |
template<typename Other > | |
weak_ptr (fcppt::shared_ptr< Other, Deleter > const &ref) | |
Constructs a weak_ptr from a compatible shared_ptr. | |
fcppt::optional::object< shared_ptr > | lock () const |
Returns a shared_ptr pointing to the shared object of this weak_ptr. | |
count_type | use_count () const noexcept |
The use count. | |
bool | expired () const noexcept |
Returns if the weak_ptr still points to a shared object. | |
void | swap (weak_ptr &other) noexcept |
Swaps the weak_ptr. | |
impl_type | std_ptr () const |
Returns the underlying std::weak_ptr object. | |
using fcppt::weak_ptr< Type, Deleter >::count_type |
The reference count type.
using fcppt::weak_ptr< Type, Deleter >::element_type = Type |
The element type, which is Type.
using fcppt::weak_ptr< Type, Deleter >::impl_type = std::weak_ptr<Type> |
The type if the std::weak_ptr
used to implement this class.
using fcppt::weak_ptr< Type, Deleter >::shared_ptr = fcppt::shared_ptr<Type, Deleter> |
The corresponding shared pointer class.
fcppt::weak_ptr< Type, Deleter >::weak_ptr | ( | ) |
Constructs an empty weak ptr.
|
explicit |
|
explicit |
Constructs a weak_ptr from a compatible shared_ptr.
Constructs a weak_ptr from the shared_ptr ref which will keep track of the shared count of the shared_ptr.
Other | A type, so that Other * is implicitly convertible to Type * |
ref | The shared_ptr to monitor |
|
nodiscardnoexcept |
|
nodiscard |
Returns a shared_ptr pointing to the shared object of this weak_ptr.
If the shared object is still alive (which means that the reference count is still greater than zero), then a new shared_ptr also owning that object will be returned. If all shared_ptrs have been destroyed, then an empty optional will be returned.
|
nodiscard |
Returns the underlying std::weak_ptr
object.
|
noexcept |
|
nodiscardnoexcept |
The use count.
If this weak_ptr is empty, zero will be returned. Otherwise the shared count of the shared object will be returned.
long
because std::shared_ptr
also uses long
.