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>;>


基础教程推荐
- 向量<unique_ptr<A>>使用初始化列表 2022-10-23
- 迭代std :: bitset中真实位的有效方法? 2022-10-18
- 明确指定任何或所有枚举数的整数值 1970-01-01
- C语言3个整数的数组 1970-01-01
- 对 STL 容器的安全并行只读访问 2022-10-25
- C++:为什么结构类需要一个虚拟方法才能成为多态? 2022-10-19
- 总计将在节日礼物上花多少钱 1970-01-01
- C++多态 1970-01-01
- C语言数组 1970-01-01
- 用指数格式表示浮点数 1970-01-01