Details
-
Suggestion
-
Resolution: Out of scope
-
Not Evaluated
-
None
-
5.0.0
-
None
-
All platforms
Description
Please consider one or more of the following member functions for addition to the QFlags class template for inclusion in a future release.
QFlags class
inline QFlags &operator~=(Enum f) { i &= ~f; return *this; } inline QFlags &operator~=(QFlags f) { i &= ~f.i; return *this; } inline QFlags &setFlag(Enum f) { i |= f; return *this; } inline QFlags &unsetFlag(Enum f) { i &= ~f; return *this; }
Justification:
Testing and combining flags is well-handled in the existing class but whenever a flag needs to be unset, compiler errors are generated (unknown conversion from int to Enum) unless an explicit typecast is used.
Example
enum EnumFlag { Enum_1 = 0x1, Enum_2 = 0x2 }; Q_DECLARE_FLAGS(EnumFlags, Enum) Q_DECLARE_OPERATORS_FOR_FLAGS(EnumFlags) EnumFlags flags(Enum_2); flags &= ~Enum_2; // compiler error: Enum_2 is converted to int flags &= static_cast<EnumFlag>(~Enum_2); // This is acceptable to the compiler but looks like a dog's breakfast // Usage for proposed new member functions flags ~= Enum_2; flags.unsetFlag(Enum_2);