QPartialOrdering Class

QPartialOrdering 表示允许无序结果的比较结果。更多

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

公共函数

QPartialOrdering(std::partial_ordering stdorder)
std::partial_ordering 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 可以通过比较一个实例和一个字面 0 来使用,例如像这样:

// 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] std::partial_ordering QPartialOrdering::operator std::partial_ordering() const

使用以下规则将QPartialOrdering 值转换为 std::partial_ordering 对象:

  • less 转换为 std::partial_ordering::less。
  • equivalent 转换为 std::partial_ordering::equivalent。
  • greater 转换为 std::partial_ordering::g 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)

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

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

如果lhsrhs 表示相同的结果,则返回 true;否则,返回 false。

© 2025 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.