For std::unordered_set<T>
the member emplace()
makes it unnecessary for the objects to be movable, either: you can emplace()
non-movable objects into the container.
To answer the question: you can't std::move()
elements out of a std::unordered_set<T>
because the elements are all const
and const
objects can't be moved. When you erase()
an std::unique_ptr<T>
from an std::unordered_set<std::unique_ptr<T>>
the pointed to object will be delete
d: there is no interface which allows you to recover the pointer while erase()
ing the element. Nor is there a splice()
member to stick the element into another container where it can be ignored until it is time to get rid of it.