The ideal solution has only become possible with C++17:
map::extract()
Std::map is typically implemented as a binary tree,
and a binary tree stores one key-value entry per memory object.
That makes it possible to move an entry by simply exchanging the ownership of that piece of memory.
This is done by just flipping some internal pointers (including rebalancing the two trees, which has to be done anyway if the end result is to have changed both trees).
This avoids not only moving the object around in memory, but any memory allocation and deallocation (which has unpredictable worst case performance).
Example:
// Before Darwin, it was thought that whales were fish.
std::map<int, std::string> fish{{1,"whaleshark"}, {2,"whale"}, {3,"shark"}};
std::map<int, std::string> mammalia{{1,"cat"}, {2,"dog"}};
// Oops, the whale belongs to mammalia.
auto whale = fish.extract(2);
whale.key() = 3;
mammalia.insert(std::move(whale));
Before C++17, you had to implement your own map in order to do this.