std::shared_ptr::unique
bool unique() const noexcept; | | (deprecated) |
|---|
检查*this是唯一shared_ptr实例管理当前对象,即use_count() == 1...
参数
%280%29
返回值
true如果*this是唯一shared_ptr实例管理当前对象,false否则。
例外
noexcept规格:
noexcept
注记
此函数在C++17中不再受欢迎,因为use_count只是多线程环境中的近似。
例
二次
#include <memory>
#include <iostream>
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';
}二次
产出:
二次
sp1.unique() == true
sp1.unique() == false二次
另见
use_count | returns the number of shared_ptr objects referring to the same managed object (public member function) |
|---|
© cppreference.com在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com

