KeyWrapper.h
1.1 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
#pragma once
template<class T>
struct KeyWrapper
{
typedef T wrapped_type;
typedef KeyWrapper<T> self_type;
enum KeyTypeEnum { KeyType_Normal, KeyType_Empty, KeyType_Deleted };
KeyTypeEnum type;
T key;
KeyWrapper() : type(KeyType_Normal), key(T()) {}
KeyWrapper(KeyTypeEnum type_) : type(type_), key(T()) {}
KeyWrapper(const T& key_) : key(key_), type(KeyType_Normal) {}
KeyWrapper(const self_type& other) : type(other.type), key(other.key) {}
operator const T&() const { return key; }
bool isNormal() const { return (type == KeyType_Normal); }
template<typename KeyComparer>
struct EqualsComparer
{
EqualsComparer(KeyComparer keyComparer) :
m_KeyComparer(keyComparer)
{
}
bool operator()(const KeyWrapper<T>& left, const KeyWrapper<T>& right) const
{
if (left.type != right.type)
return false;
if (!left.isNormal())
return true;
return m_KeyComparer(left.key, right.key);
}
private:
KeyComparer m_KeyComparer;
};
};