我应该使用什么语法来声明一个带有四个键值的多图?
我想在sc_core sc_time值之后添加另外两个unsigned int类型的值.
std::multimap<std::string, std::pair<sc_core::sc_time, sc_core::sc_time> >
Run Code Online (Sandbox Code Playgroud)
谢谢
您可以使用元组:
std::tuple<key_type1, key_type2, key_typ3, key_typ4>
Run Code Online (Sandbox Code Playgroud)
例如:
#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;
}
Run Code Online (Sandbox Code Playgroud)
另外,我想要注意的是,在声明地图时,键的模板参数首先是值,然后是值类型(参见此处).你的帖子含糊不清,所以我不知道四个值是否应该是关键或值,所以我展示了两种可能性.
编辑:正如杰明格雷很好地指出你可以使用typedef缩短这个不可思议的长类型:
typedef std::tuple<int, int, float, float> MyKeyType;
Run Code Online (Sandbox Code Playgroud)
完成此操作后,您可以MyKeyType在代码中使用它.
| 归档时间: |
|
| 查看次数: |
984 次 |
| 最近记录: |