Suppose if I have these two 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;
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.
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)
What suggestions do you have?
我相信您正在寻找嵌套地图:
std::unordered_map<Type, std::unordered_map<Location, unsigned int>>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.