From 5a6f8cac09770d315fe4a3258fa6116e65750f24 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Sun, 29 Jan 2023 21:33:34 -0500 Subject: first pass compile time optimization --- src/misc/bitwise.hpp | 38 ++++++++++++++++++++++++++++++++++++++ src/misc/is_optional.hpp | 9 +++++++++ 2 files changed, 47 insertions(+) create mode 100644 src/misc/bitwise.hpp create mode 100644 src/misc/is_optional.hpp (limited to 'src/misc') 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 + +template +struct Bitwise { + static const bool enable = false; +}; + +template +typename std::enable_if::enable, T>::type operator|(T a, T b) { + using x = typename std::underlying_type::type; + return static_cast(static_cast(a) | static_cast(b)); +} + +template +typename std::enable_if::enable, T>::type operator|=(T &a, T b) { + using x = typename std::underlying_type::type; + a = static_cast(static_cast(a) | static_cast(b)); + return a; +} + +template +typename std::enable_if::enable, T>::type operator&(T a, T b) { + using x = typename std::underlying_type::type; + return static_cast(static_cast(a) & static_cast(b)); +} + +template +typename std::enable_if::enable, T>::type operator&=(T &a, T b) { + using x = typename std::underlying_type::type; + a = static_cast(static_cast(a) & static_cast(b)); + return a; +} + +template +typename std::enable_if::enable, T>::type operator~(T a) { + return static_cast(~static_cast::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 +#include + +template +struct is_optional : std::false_type {}; + +template +struct is_optional> : std::true_type {}; -- cgit v1.2.3