-
Notifications
You must be signed in to change notification settings - Fork 0
/
ml_pair.h
81 lines (60 loc) · 1.6 KB
/
ml_pair.h
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
71
72
73
74
75
76
77
78
79
80
81
/**
* @file ml_pair.h
* @brief
* @author malin [email protected]
* @date 2015年04月13日 星期一 10时48分03秒
* @version
* @note
*/
#ifndef __ML_INTERNAL_PAIR_H
#define __ML_INTERNAL_PAIR_H
__ML_BEGIN_NAMESPACE
template<typename T1, typename T2>
struct pair
{
pair() : first(T1()), second(T2()) {}
pair(const T1 &a, const T2 &b) : first(a), second(b) {}
template<typename U1, typename U2>
pair(const pair<U1, U2> &rhs) : first(rhs.first), second(rhs.second) {}
typedef T1 first_type;
typedef T2 second_type;
T1 first;
T2 second;
};
template<typename T1, typename T2>
inline bool operator == (const pair<T1, T2> &a, const pair<T1, T2> &b)
{
return a.first == b.first && a.second == b.second;
}
template<typename T1, typename T2>
inline bool operator != (const pair<T1, T2> &a, const pair<T1, T2> &b)
{
return !(a == b);
}
template<typename T1, typename T2>
inline bool operator < (const pair<T1, T2> &a, const pair<T1, T2> &b)
{
return a.first < b.first || !(b.first < a.first) && a.second < b.second;
}
template<typename T1, typename T2>
inline bool operator <= (const pair<T1, T2> &a, const pair<T1, T2> &b)
{
return !(b < a);
}
template<typename T1, typename T2>
inline bool operator > (const pair<T1, T2> &a, const pair<T1, T2> &b)
{
return !(a <= b);
}
template<typename T1, typename T2>
inline bool operator >= (const pair<T1, T2> &a, const pair<T1, T2> &b)
{
return !(a < b);
}
template<typename T1, typename T2>
inline pair<T1, T2> make_pair(const T1 &first, const T2 &second)
{
return pair<T1, T2>(first, second);
}
__ML_END_NAMESPACE
#endif //__ML_INTERNAL_PAIR_H