#include <iostream>
#include <memory>
//C++14
std::unique_ptr<std::string> create_name()
{
//auto ptr = std::make_unique<std::string>("Testname");
//return std::move(ptr);
//Компиль попробует вернуть через move конструктор/оператор присваивания.
//Если оных нет, то вернёт через копирование, что сделать не выйдет.
return std::make_unique<std::string>("Testname");
}
//C++11
using name_ptr = std::unique_ptr<std::string>;
name_ptr create_name_2()
{
//auto ptr = ptr_string(new std::string("Testname"));
//return std::move(ptr);
//аналогично
return name_ptr(new std::string("Testname"));
}
int main()
{
auto name = create_name();
std::cout<<*name<<std::endl;
name = create_name_2();
std::cout<<*name<<std::endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bWVtb3J5PgoKCi8vQysrMTQKc3RkOjp1bmlxdWVfcHRyPHN0ZDo6c3RyaW5nPiBjcmVhdGVfbmFtZSgpCnsKCS8vYXV0byBwdHIgPSBzdGQ6Om1ha2VfdW5pcXVlPHN0ZDo6c3RyaW5nPigiVGVzdG5hbWUiKTsKCS8vcmV0dXJuIHN0ZDo6bW92ZShwdHIpOwoKCS8v0JrQvtC80L/QuNC70Ywg0L/QvtC/0YDQvtCx0YPQtdGCINCy0LXRgNC90YPRgtGMINGH0LXRgNC10LcgbW92ZSDQutC+0L3RgdGC0YDRg9C60YLQvtGAL9C+0L/QtdGA0LDRgtC+0YAg0L/RgNC40YHQstCw0LjQstCw0L3QuNGPLgoJLy/QldGB0LvQuCDQvtC90YvRhSDQvdC10YIsINGC0L4g0LLQtdGA0L3RkdGCINGH0LXRgNC10Lcg0LrQvtC/0LjRgNC+0LLQsNC90LjQtSwg0YfRgtC+INGB0LTQtdC70LDRgtGMINC90LUg0LLRi9C50LTQtdGCLgoJcmV0dXJuIHN0ZDo6bWFrZV91bmlxdWU8c3RkOjpzdHJpbmc+KCJUZXN0bmFtZSIpOwp9CgovL0MrKzExCnVzaW5nIG5hbWVfcHRyID0gc3RkOjp1bmlxdWVfcHRyPHN0ZDo6c3RyaW5nPjsKbmFtZV9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