std :: set如何保持唯一,只有std :: less? [英] How does std::set stay unique with only std::less?

查看:84
本文介绍了std :: set如何保持唯一,只有std :: less?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人知道std :: set如何仅使用std :: less来防止重复?


我试过了几个STL实现并且

他们的代码非常难以理解(为了允许不同的编译器,我猜测b
。)

Does anyone know how std::set prevents duplicates using only std::less?

I''ve tried looking through a couple of the STL implementations and
their code is pretty unreadable (to allow for different compilers, I
guess).

推荐答案

Cory Nelson写道:
Cory Nelson wrote:

有没有人知道std :: set如何使用std :: less来防止重复?

.. 。
Does anyone know how std::set prevents duplicates using only std::less?
...



和?在您看来,这里到底出了什么问题?如果你有一个''less''

操作,那么可以通过它轻松定义相等如下:


''等于b''是当且仅当'小于b''或'b小于

a''为真时才是真的。


-

祝你好运,

Andrey Tarasevich

And? What exactly is the problem here, in your opinion? If you have a ''less''
operation, then equality can be easily defined through it as follows:

''a equals b'' is true if and only if neither ''a less than b'' nor ''b less than
a'' is true.

--
Best regards,
Andrey Tarasevich


On 2006-08-02 17:38:06 -0400," Cory Nelson < ph ***** @ gmail.comsaid:
On 2006-08-02 17:38:06 -0400, "Cory Nelson" <ph*****@gmail.comsaid:

有没有人知道std :: set如何仅使用std :: less来防止重复?
Does anyone know how std::set prevents duplicates using only std::less?



它只是检查以确保每个元素都小于它之前的元素。

-

Clark S. Cox,III
cl*******@gmail.com

It just checks to make sure each element is less than the one it precedes.
--
Clark S. Cox, III
cl*******@gmail.com


Andrey Tarasevich写道:
Andrey Tarasevich wrote:

Cory Nelson写道:
Cory Nelson wrote:

有没有人知道std :: set如何使用std :: less来防止重复?

...
Does anyone know how std::set prevents duplicates using only std::less?
...



和?在您看来,这里到底出了什么问题?如果你有一个''less''

操作,那么可以通过它轻松定义相等如下:


''等于b''是当且仅当'小于b''或'b小于

a''为真时才为真。


And? What exactly is the problem here, in your opinion? If you have a ''less''
operation, then equality can be easily defined through it as follows:

''a equals b'' is true if and only if neither ''a less than b'' nor ''b less than
a'' is true.



什么?我只是希望它使用其他方式。那个

类型的比较可能是相当低效的,如果pred需要做很多工作。

And what? I was just hoping it used some other way than that. That
type of comparison might be rather inefficient if the pred needs to do
a lot of work.


-

祝你好运,

Andrey Tarasevich
--
Best regards,
Andrey Tarasevich


这篇关于std :: set如何保持唯一,只有std :: less?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆