QWeakOrdering Class

QWeakOrdering represents a comparison where equivalent values are still distinguishable. More...

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

Public Functions

QWeakOrdering(int stdorder)
QPartialOrdering operator QPartialOrdering() const

Static Public Members

const QWeakOrdering Equivalent
const QWeakOrdering Greater
const QWeakOrdering Less
bool operator!=(QWeakOrdering lhs, QWeakOrdering rhs)
bool operator==(QWeakOrdering lhs, QWeakOrdering rhs)

Detailed Description

A value of type QWeakOrdering is typically returned from a three-way comparison function. Such a function compares two objects and establishes the order of the elements relative to each other.

The possible values of type QWeakOrdering are fully represented by the following three symbolic constants:

  • Less represents that the left operand is less than the right;
  • Equivalent represents that the left operand is equivalent to the right;
  • Greater represents that the left operand is greater than the right,

QWeakOrdering 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:

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

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

See also QStrongOrdering, QPartialOrdering, and Comparison types overview.

Member Function Documentation

[default] QWeakOrdering::QWeakOrdering(int stdorder)

Constructs a QWeakOrdering object from stdorder using the following rules:

  • std::weak_ordering::less converts to Less.
  • std::weak_ordering::equivalent converts to Equivalent.
  • std::weak_ordering::greater converts to Greater.

[constexpr noexcept] QPartialOrdering QWeakOrdering::operator QPartialOrdering() const

Converts this QWeakOrdering value to a QPartialOrdering object using the following rules:

Member Variable Documentation

const QWeakOrdering QWeakOrdering::Equivalent

Represents the result of a comparison where the left operand is equivalent to the right operand.

const QWeakOrdering QWeakOrdering::Greater

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

const QWeakOrdering QWeakOrdering::Less

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

Related Non-Members

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

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

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

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