<QtCompare> - Classes and helpers for defining comparison operators

<QtCompare> 헤더 파일은 비교 연산자를 정의하기 위한 Qt::*_ordering 유형 및 헬퍼 매크로를 정의합니다. 더 보기...

Header: #include <QtCompare>

함수

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

자세한 설명

Qt::partial_ordering이 헤더는 Qt::weak_ordering, Qt::strong_ordering 형을 소개합니다. , 형은 std::*_ordering 형의 Qt C++17 백포트입니다.

이 헤더에는 C++17에서 3방향 비교를 구현하기 위한 함수도 포함되어 있습니다.

Qt::compareThreeWay() 함수 오버로드는 빌트인 C++ 타입에 대한 3방향 비교를 제공합니다.

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 가 열거형인 경우에만 과부하 해결에 참여합니다.

이 함수는 Enum 을 기본 유형으로 변환하고 정수형에 대한 오버로드를 호출합니다.

lhsrhs 사이의 관계를 나타내는 Qt::strong_ordering 의 인스턴스를 반환합니다.

이 함수는 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방향 비교를 구현합니다.

참고: 이 함수는 FloatType 이 내장 부동 소수점 유형이고 IntType 이 내장 적분 유형인 경우에만 과부하 해결에 참여합니다.

이 함수는 rhsFloatType 으로 변환하고 부동 소수점 유형에 대한 오버로드를 호출합니다.

lhsrhs 사이의 관계를 나타내는 Qt::partial_ordering 의 인스턴스를 반환합니다. lhs 이 숫자(NaN)가 아닌 경우 Qt::partial_ordering::unordered 이 반환됩니다.

이 함수는 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방향 비교를 구현합니다.

참고: 이 함수는 IntType 가 내장된 적분 유형이고 FloatType 가 내장된 부동 소수점 유형인 경우에만 과부하 해결에 참여합니다.

이 함수는 lhsFloatType 으로 변환하고 부동 소수점 유형에 대한 오버로드를 호출합니다.

lhsrhs 사이의 관계를 나타내는 Qt::partial_ordering 의 인스턴스를 반환합니다. rhs 이 숫자(NaN)가 아닌 경우 Qt::partial_ordering::unordered 이 반환됩니다.

이 함수는 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방향 비교를 구현합니다.

참고: 이 함수는 LeftFloatRightFloat 이 모두 내장 부동소수점 유형인 경우에만 과부하 확인에 참여합니다.

LeftFloatRightFloat 이 내장 부동소수점 유형인 경우 lhs <=> rhs 을 반환합니다. 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)
};

lhsrhs 사이의 관계를 나타내는 Qt::partial_ordering 의 인스턴스를 반환합니다. lhs 또는 rhs 가 숫자(NaN)가 아닌 경우 Qt::partial_ordering::unordered 가 반환됩니다.

이 함수는 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방향 비교를 구현합니다.

참고: 이 함수는 LeftIntRightInt 가 모두 내장된 적분 유형인 경우에만 과부하 해결에 참여합니다.

LeftIntRightInt 이 내장된 적분 유형인 경우 lhs <=> rhs 을 반환합니다. 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)
};

lhsrhs 사이의 관계를 나타내는 Qt::strong_ordering 의 인스턴스를 반환합니다.

이 함수는 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)

이것은 오버로드된 함수입니다.

Qt::totally_ordered_wrapper 로 래핑된 포인터의 3방향 비교를 구현합니다. 비교를 수행할 때 포인터에 대해 엄격한 전체 순서를 사용합니다.

참고: 이 함수는 TU 이 같은 타입이거나 기본 타입과 파생 타입인 경우 과부하 해결에 참여합니다.

lhsrhs 사이의 관계를 나타내는 Qt::strong_ordering 의 인스턴스를 반환합니다.

이 함수는 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)

이 함수는 오버로드된 함수입니다.

Qt::totally_ordered_wrapper 로 래핑된 포인터와 일반 포인터의 3방향 비교를 구현합니다. 비교를 수행할 때 포인터에 대해 엄격한 전체 순서를 사용합니다.

참고: 이 함수는 TU 이 동일한 유형이거나 기본 유형과 파생 유형인 경우 과부하 해결에 참여합니다.

lhsrhs 사이의 관계를 나타내는 Qt::strong_ordering 의 인스턴스를 반환합니다.

이 함수는 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)

이것은 오버로드된 함수입니다.

Qt::totally_ordered_wrapper 로 래핑된 포인터와 std::nullptr_t 의 3방향 비교를 구현합니다.

lhsrhs 사이의 관계를 나타내는 Qt::strong_ordering 의 인스턴스를 반환합니다.

이 함수는 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)

이 함수는 오버로드된 함수입니다.

일반 포인터와 Qt::totally_ordered_wrapper 로 래핑된 포인터의 3방향 비교를 구현합니다. 비교를 수행할 때 포인터에 대해 엄격한 전체 순서를 사용합니다.

참고: 이 함수는 TU 이 동일한 유형이거나 기본 유형과 파생 유형인 경우 과부하 해결에 참여합니다.

lhsrhs 사이의 관계를 나타내는 Qt::strong_ordering 의 인스턴스를 반환합니다.

이 함수는 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)

이 함수는 오버로드된 함수입니다.

Qt::totally_ordered_wrapper 으로 래핑된 포인터로 std::nullptr_t 의 3방향 비교를 구현합니다.

lhsrhs 사이의 관계를 나타내는 Qt::strong_ordering 의 인스턴스를 반환합니다.

이 함수는 Qt 6.8에 도입되었습니다.

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

lhsrhs 에서 3자 비교를 수행하고 그 결과로 Qt 주문 유형 중 하나를 반환합니다. 이 함수는 C++17과 C++20 모두에서 사용할 수 있습니다.

실제 반환되는 유형은 LeftTypeRightType 에 따라 다릅니다.

참고: 이 함수 템플릿은 (LeftType, RightType) 쌍 또는 역방향 (RightType, LeftType) 쌍에 대해 compareThreeWay() 을 구현한 경우에만 사용할 수 있습니다.

이 메서드는 다음과 같습니다.

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

와 같으며, 여기서 Qt::compareThreeWay 는 내장형에 대한 3자 비교의 Qt XML 구현입니다.

무료 compareThreeWay 함수는 사용자 정의 유형에 대한 3방향 비교를 제공해야 합니다. 함수는 Qt 순서 유형 중 하나를 반환해야 합니다.

Qt는 일부 유형에 대해 compareThreeWay 구현을 제공합니다.

참고: 향후 Qt 릴리스에서 더 많은 Qt 유형이 지원될 예정이므로 Qt 유형에 대해 compareThreeWay() 을 다시구현하지 마십시오.

LeftTypeRightType 에 대해 전혀 모르는 경우 이 함수는 주로 일반 코드에서 사용하십시오.

타입을 알고 있다면, 내장 타입의 경우

  • Qt::compareThreeWay 내장 타입의 경우
  • compareThreeWay 사용자 정의 타입의 경우

C++20 이상으로만 컴파일되는 코드에서는 operator<=>() 을 직접 사용하십시오.

이 기능은 Qt 6.7에 도입되었습니다.

Qt::partial_ordering, Qt::weak_ordering, Qt::strong_ordering참조하세요 .

© 2025 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.