#include <iostream>
#include <memory>
std::unique_ptr<std::string> func ()
{
std::unique_ptr<std::string> ptr(new std::string("hey"));
return ptr;
}
std::unique_ptr<std::string> func2(std::unique_ptr<std::string> ptr)
{
return ptr;
}
int main()
{
auto name = func();
std::cout<<*name<<std::endl;
std::cout<<"Name ptr: "<<name.get()<<std::endl;
auto name2 = func2(std::move(name));
std::cout<<*name2<<std::endl;
std::cout<<"Name ptr: "<<name.get()<<std::endl;
std::cout<<"Name2 ptr: "<<name2.get()<<std::endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bWVtb3J5PgoKc3RkOjp1bmlxdWVfcHRyPHN0ZDo6c3RyaW5nPiBmdW5jICgpIAp7CglzdGQ6OnVuaXF1ZV9wdHI8c3RkOjpzdHJpbmc+IHB0cihuZXcgc3RkOjpzdHJpbmcoImhleSIpKTsKCXJldHVybiBwdHI7Cn0KCnN0ZDo6dW5pcXVlX3B0cjxzdGQ6OnN0cmluZz4gZnVuYzIoc3RkOjp1bmlxdWVfcHRyPHN0ZDo6c3RyaW5nPiBwdHIpCnsKCXJldHVybiBwdHI7Cn0KCmludCBtYWluKCkgCnsKCWF1dG8gbmFtZSA9IGZ1bmMoKTsKCXN0ZDo6Y291dDw8Km5hbWU8PHN0ZDo6ZW5kbDsKCXN0ZDo6Y291dDw8Ik5hbWUgcHRyOiAiPDxuYW1lLmdldCgpPDxzdGQ6OmVuZGw7CgkKCWF1dG8gbmFtZTIgPSBmdW5jMihzdGQ6Om1vdmUobmFtZSkpOwoJc3RkOjpjb3V0PDwqbmFtZTI8PHN0ZDo6ZW5kbDsKCQoJc3RkOjpjb3V0PDwiTmFtZSBwdHI6ICI8PG5hbWUuZ2V0KCk8PHN0ZDo6ZW5kbDsKCXN0ZDo6Y291dDw8Ik5hbWUyIHB0cjogIjw8bmFtZTIuZ2V0KCk8PHN0ZDo6ZW5kbDsKCXJldHVybiAwOwp9