c++ - "compares less than 0"是什么意思?

标签 c++ terminology comparison-operators c++20 spaceship-operator

上下文

当我在阅读时 Consistent comparison ,我注意到动词 to compare 的一种特殊用法:

There’s a new three-way comparison operator, <=>. The expression a <=> b returns an object that compares <0 if a < b, compares >0 if a > b, and compares ==0 if a and b are equal/equivalent.

在互联网上找到的另一个例子(重点是我的):

It returns a value that compares less than zero on failure. Otherwise, the returned value can be used as the first argument on a later call to get.

最后一个example ,在 GitHub 上找到(重点是我的):

// Perform a circular 16 bit compare.
// If the distance between the two numbers is larger than 32767,
// and the numbers are larger than 32768, subtract 65536
// Thus, 65535 compares less than 0, but greater than 65534
// This handles the 65535->0 wrap around case correctly

当然,对于有经验的程序员来说,意思是很清楚的。但是在这些示例中使用动词 to compare 的方式在任何标准英语形式中都不标准。

问题*

  • 如何编程jargon句子“The object compares less than zero”翻译成简单的英语
  • 这是否意味着如果将对象与0 进行比较,结果将“小于零”?
  • 为什么说“对象小于零”而不是“对象比较小于零”是错误的?

* 我在 English Language Learners 上寻求帮助和 English Language & Usage .

最佳答案

“compares <0”用简单的英语就是“比较小于零”。

我相信这是一个常见的速记。

所以将这个应用到整个句子中得到:

The expression a <=> b returns an object that compares less than zero if a is less than b, compares greater than zero if a is greater than b, and compares equal to zero if a and b are equal/equivalent.

这真是一口。我明白为什么作者会选择使用符号。

关于c++ - "compares less than 0"是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47498486/

相关文章:

c# - 比较可为空的 DateTimeOffset 变量的最佳方法?

c++ - 如何强制 Windows FAT32 驱动程序重新加载 FAT 表?

c++ - libxml2 xmlChar * 到 std::wstring

namespaces - 上下文和命名空间有什么区别?

c++ - 定义运算符的实际原因!=

c++ - 迁移到VS2013比较运算符错误C2678 :binary '==' no operator

python - 在嵌入式 PyQt 应用程序中使用 QThread

c++ - 在 lambda 表达式中,通过 [&captured] 和 [&local = captured] 捕获有什么区别?

c# - 流是什么意思?它的特点是什么?

terminology - 静态/动态与强/弱