summaryrefslogtreecommitdiff
path: root/src/misc
diff options
context:
space:
mode:
Diffstat (limited to 'src/misc')
-rw-r--r--src/misc/bitwise.hpp38
-rw-r--r--src/misc/is_optional.hpp9
2 files changed, 47 insertions, 0 deletions
diff --git a/src/misc/bitwise.hpp b/src/misc/bitwise.hpp
new file mode 100644
index 0000000..ecce333
--- /dev/null
+++ b/src/misc/bitwise.hpp
@@ -0,0 +1,38 @@
+#pragma once
+#include <type_traits>
+
+template<typename T>
+struct Bitwise {
+ static const bool enable = false;
+};
+
+template<typename T>
+typename std::enable_if<Bitwise<T>::enable, T>::type operator|(T a, T b) {
+ using x = typename std::underlying_type<T>::type;
+ return static_cast<T>(static_cast<x>(a) | static_cast<x>(b));
+}
+
+template<typename T>
+typename std::enable_if<Bitwise<T>::enable, T>::type operator|=(T &a, T b) {
+ using x = typename std::underlying_type<T>::type;
+ a = static_cast<T>(static_cast<x>(a) | static_cast<x>(b));
+ return a;
+}
+
+template<typename T>
+typename std::enable_if<Bitwise<T>::enable, T>::type operator&(T a, T b) {
+ using x = typename std::underlying_type<T>::type;
+ return static_cast<T>(static_cast<x>(a) & static_cast<x>(b));
+}
+
+template<typename T>
+typename std::enable_if<Bitwise<T>::enable, T>::type operator&=(T &a, T b) {
+ using x = typename std::underlying_type<T>::type;
+ a = static_cast<T>(static_cast<x>(a) & static_cast<x>(b));
+ return a;
+}
+
+template<typename T>
+typename std::enable_if<Bitwise<T>::enable, T>::type operator~(T a) {
+ return static_cast<T>(~static_cast<typename std::underlying_type<T>::type>(a));
+}
diff --git a/src/misc/is_optional.hpp b/src/misc/is_optional.hpp
new file mode 100644
index 0000000..2c7c973
--- /dev/null
+++ b/src/misc/is_optional.hpp
@@ -0,0 +1,9 @@
+#pragma once
+#include <optional>
+#include <type_traits>
+
+template<typename T>
+struct is_optional : std::false_type {};
+
+template<typename T>
+struct is_optional<std::optional<T>> : std::true_type {};