What#39;s the difference between std::multimaplt;key, valuegt; and std::maplt;key, std::setlt;valuegt; gt;(std::multimaplt;key,valuegt; 有什么区别?和 std::mapkey, std::setvalue;gt;)
问题描述
我发现他们只有一个键和多个值.
I found that they have one key and multiple values which is unique.
推荐答案
multimap 存储成对的 (key, value),其中 key 和 value 都可以出现多次.
The multimap stores pairs of (key, value) where both key and value can appear several times.
map
只会为特定键存储每个值一次.为此,它必须能够比较值,而不仅仅是键.
The map<key, set<value>>
will only store each value once for a specific key. To do that, it will have to be able to compare the values, not just the keys.
比较相等的值是否相等,或者您是否希望单独存储它们取决于您的应用程序.也许它们包含不同但不参与集合比较的字段.
It depends on your application if the values that compare equal are equivalent, or if you wish to store them separately anyway. Perhaps they contain fields that are different but do not take part in the comparison for the set.
这篇关于std::multimap<key,value> 有什么区别?和 std::map<key, std::set<value>;>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:std::multimap<key,value> 有什么区别?和 std::map<key, std::set<value>;>
基础教程推荐
- 分别使用%o和%x以八进制或十六进制格式显示整 1970-01-01
- C语言访问数组元素 1970-01-01
- C++ #define 1970-01-01
- 初始化变量和赋值运算符 1970-01-01
- C++定义类对象 1970-01-01
- end() 能否成为 stl 容器的昂贵操作 2022-10-23
- C++输入/输出运算符重载 1970-01-01
- 使用scanf()读取字符串 1970-01-01
- 明确指定任何或所有枚举数的整数值 1970-01-01
- C++按值调用 1970-01-01