mardi 28 août 2018

std::move(key) while iterating over unordered_map

Is the following safe?

unordered_map<string, string> my_map;
unordered_map<string, double> new_map;
for(auto&& [key, value] : my_map) {
    new_map.insert({std::move(key), std::stod(value)});
}

I'm not using my_map after the loop, is it ok to move from the key while iterating over it?

Aucun commentaire:

Enregistrer un commentaire