#include <iostream>
#include <memory>
void fnRef(std::shared_ptr<int>& ptr)
{
auto lambda = [=]() { std::cout << ptr.use_count() << ':' << __PRETTY_FUNCTION__ << '\n'; };
lambda();
}
void fnVal(std::shared_ptr<int> ptr)
{
auto lambda = [=]() { std::cout << ptr.use_count() << ':' << __PRETTY_FUNCTION__ << '\n'; };
lambda();
}
int main()
{
std::shared_ptr<int> ptr(new int);
for (int i=0; i<10; ++i)
fnVal(ptr);
std::cout << '\n';
for (int i=0; i<10; ++i)
fnRef(ptr);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bWVtb3J5PgoKdm9pZCBmblJlZihzdGQ6OnNoYXJlZF9wdHI8aW50PiYgcHRyKQp7CiAgICBhdXRvIGxhbWJkYSA9IFs9XSgpIHsgc3RkOjpjb3V0IDw8IHB0ci51c2VfY291bnQoKSA8PCAnOicgPDwgX19QUkVUVFlfRlVOQ1RJT05fXyA8PCAnXG4nOyB9OwogICAgbGFtYmRhKCk7Cn0KCnZvaWQgZm5WYWwoc3RkOjpzaGFyZWRfcHRyPGludD4gcHRyKQp7CiAgICBhdXRvIGxhbWJkYSA9IFs9XSgpIHsgc3RkOjpjb3V0IDw8IHB0ci51c2VfY291bnQoKSA8PCAnOicgPDwgX19QUkVUVFlfRlVOQ1RJT05fXyA8PCAnXG4nOyB9OwogICAgbGFtYmRhKCk7Cn0KCmludCBtYWluKCkKewogICAgc3RkOjpzaGFyZWRfcHRyPGludD4gcHRyKG5ldyBpbnQpOwogICAgZm9yIChpbnQgaT0wOyBpPDEwOyArK2kpCiAgICAgICAgZm5WYWwocHRyKTsKICAgIHN0ZDo6Y291dCA8PCAnXG4nOwogICAgCiAgICBmb3IgKGludCBpPTA7IGk8MTA7ICsraSkKICAgICAgICBmblJlZihwdHIpOwoKICAgIHJldHVybiAwOwp9