std::weak_ptr::use_count

From cppreference.com
< cpp‎ | memory‎ | weak ptr
 
 
Utilities library
Type support (basic types, RTTI, type traits)
Dynamic memory management
Error handling
Program utilities
Variadic functions
Date and time
Function objects
(C++11)
Relational operators
Optional and any
(C++17)
(C++17)
Pairs and tuples
(C++11)
(C++17)
Swap, forward and move
(C++14)
(C++11)
(C++11)
Type operations
(C++11)
(C++17)
 
 
 
long use_count() const;
(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.

Contents

[edit] Parameters

(none)

[edit] Return value

The number of shared_ptr instances sharing the ownership of the managed object.

[edit] Exceptions

noexcept specification:  
noexcept
  

[edit] Notes

expired() may be faster than use_count().

[edit] Example

[edit] See also

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