在我最近阅读的一篇文章中,作者提到以下使用std::map::emplace的方式可能会导致内存泄漏,但我不明白为什么会这样。
// might leak if allocation fails due to insufficient memory for an object A
std::map<int, std::unique_ptr<A>> m;
m.emplace(1, std::make_unique<A>("Ann",63));
有人可以解释吗?