QPartialOrdering Class

QPartialOrdering represents the result of a comparison that allows for unordered results. More...

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

Public Functions

QPartialOrdering(int stdorder)

Static Public Members

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)

Detailed Description

A value of type QPartialOrdering is typically returned from a three-way comparison function. Such a function compares two objects, establishing whether they are ordered and, if so, their ordering. It uses this return type to indicate that the ordering is partial; that is, not all pairs of values are ordered.

QPartialOrdering has four values, represented by the following symbolic constants:

  • less represents that the left operand is less than the right;
  • equivalent represents that the two operands are equivalent;
  • greater represents that the left operand is greater than the right;
  • unordered represents that the two operands are not ordered.

QPartialOrdering is idiomatically used by comparing an instance against a literal zero, for instance like this:

 // 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
 }

Comparing QPartialOrdering::unordered against literal 0 always returns a false result.

See also Qt::strong_ordering, Qt::weak_ordering, and Comparison types overview.

Member Function Documentation

[default] QPartialOrdering::QPartialOrdering(int stdorder)

Constructs a QPartialOrdering object from stdorder using the following rules:

  • std::partial_ordering::less converts to less.
  • std::partial_ordering::equivalent converts to equivalent.
  • std::partial_ordering::greater converts to greater.
  • std::partial_ordering::unordered converts to unordered

Member Variable Documentation

const QPartialOrdering QPartialOrdering::Equivalent

Represents the result of a comparison where the two operands are equivalent.

const QPartialOrdering QPartialOrdering::Greater

Represents the result of a comparison where the left operand is greater than the right operand.

const QPartialOrdering QPartialOrdering::Less

Represents the result of a comparison where the left operand is less than the right operand.

const QPartialOrdering QPartialOrdering::Unordered

Represents the result of a comparison where there is no ordering relationship between the two operands.

const QPartialOrdering QPartialOrdering::equivalent

Represents the result of a comparison where the two operands are equivalent.

const QPartialOrdering QPartialOrdering::greater

Represents the result of a comparison where the left operand is greater than the right operand.

const QPartialOrdering QPartialOrdering::less

Represents the result of a comparison where the left operand is less than the right operand.

const QPartialOrdering QPartialOrdering::unordered

Represents the result of a comparison where there is no ordering relationship between the two operands.

Related Non-Members

[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)

Converts o into the result of one of the six relational operators:

FunctionOperation
is_eqo == 0
is_neqo != 0
is_lto < 0
is_lteqo <= 0
is_gto > 0
is_gteqo >= 0

These functions are provided for compatibility with std::partial_ordering.

This function was introduced in Qt 6.7.

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

Return true if lhs and rhs represent different results; otherwise, returns true.

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

Return true if lhs and rhs represent the same result; otherwise, returns false.