-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpair.hpp
108 lines (90 loc) · 2.68 KB
/
pair.hpp
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pair.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: alyasar <alyasar@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/02 21:53:36 by alyasar #+# #+# */
/* Updated: 2023/01/09 15:58:11 by alyasar ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef PAIR_HPP
# define PAIR_HPP
namespace ft
{
template<class T1, class T2>
struct pair
{
/* --------------- TYPEDEFS --------------- */
typedef T1 first_type;
typedef T2 second_type;
/* --------------- MEMBER OBJECTS --------------- */
first_type first;
second_type second;
/* --------------- CONSTRUCTORS --------------- */
pair()
: first(first_type()), second(second_type())
{
}
pair(const first_type &f, const second_type &s)
: first(f), second(s)
{
}
template<class U1, class U2>
pair(const pair<U1, U2> &p)
: first(p.first), second(p.second)
{
}
pair(const pair &other)
: first(other.first), second(other.second)
{
}
pair &operator=(const pair &other)
{
if (*this != other)
{
first = other.first;
second = other.second;
}
return (*this);
}
};
/* --------------- NON-MEMBER FUNCTIONS FOR PAIR --------------- */
template<class T1, class T2>
pair<T1, T2> make_pair(T1 t, T2 u)
{
return (pair<T1, T2>(t, u));
}
template<class T1, class T2>
bool operator==(const pair<T1, T2> &lhs, const pair<T1, T2> &rhs)
{
return (lhs.first == rhs.first && lhs.second == rhs.second);
}
template<class T1, class T2>
bool operator!=(const pair<T1, T2> &lhs, const pair<T1, T2> &rhs)
{
return (!(lhs == rhs));
}
template<class T1, class T2>
bool operator<(const pair<T1, T2> &lhs, const pair<T1, T2> &rhs)
{
return ((lhs.first < rhs.first) || (lhs.first == rhs.first && lhs.second < rhs.second)); // BURA YANLIS OLABILIR BELKI
}
template<class T1, class T2>
bool operator>(const pair<T1, T2> &lhs, const pair<T1, T2> &rhs)
{
return (rhs < lhs);
}
template<class T1, class T2>
bool operator<=(const pair<T1, T2> &lhs, const pair<T1, T2> &rhs)
{
return (!(rhs < lhs));
}
template<class T1, class T2>
bool operator>=(const pair<T1, T2> &lhs, const pair<T1, T2> &rhs)
{
return (!(lhs < rhs));
}
}
#endif