Windows Dev Center

The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.


Tests if owned resource is unique.

bool unique() const;

The member function returns true if no other shared_ptr object owns the resource that is owned by *this, otherwise false.


// std_tr1__memory__shared_ptr_unique.cpp 
// compile with: /EHsc 
#include <memory> 
#include <iostream> 
struct deleter 
    void operator()(int *p) 
        delete p; 
int main() 
    std::shared_ptr<int> sp1(new int(5)); 
    std::cout << "sp1.unique() == " << std::boolalpha 
        << sp1.unique() << std::endl; 
    std::shared_ptr<int> sp2(sp1); 
    std::cout << "sp1.unique() == " << std::boolalpha 
        << sp1.unique() << std::endl; 
    return (0); 
sp1.unique() == true
sp1.unique() == false

Header: <memory>

Namespace: std

© 2015 Microsoft