- Qt 6.11
- Qt Core
- C++ Classes
- weak_ordering
- Qt 6.11.1 Reference Documentation

# Qt::weak_ordering Class

class Qt::weak_ordering

Qt::weak_ordering represents a comparison where equivalent values are still distinguishable. More...

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

- List of all members, including inherited members

## Public Functions

| weak_ordering(std::weak_ordering stdorder)
| operator Qt::partial_ordering() const
| operator std::weak_ordering() const

## Static Public Members

const Qt::weak_ordering | equivalent
const Qt::weak_ordering | greater
const Qt::weak_ordering | less

## Related Non-Members

bool | is_eq(Qt::weak_ordering o)
bool | is_gt(Qt::weak_ordering o)
bool | is_gteq(Qt::weak_ordering o)
bool | is_lt(Qt::weak_ordering o)
bool | is_lteq(Qt::weak_ordering o)
bool | is_neq(Qt::weak_ordering o)
bool | operator!=(Qt::weak_ordering lhs, Qt::weak_ordering rhs)
bool | operator==(Qt::weak_ordering lhs, Qt::weak_ordering rhs)

## Detailed Description

A value of type Qt::weak_ordering is typically returned from a three-way comparison function. Such a function compares two objects and establishes how they are ordered. It uses this return type to indicate that the ordering is weak; that is, equivalent values may be distinguishable.

Qt::weak_ordering has three values, represented by the following 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,

Qt::weak_ordering 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:

     Qt::weak_ordering compare(T lhs, T rhs); // defined out-of-line
     ~~~

     Qt::weak_ordering 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 Qt::strong_ordering, Qt::partial_ordering, and Comparison types overview.

## Member Function Documentation

### `[constexpr noexcept]` weak_ordering::weak_ordering(std::weak_ordering stdorder)

Constructs a Qt::weak_ordering 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]` weak_ordering::operator Qt::partial_ordering() const

Converts this Qt::weak_ordering value to a Qt::partial_ordering object using the following rules:

- less converts to Qt::partial_ordering::less.
- equivalent converts to Qt::partial_ordering::equivalent.
- greater converts to Qt::partial_ordering::greater.

### `[constexpr noexcept]` weak_ordering::operator std::weak_ordering() const

Converts this Qt::weak_ordering value to a std::weak_ordering object using the following rules:

- less converts to std::weak_ordering::less.
- equivalent converts to std::weak_ordering::equivalent.
- greater converts to std::weak_ordering::greater.

## Member Variable Documentation

### const Qt::weak_ordering weak_ordering::equivalent

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

### const Qt::weak_ordering weak_ordering::greater

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

### const Qt::weak_ordering weak_ordering::less

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

## Related Non-Members

### `[constexpr noexcept]` bool is_eq(Qt::weak_ordering o)

### `[constexpr noexcept]` bool is_neq(Qt::weak_ordering o)

### `[constexpr noexcept]` bool is_lt(Qt::weak_ordering o)

### `[constexpr noexcept]` bool is_lteq(Qt::weak_ordering o)

### `[constexpr noexcept]` bool is_gt(Qt::weak_ordering o)

### `[constexpr noexcept]` bool is_gteq(Qt::weak_ordering o)

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

Function | Operation
--- | ---
`is_eq` | o `== 0`
`is_neq` | o `!= 0`
`is_lt` | o `< 0`
`is_lteq` | o `<= 0`
`is_gt` | o `> 0`
`is_gteq` | o `>= 0`

These functions are provided for compatibility with `std::weak_ordering`.

### `[constexpr noexcept]` bool operator!=(Qt::weak_ordering lhs, Qt::weak_ordering rhs)

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

### `[constexpr noexcept]` bool operator==(Qt::weak_ordering lhs, Qt::weak_ordering rhs)

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