lundi 23 septembre 2019

Construct unordered_map with a value_type of unique_ptr

This snippet of code doesn't seem to work because the unique pointer gets stored into a pair object and then is attempted to be copied from it. Can this be avoided?

std::unordered_map<std::string,std::unique_ptr<int>> _map {
    {"hello", std::make_unique<int>(7)}
};

A full code example and compilation error can be seen here http://cpp.sh/7uc3a

Aucun commentaire:

Enregistrer un commentaire