|
constexpr | SafeWeakPtr () noexcept=default |
| Default constructor. Constructs empty weak_ptr. More...
|
|
template<typename Y > |
| SafeWeakPtr (const SafeWeakPtr< Y, SharedMutex, SharedLock, UniqueLock > &other) |
| Constructs new SafeWeakPtr that shares an object with other . More...
|
|
template<typename Y > |
| SafeWeakPtr (const SafeSharedPtr< Y, SharedMutex, SharedLock, UniqueLock > &other) |
| Constructs new SafeWeakPtr that shares an object with other . More...
|
|
| ~SafeWeakPtr ()=default |
| Destroys the weak_ptr object. Results in no effect to the managed object. More...
|
|
SafeWeakPtr< T > & | operator= (const SafeWeakPtr< T > &other) noexcept |
| Replaces the managed object with the one managed by other . More...
|
|
template<typename Y > |
SafeWeakPtr< T > & | operator= (const SafeWeakPtr< Y, SharedMutex, SharedLock, UniqueLock > &other) noexcept |
| Replaces the managed object with the one managed by other . More...
|
|
void | reset () noexcept |
| Releases the ownership of the managed object. After the call *this manages no object. More...
|
|
void | swap (SafeWeakPtr< T > &other) noexcept |
| Exchanges the contents of *this and other . More...
|
|
long | use_count () const noexcept |
| Returns the number of SafeSharedPtr instances that share ownership of the managed object, or 0 if the managed object has already been deleted, i.e. *this is empty. More...
|
|
bool | expired () const noexcept |
| Checks whether the referenced object was already deleted. More...
|
|
SafeSharedPtr< T > | lock () const noexcept |
| Creates a SafeSharedPtr that manages the referenced object. More...
|
|
template<typename Y , typename M , typename R , typename W > |
bool | owner_before (const SafeWeakPtr< Y, M, R, W > &other) const |
| Provides owner-based ordering of weak pointers. More...
|
|
template<typename Y , typename M , typename R , typename W > |
bool | owner_before (const SafeSharedPtr< Y, M, R, W > &other) const |
| Provides owner-based ordering of weak pointers. More...
|
|
template<typename T, typename mutex_t = shared_mutex_t, typename read_lock_t = shared_lock_t, typename write_lock_t = unique_lock_t>
class Memory::SafeWeakPtr< T, mutex_t, read_lock_t, write_lock_t >
Wrapper to std::weak_ptr
to provide weak reference for SafeSharedPtr.
- Template Parameters
-
T | Type of the object held by SafeWeakPtr. |
mutex_t | Type of the mutex used, default is shared_mutex_t. |
read_lock_t | Type of the read-lock used, default is shared_lock_t. |
write_lock_t | Type of the write-lock used, default is unique_lock_t. |
Same API as std::weak_ptr
.
See https://en.cppreference.com/w/cpp/memory/weak_ptr for more details of functionalities with std::weak_ptr.
- Note
- Before C++17, for the purposes of the description below, a pointer type
Y*
requires that Y*
must be implicitly convertible to T*
.
Since C++17, for the purposes of the description below, a pointer type Y*
is said to be compatible with a pointer type T*
if either Y*
is convertible to T*
or Y
is the array type U[N]
and T
is U cv []
(where cv is some set of cv-qualifiers).
Since C++17, default deleter called on destructor will use delete[]
if T
is an arry type;
- See also
- SafeSharedPtr
template<typename T , typename mutex_t = shared_mutex_t, typename read_lock_t = shared_lock_t, typename write_lock_t = unique_lock_t>
Replaces the managed object with the one managed by other
.
- Parameters
-
other | Smart pointer to share an object with. |
- Returns
*this
.
The object is shared with other
. If other
manages no object, *this
manages no object too. Equivalent to SafeWeakPtr<T>(other).swap(*this)
.
- Note
- The implementation may meet the requirements without creating a temporary SafeWeakPtr object.
template<typename T , typename mutex_t = shared_mutex_t, typename read_lock_t = shared_lock_t, typename write_lock_t = unique_lock_t>
template<typename Y >
Replaces the managed object with the one managed by other
.
- Template Parameters
-
Y | Element type of input pointer |
- Parameters
-
other | Smart pointer to share an object with. |
- Returns
*this
.
The object is shared with other
. If other
manages no object, *this
manages no object too. Equivalent to SafeWeakPtr<T>(other).swap(*this)
.
- Note
- The implementation may meet the requirements without creating a temporary SafeWeakPtr object.
template<typename T , typename mutex_t = shared_mutex_t, typename read_lock_t = shared_lock_t, typename write_lock_t = unique_lock_t>
Checks whether the referenced object was already deleted.
- Returns
true
if the managed object has already been deleted, false
otherwise.
Equivalent to use_count() == 0
. The destructor for the managed object may not yet have been called, but this object's destruction is imminent (or may have already happened).
- Note
- This function is inherently racy if the managed object is shared among threads. In particular, a false result may become stale before it can be used. A true result is reliable.
- See also
- lock, use_count
template<typename T , typename mutex_t = shared_mutex_t, typename read_lock_t = shared_lock_t, typename write_lock_t = unique_lock_t>
Creates a SafeSharedPtr
that manages the referenced object.
- Returns
- A
SafeSharedPtr
which shares ownership of the owned object if expired returns false
. Else returns default-constructed SafeSharedPtr
of type T
.
Creates a new SafeSharedPtr
that shares ownership of the managed object. If there is no managed object, i.e. *this
is empty, then the returned SafeSharedPtr
also is empty.\n Effectively returns expired() ? SafeSharedPtr<T>() : SafeSharedPtr<T>(*this)
, executed atomically.
- Note
- Both this function and the constructor of
SafeSharedPtr
may be used to acquire temporary ownership of the managed object referred to by a SafeWeakPtr. The difference is that the constructor of SafeSharedPtr throws an exception when its SafeWeakPtr argument is empty, while lock()
constructs an empty SafeSharedPtr<T>.
template<typename T , typename mutex_t = shared_mutex_t, typename read_lock_t = shared_lock_t, typename write_lock_t = unique_lock_t>
template<typename Y , typename M , typename R , typename W >
Provides owner-based ordering of weak pointers.
- Template Parameters
-
Y | Type of the object managed by input pointer. |
M | Type of the mutex used, default is shared_mutex_t. |
R | Type of the read-lock used, default is shared_lock_t. |
W | Type of the write-lock used, default is unique_lock_t. |
- Parameters
-
- Returns
true
if *this
precedes other, false
otherwise. Common implementations compare the addresses of the control blocks.
Checks whether this SafeWeakPtr precedes other in implementation defined owner-based (as opposed to value-based) order. The order is such that two smart pointers compare equivalent only if they are both empty or if they both own the same object, even if the values of the pointers obtained by get() are different (e.g. because they point at different subobjects within the same object).
This ordering is used to make shared and weak pointers usable as keys in associative containers, typically through std::owner_less.
template<typename T , typename mutex_t = shared_mutex_t, typename read_lock_t = shared_lock_t, typename write_lock_t = unique_lock_t>
template<typename Y , typename M , typename R , typename W >
Provides owner-based ordering of weak pointers.
- Template Parameters
-
Y | Type of the object managed by input pointer. |
M | Type of the mutex used, default is shared_mutex_t. |
R | Type of the read-lock used, default is shared_lock_t. |
W | Type of the write-lock used, default is unique_lock_t. |
- Parameters
-
- Returns
true
if *this
precedes other, false
otherwise. Common implementations compare the addresses of the control blocks.
Checks whether this SafeWeakPtr precedes other in implementation defined owner-based (as opposed to value-based) order. The order is such that two smart pointers compare equivalent only if they are both empty or if they both own the same object, even if the values of the pointers obtained by get() are different (e.g. because they point at different subobjects within the same object).
This ordering is used to make shared and weak pointers usable as keys in associative containers, typically through std::owner_less.
template<typename T , typename mutex_t = shared_mutex_t, typename read_lock_t = shared_lock_t, typename write_lock_t = unique_lock_t>
template<typename Y , typename M , typename R , typename W >