std::shared_ptr::unique(3)
π NAME π
okay so bestie, this is the C++ Standard Libary manual page, section 3, for std::shared_ptr::unique. And the original NAME line was literally std::shared_ptr::unique - std::shared_ptr::unique, so we're honoring that iconic duplication: the function is std::shared_ptr::unique, and it is also std::shared_ptr::unique. no notes. π
β¨ Synopsis β¨
bool unique() const noexcept; (deprecated in C++17)
(removed in C++20)
This member function checks whether *this is the only shared_ptr instance managing the current object β like, the actual question is whether use_count() == 1. that's the tea. π
πΈ Parameters πΈ
(none)β no parameters. not a single one. empty. π«Ά
π Return value π
trueif*thisis the onlyshared_ptrinstance managing the current objectfalseotherwise.
π¦ Notes π¦
This function was deprecated in C++17 and removed in C++20 because use_count is only an approximation in multithreaded environment (see Notes in use_count). so yeah, she's a legacy icon, not a current-era baddie. π
β οΈ technical caveat, bestie: the deprecation and removal are real. use_count is only an approximation in multithreaded environment β that's why the function got retired. don't @ me, @ the standard. π
π§ Example π§
Run this code:
// Run this code
#include <iostream>
#include <memory>
int main()
{
auto sp1 = std::make_shared<int>(5);
std::cout << std::boolalpha;
std::cout << "sp1.unique() == " << sp1.unique() << '\n';
std::shared_ptr<int> sp2 = sp1;
std::cout << "sp1.unique() == " << sp1.unique() << '\n';
}
π Output π
sp1.unique() == true
sp1.unique() == false
π See also π
use_countβ returns the number ofshared_ptrobjects referring to the same managed object (public member function).
okay that's the whole page, bestie β sourced from http://cppreference.com, dated 2024.06.10. mwah π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms