Iros
 
Loading...
Searching...
No Matches
bitwise_enum.h
Go to the documentation of this file.
1#pragma once
2
4
5#define DI_DEFINE_ENUM_BITWISE_OPERATIONS(Type) \
6 static_assert(::di::concepts::Enum<Type>); \
7 constexpr auto operator~(Type a)->Type { \
8 return static_cast<Type>(~::di::util::to_underlying(a)); \
9 } \
10 constexpr auto operator|(Type a, Type b)->Type { \
11 return static_cast<Type>(::di::util::to_underlying(a) | ::di::util::to_underlying(b)); \
12 } \
13 constexpr auto operator&(Type a, Type b)->Type { \
14 return static_cast<Type>(::di::util::to_underlying(a) & ::di::util::to_underlying(b)); \
15 } \
16 constexpr auto operator^(Type a, Type b)->Type { \
17 return static_cast<Type>(::di::util::to_underlying(a) ^ ::di::util::to_underlying(b)); \
18 } \
19 constexpr auto operator|=(Type& a, Type b)->Type& { \
20 return a = a | b; \
21 } \
22 constexpr auto operator&=(Type& a, Type b)->Type& { \
23 return a = a & b; \
24 } \
25 constexpr auto operator^=(Type& a, Type b)->Type& { \
26 return a = a ^ b; \
27 } \
28 constexpr auto operator!(Type a)->bool { \
29 return !::di::util::to_underlying(a); \
30 }