blob: 4d4cf8fcfc969255b07ff5a1dc2f3dccb7ec852d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
#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));
}
|