Compartilhar via


shared_ptr::unique

Tests if owned resource is unique.

bool unique() const;

Remarks

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

Example

 

// 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

Requirements

Header: <memory>

Namespace: std

See Also

Reference

shared_ptr Class