32 #ifndef HERMES_COMMON_BITMASK_OPERATORS_H
33 #define HERMES_COMMON_BITMASK_OPERATORS_H
35 #include <type_traits>
58 #define HERMES_ENABLE_BITMASK_OPERATORS(x) \
60 struct EnableBitMaskOperators<x> \
62 static const bool enable = true; \
84 #define HERMES_MASK_BIT(MASK, BIT) (((MASK) & (BIT)) == (BIT))
88 template<
typename Enum>
98 template<
typename Enum>
100 typename std::enable_if<EnableBitMaskOperators<Enum>::enable, Enum>::type
103 using underlying =
typename std::underlying_type<Enum>::type;
104 return static_cast<Enum
> (
105 static_cast<underlying
>(lhs) |
106 static_cast<underlying
>(rhs)
115 template<
typename Enum>
117 typename std::enable_if<EnableBitMaskOperators<Enum>::enable, Enum>::type
120 using underlying =
typename std::underlying_type<Enum>::type;
121 return static_cast<Enum
> (
122 static_cast<underlying
>(lhs) &
123 static_cast<underlying
>(rhs)
132 template<
typename Enum>
134 typename std::enable_if<EnableBitMaskOperators<Enum>::enable, Enum>::type
136 using underlying =
typename std::underlying_type<Enum>::type;
137 return static_cast<Enum
> (
138 static_cast<underlying
>(lhs) ^
139 static_cast<underlying
>(rhs)
147 template<
typename Enum>
149 typename std::enable_if<EnableBitMaskOperators<Enum>::enable, Enum>::type
152 using underlying =
typename std::underlying_type<Enum>::type;
153 return static_cast<Enum
> (
154 ~static_cast<underlying>(rhs)
HERMES_DEVICE_CALLABLE std::enable_if< EnableBitMaskOperators< Enum >::enable, Enum >::type operator^(Enum lhs, Enum rhs)
adds ^ operation support
Definition: bitmask_operators.h:135
HERMES_DEVICE_CALLABLE std::enable_if< EnableBitMaskOperators< Enum >::enable, Enum >::type operator&(Enum lhs, Enum rhs)
Definition: bitmask_operators.h:118
HERMES_DEVICE_CALLABLE std::enable_if< EnableBitMaskOperators< Enum >::enable, Enum >::type operator|(Enum lhs, Enum rhs) noexcept
Definition: bitmask_operators.h:101
HERMES_DEVICE_CALLABLE std::enable_if< EnableBitMaskOperators< Enum >::enable, Enum >::type operator~(Enum rhs)
adds ~ operation support
Definition: bitmask_operators.h:150
#define HERMES_DEVICE_CALLABLE
Specifies that the function can be called from both host and device sides.
Definition: defs.h:45
Wrapper struct to add bitwise operations to enum class.
Definition: bitmask_operators.h:89
static const bool enable
enable flag
Definition: bitmask_operators.h:90