dimanche 31 mai 2020

Can't assign empty initializer to vector of unique_ptrs

I have the following code:

std::unordered_map<std::string, std::vector<std::unique_ptr<class EventTrigger>>> triggers;

if (triggers.end() == triggers.find(eventName)) {
   triggers[eventName] = {};
}

That results in an error about using a deleted constructor of unique_ptr. If, on the other hand, I do this, everything compiles fine:

if (triggers.end() == triggers.find(eventName)) {
   triggers[eventName] = std::vector<std::unique_ptr<class EventTrigger>>();
}

Can anyone explain why this is happening? I thought the empty initializer list would have resulted in an empty vector being assigned to triggers[eventName].

Aucun commentaire:

Enregistrer un commentaire