From 7507afccee63057269a76f39a6d9bde7cf4427f4 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Wed, 28 Apr 2021 19:43:47 +0200 Subject: [PATCH] QFlags: streamline some macros There's little point at keeping the separate Q_DECLARE_INCOMPATIBLE_FLAGS macro, only to invoke it exactly once (from the expansion of Q_DECLARE_OPERATORS_FOR_FLAGS). Besides, Q_DECLARE_OPERATORS_FOR_FLAGS already had some "incompatible" operators in its expansion (the deleted arithmetic ones), so adding the "incompatible" ones in there is consistent. Change-Id: I591d57af8eec5b03ecaa7a3b0de23a967b13f7a5 Reviewed-by: Thiago Macieira --- src/corelib/global/qflags.h | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/corelib/global/qflags.h b/src/corelib/global/qflags.h index 772d97a964..34e2c5bc86 100644 --- a/src/corelib/global/qflags.h +++ b/src/corelib/global/qflags.h @@ -162,14 +162,6 @@ private: typedef QFlags Flags; #endif -#define Q_DECLARE_INCOMPATIBLE_FLAGS(Flags) \ -constexpr inline QIncompatibleFlag operator|(Flags::enum_type f1, int f2) noexcept \ -{ return QIncompatibleFlag(int(f1) | f2); } \ -constexpr inline void operator+(int f1, Flags::enum_type f2) noexcept = delete; \ -constexpr inline void operator+(Flags::enum_type f1, int f2) noexcept = delete; \ -constexpr inline void operator-(int f1, Flags::enum_type f2) noexcept = delete; \ -constexpr inline void operator-(Flags::enum_type f1, int f2) noexcept = delete; - #define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags) \ constexpr inline QFlags operator|(Flags::enum_type f1, Flags::enum_type f2) noexcept \ { return QFlags(f1) | f2; } \ @@ -181,8 +173,12 @@ constexpr inline void operator+(int f1, QFlags f2) noexcept = constexpr inline void operator-(Flags::enum_type f1, Flags::enum_type f2) noexcept = delete; \ constexpr inline void operator-(Flags::enum_type f1, QFlags f2) noexcept = delete; \ constexpr inline void operator-(int f1, QFlags f2) noexcept = delete; \ -Q_DECLARE_INCOMPATIBLE_FLAGS(Flags) - +constexpr inline QIncompatibleFlag operator|(Flags::enum_type f1, int f2) noexcept \ +{ return QIncompatibleFlag(int(f1) | f2); } \ +constexpr inline void operator+(int f1, Flags::enum_type f2) noexcept = delete; \ +constexpr inline void operator+(Flags::enum_type f1, int f2) noexcept = delete; \ +constexpr inline void operator-(int f1, Flags::enum_type f2) noexcept = delete; \ +constexpr inline void operator-(Flags::enum_type f1, int f2) noexcept = delete; QT_END_NAMESPACE