diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2023-01-29 21:33:34 -0500 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2023-01-29 21:33:34 -0500 |
commit | 5a6f8cac09770d315fe4a3258fa6116e65750f24 (patch) | |
tree | d74c5407e4ba9b11700666ce1eed0c94984ae14a /src/misc | |
parent | ff47134dc64ac2f0fa7bfee64313b2522709b9b9 (diff) | |
download | abaddon-portaudio-5a6f8cac09770d315fe4a3258fa6116e65750f24.tar.gz abaddon-portaudio-5a6f8cac09770d315fe4a3258fa6116e65750f24.zip |
first pass compile time optimization
Diffstat (limited to 'src/misc')
-rw-r--r-- | src/misc/bitwise.hpp | 38 | ||||
-rw-r--r-- | src/misc/is_optional.hpp | 9 |
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 {}; |