|
Mbed OS Reference
|
Loading...
Searching...
No Matches
17#ifndef MBED_SCOPED_ENUM_FLAGS_H
18#define MBED_SCOPED_ENUM_FLAGS_H
22#define ENUM_FLAG_BITWISE_OPERATOR(T, OP) \
23inline constexpr T operator OP(T lhs, T rhs) \
25 return T (static_cast<std::underlying_type_t<T>>(lhs) OP \
26 static_cast<std::underlying_type_t<T>>(rhs)); \
30#define ENUM_FLAG_COMPOUND_ASSIGNMENT_OPERATOR(T, OP) \
31inline constexpr T &operator OP(T &lhs, T rhs) \
33 return lhs = lhs OP rhs; \
69#define MBED_ENUM_FLAG_APPLY_OPERATORS(T) \
70 inline constexpr T operator ~(T lhs) \
72 return T(~static_cast<std::underlying_type_t<T>>(lhs)); \
74 ENUM_FLAG_BITWISE_OPERATOR(T, |) \
75 ENUM_FLAG_BITWISE_OPERATOR(T, ^) \
76 ENUM_FLAG_BITWISE_OPERATOR(T, &) \
77 ENUM_FLAG_COMPOUND_ASSIGNMENT_OPERATOR(T, |=) \
78 ENUM_FLAG_COMPOUND_ASSIGNMENT_OPERATOR(T, ^=) \
79 ENUM_FLAG_COMPOUND_ASSIGNMENT_OPERATOR(T, &=) \
80 static_assert(true, "This assert true is to require a semicolon to terminate the macro.") \
89#define SCOPED_ENUM_FLAGS_TYPED(T, UNDERLYING_T) \
90 enum class T : UNDERLYING_T; \
91 MBED_ENUM_FLAG_APPLY_OPERATORS(T); \
92 enum class T : UNDERLYING_T
100#define SCOPED_ENUM_FLAGS_UNTYPED(T) \
102 MBED_ENUM_FLAG_APPLY_OPERATORS(T); \
105#define MBED_SCOPED_ENUM_FLAGS_CHOOSER(_1, _2, NAME, ...) NAME
165#define MBED_SCOPED_ENUM_FLAGS(...) MBED_SCOPED_ENUM_FLAGS_CHOOSER(__VA_ARGS__, SCOPED_ENUM_FLAGS_TYPED, SCOPED_ENUM_FLAGS_UNTYPED)(__VA_ARGS__)