From a6f095c01e93090e185afd0d9f26bf4565a552ed Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 4 May 2018 11:51:47 +0200 Subject: compat, logic/pipeline: add bitwise enum operators --- compat/enum-operators.hpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 compat/enum-operators.hpp (limited to 'compat') diff --git a/compat/enum-operators.hpp b/compat/enum-operators.hpp new file mode 100644 index 00000000..e956c461 --- /dev/null +++ b/compat/enum-operators.hpp @@ -0,0 +1,28 @@ +#pragma once + +#include + +#define OTR_FLAGS_OP2(type, op) \ + inline type operator op (type a, type b) \ + { \ + using t__ = std::underlying_type_t; \ + return static_cast(t__((a)) op t__((b))); \ + } // end + +#define OTR_FLAGS_SHIFT(type, op) \ + type operator op (type, unsigned) = delete; + +#define OTR_FLAGS_OP1(type, op) \ + inline type operator op (type x) \ + { \ + using t__ = std::underlying_type_t; \ + return static_cast(t__((x))); \ + } // 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 -- cgit v1.2.3