mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
AK: Change EnumBits has_flag() to check all flags in mask are present
Co-authored-by: Brian Gianforcaro <b.gianfo@gmail.com>
This commit is contained in:
parent
2df4d977e2
commit
03b76e4ba0
Notes:
sideshowbarker
2024-07-18 08:56:55 +09:00
Author: https://github.com/timmot Commit: https://github.com/SerenityOS/serenity/commit/03b76e4ba05 Pull-request: https://github.com/SerenityOS/serenity/pull/8724 Reviewed-by: https://github.com/bgianfo ✅ Reviewed-by: https://github.com/kleinesfilmroellchen ✅
1 changed files with 58 additions and 58 deletions
116
AK/EnumBits.h
116
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<Enum>; \
|
||||
return static_cast<Enum>( \
|
||||
static_cast<Type>(lhs) | static_cast<Type>(rhs)); \
|
||||
} \
|
||||
\
|
||||
[[nodiscard]] Prefix constexpr Enum operator&(Enum lhs, Enum rhs) \
|
||||
{ \
|
||||
using Type = UnderlyingType<Enum>; \
|
||||
return static_cast<Enum>( \
|
||||
static_cast<Type>(lhs) & static_cast<Type>(rhs)); \
|
||||
} \
|
||||
\
|
||||
[[nodiscard]] Prefix constexpr Enum operator^(Enum lhs, Enum rhs) \
|
||||
{ \
|
||||
using Type = UnderlyingType<Enum>; \
|
||||
return static_cast<Enum>( \
|
||||
static_cast<Type>(lhs) ^ static_cast<Type>(rhs)); \
|
||||
} \
|
||||
\
|
||||
[[nodiscard]] Prefix constexpr Enum operator~(Enum rhs) \
|
||||
{ \
|
||||
using Type = UnderlyingType<Enum>; \
|
||||
return static_cast<Enum>( \
|
||||
~static_cast<Type>(rhs)); \
|
||||
} \
|
||||
\
|
||||
Prefix constexpr Enum& operator|=(Enum& lhs, Enum rhs) \
|
||||
{ \
|
||||
using Type = UnderlyingType<Enum>; \
|
||||
lhs = static_cast<Enum>( \
|
||||
static_cast<Type>(lhs) | static_cast<Type>(rhs)); \
|
||||
return lhs; \
|
||||
} \
|
||||
\
|
||||
Prefix constexpr Enum& operator&=(Enum& lhs, Enum rhs) \
|
||||
{ \
|
||||
using Type = UnderlyingType<Enum>; \
|
||||
lhs = static_cast<Enum>( \
|
||||
static_cast<Type>(lhs) & static_cast<Type>(rhs)); \
|
||||
return lhs; \
|
||||
} \
|
||||
\
|
||||
Prefix constexpr Enum& operator^=(Enum& lhs, Enum rhs) \
|
||||
{ \
|
||||
using Type = UnderlyingType<Enum>; \
|
||||
lhs = static_cast<Enum>( \
|
||||
static_cast<Type>(lhs) ^ static_cast<Type>(rhs)); \
|
||||
return lhs; \
|
||||
} \
|
||||
\
|
||||
Prefix constexpr bool has_flag(Enum value, Enum mask) \
|
||||
{ \
|
||||
using Type = UnderlyingType<Enum>; \
|
||||
return static_cast<Type>(value & mask) != 0; \
|
||||
#define _AK_ENUM_BITWISE_OPERATORS_INTERNAL(Enum, Prefix) \
|
||||
\
|
||||
[[nodiscard]] Prefix constexpr Enum operator|(Enum lhs, Enum rhs) \
|
||||
{ \
|
||||
using Type = UnderlyingType<Enum>; \
|
||||
return static_cast<Enum>( \
|
||||
static_cast<Type>(lhs) | static_cast<Type>(rhs)); \
|
||||
} \
|
||||
\
|
||||
[[nodiscard]] Prefix constexpr Enum operator&(Enum lhs, Enum rhs) \
|
||||
{ \
|
||||
using Type = UnderlyingType<Enum>; \
|
||||
return static_cast<Enum>( \
|
||||
static_cast<Type>(lhs) & static_cast<Type>(rhs)); \
|
||||
} \
|
||||
\
|
||||
[[nodiscard]] Prefix constexpr Enum operator^(Enum lhs, Enum rhs) \
|
||||
{ \
|
||||
using Type = UnderlyingType<Enum>; \
|
||||
return static_cast<Enum>( \
|
||||
static_cast<Type>(lhs) ^ static_cast<Type>(rhs)); \
|
||||
} \
|
||||
\
|
||||
[[nodiscard]] Prefix constexpr Enum operator~(Enum rhs) \
|
||||
{ \
|
||||
using Type = UnderlyingType<Enum>; \
|
||||
return static_cast<Enum>( \
|
||||
~static_cast<Type>(rhs)); \
|
||||
} \
|
||||
\
|
||||
Prefix constexpr Enum& operator|=(Enum& lhs, Enum rhs) \
|
||||
{ \
|
||||
using Type = UnderlyingType<Enum>; \
|
||||
lhs = static_cast<Enum>( \
|
||||
static_cast<Type>(lhs) | static_cast<Type>(rhs)); \
|
||||
return lhs; \
|
||||
} \
|
||||
\
|
||||
Prefix constexpr Enum& operator&=(Enum& lhs, Enum rhs) \
|
||||
{ \
|
||||
using Type = UnderlyingType<Enum>; \
|
||||
lhs = static_cast<Enum>( \
|
||||
static_cast<Type>(lhs) & static_cast<Type>(rhs)); \
|
||||
return lhs; \
|
||||
} \
|
||||
\
|
||||
Prefix constexpr Enum& operator^=(Enum& lhs, Enum rhs) \
|
||||
{ \
|
||||
using Type = UnderlyingType<Enum>; \
|
||||
lhs = static_cast<Enum>( \
|
||||
static_cast<Type>(lhs) ^ static_cast<Type>(rhs)); \
|
||||
return lhs; \
|
||||
} \
|
||||
\
|
||||
Prefix constexpr bool has_flag(Enum value, Enum mask) \
|
||||
{ \
|
||||
using Type = UnderlyingType<Enum>; \
|
||||
return static_cast<Type>(value & mask) == static_cast<Type>(mask); \
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue