I have a class that contains a unique_ptr. I want to place instances of this class inside a container (specifically std::map). This works using std::move
and .emplace
however, I would like to perform all this initialization within the container's initializer list. Is this possible?
I suspect Foo
gets initialized in the initializer list then copied which is causing the problem. I've tried added a std::move
in the initializer list but that hasn't solved the problem.
class Foo
{
public:
std::unique_ptr<std::string> my_str_ptrs;
}
Compilation Fails "attempting to access a deleted function". This is an example of what I want to do
std::map<std::string, Foo> my_map{
{"a", Foo{}}
};
Compilation Succeeds
std::map<std::string, Foo> my_map;
my_map.emplace("a", Foo{});