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 <thiago.macieira@intel.com>
This commit is contained in:
Giuseppe D'Angelo 2021-04-28 19:43:47 +02:00
parent 99e95a2cc6
commit 7507afccee

View File

@ -162,14 +162,6 @@ private:
typedef QFlags<Enum> 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<Flags::enum_type> operator|(Flags::enum_type f1, Flags::enum_type f2) noexcept \
{ return QFlags<Flags::enum_type>(f1) | f2; } \
@ -181,8 +173,12 @@ constexpr inline void operator+(int f1, QFlags<Flags::enum_type> 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<Flags::enum_type> f2) noexcept = delete; \
constexpr inline void operator-(int f1, QFlags<Flags::enum_type> 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