1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
// shared_ptr::unique
#include <iostream>
#include <memory>
int main () {
std::shared_ptr<int> foo;
std::shared_ptr<int> bar (new int);
std::cout << "foo unique?\n" << std::boolalpha;
std::cout << "1: " << foo.unique() << '\n'; // false (empty)
foo = bar;
std::cout << "2: " << foo.unique() << '\n'; // false (shared with bar)
bar = nullptr;
std::cout << "3: " << foo.unique() << '\n'; // true
return 0;
}
|