BLI: improve enum operators

* Use unsigned integer types for bit operations.
* Use 64 bit integer instead of 32 bit.
* Support scoped enumes (aka `enum class`) by adding some more casts.
This commit is contained in:
Jacques Lucke 2021-06-28 13:10:48 +02:00
parent 2dbb492268
commit f7e2559fd6
1 changed files with 6 additions and 5 deletions

View File

@ -788,23 +788,24 @@ extern bool BLI_memory_is_zero(const void *arr, const size_t arr_size);
extern "C++" { \
inline constexpr _enum_type operator|(_enum_type a, _enum_type b) \
{ \
return static_cast<_enum_type>(static_cast<int>(a) | b); \
return static_cast<_enum_type>(static_cast<uint64_t>(a) | static_cast<uint64_t>(b)); \
} \
inline constexpr _enum_type operator&(_enum_type a, _enum_type b) \
{ \
return static_cast<_enum_type>(static_cast<int>(a) & b); \
return static_cast<_enum_type>(static_cast<uint64_t>(a) & static_cast<uint64_t>(b)); \
} \
inline constexpr _enum_type operator~(_enum_type a) \
{ \
return static_cast<_enum_type>(~static_cast<int>(a) & (2 * _max_enum_value - 1)); \
return static_cast<_enum_type>(~static_cast<uint64_t>(a) & \
(2 * static_cast<uint64_t>(_max_enum_value) - 1)); \
} \
inline _enum_type &operator|=(_enum_type &a, _enum_type b) \
{ \
return a = static_cast<_enum_type>(static_cast<int>(a) | b); \
return a = static_cast<_enum_type>(static_cast<uint64_t>(a) | static_cast<uint64_t>(b)); \
} \
inline _enum_type &operator&=(_enum_type &a, _enum_type b) \
{ \
return a = static_cast<_enum_type>(static_cast<int>(a) & b); \
return a = static_cast<_enum_type>(static_cast<uint64_t>(a) & static_cast<uint64_t>(b)); \
} \
} /* extern "C++" */