This repository was archived by the owner on Jan 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathbitmask_operators.hpp
More file actions
70 lines (59 loc) · 2.5 KB
/
Copy pathbitmask_operators.hpp
File metadata and controls
70 lines (59 loc) · 2.5 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#pragma once
#include <type_traits>
namespace cppgit2 {
template <typename Enum> struct EnableBitMaskOperators {
static const bool enable = false;
};
template <typename Enum>
typename std::enable_if<EnableBitMaskOperators<Enum>::enable, Enum>::type
operator|(Enum lhs, Enum rhs) {
using underlying = typename std::underlying_type<Enum>::type;
return static_cast<Enum>(static_cast<underlying>(lhs) |
static_cast<underlying>(rhs));
}
template <typename Enum>
typename std::enable_if<EnableBitMaskOperators<Enum>::enable, Enum>::type
operator&(Enum lhs, Enum rhs) {
using underlying = typename std::underlying_type<Enum>::type;
return static_cast<Enum>(static_cast<underlying>(lhs) &
static_cast<underlying>(rhs));
}
template <typename Enum>
typename std::enable_if<EnableBitMaskOperators<Enum>::enable, Enum>::type
operator^(Enum lhs, Enum rhs) {
using underlying = typename std::underlying_type<Enum>::type;
return static_cast<Enum>(static_cast<underlying>(lhs) ^
static_cast<underlying>(rhs));
}
template <typename Enum>
typename std::enable_if<EnableBitMaskOperators<Enum>::enable, Enum>::type
operator~(Enum rhs) {
using underlying = typename std::underlying_type<Enum>::type;
return static_cast<Enum>(~static_cast<underlying>(rhs));
}
template <typename Enum>
typename std::enable_if<EnableBitMaskOperators<Enum>::enable, Enum>::type
operator|=(Enum &lhs, Enum rhs) {
using underlying = typename std::underlying_type<Enum>::type;
lhs = static_cast<Enum>(static_cast<underlying>(lhs) |
static_cast<underlying>(rhs));
}
template <typename Enum>
typename std::enable_if<EnableBitMaskOperators<Enum>::enable, Enum>::type
operator&=(Enum &lhs, Enum rhs) {
using underlying = typename std::underlying_type<Enum>::type;
lhs = static_cast<Enum>(static_cast<underlying>(lhs) &
static_cast<underlying>(rhs));
}
template <typename Enum>
typename std::enable_if<EnableBitMaskOperators<Enum>::enable, Enum>::type
operator^=(Enum &lhs, Enum rhs) {
using underlying = typename std::underlying_type<Enum>::type;
lhs = static_cast<Enum>(static_cast<underlying>(lhs) ^
static_cast<underlying>(rhs));
}
#define ENABLE_BITMASK_OPERATORS(x) \
template <> struct EnableBitMaskOperators<x> { \
static const bool enable = true; \
};
} // namespace cppgit2