<QtCompare> - 用於定義比較運算符的類和幫手

< QtCompare > 頭文件定義 Qt::*_ordering 類型和幫手宏為定義比較運算符。 更多...

頭: #include <QtCompare>

函數

(從 6.7 起) Qt::strong_ordering compareThreeWay (Enum lhs , Enum rhs )
(從 6.7 起) auto compareThreeWay (FloatType lhs , IntType rhs )
(從 6.7 起) auto compareThreeWay (IntType lhs , FloatType rhs )
(從 6.7 起) auto compareThreeWay (LeftFloat lhs , RightFloat rhs )
(從 6.7 起) auto compareThreeWay (LeftInt lhs , RightInt rhs )
(從 6.8 起) Qt::strong_ordering compareThreeWay (Qt::totally_ordered_wrapper<T *> lhs , Qt::totally_ordered_wrapper<U *> rhs )
(從 6.8 起) Qt::strong_ordering compareThreeWay (Qt::totally_ordered_wrapper<T *> lhs , U * rhs )
(從 6.8 起) Qt::strong_ordering compareThreeWay (Qt::totally_ordered_wrapper<T *> lhs , std::nullptr_t rhs )
(從 6.8 起) Qt::strong_ordering compareThreeWay (U * lhs , Qt::totally_ordered_wrapper<T *> rhs )
(從 6.8 起) Qt::strong_ordering compareThreeWay (std::nullptr_t lhs , Qt::totally_ordered_wrapper<T *> rhs )
(從 6.7 起) auto qCompareThreeWay (const LeftType & lhs , const RightType & rhs )

詳細描述

此 Header (頭) 引入 Qt::partial_ordering , Qt::weak_ordering ,和 Qt::strong_ordering 類型,它們是 Qt 的 C++17 後端對於 std::*_ordering 類型。

此 Header (頭) 還包含用於實現 C++17 的 3 嚮比較函數。

The Qt::compareThreeWay() 函數重載為內置 C++ 類型提供 3 嚮比較。

The qCompareThreeWay () 模闆充當一般 3 嚮比較實現。它依賴 Qt::compareThreeWay() 和自由 compareThreeWay() 函數在其實現中。

函數文檔編製

[constexpr noexcept, since 6.7] template <typename Enum, Qt::if_enum<Enum> = true> Qt::strong_ordering compareThreeWay ( Enum lhs , Enum rhs )

實現枚舉類型的 3 嚮比較。

此函數轉換 Enum 到其底層類型,並調用用於整型類型的重載。

返迴實例化的 Qt::strong_ordering 錶示關係介於 lhs and rhs .

約束

Participates in overload resolution only if Enum 是枚舉類型。

這是重載函數。

該函數在 Qt 6.7 引入。

[constexpr noexcept, since 6.7] template <typename FloatType, typename IntType, Qt::if_floating_point<FloatType> = true, Qt::if_integral<IntType> = true> auto compareThreeWay ( FloatType lhs , IntType rhs )

實現浮點類型和整型類型的 3 嚮比較。

此函數轉換 rhs to FloatType 並調用用於浮點類型的重載。

返迴實例化的 Qt::partial_ordering 錶示關係介於 lhs and rhs 。若 lhs 是 NaN (非數字), Qt::partial_ordering::unordered 被返迴。

約束

Participates in overload resolution only if FloatType is a built-in floating-point type and IntType is a built-in integral type.

這是重載函數。

該函數在 Qt 6.7 引入。

[constexpr noexcept, since 6.7] template <typename IntType, typename FloatType, Qt::if_integral<IntType> = true, Qt::if_floating_point<FloatType> = true> auto compareThreeWay ( IntType lhs , FloatType rhs )

實現整型類型和浮點類型的 3 嚮比較。

此函數轉換 lhs to FloatType 並調用用於浮點類型的重載。

返迴實例化的 Qt::partial_ordering 錶示關係介於 lhs and rhs 。若 rhs 是 NaN (非數字), Qt::partial_ordering::unordered 被返迴。

約束

Participates in overload resolution only if IntType 是內置整型類型和 FloatType 是內置浮點類型。

這是重載函數。

該函數在 Qt 6.7 引入。

[constexpr noexcept, since 6.7] template <typename LeftFloat, typename RightFloat, Qt::if_floating_point<LeftFloat> = true, Qt::if_floating_point<RightFloat> = true> auto compareThreeWay ( LeftFloat lhs , RightFloat rhs )

實現浮點類型的 3 嚮比較。

返迴 lhs <=> rhs ,提供的 LeftFloat and RightFloat 是內置浮點類型。不像 operator<=>() ,此函數模闆還可用於 C++17。見 cppreference 瞭解更多細節。

此函數還可以用於自定義 compareThreeWay() 函數,當排序由內置類型錶示的自定義類的成員時:

class MyClass {
public:
    ...
private:
    double value;
    ...
    friend Qt::partial_ordering
    compareThreeWay(const MyClass &lhs, const MyClass &rhs) noexcept
    { return Qt::compareThreeWay(lhs.value, rhs.value); }
    Q_DECLARE_PARTIALLY_ORDERED(MyClass)
};
					

返迴實例化的 Qt::partial_ordering 錶示關係介於 lhs and rhs 。若 lhs or rhs 是 NaN (非數字), Qt::partial_ordering::unordered 被返迴。

約束

Participates in overload resolution only if both LeftFloat and RightFloat 是內置浮點類型。

這是重載函數。

該函數在 Qt 6.7 引入。

[constexpr noexcept, since 6.7] template <typename LeftInt, typename RightInt, Qt::if_integral<LeftInt> = true, Qt::if_integral<RightInt> = true> auto compareThreeWay ( LeftInt lhs , RightInt rhs )

實現整型類型的 3 嚮比較。

返迴 lhs <=> rhs ,提供的 LeftInt and RightInt 是內置整型類型。不像 operator<=>() ,此函數模闆還可用於 C++17。見 cppreference 瞭解更多細節。

此函數還可以用於自定義 compareThreeWay() 函數,當排序由內置類型錶示的自定義類的成員時:

class MyClass {
public:
    ...
private:
    int value;
    ...
    friend Qt::strong_ordering
    compareThreeWay(const MyClass &lhs, const MyClass &rhs) noexcept
    { return Qt::compareThreeWay(lhs.value, rhs.value); }
    Q_DECLARE_STRONGLY_ORDERED(MyClass)
};
					

返迴實例化的 Qt::strong_ordering 錶示關係介於 lhs and rhs .

約束

Participates in overload resolution only if both LeftInt and RightInt 是內置整型類型。

這是重載函數。

該函數在 Qt 6.7 引入。

[constexpr noexcept, since 6.8] template <typename T, typename U, Qt::if_compatible_pointers<T, U> = true> Qt::strong_ordering compareThreeWay ( Qt::totally_ordered_wrapper < T *> lhs , Qt::totally_ordered_wrapper < U *> rhs )

Implements three-way comparison of pointers that are wrapped into Qt::totally_ordered_wrapper . Uses strict total order over pointers when doing the comparison.

返迴實例化的 Qt::strong_ordering 錶示關係介於 lhs and rhs .

約束

Participates in overload resolution only if T and U are the same type, or base and derived types.

這是重載函數。

該函數在 Qt 6.8 引入。

[constexpr noexcept, since 6.8] template <typename T, typename U, Qt::if_compatible_pointers<T, U> = true> Qt::strong_ordering compareThreeWay ( Qt::totally_ordered_wrapper < T *> lhs , U * rhs )

Implements three-way comparison of a pointer wrapped into Qt::totally_ordered_wrapper with a normal pointer. Uses strict total order over pointers when doing the comparison.

返迴實例化的 Qt::strong_ordering 錶示關係介於 lhs and rhs .

約束

Participates in overload resolution only if T and U are the same type, or base and derived types.

這是重載函數。

該函數在 Qt 6.8 引入。

[constexpr noexcept, since 6.8] template <typename T> Qt::strong_ordering compareThreeWay ( Qt::totally_ordered_wrapper < T *> lhs , std::nullptr_t rhs )

Implements three-way comparison of a pointer wrapped into Qt::totally_ordered_wrapper with std::nullptr_t .

返迴實例化的 Qt::strong_ordering 錶示關係介於 lhs and rhs .

這是重載函數。

該函數在 Qt 6.8 引入。

[constexpr noexcept, since 6.8] template <typename T, typename U, Qt::if_compatible_pointers<T, U> = true> Qt::strong_ordering compareThreeWay ( U * lhs , Qt::totally_ordered_wrapper < T *> rhs )

Implements three-way comparison of a normal pointer with a pointer wrapped into Qt::totally_ordered_wrapper . Uses strict total order over pointers when doing the comparison.

返迴實例化的 Qt::strong_ordering 錶示關係介於 lhs and rhs .

約束

Participates in overload resolution only if T and U are the same type, or base and derived types.

這是重載函數。

該函數在 Qt 6.8 引入。

[constexpr noexcept, since 6.8] template <typename T> Qt::strong_ordering compareThreeWay ( std::nullptr_t lhs , Qt::totally_ordered_wrapper < T *> rhs )

Implements three-way comparison of std::nullptr_t with a pointer wrapped into Qt::totally_ordered_wrapper .

返迴實例化的 Qt::strong_ordering 錶示關係介於 lhs and rhs .

這是重載函數。

該函數在 Qt 6.8 引入。

[since 6.7] template <typename LeftType, typename RightType> auto qCompareThreeWay (const LeftType & lhs , const RightType & rhs )

Performs the three-way comparison on lhs and rhs and returns one of the Qt ordering types as a result. This function is available for both C++17 and C++20.

The actual returned type depends on LeftType and RightType .

注意: This function template is only available when compareThreeWay() is implemented for the (LeftType, RightType) pair or the reversed (RightType, LeftType) pair.

This method is equivalent to

using Qt::compareThreeWay;
return compareThreeWay(lhs, rhs);
					

where Qt::compareThreeWay is the Qt implementation of three-way comparison for built-in types.

The free compareThreeWay functions should provide three-way comparison for custom types. The functions should return one of the Qt ordering types.

Qt 提供 compareThreeWay implementation for some of its types.

注意: Do not re-implement compareThreeWay() for Qt types, as more Qt types will get support for it in future Qt releases.

Use this function primarly in generic code, when you know nothing about LeftType and RightType .

If you know the types, use

  • Qt::compareThreeWay 對於內置類型
  • compareThreeWay for custom types

使用 operator<=>() directly in code that will only be compiled with C++20 or later.

該函數在 Qt 6.7 引入。

另請參閱 Qt::partial_ordering , Qt::weak_ordering ,和 Qt::strong_ordering .