地图的key排序是基于less<>的而不是==,那么它的行为就和multi地图一样啊

map的key排序是基于less<>的而不是==,那么它的行为就和multimap一样啊?
(1)例如,我有一个map的key是int类型,那么当我插入一个(1,xxx)以后,我再次插入一个(1,yyy),那么map的默认key比较函数less<>会比较1<1,得到false,那么岂不是需要创建一个新的节点,把(1,yyy)放到(1,xxx)之前?
既然less<>判断是 "<",所以我觉得map应该就和multimap行为相同啊。

换句话说,对于相同的key,map的insert为何覆盖,而不是新创建一个,这是为什么? 是标准规定了要这么实现的吗?

(2)more effective c++都说了map的key比较是判断"等价"而非"相等",然后对于整数类型的key而言,等价和相等没有差别,为什么在实际中map的行为是如果有同样的key插入,原来那个元素就被覆盖呢?
map中的排序和查找都是基于"等价"的概念,对吧?

我感觉非常的矛盾,求解释和澄清!

------解决思路----------------------
地图的key排序是基于less<>的而不是==,那么它的行为就和multi地图一样啊理解讨论之前请先学会如何观察

计算机组成原理→DOS命令→汇编语言→C语言(不包括C++)、代码书写规范→数据结构、编译原理、操作系统→计算机网络、数据库原理、正则表达式→其它语言(包括C++)、架构……

对学习编程者的忠告:
地图的key排序是基于less<>的而不是==,那么它的行为就和multi地图一样啊多用小脑和手,少用大脑、眼睛和嘴,会更快地学会编程!
眼过千遍不如手过一遍!
书看千行不如手敲一行!
手敲千行不如单步一行!
单步源代码千行不如单步Debug版对应汇编一行!
单步Debug版对应汇编千行不如单步Release版对应汇编一行!

单步类的实例“构造”或“复制”或“作为函数参数”或“作为函数返回值返回”或“参加各种运算”或“退出作用域”的语句对应的汇编代码几步后,就会来到该类的“构造函数”或“复制构造函数”或“运算符重载”或“析构函数”对应的C/C++源代码处。

VC调试时按Alt+8、Alt+7、Alt+6和Alt+5,打开汇编窗口、堆栈窗口、内存窗口和寄存器窗口看每句C对应的汇编、单步执行并观察相应堆栈、内存和寄存器变化,这样过一遍不就啥都明白了吗。
对VC来说,所谓‘调试时’就是编译连接通过以后,按F10或F11键单步执行一步以后的时候,或者在某行按F9设了断点后按F5执行停在该断点处的时候。
(Turbo C或Borland C用Turbo Debugger调试,Linux或Unix下用GDB调试时,看每句C对应的汇编并单步执行观察相应内存和寄存器变化。)

------解决思路----------------------
1. std::less 其实可以比较大于,小于,和定于的, 比如
x, y 的比较
如果 less(x, y) == true: x<y; 否则如果less<y, x> == true: x > y; 否则 x == y;
所以map的insert在Key相同的时候是覆盖,而不是增加。

2. more effective c++ 我没有看过,
不过我知道map保证Key值的唯一,如果插入的Key相同,Value会被覆盖,这样才是map呀。
multimap允许相同的Key存在。


------解决思路----------------------
(1) 标准规定要覆盖的,map 中不会出现重复键值。至于你的例子,(1,xxx) < (1,yyy) 和 (1,xxx) < (1,yyy) 同时为 false,说明他们两个等价,所以新来的就替代旧有的了。

(2) map 是基于小于比较的,这样才能排序。两个元素a,b等价当且仅当 a<b 和 b<a 同为 false,即根据排序准则无法决定哪个元素小。
------解决思路----------------------
引自C++ 标准

23.2.4 Associative containers 
3 The phrase “equivalence of keys” means the equivalence relation imposed by the comparison and not the operator== on keys. That is, two keys k1 and k2 are considered to be equivalent if for the comparison object comp, comp(k1, k2) == false && comp(k2, k1) == false. For any two keys k1 and k2 in the same container, calling comp(k1, k2) shall always return the same value. 
4 An associative container supports unique keys if it may contain at most one element for each key. Otherwise, it supports equivalent keys. The set and map classes support unique keys;the multiset and multimap classes support equivalent keys. For multiset and multimap, insert, emplace, and erase preserve the relative ordering of equivalent elements. 

map.insert方法的说明

 Inserts t if and only if there is no element in the container with key equivalent to the key of t. The bool component of the returned pair is true if and only if the insertion takes place, and the iterator component of the pair points to the element with key equivalent to the key of t.

multimpa.insert的方法说明

 Inserts t and returns the iterator pointing to the newly inserted element. If a range containing elements equivalent to t exists in a_eq, t is inserted at the end of that range.




------解决思路----------------------
引用
对于相同的key,map的insert为何覆盖,而不是新创建一个,这是为什么

相同的key, 必然是等级的。 等价的key,  instert 返回<..., false>, 并没有覆盖。