|
| | WeakPtr ()=default |
| |
| | WeakPtr (std::nullptr_t) |
| |
template<typename U >
requires (std::convertible_to<U*, T*>) |
| | WeakPtr (const WeakPtr< U > &other) |
| | Allow conversion from U to T provided U "is a" T.
|
| |
template<typename U >
requires (std::convertible_to<U*, T*>) |
| WeakPtr & | operator= (const WeakPtr< U > &other) |
| |
template<typename U >
requires (std::convertible_to<U*, T*>) |
| | WeakPtr (WeakPtr< U > &&other) |
| |
template<typename U >
requires (std::convertible_to<U*, T*>) |
| WeakPtr & | operator= (WeakPtr< U > &&other) |
| |
| T * | get () const |
| |
| T & | operator* () const |
| | Provide access to the underlying T as a reference.
|
| |
| T * | operator-> () const |
| | Used to call methods on the underlying T.
|
| |
| | operator bool () const |
| | Allow conditionals to test validity, e.g.
|
| |
| void | reset () |
| | Resets the WeakPtr to hold nothing.
|
| |
| bool | MaybeValid () const |
| | Do not use this method.
|
| |
| bool | WasInvalidated () const |
| | Returns whether the object |this| points to has been invalidated.
|
| |
template<typename T>
class base::WeakPtr< T >
The WeakPtr class holds a weak reference to |T*|.
This class is designed to be used like a normal pointer. You should always null-test an object of this class before using it or invoking a method that may result in the underlying object being destroyed.
EXAMPLE:
class Foo { ... };
WeakPtr<Foo> foo;
if (foo)
foo->method();
WeakPtr intentionally doesn't implement operator== or operator<=>, because comparisons of weak references are inherently unstable. If the comparison takes validity into account, the result can change at any time as pointers are invalidated. If it depends only on the underlying pointer value, even after the pointer is invalidated, unrelated WeakPtrs can unexpectedly compare equal if the address is reused.
Do not use this method.
Almost all callers should instead use operator bool().
There are a few rare cases where the caller intentionally needs to check validity of a base::WeakPtr on a thread different from the bound thread as an unavoidable performance optimization.
Returns false if the WeakPtr is confirmed to be invalid. This call is safe to make from any thread, e.g. to optimize away unnecessary work, but IsValid() must always be called, on the correct thread, before actually using the pointer.
Warning: as with any object, this call is only thread-safe if the WeakPtr instance isn't being re-assigned or reset() racily with this call.