18 #ifndef COMMON_ENUM_FLAGS_H 19 #define COMMON_ENUM_FLAGS_H 56 template<
typename T>
struct enum_flags_type {};
61 #define DEF_ENUM_FLAGS_TYPE(enum_type, flags_type) \ 62 typedef enum_flags<enum_type> flags_type; \ 64 struct enum_flags_type<enum_type> \ 66 typedef enum_flags<enum_type> type; \ 71 template<
int size,
bool sign>
class integer_for_size {
typedef void type; };
72 template<>
struct integer_for_size<1, 0> {
typedef uint8_t
type; };
73 template<>
struct integer_for_size<2, 0> {
typedef uint16_t
type; };
74 template<>
struct integer_for_size<4, 0> {
typedef uint32_t
type; };
75 template<>
struct integer_for_size<8, 0> {
typedef uint64_t
type; };
76 template<>
struct integer_for_size<1, 1> {
typedef int8_t
type; };
77 template<>
struct integer_for_size<2, 1> {
typedef int16_t
type; };
78 template<>
struct integer_for_size<4, 1> {
typedef int32_t
type; };
79 template<>
struct integer_for_size<8, 1> {
typedef int64_t
type; };
82 struct enum_underlying_type
85 integer_for_size<sizeof (T), static_cast<bool>(T (-1) < T (0))>::
type 112 underlying_value ()
const 120 : m_enum_value ((enum_type) 0)
125 enum_flags (enum_type e)
128 enum_flags (
struct enum_flags::zero_type *zero)
129 : m_enum_value ((enum_type) 0)
132 enum_flags &operator&= (enum_type e)
134 m_enum_value = (enum_type) (underlying_value () & e);
137 enum_flags &operator|= (enum_type e)
139 m_enum_value = (enum_type) (underlying_value () | e);
142 enum_flags &operator^= (enum_type e)
144 m_enum_value = (enum_type) (underlying_value () ^ e);
148 operator enum_type ()
const 155 return (enum_type) (underlying_value () & e);
157 enum_flags operator| (enum_type e)
const 159 return (enum_type) (underlying_value () | e);
161 enum_flags operator^ (enum_type e)
const 163 return (enum_type) (underlying_value () ^ e);
165 enum_flags operator~ ()
const 167 return (enum_type) ~underlying_value ();
173 enum_type m_enum_value;
178 template <
typename enum_type>
182 return enum_flags<enum_type> (e1) & e2;
185 template <
typename enum_type>
187 operator| (enum_type e1, enum_type e2)
189 return enum_flags<enum_type> (e1) | e2;
192 template <
typename enum_type>
194 operator^ (enum_type e1, enum_type e2)
196 return enum_flags<enum_type> (e1) ^ e2;
199 template <
typename enum_type>
201 operator~ (enum_type e)
203 return ~enum_flags<enum_type> (e);
210 #define DEF_ENUM_FLAGS_TYPE(enum_type, flags_type) \ 211 typedef enum_type flags_type
void * operator &(const value_type &)=delete