How to correct move resource from existed unique_ptr to another created in container? I want to put to container some unique_ptr with resource from another unique_ptr. Or maybe move one unique_ptr from one container to another container.
Some code with creation is here:
#include <memory>
#include <map>
#include <string>
struct MyClass
{
std::string s;
};
int main(int argc, char* argv[])
{
std::map<std::string, MyClass> container;
std::unique_ptr<MyClass> tmp = std::make_unique<MyClass>();
tmp->s = "test string";
auto result = container.emplace(std::piecewise_construct,
std::make_tuple("test"),
std::make_tuple(std::move(tmp))
);
return 0;
}