diff options
Diffstat (limited to 'src/common/common_funcs.h')
| -rw-r--r-- | src/common/common_funcs.h | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/src/common/common_funcs.h b/src/common/common_funcs.h index 88cf5250a..367b6bf6e 100644 --- a/src/common/common_funcs.h +++ b/src/common/common_funcs.h | |||
| @@ -53,43 +53,49 @@ __declspec(dllimport) void __stdcall DebugBreak(void); | |||
| 53 | // Call directly after the command or use the error num. | 53 | // Call directly after the command or use the error num. |
| 54 | // This function might change the error code. | 54 | // This function might change the error code. |
| 55 | // Defined in Misc.cpp. | 55 | // Defined in Misc.cpp. |
| 56 | std::string GetLastErrorMsg(); | 56 | [[nodiscard]] std::string GetLastErrorMsg(); |
| 57 | 57 | ||
| 58 | #define DECLARE_ENUM_FLAG_OPERATORS(type) \ | 58 | #define DECLARE_ENUM_FLAG_OPERATORS(type) \ |
| 59 | constexpr type operator|(type a, type b) noexcept { \ | 59 | [[nodiscard]] constexpr type operator|(type a, type b) noexcept { \ |
| 60 | using T = std::underlying_type_t<type>; \ | 60 | using T = std::underlying_type_t<type>; \ |
| 61 | return static_cast<type>(static_cast<T>(a) | static_cast<T>(b)); \ | 61 | return static_cast<type>(static_cast<T>(a) | static_cast<T>(b)); \ |
| 62 | } \ | 62 | } \ |
| 63 | constexpr type operator&(type a, type b) noexcept { \ | 63 | [[nodiscard]] constexpr type operator&(type a, type b) noexcept { \ |
| 64 | using T = std::underlying_type_t<type>; \ | 64 | using T = std::underlying_type_t<type>; \ |
| 65 | return static_cast<type>(static_cast<T>(a) & static_cast<T>(b)); \ | 65 | return static_cast<type>(static_cast<T>(a) & static_cast<T>(b)); \ |
| 66 | } \ | 66 | } \ |
| 67 | constexpr type& operator|=(type& a, type b) noexcept { \ | 67 | [[nodiscard]] constexpr type operator^(type a, type b) noexcept { \ |
| 68 | using T = std::underlying_type_t<type>; \ | 68 | using T = std::underlying_type_t<type>; \ |
| 69 | a = static_cast<type>(static_cast<T>(a) | static_cast<T>(b)); \ | 69 | return static_cast<type>(static_cast<T>(a) ^ static_cast<T>(b)); \ |
| 70 | } \ | ||
| 71 | constexpr type& operator|=(type& a, type b) noexcept { \ | ||
| 72 | a = a | b; \ | ||
| 70 | return a; \ | 73 | return a; \ |
| 71 | } \ | 74 | } \ |
| 72 | constexpr type& operator&=(type& a, type b) noexcept { \ | 75 | constexpr type& operator&=(type& a, type b) noexcept { \ |
| 73 | using T = std::underlying_type_t<type>; \ | 76 | a = a & b; \ |
| 74 | a = static_cast<type>(static_cast<T>(a) & static_cast<T>(b)); \ | 77 | return a; \ |
| 78 | } \ | ||
| 79 | constexpr type& operator^=(type& a, type b) noexcept { \ | ||
| 80 | a = a ^ b; \ | ||
| 75 | return a; \ | 81 | return a; \ |
| 76 | } \ | 82 | } \ |
| 77 | constexpr type operator~(type key) noexcept { \ | 83 | [[nodiscard]] constexpr type operator~(type key) noexcept { \ |
| 78 | using T = std::underlying_type_t<type>; \ | 84 | using T = std::underlying_type_t<type>; \ |
| 79 | return static_cast<type>(~static_cast<T>(key)); \ | 85 | return static_cast<type>(~static_cast<T>(key)); \ |
| 80 | } \ | 86 | } \ |
| 81 | constexpr bool True(type key) noexcept { \ | 87 | [[nodiscard]] constexpr bool True(type key) noexcept { \ |
| 82 | using T = std::underlying_type_t<type>; \ | 88 | using T = std::underlying_type_t<type>; \ |
| 83 | return static_cast<T>(key) != 0; \ | 89 | return static_cast<T>(key) != 0; \ |
| 84 | } \ | 90 | } \ |
| 85 | constexpr bool False(type key) noexcept { \ | 91 | [[nodiscard]] constexpr bool False(type key) noexcept { \ |
| 86 | using T = std::underlying_type_t<type>; \ | 92 | using T = std::underlying_type_t<type>; \ |
| 87 | return static_cast<T>(key) == 0; \ | 93 | return static_cast<T>(key) == 0; \ |
| 88 | } | 94 | } |
| 89 | 95 | ||
| 90 | namespace Common { | 96 | namespace Common { |
| 91 | 97 | ||
| 92 | constexpr u32 MakeMagic(char a, char b, char c, char d) { | 98 | [[nodiscard]] constexpr u32 MakeMagic(char a, char b, char c, char d) { |
| 93 | return u32(a) | u32(b) << 8 | u32(c) << 16 | u32(d) << 24; | 99 | return u32(a) | u32(b) << 8 | u32(c) << 16 | u32(d) << 24; |
| 94 | } | 100 | } |
| 95 | 101 | ||