STL联系关系容器为什么要定义等价关系? 明明是大小比较
STL关联容器为什么要定义等价关系? 明明是大小比较啊
关联容器自动排序,也就是通过greater或者less来决定顺序。为什么C++语言标准里面说关联容器是通过等价关系来决定顺序呢?
等价关系里面并没有a<b啊,离散数学里面的等价关系是等价类的划分,用来把一个大的集合划分成小集合,例如同余等价类。这个和C++的 equivalence 是同一个概念吗?
而map/set的排序要么是greater要么是less,不会同时判断a<b和b<a是否都成立,感觉并不是等价关系啊。
可能我的表述有些错误的地方,但是希望我把问题说清楚了。还请大侠指教。
------解决思路----------------------
参看《effictive STL》
------解决思路----------------------
可以参考std::rel_ops
------解决思路----------------------
楼上的解说是正解,请楼主仔细理解下
------解决思路----------------------
Each associative container is parameterized on Key and an ordering relation Compare that induces a strict
weak ordering (25.4) on elements of Key. In addition, map and multimap associate an arbitrary mapped type
T with the Key. The object of type Compare is called the comparison object of a container
------解决思路----------------------
具体看25.4
关联容器自动排序,也就是通过greater或者less来决定顺序。为什么C++语言标准里面说关联容器是通过等价关系来决定顺序呢?
等价关系里面并没有a<b啊,离散数学里面的等价关系是等价类的划分,用来把一个大的集合划分成小集合,例如同余等价类。这个和C++的 equivalence 是同一个概念吗?
而map/set的排序要么是greater要么是less,不会同时判断a<b和b<a是否都成立,感觉并不是等价关系啊。
可能我的表述有些错误的地方,但是希望我把问题说清楚了。还请大侠指教。
------解决思路----------------------
参看《effictive STL》
------解决思路----------------------
可以参考std::rel_ops
------解决思路----------------------
楼上的解说是正解,请楼主仔细理解下
------解决思路----------------------
Each associative container is parameterized on Key and an ordering relation Compare that induces a strict
weak ordering (25.4) on elements of Key. In addition, map and multimap associate an arbitrary mapped type
T with the Key. The object of type Compare is called the comparison object of a container
------解决思路----------------------
具体看25.4