本页内容

QPartialOrdering Class

QPartialOrdering 表示一种允许结果无特定顺序的比较结果。更多内容...

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

公共函数

QPartialOrdering(std::partial_ordering stdorder)
operator std::partial_ordering() const

静态公共成员

const QPartialOrdering Equivalent
const QPartialOrdering Greater
const QPartialOrdering Less
const QPartialOrdering Unordered
const QPartialOrdering equivalent
const QPartialOrdering greater
const QPartialOrdering less
const QPartialOrdering unordered
(since 6.7) bool is_eq(QPartialOrdering o)
(since 6.7) bool is_gt(QPartialOrdering o)
(since 6.7) bool is_gteq(QPartialOrdering o)
(since 6.7) bool is_lt(QPartialOrdering o)
(since 6.7) bool is_lteq(QPartialOrdering o)
(since 6.7) bool is_neq(QPartialOrdering o)
bool operator!=(QPartialOrdering lhs, QPartialOrdering rhs)
bool operator==(QPartialOrdering lhs, QPartialOrdering rhs)

详细说明

三元比较函数通常返回 QPartialOrdering 类型的值。此类函数用于比较两个对象,以确定它们之间是否存在排序关系;若存在,则确定其排序关系。它使用此返回类型来表示该排序关系是部分的,即并非所有值对都具有排序关系。

QPartialOrdering 有四个值,由以下符号常量表示:

  • less 表示左操作数小于右操作数;
  • equivalent 表示两个操作数相等;
  • greater 表示左操作数小于右操作数;
  • unordered 表示两个操作数之间无序。

QPartialOrdering 的惯用写法是将实例与字面量零进行比较,例如如下所示:

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

QPartialOrdering compare(T lhs, T rhs); // defined out-of-line
~~~

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

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

将QPartialOrdering::unordered 与字面量0进行比较时,始终返回false 的结果。

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

成员函数文档

[constexpr noexcept] QPartialOrdering::QPartialOrdering(std::partial_ordering stdorder)

根据以下规则,使用stdorder 构建一个QPartialOrdering对象:

  • std::partial_ordering::less 转换为less 。
  • std::partial_ordering::equivalent 转换为equivalent 。
  • std::partial_ordering::greater 转换为greater 。
  • std::partial_ordering::unordered 转换为unordered

[constexpr noexcept] QPartialOrdering::operator std::partial_ordering() const

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

  • less 转换为 std::partial_ordering::less。
  • equivalent 转换为 std::partial_ordering::equivalent。
  • greater 转换为 std::partial_ordering::greater。
  • unordered 转换为 std::partial_ordering::unordered。

成员变量文档

const QPartialOrdering QPartialOrdering::Equivalent

表示两个操作数相等的比较结果。

const QPartialOrdering QPartialOrdering::Greater

表示一项比较的结果,其中左侧操作数大于右侧操作数。

const QPartialOrdering QPartialOrdering::Less

表示一项比较的结果,其中左侧操作数小于右侧操作数。

const QPartialOrdering QPartialOrdering::Unordered

表示在两个操作数之间不存在排序关系时的比较结果。

const QPartialOrdering QPartialOrdering::equivalent

表示两个操作数相等时的比较结果。

const QPartialOrdering QPartialOrdering::greater

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

const QPartialOrdering QPartialOrdering::less

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

const QPartialOrdering QPartialOrdering::unordered

表示在两个操作数之间不存在排序关系时的比较结果。

相关非成员

[constexpr noexcept, since 6.7] bool is_eq(QPartialOrdering o)

[constexpr noexcept, since 6.7] bool is_gt(QPartialOrdering o)

[constexpr noexcept, since 6.7] bool is_gteq(QPartialOrdering o)

[constexpr noexcept, since 6.7] bool is_lt(QPartialOrdering o)

[constexpr noexcept, since 6.7] bool is_lteq(QPartialOrdering o)

[constexpr noexcept, since 6.7] bool is_neq(QPartialOrdering o)

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

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

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

这些函数于 Qt 6.7 中引入。

[constexpr noexcept] bool operator!=(QPartialOrdering lhs, QPartialOrdering rhs)

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

[constexpr noexcept] bool operator==(QPartialOrdering lhs, QPartialOrdering 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.