问题描述
定义:
因此,我们假设<
和>
具有我们通常在日常生活中使用的含义.不过,在某些编程语言(例如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
另外,在N4140(C ++ 14国际标准)中,严格的弱排序定义为
Also, in N4140 (C++14 International Standard), strict weak ordering is defines as
其中 comp
被定义为
问题:
>"是否满足严格的弱排序?我希望如此,但没有信心.
Does ">" satisfy strict weak ordering? I expect so, but have no confidence.
推荐答案
数学上的严格大于关系是严格的弱排序.
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.
一些例子:
- 不满足属性要求的运算符重载. 未指向同一数组的指针上的
-
>
运算符具有未指定的结果. -
>
不能满足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.
这篇关于更大的运算符“>"是否会满足严格的弱排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!