14template <
typename enum_type>
15constexpr std::underlying_type_t<enum_type>
to_underlying(enum_type e) {
return static_cast<std::underlying_type_t<enum_type>
>(e); }
18#define DECLARE_POSTFIX_INCREMENT(enum_type) \
19 inline constexpr enum_type operator ++(enum_type& e, int) \
21 enum_type e_org = e; \
22 e = static_cast<enum_type>(to_underlying(e) + 1); \
25 inline constexpr enum_type operator --(enum_type& e, int) \
27 enum_type e_org = e; \
28 e = static_cast<enum_type>(to_underlying(e) - 1); \
35#define DECLARE_ENUM_AS_BIT_SET(enum_type) \
36 inline constexpr enum_type operator | (enum_type m1, enum_type m2) { return static_cast<enum_type>(to_underlying(m1) | to_underlying(m2)); } \
37 inline constexpr enum_type operator & (enum_type m1, enum_type m2) { return static_cast<enum_type>(to_underlying(m1) & to_underlying(m2)); } \
38 inline constexpr enum_type operator ^ (enum_type m1, enum_type m2) { return static_cast<enum_type>(to_underlying(m1) ^ to_underlying(m2)); } \
39 inline constexpr enum_type& operator |= (enum_type& m1, enum_type m2) { m1 = m1 | m2; return m1; } \
40 inline constexpr enum_type& operator &= (enum_type& m1, enum_type m2) { m1 = m1 & m2; return m1; } \
41 inline constexpr enum_type& operator ^= (enum_type& m1, enum_type m2) { m1 = m1 ^ m2; return m1; } \
42 inline constexpr enum_type operator ~(enum_type m) { return static_cast<enum_type>(~to_underlying(m)); }
45#define DECLARE_ENUM_AS_ADDABLE(EnumType) \
46 template <typename OtherEnumType, typename = typename std::enable_if<std::is_enum_v<OtherEnumType>, OtherEnumType>::type> \
47 constexpr OtherEnumType operator + (OtherEnumType m1, EnumType m2) { \
48 return static_cast<OtherEnumType>(to_underlying(m1) + to_underlying(m2)); \
57template <
typename T,
class =
typename std::enable_if_t<std::is_enum_v<T>>>
58debug_inline
constexpr bool HasFlag(
const T x,
const T y)
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23)
debug_inline constexpr bool HasFlag(const T x, const T y)
Checks if a value in a bitset enum is set.