Does the C++ standard guarantee that a failed insertion into an associative container will not modify the rvalue-reference argument?
Explicit and unequivocal NO. Standard doesn’t have this guarantee, and this is why try_emplace exists. See notes: Unlike insert or emplace, these functions do not move from rvalue arguments if the insertion does not happen, which makes it easy to manipulate maps whose values are move-only types, such as std::map<std::string, std::unique_ptr<foo>>. In addition, try_emplace treats … Read more