-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpair.h
47 lines (37 loc) · 1.3 KB
/
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
#ifndef EXERCISE_II__PAIR_H_
#define EXERCISE_II__PAIR_H_
#include <utility>
#include <bits/unique_ptr.h>
#include "metaprogramming.h"
template<typename T, typename U>
struct Pair {
T first;
U second;
inline bool operator==(Pair<T, U> &rhs) {
return first == rhs.first && second == rhs.second;
}
inline bool operator<(Pair<T, U> &rhs) {
return first < rhs.first || (first == rhs.first && second < rhs.second);
}
inline bool operator>(Pair<T, U> &rhs) {
return first > rhs.first || (first == rhs.first && second > rhs.second);
}
inline bool operator<=(Pair<T, U> &rhs) {
return first <= rhs.first || (first == rhs.first && second <= rhs.second);
}
inline bool operator>=(Pair<T, U> &rhs) {
return first >= rhs.first || (first == rhs.first && second >= rhs.second);
}
inline bool operator!=(Pair<T, U> &rhs) {
return first != rhs.first || second != rhs.second;
}
};
template <typename T, typename U>
inline Pair<typename decay_and_strip<T>::Type, typename decay_and_strip<U>::Type>
make_pair(T &&first, U &&second) {
using DS_First = typename decay_and_strip<T>::Type;
using DS_Second = typename decay_and_strip<U>::Type;
using Pair_Type = Pair<DS_First, DS_Second>;
return Pair_Type{std::forward<T>(first), std::forward<U>(second)};
}
#endif //EXERCISE_II__PAIR_H_