mirror of
https://github.com/uowuo/abaddon.git
synced 2026-08-15 05:19:58 +00:00
46 lines
1.3 KiB
C++
46 lines
1.3 KiB
C++
#pragma once
|
|
#include <type_traits>
|
|
|
|
namespace util {
|
|
template<typename T>
|
|
bool FlagSet(T flags, T value) {
|
|
return (flags & value) == value;
|
|
}
|
|
} // namespace util
|
|
|
|
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));
|
|
}
|