-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpair.h
More file actions
87 lines (70 loc) · 2.03 KB
/
pair.h
File metadata and controls
87 lines (70 loc) · 2.03 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#pragma once
#include <ostream>
namespace ft {
template<class T1, class T2>
struct pair {
typedef T1 first_type;
typedef T2 second_type;
T1 first;
T2 second;
pair() : first(), second() {}
template<class T, class U>
pair(const T &a, const U &b): first(a), second(b) {}
template<class T, class U>
pair &operator=(const pair<T, U> &other) {
if (*this != &other) {
first = other.first;
second = other.second;
}
return *this;
}
template<class T, class U>
pair(const pair<T, U> &other) : first(other.first), second(other.second) {
}
pair(const pair& p): first(p.first), second(p.second){};
bool operator==(const pair &rhs) const;
bool operator!=(const pair &rhs) const;
bool operator<(const pair &rhs) const;
bool operator>(const pair &rhs) const;
bool operator<=(const pair &rhs) const;
bool operator>=(const pair &rhs) const;
};
template<class T1, class T2>
bool pair<T1, T2>::operator<(const pair &rhs) const {
if (first < rhs.first)
return true;
if (rhs.first < first)
return false;
return second < rhs.second;
}
template<class T1, class T2>
bool pair<T1, T2>::operator>(const pair &rhs) const {
return rhs < *this;
}
template<class T1, class T2>
bool pair<T1, T2>::operator<=(const pair &rhs) const {
return !(rhs < *this);
}
template<class T1, class T2>
bool pair<T1, T2>::operator>=(const pair &rhs) const {
return !(*this < rhs);
}
template<class T1, class T2>
bool pair<T1, T2>::operator==(const pair &rhs) const {
return first == rhs.first &&
second == rhs.second;
}
template<class T1, class T2>
bool pair<T1, T2>::operator!=(const pair &rhs) const {
return !(rhs == *this);
}
template<class T1, class T2>
pair<T1, T2> make_pair(T1 t, T2 u) {
return pair<T1, T2>(t, u);
}
}
template<class T, class U>
std::ostream &operator<<(std::ostream &os, const ft::pair<T, U> &pair) {
os << "[ " << pair.first << " # " << pair.second << " ]";
return os;
}