我应该使用什么语法来声明一个带有四个键值的多图?
我想在sc_core sc_time值之后添加两个来自 unsigned int 的值。
std::multimap<std::string, std::pair<sc_core::sc_time, sc_core::sc_time> >
由于
答案 0 :(得分:5)
您可以使用元组:
std::tuple<key_type1, key_type2, key_typ3, key_typ4>
例如:
#include <map>
#include <string>
#include <tuple>
int main(int argc, char* argv[])
{
std::map<std::tuple<int, int, float, float>, std::string> myMap; // if you meant 4 values as a key
std::map<std::string, std::tuple<int, int, float, float>> myMap2; // if you meant 4 values for each string key
return 0;
}
另外,我想指出,在声明地图时,首先是键的模板参数,然后是值类型(请参阅here)。你的帖子含糊不清,所以我不知道这四个值是否应该是关键或值,所以我展示了两种可能性。
编辑:正如Jamin Gray所指出的那样,你可以使用typedef缩短这个不可思议的长类型:
typedef std::tuple<int, int, float, float> MyKeyType;
完成此操作后,您可以在代码中使用MyKeyType
。