diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2023-02-07 15:03:03 -0500 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2023-02-07 15:03:03 -0500 |
commit | c1303bd289013a504b529f8f19444f12e4884040 (patch) | |
tree | 9318ba0b3b660264cba5c4a467b6f79cf80188e0 /src/misc/bitwise.hpp | |
parent | ea04035f0db8fa990dd7ca8dd1a64f56bceb82e2 (diff) | |
parent | 4dd0eb24c40a7276dea4fc349d885f4277795dcb (diff) | |
download | abaddon-portaudio-c1303bd289013a504b529f8f19444f12e4884040.tar.gz abaddon-portaudio-c1303bd289013a504b529f8f19444f12e4884040.zip |
Merge branch 'master' into voice
Diffstat (limited to 'src/misc/bitwise.hpp')
-rw-r--r-- | src/misc/bitwise.hpp | 38 |
1 files changed, 38 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)); +} |