Efficiently erase a unique_ptr from an unordered_set
问题 I am storing the ownership of some objects inside an unordered_set , using unique_ptr s. But I don't know a good way to erase one of them from the set, when the time comes. Code looks something like this: typedef unique_ptr<MyType> MyPtr; unordered_set<MyPtr> owner; MyPtr p = make_unique<MyType>("foo") MyType *pRaw = p.get(); owner.insert(std::move(p)); // Later ... // I want to do something like this (cannot be written as-is, of course): // owner.erase(pRaw); Is there a way to do this? I can