mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-22 22:05:38 +00:00
common: Add macro for generating static/friend enum class operators
This commit is contained in:
parent
f5e1d443fa
commit
d8a02d7a15
|
@ -232,3 +232,42 @@ ALWAYS_INLINE constexpr T SignExtendN(T value)
|
|||
static_cast<std::underlying_type<type_>::type>(rhs)); \
|
||||
return lhs; \
|
||||
}
|
||||
|
||||
#define IMPLEMENT_STATIC_FRIEND_ENUM_CLASS_BITWISE_OPERATORS(type_) \
|
||||
ALWAYS_INLINE constexpr static friend type_ operator&(type_ lhs, type_ rhs) \
|
||||
{ \
|
||||
return static_cast<type_>(static_cast<std::underlying_type<type_>::type>(lhs) & \
|
||||
static_cast<std::underlying_type<type_>::type>(rhs)); \
|
||||
} \
|
||||
ALWAYS_INLINE constexpr static friend type_ operator|(type_ lhs, type_ rhs) \
|
||||
{ \
|
||||
return static_cast<type_>(static_cast<std::underlying_type<type_>::type>(lhs) | \
|
||||
static_cast<std::underlying_type<type_>::type>(rhs)); \
|
||||
} \
|
||||
ALWAYS_INLINE constexpr static friend type_ operator^(type_ lhs, type_ rhs) \
|
||||
{ \
|
||||
return static_cast<type_>(static_cast<std::underlying_type<type_>::type>(lhs) ^ \
|
||||
static_cast<std::underlying_type<type_>::type>(rhs)); \
|
||||
} \
|
||||
ALWAYS_INLINE constexpr static friend type_ operator~(type_ val) \
|
||||
{ \
|
||||
return static_cast<type_>(~static_cast<std::underlying_type<type_>::type>(val)); \
|
||||
} \
|
||||
ALWAYS_INLINE constexpr static friend type_& operator&=(type_& lhs, type_ rhs) \
|
||||
{ \
|
||||
lhs = static_cast<type_>(static_cast<std::underlying_type<type_>::type>(lhs) & \
|
||||
static_cast<std::underlying_type<type_>::type>(rhs)); \
|
||||
return lhs; \
|
||||
} \
|
||||
ALWAYS_INLINE constexpr static friend type_& operator|=(type_& lhs, type_ rhs) \
|
||||
{ \
|
||||
lhs = static_cast<type_>(static_cast<std::underlying_type<type_>::type>(lhs) | \
|
||||
static_cast<std::underlying_type<type_>::type>(rhs)); \
|
||||
return lhs; \
|
||||
} \
|
||||
ALWAYS_INLINE constexpr static friend type_& operator^=(type_& lhs, type_ rhs) \
|
||||
{ \
|
||||
lhs = static_cast<type_>(static_cast<std::underlying_type<type_>::type>(lhs) ^ \
|
||||
static_cast<std::underlying_type<type_>::type>(rhs)); \
|
||||
return lhs; \
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue