-
Notifications
You must be signed in to change notification settings - Fork 553
Expand file tree
/
Copy pathhandle.h
More file actions
47 lines (37 loc) · 1.29 KB
/
handle.h
File metadata and controls
47 lines (37 loc) · 1.29 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
#ifndef SOVLESPACE_HANDLE_H
#define SOVLESPACE_HANDLE_H
#include <functional>
#include <type_traits>
namespace SolveSpace {
/// Trait indicating which types are handle types and should get the associated operators.
/// Specialize for each handle type and inherit from std::true_type.
template<class T>
struct IsHandleOracle : std::false_type {};
// Equality-compare any two instances of a handle type.
template<class T>
static inline typename std::enable_if<IsHandleOracle<T>::value, bool>::type
operator==(T const &lhs, T const &rhs) {
return lhs.v == rhs.v;
}
// Inequality-compare any two instances of a handle type.
template<class T>
static inline typename std::enable_if<IsHandleOracle<T>::value, bool>::type
operator!=(T const &lhs, T const &rhs) {
return !(lhs == rhs);
}
// Less-than-compare any two instances of a handle type.
template<class T>
static inline typename std::enable_if<IsHandleOracle<T>::value, bool>::type
operator<(T const &lhs, T const &rhs) {
return lhs.v < rhs.v;
}
template<class T>
struct HandleHasher {
static_assert(IsHandleOracle<T>::value, "Not a valid handle type");
inline size_t operator()(const T &h) const {
using Hasher = std::hash<decltype(T::v)>;
return Hasher{}(h.v);
}
};
} // namespace SolveSpace
#endif // !SOVLESPACE_HANDLE_H