c++ - 在深度 std::unordered_map 中插入唯一指针

标签 c++ c++14 unique-ptr unordered-map

如何在我拥有的深度无序映射中插入唯一的指针?

std::unordered_map<uint64_t, std::unordered_map<uint64_t, std::unordered_map<uint64_t, std::unique_ptr<MyStruct>>>>

(C++14)

最佳答案

给定 map

std::unordered_map<uint64_t, std::unordered_map<uint64_t, std::unordered_map<uint64_t, std::unique_ptr<MyStruct>>>> m;

和一个unique_ptr

auto s = std::make_unique<MyStruct>();

您可以将其插入 map 中,如下所示:

m[1][2][3] = std::move(s);

关于c++ - 在深度 std::unordered_map 中插入唯一指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69038861/

相关文章:

c++ - 为什么 RVO 不应用于基类子对象初始化?

c++ - boost 矩阵与遗物

c++ - 信号槽弄得一团糟

c++ - nonptr-new-declarator 中的错误表达式

c++ - 依赖注入(inject)和所有权问题

c++ - Unique_ptr 容器或 unique_ptr 元素

c++ - `std::vector< std::unique_ptr< T >>` 错误

c++ - 如何使用 lambda 和函数作为 unique_ptr 的自定义删除器

c++ - 带有派生类的 std::unique_ptr

c++ - 错误 : 'T' is not a template