std::weak_ptr::expired - cppreference.com (original) (raw)

| bool expired() const noexcept; | | (since C++11) | | ------------------------------ | | ------------- |

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).

[edit] Parameters

(none)

[edit] Return value

true if the managed object has already been deleted, false otherwise.

[edit] Notes

If the managed object is shared among threads, it is only meaningful when expired() returns true.

[edit] Example

Demonstrates how expired is used to check validity of the pointer.

Output:

gw is valid gw is expired

[edit] See also

| | creates a shared_ptr that manages the referenced object (public member function) [edit] | | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | | returns the number of shared_ptr objects that manage the object (public member function) [edit] |