|
253 | 253 |
|
254 | 254 | #define NBL_FOREACH(WHAT, ... ) NBL_EVAL(NBL_CONCATENATE(NBL_FOREACH_,NBL_VA_ARGS_COUNT(__VA_ARGS__))(WHAT, __VA_ARGS__))
|
255 | 255 |
|
| 256 | +#define NBL_ENUM_ADD_BITWISE_OPERATORS(EnumType) \ |
| 257 | + inline constexpr EnumType operator&(const EnumType& lhs, const EnumType& rhs) noexcept \ |
| 258 | + { \ |
| 259 | + using T = typename std::underlying_type_t<EnumType>; \ |
| 260 | + return static_cast<EnumType>(static_cast<T>(lhs) & static_cast<T>(rhs)); \ |
| 261 | + } \ |
| 262 | + \ |
| 263 | + inline constexpr EnumType& operator&=(EnumType& lhs, const EnumType& rhs) noexcept \ |
| 264 | + { \ |
| 265 | + return lhs = lhs & rhs; \ |
| 266 | + } \ |
| 267 | + \ |
| 268 | + inline constexpr EnumType operator|(const EnumType& lhs, const EnumType& rhs) noexcept \ |
| 269 | + { \ |
| 270 | + using T = typename std::underlying_type_t<EnumType>; \ |
| 271 | + return static_cast<EnumType>(static_cast<T>(lhs) | static_cast<T>(rhs)); \ |
| 272 | + } \ |
| 273 | + \ |
| 274 | + inline constexpr EnumType& operator|=(EnumType& lhs, const EnumType& rhs) noexcept \ |
| 275 | + { \ |
| 276 | + return lhs = lhs | rhs; \ |
| 277 | + } \ |
| 278 | + \ |
| 279 | + inline constexpr EnumType operator^(const EnumType& lhs, const EnumType& rhs) noexcept \ |
| 280 | + { \ |
| 281 | + using T = typename std::underlying_type_t<EnumType>; \ |
| 282 | + return static_cast<EnumType>(static_cast<T>(lhs) ^ static_cast<T>(rhs)); \ |
| 283 | + } \ |
| 284 | + \ |
| 285 | + inline constexpr EnumType& operator^=(EnumType& lhs, const EnumType& rhs) noexcept \ |
| 286 | + { \ |
| 287 | + return lhs = lhs ^ rhs; \ |
| 288 | + } \ |
| 289 | + \ |
| 290 | + inline constexpr EnumType& operator~(EnumType& e) noexcept \ |
| 291 | + { \ |
| 292 | + using T = typename std::underlying_type_t<EnumType>; \ |
| 293 | + return e = static_cast<EnumType>(~static_cast<T>(e)); \ |
| 294 | + } \ |
| 295 | + /**/ |
| 296 | + |
256 | 297 |
|
257 | 298 | #endif
|
0 commit comments