std::multimap&lt;key,value&gt; 有什么区别?和 std::map<key, std::set<value>;&gt;

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

本文介绍了std::multimap&lt;key,value&gt; 有什么区别?和 std::map<key, std::set<value>;&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&lt;key,value&gt; 有什么区别?和 std::map<key, std::set<value>;&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:std::multimap&lt;key,value&gt; 有什么区别?和 std::map<key, std::set<value>;&gt;