本页内容

Qt::weak_ordering Class

class Qt::weak_ordering

Qt::weak_ordering 表示一种比较,其中等效的数值仍然可以区分。更多...

标题: #include <QtCompare>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core
自: Qt 6.7

公共函数

weak_ordering(std::weak_ordering stdorder)
operator Qt::partial_ordering() const
operator std::weak_ordering() const

静态公共成员

const Qt::weak_ordering equivalent
const Qt::weak_ordering greater
const Qt::weak_ordering less
bool is_eq(Qt::weak_ordering o)
bool is_gt(Qt::weak_ordering o)
bool is_gteq(Qt::weak_ordering o)
bool is_lt(Qt::weak_ordering o)
bool is_lteq(Qt::weak_ordering o)
bool is_neq(Qt::weak_ordering o)
bool operator!=(Qt::weak_ordering lhs, Qt::weak_ordering rhs)
bool operator==(Qt::weak_ordering lhs, Qt::weak_ordering rhs)

详细说明

三路比较函数通常返回Qt::weak_ordering 类型的值。此类函数用于比较两个对象并确定它们的排序关系。它使用此返回类型来表示该排序关系为弱排序;也就是说,等价的值可能被区分开来。

Qt::weak_ordering 该类型有三个取值,由以下符号常量表示:

  • less 表示左操作数小于右操作数;
  • equivalent 表示左操作数等同于右操作数;
  • greater 表示左操作数大于右操作数;

Qt::weak_ordering 惯例上通过将实例与字面量零进行比较来使用,例如如下所示:

// given a, b, c, d as objects of some type that allows for a 3-way compare,
// and a compare function declared as follows:

Qt::weak_ordering compare(T lhs, T rhs); // defined out-of-line
~~~

Qt::weak_ordering result = compare(a, b);
if (result < 0) {
    // a is less than b
}

if (compare(c, d) >= 0) {
    // c is greater than or equivalent to d
}

另请参阅 Qt::strong_ordering 、Qt::partial_ordering 以及《比较类型概述》。

成员函数文档

[constexpr noexcept] weak_ordering::weak_ordering(std::weak_ordering stdorder)

根据以下规则,从 `stdorder ` 构造一个 `Qt::weak_ordering ` 对象:

  • std::weak_ordering::less 转换为less 。
  • std::weak_ordering::equivalent 可转换为equivalent 。
  • std::weak_ordering::greater 转换为greater 。

[constexpr noexcept] weak_ordering::operator Qt::partial_ordering() const

根据以下规则,将此Qt::weak_ordering 值转换为Qt::partial_ordering 对象:

[constexpr noexcept] weak_ordering::operator std::weak_ordering() const

根据以下规则,将此Qt::weak_ordering 值转换为 std::weak_ordering 对象:

  • less 转换为 std::weak_ordering::less。
  • equivalent 转换为 std::weak_ordering::equivalent。
  • greater 转换为 std::weak_ordering::greater。

成员变量文档

const Qt::weak_ordering weak_ordering::equivalent

表示左操作数与右操作数相等的比较结果。

const Qt::weak_ordering weak_ordering::greater

表示左操作数大于右操作数的比较结果。

const Qt::weak_ordering weak_ordering::less

表示左操作数小于右操作数的比较结果。

相关非成员

[constexpr noexcept] bool is_eq(Qt::weak_ordering o)

[constexpr noexcept] bool is_gt(Qt::weak_ordering o)

[constexpr noexcept] bool is_gteq(Qt::weak_ordering o)

[constexpr noexcept] bool is_lt(Qt::weak_ordering o)

[constexpr noexcept] bool is_lteq(Qt::weak_ordering o)

[constexpr noexcept] bool is_neq(Qt::weak_ordering o)

将o 转换为以下六个关系运算符之一的结果:

函数操作
is_eqo == 0
is_neqo != 0
is_lto < 0
is_lteqo <= 0
is_gto > 0
is_gteqo >= 0

提供这些函数是为了与std::weak_ordering 保持兼容。

[constexpr noexcept] bool operator!=(Qt::weak_ordering lhs, Qt::weak_ordering rhs)

如果lhs 和rhs 表示不同的结果,则返回 true;否则,返回 true。

[constexpr noexcept] bool operator==(Qt::weak_ordering lhs, Qt::weak_ordering rhs)

如果 `lhs ` 和 `rhs ` 表示相同的结果,则返回 `true`;否则,返回 `false`。

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.