< cpp‎ | memory‎ | weak ptr
Utilities library
General utilities
Date and time
Function objects
Formatting library (C++20)
Relational operators (deprecated in C++20)
Integer comparison functions
Swap and type operations
Common vocabulary types

Elementary string conversions
Dynamic memory management
Uninitialized storage
Garbage collection support
C Library
Low level memory management
long use_count() const noexcept;
(since C++11)

Returns the number of shared_ptr instances that share ownership of the managed object, or 0 if the managed object has already been deleted, i.e. *this is empty.


[edit] Parameters


[edit] Return value

The number of shared_ptr instances sharing the ownership of the managed object at the instant of the call.

[edit] Notes

expired() may be faster than use_count(). This function is inherently racy, if the managed object is shared among threads that might be creating and destroying copies of the shared_ptr: then, the result is reliable only if it matches the number of copies uniquely owned by the calling thread, or zero; any other value may become stale before it can be used.

[edit] Example

[edit] See also

checks whether the referenced object was already deleted
(public member function) [edit]