diff options
author | bunnei <bunneidev@gmail.com> | 2020-03-20 22:40:03 -0400 |
---|---|---|
committer | bunnei <bunneidev@gmail.com> | 2020-04-17 00:59:27 -0400 |
commit | b11b424a2df48c6e17968be1d6dd2b69c7c728db (patch) | |
tree | a28052da071b98bdf3533a576e56daa1d30d2a00 /src/common/common_funcs.h | |
parent | f2676efe23f03c1755715d049d53e26d1dac1864 (diff) |
common: common_funcs: Add a macro for defining enum flag operators.
Diffstat (limited to 'src/common/common_funcs.h')
-rw-r--r-- | src/common/common_funcs.h | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/common/common_funcs.h b/src/common/common_funcs.h index 052254678d..88cf5250ad 100644 --- a/src/common/common_funcs.h +++ b/src/common/common_funcs.h @@ -55,6 +55,38 @@ __declspec(dllimport) void __stdcall DebugBreak(void); // Defined in Misc.cpp. std::string GetLastErrorMsg(); +#define DECLARE_ENUM_FLAG_OPERATORS(type) \ + constexpr type operator|(type a, type b) noexcept { \ + using T = std::underlying_type_t<type>; \ + return static_cast<type>(static_cast<T>(a) | static_cast<T>(b)); \ + } \ + constexpr type operator&(type a, type b) noexcept { \ + using T = std::underlying_type_t<type>; \ + return static_cast<type>(static_cast<T>(a) & static_cast<T>(b)); \ + } \ + constexpr type& operator|=(type& a, type b) noexcept { \ + using T = std::underlying_type_t<type>; \ + a = static_cast<type>(static_cast<T>(a) | static_cast<T>(b)); \ + return a; \ + } \ + constexpr type& operator&=(type& a, type b) noexcept { \ + using T = std::underlying_type_t<type>; \ + a = static_cast<type>(static_cast<T>(a) & static_cast<T>(b)); \ + return a; \ + } \ + constexpr type operator~(type key) noexcept { \ + using T = std::underlying_type_t<type>; \ + return static_cast<type>(~static_cast<T>(key)); \ + } \ + constexpr bool True(type key) noexcept { \ + using T = std::underlying_type_t<type>; \ + return static_cast<T>(key) != 0; \ + } \ + constexpr bool False(type key) noexcept { \ + using T = std::underlying_type_t<type>; \ + return static_cast<T>(key) == 0; \ + } + namespace Common { constexpr u32 MakeMagic(char a, char b, char c, char d) { |