std::shared_ptr::unique - cppreference.com (original) (raw)

| bool unique() const noexcept; | | (deprecated in C++17) (removed in C++20) | | ----------------------------- | | ---------------------------------------- |

Checks if *this is the only shared_ptr instance managing the current object, i.e. whether use_count() == 1.

[edit] Parameters

(none)

[edit] Return value

true if *this is the only shared_ptr instance managing the current object, false otherwise.

[edit] Notes

This function was deprecated in C++17 and removed in C++20 because use_count() == 1 is meaningless in multithreaded environment (see Notes in use_count).

[edit] Example

Output:

sp1.unique() == true sp1.unique() == false

[edit] See also

| | returns the number of shared_ptr objects referring to the same managed object (public member function) [edit] | | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |