STL关联容器为什么要定义等价关系? 明明是大小比较啊

sakoky 2015-09-18 09:19:33
关联容器自动排序,也就是通过greater或者less来决定顺序。为什么C++语言标准里面说关联容器是通过等价关系来决定顺序呢?

等价关系里面并没有a<b啊,离散数学里面的等价关系是等价类的划分,用来把一个大的集合划分成小集合,例如同余等价类。这个和C++的 equivalence 是同一个概念吗?

而map/set的排序要么是greater要么是less,不会同时判断a<b和b<a是否都成立,感觉并不是等价关系啊。

可能我的表述有些错误的地方,但是希望我把问题说清楚了。还请大侠指教。
...全文
299 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
mujiok2003 2015-09-18
  • 打赏
  • 举报
回复
引用 4 楼 mujiok2003 的回复:
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
mujiok2003 2015-09-18
  • 打赏
  • 举报
回复
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
CyberLogix 2015-09-18
  • 打赏
  • 举报
回复
楼上的解说是正解,请楼主仔细理解下
iyomumx 2015-09-18
  • 打赏
  • 举报
回复
可以参考std::rel_ops
引用
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.
yshuise 2015-09-18
  • 打赏
  • 举报
回复
参看《effictive STL》

65,210

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧