[ Web Proxy ]
URL:
Viewing: https://ru.cppreference.com/cpp/memory/shared_ptr/unique [Back]  [Original]

std::shared_ptr::unique cppreference.com
cppreference.com

std::shared_ptr::unique

cppreference.com
 
C++
(C++20)
(C++20)
(C++11)
(C++20)
/
(C++11)
(C++11)
(C++11)
(C++17)
 
 
no section name
no section name
(C++11)( C++23)
(C++11)( C++23)
(C++11)( C++23)
(C++11)( C++23)
(C++11)( C++23)
(C++11)( C++23)



no section name
 
 
<tbody> </tbody>
bool unique() const noexcept;
( C++17)
( C++20)

, *this shared_ptr, , .. use_count() == 1.

()

true, *this shared_ptr, , false .

C++17 C++20, use_count ( 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

shared_ptr,
(public -) []

Web Proxy Viewer  |  New URL  |  Original Page