Is the point at which std::map::emplace creates an object (i.e. calls a constructor) somehow defined in the standard? If so, will such a key occur before or after?
This is of great importance in the following cases:
struct X {}; std::map<int, std::unique_ptr<X> > map; void f(int x) { map.emplace(x, new X); }
If the object is created first, everything is cool (unique_ptr is designed and owns the resource), but if it is created after verification, a memory leak occurs in the event of a duplicate key.
Everything I could find in the Standard
Inserts a value_type t object constructed with std::forward<Args>(args)... if and only if the element does not have an element with a container with a key equivalent to t.
which does not address the question that I have.
c ++ language-lawyer c ++ 11
SergeyA
source share