unordered_map不同的自定义类型

unordered_map of different custom types

本文关键字:自定义 类型 map unordered      更新时间:2023-10-16

假设我有这两个enums

enum Type
{
    Type1,
    Type2
};
enum Location
{
    Location1,
    Location2,
    Location3
};

现在我想要一个可以引用的容器,例如container[Type1][Location1] = 5;

我不需要对元素进行排序,但我需要能够有重复container[Type1]可以是Location1Location2等。

我想使用一种unordered_multimap<pair<Type, Location>, unsigned int>>,它提供了我想要的东西,但不允许我访问所描述的元素(或者至少我不知道该怎么做)

你有什么建议?

我相信

你正在寻找嵌套地图:

std::unordered_map<Type, std::unordered_map<Location, unsigned int>>