更大的运算符“>"是否会满足严格的弱排序? [英] Does greater operator ">" satisfy strict weak ordering?

查看:59
本文介绍了更大的运算符“>"是否会满足严格的弱排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

定义:

< 是二进制关系,其中 a<b 表示" a 小于 b ".

Let < be a binary relation where a < b means "a is less than b".

> 为二进制关系,其中 a>b 表示" a 大于 b ".

Let > be a binary relation where a > b means "a is greater than b".

因此,我们假设< > 具有我们通常在日常生活中使用的含义.不过,在某些编程语言(例如C ++)中,我们可以重载它们以提供不同的定义,此后我们就不再考虑了.

So, we assume < and > have meanings we usually use in a daily life. Though, in some programming languages (e.g. C++), we can overload them to give them different definitions, hereafter we don't think about that.

上下文:

到目前为止,我阅读了严格弱排序的数学定义(例如Wikipedia ),我认为< > 都满意.但是,我在许多网站上看到的所有示例都仅引用< .甚至还有一个网站,其中说

As far I read mathematical definition of strict weak ordering (e.g. Wikipedia), I think both < and > satify it. However, all examples I saw in many websites refer only to <. There is even a website which says

它们的大致含义是严格弱排序必须以小于"的方式进行操作:如果a小于b,则b不小于a,如果a小于b,b小于c然后a小于c,依此类推.

what they roughly mean is that a Strict Weak Ordering has to behave the way that "less than" behaves: if a is less than b then b is not less than a, if a is less than b and b is less than c then a is less than c, and so on.


另外,在N4140(C ++ 14国际标准)中,严格的弱排序定义为


Also, in N4140 (C++14 International Standard), strict weak ordering is defines as

(§25.4-4)如果将 equiv(a,b)定义为!comp(a,b)&&!comp(b,a),那么要求 comp equiv 都是传递关系

(§25.4-4) If we define equiv(a, b) as !comp(a, b) && !comp(b, a), then the requirements are that comp and equiv both be transitive relations

其中 comp 被定义为

(§25.4-2)比较是函数对象类型(20.9).当上下文转换为 bool (第4条)时,应用于 Compare 类型的对象的函数调用操作的返回值将产生 true ,如果呼叫的第一个参数小于第二个参数,小于第二个参数,否则为 false . Compare comp 始终用于算法假设有排序关系.

(§25.4-2) Compare is a function object type (20.9). The return value of the function call operation applied to an object of type Compare, when contextually converted to bool (Clause 4), yields true if the first argument of the call is less than the second, and false otherwise. Compare comp is used throughout for algorithms assuming an ordering relation.


问题:

>"是否满足严格的弱排序?我希望如此,但没有信心.

Does ">" satisfy strict weak ordering? I expect so, but have no confidence.

推荐答案

更大的运算符>"是否满足严格的弱排序?

Does greater operator ">" satisfy strict weak ordering?

数学上的严格大于关系是严格的弱排序.

The mathematical strict greater than relation is a strict weak ordering.

对于C ++语言中的运算符:对于所有整数类型:是.一般而言:否,但在大多数情况下是.同样适用于严格小于运算符.

As for the operator in C++ langauge: For all integers types: Yes. In general: No, but in most cases yes. Same applies to strict less than operator.

对于令人困惑的引号,小于" 在此意在传达以下含义:这意味着排序操作的最终结果是一个非递减序列,即对象是较少"或等于它们之后的对象.如果将 std :: greater 用作比较对象,则较大的值将按顺序较小".

As for the confusing quote, "is less than" in that context intends to convey that means that the the end result of the sort operation is a non-decreasing sequence i.e. objects are "less" or equal to objects after them. If std::greater is used as comparison object, then greater values are "lesser" in order.

这可能会造成混淆,但并非旨在排除严格大于运算符.

This may be confusing, but is not intended to exclude strict greater than operator.

在什么情况下>不满足严格的弱排序?

what is the case where > doesn't satisfy strict weak ordering?

一些例子:

  • 不满足属性要求的运算符重载.
  • 未指向同一数组的指针上的
  • > 运算符具有未指定的结果.
  • > 不能满足IEEE-754表示形式对浮点类型的不自反性要求,除非从该域中排除NaN.
  • Overloaded operators that don't satisfy the properties.
  • > operator on pointers that do not point to the same array has unspecified result.
  • > does not satisfy irreflexivity requirement for floating point types in IEEE-754 representation unless NaNs are excluded from the domain.

这篇关于更大的运算符“&gt;"是否会满足严格的弱排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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