2 ms·
Or, put a pointer in the container and ensure the container and the pointee have similar ownership/lifetime characteristics. Presumably a non-copyable, non-mov
by fooker 3y ago
Or, put a pointer in the container and ensure the container and the pointee have similar ownership/lifetime characteristics.
Presumably a non-copyable, non-movable object has these restrictions for a reason.
- pfitzen 3y agoPassing a pointer doesn't always solve the problem. The idea behind std::piecewise_construct is to control the time at which the non-moveable object is constructed. Simply passing a pointer means the object is created outside the container; before the container is created. With std::emplace the container is already (partially) created and gets control over creating the objects it is going to contain. The container gets the power to change the arguments to the constructor of its contained objects.