Qt::partial_ordering Class
class Qt::partial_orderingQt::partial_ordering 表示一种允许结果无特定顺序的比较结果。更多...
| 标题: | #include <QtCompare> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
| qmake: | QT += core |
| 自: | Qt 6.7 |
公共函数
| partial_ordering(std::partial_ordering stdorder) | |
| operator std::partial_ordering() const |
静态公共成员
| const Qt::partial_ordering | equivalent |
| const Qt::partial_ordering | greater |
| const Qt::partial_ordering | less |
| const Qt::partial_ordering | unordered |
相关的非成员
| bool | is_eq(Qt::partial_ordering o) |
| bool | is_gt(Qt::partial_ordering o) |
| bool | is_gteq(Qt::partial_ordering o) |
| bool | is_lt(Qt::partial_ordering o) |
| bool | is_lteq(Qt::partial_ordering o) |
| bool | is_neq(Qt::partial_ordering o) |
| bool | operator!=(Qt::partial_ordering lhs, Qt::partial_ordering rhs) |
| bool | operator==(Qt::partial_ordering lhs, Qt::partial_ordering rhs) |
详细描述
三元比较函数通常返回类型为Qt::partial_ordering 的值。此类函数用于比较两个对象,以确定它们之间是否存在顺序关系;若存在,则确定其排序关系。它使用此返回类型来表示该排序关系是部分的;也就是说,并非所有值对都有明确的排序关系。
Qt::partial_ordering 该类型有四个取值,分别由以下符号常量表示:
- less 表示左操作数小于右操作数;
- equivalent 表示两个操作数相等;
- greater 表示左操作数小于右操作数;
- unordered 表示两个操作数无序。
Qt::partial_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::partial_ordering compare(T lhs, T rhs); // defined out-of-line
~~~
Qt::partial_ordering 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
}将Qt::partial_ordering::unordered 与字面量0进行比较时,始终返回false 的结果。
另请参阅 ` Qt::strong_ordering`、`Qt::weak_ordering` 以及“比较类型概述”。
成员函数文档
[constexpr noexcept] partial_ordering::partial_ordering(std::partial_ordering stdorder)
根据以下规则,从stdorder 构建一个Qt::partial_ordering 对象:
- std::partial_ordering::less 转换为less 。
- std::partial_ordering::equivalent 可转换为equivalent 。
- std::partial_ordering::greater 转换为greater 。
- std::partial_ordering::unordered 转换为unordered
[constexpr noexcept] partial_ordering::operator std::partial_ordering() const
根据以下规则,将此Qt::partial_ordering 值转换为 std::partial_ordering 对象:
- less 转换为 std::partial_ordering::less。
- equivalent 转换为 std::partial_ordering::equivalent。
- greater 转换为 std::partial_ordering::greater。
- unordered 转换为 std::partial_ordering::unordered。
成员变量文档
const Qt::partial_ordering partial_ordering::equivalent
表示两个操作数相等时的比较结果。
const Qt::partial_ordering partial_ordering::greater
表示左操作数大于右操作数的比较结果。
const Qt::partial_ordering partial_ordering::less
表示一次比较的结果,其中左侧操作数小于右侧操作数。
const Qt::partial_ordering partial_ordering::unordered
表示在两个操作数之间不存在排序关系时的比较结果。
相关非成员
[constexpr noexcept] bool is_eq(Qt::partial_ordering o)
[constexpr noexcept] bool is_gt(Qt::partial_ordering o)
[constexpr noexcept] bool is_gteq(Qt::partial_ordering o)
[constexpr noexcept] bool is_lt(Qt::partial_ordering o)
[constexpr noexcept] bool is_lteq(Qt::partial_ordering o)
[constexpr noexcept] bool is_neq(Qt::partial_ordering o)
将o 转换为以下六个关系运算符之一的结果:
| 函数 | 操作 |
|---|---|
is_eq | o == 0 |
is_neq | o != 0 |
is_lt | o < 0 |
is_lteq | o <= 0 |
is_gt | o > 0 |
is_gteq | o >= 0 |
提供这些函数是为了与std::partial_ordering 保持兼容。
[constexpr noexcept] bool operator!=(Qt::partial_ordering lhs, Qt::partial_ordering rhs)
如果lhs 和rhs 表示不同的结果,则返回 true;否则,返回 true。
[constexpr noexcept] bool operator==(Qt::partial_ordering lhs, Qt::partial_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.