indigoX
enum_class_bitwise.hpp
Go to the documentation of this file.
1 #include <type_traits>
2 
3 #ifndef INDIGOX_UTILS_ENUM_CLASS_BITWISE_HPP
4 #define INDIGOX_UTILS_ENUM_CLASS_BITWISE_HPP
5 
6 #define BITWISE_OPERATORS(enum_type) \
7  inline enum_type operator|(enum_type l, enum_type r) { \
8  using T = std::underlying_type_t<enum_type>; \
9  return static_cast<enum_type>(static_cast<T>(l) | static_cast<T>(r)); \
10  } \
11  inline enum_type &operator|=(enum_type &l, enum_type r) { \
12  using T = std::underlying_type_t<enum_type>; \
13  l = static_cast<enum_type>(static_cast<T>(l) | static_cast<T>(r)); \
14  return l; \
15  } \
16  inline enum_type operator&(enum_type l, enum_type r) { \
17  using T = std::underlying_type_t<enum_type>; \
18  return static_cast<enum_type>(static_cast<T>(l) & static_cast<T>(r)); \
19  } \
20  inline enum_type &operator&=(enum_type &l, enum_type r) { \
21  using T = std::underlying_type_t<enum_type>; \
22  l = static_cast<enum_type>(static_cast<T>(l) & static_cast<T>(r)); \
23  return l; \
24  }
25 
26 #endif /* INDIGOX_UTILS_ENUM_CLASS_BITWISE_HPP */