Created
November 28, 2025 02:24
-
-
Save Pikachuxxxx/6b2739720bf22335ad2a4d75e8d010c8 to your computer and use it in GitHub Desktop.
enum class explicit operators
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #define DECLARE_ENUM_BITWISE_OPERATORS(enum_type) \ | |
| inline constexpr enum_type operator |(enum_type lhs, enum_type rhs) { return static_cast<enum_type> ( static_cast<std::underlying_type<enum_type>::type>(lhs) | static_cast<std::underlying_type<enum_type>::type>(rhs) ); } \ | |
| inline constexpr enum_type operator &(enum_type lhs, enum_type rhs) { return static_cast<enum_type> ( static_cast<std::underlying_type<enum_type>::type>(lhs) & static_cast<std::underlying_type<enum_type>::type>(rhs) ); } \ | |
| inline constexpr enum_type operator ^(enum_type lhs, enum_type rhs) { return static_cast<enum_type> ( static_cast<std::underlying_type<enum_type>::type>(lhs) ^ static_cast<std::underlying_type<enum_type>::type>(rhs) ); } \ | |
| inline constexpr enum_type operator ~(enum_type lhs) { return static_cast<enum_type> ( ~static_cast<std::underlying_type<enum_type>::type>(lhs) ); } \ | |
| inline constexpr enum_type operator |=(enum_type& lhs, enum_type rhs) { lhs = static_cast<enum_type> ( static_cast<std::underlying_type<enum_type>::type>(lhs) | static_cast<std::underlying_type<enum_type>::type>(rhs) ); return lhs; } \ | |
| inline constexpr enum_type operator &=(enum_type& lhs, enum_type rhs) { lhs = static_cast<enum_type> ( static_cast<std::underlying_type<enum_type>::type>(lhs) & static_cast<std::underlying_type<enum_type>::type>(rhs) ); return lhs; } \ | |
| inline constexpr enum_type operator ^=(enum_type& lhs, enum_type rhs) { lhs = static_cast<enum_type> ( static_cast<std::underlying_type<enum_type>::type>(lhs) ^ static_cast<std::underlying_type<enum_type>::type>(rhs) ); return lhs; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment