summaryrefslogtreecommitdiffhomepage
path: root/compat/enum-operators.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'compat/enum-operators.hpp')
-rw-r--r--compat/enum-operators.hpp33
1 files changed, 25 insertions, 8 deletions
diff --git a/compat/enum-operators.hpp b/compat/enum-operators.hpp
index dc39f2f1..188a081d 100644
--- a/compat/enum-operators.hpp
+++ b/compat/enum-operators.hpp
@@ -5,24 +5,41 @@
#define OTR_FLAGS_OP2(type, op) \
inline type operator op (type a, type b) \
{ \
- using t__ = std::underlying_type_t<type>; \
- return static_cast<type>(t__((a)) op t__((b))); \
+ using t_ = std::underlying_type_t<type>; \
+ return type(t_((a)) op t_((b))); \
} // end
-#define OTR_FLAGS_SHIFT(type, op) \
- type operator op (type, unsigned) = delete
+#define OTR_FLAGS_DELETE_SHIFT(type, op) \
+ template<typename u> \
+ type operator op (type, u) = delete // end
#define OTR_FLAGS_OP1(type, op) \
inline type operator op (type x) \
{ \
- using t__ = std::underlying_type_t<type>; \
- return static_cast<type>(t__((x))); \
+ using t_ = std::underlying_type_t<type>; \
+ return type(op t_((x))); \
} // end
+#define OTR_FLAGS_ASSIGN_OP(type, op) \
+ inline type& operator op ## = (type& lhs, type rhs) \
+ { \
+ using t_ = std::underlying_type_t<decltype(rhs)>; \
+ lhs = type(t_((lhs)) op t_((rhs))); \
+ return lhs; \
+ } //end
+
+#define OTR_FLAGS_DELETE_SHIFT_ASSIGN(type, op) \
+ type operator op ## = (type& lhs, type rhs) = delete //end
+
#define DEFINE_ENUM_OPERATORS(type) \
OTR_FLAGS_OP2(type, |) \
OTR_FLAGS_OP2(type, &) \
OTR_FLAGS_OP2(type, ^) \
OTR_FLAGS_OP1(type, ~) \
- OTR_FLAGS_SHIFT(type, <<); \
- OTR_FLAGS_SHIFT(type, >>) // end
+ OTR_FLAGS_DELETE_SHIFT(type, <<); \
+ OTR_FLAGS_DELETE_SHIFT(type, >>); \
+ OTR_FLAGS_ASSIGN_OP(type, |) \
+ OTR_FLAGS_ASSIGN_OP(type, &) \
+ OTR_FLAGS_ASSIGN_OP(type, ^) \
+ OTR_FLAGS_DELETE_SHIFT_ASSIGN(type, <<); \
+ OTR_FLAGS_DELETE_SHIFT_ASSIGN(type, >>) // end