From de752e8994220639b2934b769e83bab0e56a00c9 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 3 Jun 2019 23:03:30 +0200 Subject: [PATCH] QLatin1Char: add comparison operators with char When QT_NO_CAST_FROM_ASCII is in effect, `char == QLatinChar` no longer compiles, because the QChar(char) ctor has become private. Fix by supplying the missing mixed-type operators. [ChangeLog][QtCore][QLatin1Char] Comparison against char now works even in QT_NO_CAST_FROM_ASCII builds. Change-Id: I86f5ec8e2ddfcda72f5928086cb298bd00b42544 Reviewed-by: Thiago Macieira --- src/corelib/tools/qchar.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/corelib/tools/qchar.h b/src/corelib/tools/qchar.h index be344838ed3..73344ecf525 100644 --- a/src/corelib/tools/qchar.h +++ b/src/corelib/tools/qchar.h @@ -58,6 +58,19 @@ private: char ch; }; +Q_DECL_CONSTEXPR inline bool operator==(char lhs, QLatin1Char rhs) noexcept { return lhs == rhs.toLatin1(); } +Q_DECL_CONSTEXPR inline bool operator!=(char lhs, QLatin1Char rhs) noexcept { return lhs != rhs.toLatin1(); } +Q_DECL_CONSTEXPR inline bool operator<=(char lhs, QLatin1Char rhs) noexcept { return lhs <= rhs.toLatin1(); } +Q_DECL_CONSTEXPR inline bool operator>=(char lhs, QLatin1Char rhs) noexcept { return lhs >= rhs.toLatin1(); } +Q_DECL_CONSTEXPR inline bool operator< (char lhs, QLatin1Char rhs) noexcept { return lhs < rhs.toLatin1(); } +Q_DECL_CONSTEXPR inline bool operator> (char lhs, QLatin1Char rhs) noexcept { return lhs > rhs.toLatin1(); } + +Q_DECL_CONSTEXPR inline bool operator==(QLatin1Char lhs, char rhs) noexcept { return lhs.toLatin1() == rhs; } +Q_DECL_CONSTEXPR inline bool operator!=(QLatin1Char lhs, char rhs) noexcept { return lhs.toLatin1() != rhs; } +Q_DECL_CONSTEXPR inline bool operator<=(QLatin1Char lhs, char rhs) noexcept { return lhs.toLatin1() <= rhs; } +Q_DECL_CONSTEXPR inline bool operator>=(QLatin1Char lhs, char rhs) noexcept { return lhs.toLatin1() >= rhs; } +Q_DECL_CONSTEXPR inline bool operator< (QLatin1Char lhs, char rhs) noexcept { return lhs.toLatin1() < rhs; } +Q_DECL_CONSTEXPR inline bool operator> (QLatin1Char lhs, char rhs) noexcept { return lhs.toLatin1() > rhs; } class Q_CORE_EXPORT QChar { public: