From 03b76e4ba0594f148c6cbe05339b0b87a791c04f Mon Sep 17 00:00:00 2001 From: Timothy Date: Wed, 14 Jul 2021 21:57:11 +1000 Subject: [PATCH] AK: Change EnumBits has_flag() to check all flags in mask are present Co-authored-by: Brian Gianforcaro --- AK/EnumBits.h | 116 +++++++++++++++++++++++++------------------------- 1 file changed, 58 insertions(+), 58 deletions(-) diff --git a/AK/EnumBits.h b/AK/EnumBits.h index b806aaa46b0..a1216b8c26d 100644 --- a/AK/EnumBits.h +++ b/AK/EnumBits.h @@ -20,62 +20,62 @@ #define AK_ENUM_BITWISE_FRIEND_OPERATORS(Enum) \ _AK_ENUM_BITWISE_OPERATORS_INTERNAL(Enum, friend) -#define _AK_ENUM_BITWISE_OPERATORS_INTERNAL(Enum, Prefix) \ - \ - [[nodiscard]] Prefix constexpr Enum operator|(Enum lhs, Enum rhs) \ - { \ - using Type = UnderlyingType; \ - return static_cast( \ - static_cast(lhs) | static_cast(rhs)); \ - } \ - \ - [[nodiscard]] Prefix constexpr Enum operator&(Enum lhs, Enum rhs) \ - { \ - using Type = UnderlyingType; \ - return static_cast( \ - static_cast(lhs) & static_cast(rhs)); \ - } \ - \ - [[nodiscard]] Prefix constexpr Enum operator^(Enum lhs, Enum rhs) \ - { \ - using Type = UnderlyingType; \ - return static_cast( \ - static_cast(lhs) ^ static_cast(rhs)); \ - } \ - \ - [[nodiscard]] Prefix constexpr Enum operator~(Enum rhs) \ - { \ - using Type = UnderlyingType; \ - return static_cast( \ - ~static_cast(rhs)); \ - } \ - \ - Prefix constexpr Enum& operator|=(Enum& lhs, Enum rhs) \ - { \ - using Type = UnderlyingType; \ - lhs = static_cast( \ - static_cast(lhs) | static_cast(rhs)); \ - return lhs; \ - } \ - \ - Prefix constexpr Enum& operator&=(Enum& lhs, Enum rhs) \ - { \ - using Type = UnderlyingType; \ - lhs = static_cast( \ - static_cast(lhs) & static_cast(rhs)); \ - return lhs; \ - } \ - \ - Prefix constexpr Enum& operator^=(Enum& lhs, Enum rhs) \ - { \ - using Type = UnderlyingType; \ - lhs = static_cast( \ - static_cast(lhs) ^ static_cast(rhs)); \ - return lhs; \ - } \ - \ - Prefix constexpr bool has_flag(Enum value, Enum mask) \ - { \ - using Type = UnderlyingType; \ - return static_cast(value & mask) != 0; \ +#define _AK_ENUM_BITWISE_OPERATORS_INTERNAL(Enum, Prefix) \ + \ + [[nodiscard]] Prefix constexpr Enum operator|(Enum lhs, Enum rhs) \ + { \ + using Type = UnderlyingType; \ + return static_cast( \ + static_cast(lhs) | static_cast(rhs)); \ + } \ + \ + [[nodiscard]] Prefix constexpr Enum operator&(Enum lhs, Enum rhs) \ + { \ + using Type = UnderlyingType; \ + return static_cast( \ + static_cast(lhs) & static_cast(rhs)); \ + } \ + \ + [[nodiscard]] Prefix constexpr Enum operator^(Enum lhs, Enum rhs) \ + { \ + using Type = UnderlyingType; \ + return static_cast( \ + static_cast(lhs) ^ static_cast(rhs)); \ + } \ + \ + [[nodiscard]] Prefix constexpr Enum operator~(Enum rhs) \ + { \ + using Type = UnderlyingType; \ + return static_cast( \ + ~static_cast(rhs)); \ + } \ + \ + Prefix constexpr Enum& operator|=(Enum& lhs, Enum rhs) \ + { \ + using Type = UnderlyingType; \ + lhs = static_cast( \ + static_cast(lhs) | static_cast(rhs)); \ + return lhs; \ + } \ + \ + Prefix constexpr Enum& operator&=(Enum& lhs, Enum rhs) \ + { \ + using Type = UnderlyingType; \ + lhs = static_cast( \ + static_cast(lhs) & static_cast(rhs)); \ + return lhs; \ + } \ + \ + Prefix constexpr Enum& operator^=(Enum& lhs, Enum rhs) \ + { \ + using Type = UnderlyingType; \ + lhs = static_cast( \ + static_cast(lhs) ^ static_cast(rhs)); \ + return lhs; \ + } \ + \ + Prefix constexpr bool has_flag(Enum value, Enum mask) \ + { \ + using Type = UnderlyingType; \ + return static_cast(value & mask) == static_cast(mask); \ }