mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-10 23:17:27 +00:00
Merge pull request #3888 from bog-dan-ro/master
Define bit mask operators for scoped enums bitfields
This commit is contained in:
@@ -1485,6 +1485,35 @@ volatile __attribute__((weak)) const char *flatbuffer_version_string =
|
||||
|
||||
#endif // !defined(_WIN32) && !defined(__CYGWIN__)
|
||||
|
||||
#define DEFINE_BITMASK_OPERATORS(E)\
|
||||
inline E operator | (E lhs, E rhs){\
|
||||
using T = std::underlying_type<E>::type;\
|
||||
return E(T(lhs) | T(rhs));\
|
||||
}\
|
||||
inline E operator & (E lhs, E rhs){\
|
||||
using T = std::underlying_type<E>::type;\
|
||||
return E(T(lhs) & T(rhs));\
|
||||
}\
|
||||
inline E operator ^ (E lhs, E rhs){\
|
||||
using T = std::underlying_type<E>::type;\
|
||||
return E(T(lhs) ^ T(rhs));\
|
||||
}\
|
||||
inline E operator ~ (E lhs){\
|
||||
using T = std::underlying_type<E>::type;\
|
||||
return E(~T(lhs));\
|
||||
}\
|
||||
inline E operator |= (E &lhs, E rhs){\
|
||||
lhs = lhs | rhs;\
|
||||
return lhs;\
|
||||
}\
|
||||
inline E operator &= (E &lhs, E rhs){\
|
||||
lhs = lhs & rhs;\
|
||||
return lhs;\
|
||||
}\
|
||||
inline E operator ^= (E &lhs, E rhs){\
|
||||
lhs = lhs ^ rhs;\
|
||||
return lhs;\
|
||||
}
|
||||
/// @endcond
|
||||
} // namespace flatbuffers
|
||||
|
||||
|
||||
Reference in New Issue
Block a user