Using a std::unordered_set of std::unique_ptr

后端 未结 4 2078
南旧
南旧 2021-01-07 16:40

Assume I have a set of unique_ptr:

std::unordered_set > my_set;

I\'m not sure what\'s the safe way to

4条回答
  •  失恋的感觉
    2021-01-07 17:26

    You can use a std::map> instead of a set. Then you can add elements like this:

     std::unique_ptr instance(new MyClass);
     map.emplace(instance.get(), std::move(instance));
    

提交回复
热议问题