[英]unordered_map of different custom types
Suppose if I have these two enums
: 假设我有两个
enums
:
enum Type
{
Type1,
Type2
};
enum Location
{
Location1,
Location2,
Location3
};
Now I would like to have a container that I can reference like container[Type1][Location1] = 5;
现在,我想要一个可以引用的容器,例如
container[Type1][Location1] = 5;
I don't need the elements to be sorted but I need to be able to have duplicates like container[Type1]
can be either Location1
or Location2
etc. 我不需要对元素进行排序,但是我需要能够有重复,例如
container[Type1]
可以是Location1
或Location2
等。
I was thinking to use an unordered_multimap<pair<Type, Location>, unsigned int>>
which kind of provides what I want, but does not allow me to access the elements as described (or at least I don't know how to do that) 我当时在考虑使用
unordered_multimap<pair<Type, Location>, unsigned int>>
那种提供我想要的东西,但不允许我访问所描述的元素(或者至少我不知道该怎么做)那)
What suggestions do you have? 您有什么建议?
我相信您正在寻找嵌套地图:
std::unordered_map<Type, std::unordered_map<Location, unsigned int>>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.