-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools.hpp
186 lines (168 loc) · 3.83 KB
/
tools.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#pragma once
#include <iostream>
#include "iterator_traits.hpp"
namespace ft
{
template <class T, T v>
struct integral_constant
{
static const T value = v;
typedef T value_type;
typedef integral_constant type;
};
template <typename T>
struct is_integral : integral_constant<bool, false>
{
};
template <>
struct is_integral<bool> : integral_constant<bool, true>
{
};
template <>
struct is_integral<char> : integral_constant<bool, true>
{
};
template <>
struct is_integral<char16_t> : integral_constant<bool, true>
{
};
template <>
struct is_integral<char32_t> : integral_constant<bool, true>
{
};
template <>
struct is_integral<wchar_t> : integral_constant<bool, true>
{
};
template <>
struct is_integral<short> : integral_constant<bool, true>
{
};
template <>
struct is_integral<int> : integral_constant<bool, true>
{
};
template <>
struct is_integral<long> : integral_constant<bool, true>
{
};
template <>
struct is_integral<long long> : integral_constant<bool, true>
{
};
template <bool, typename T = void>
struct enable_if
{
};
template <typename T>
struct enable_if<true, T>
{
typedef T type;
};
template <class InputIterator1, class InputIterator2>
bool lexicographical_compare(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2)
{
while (first1 != last1 && first2 != last2)
if (*first1 < *first2)
return true;
else if (*first2 < *first1)
return false;
else
++first1, ++first2;
return first1 == last1 && first2 != last2;
}
template <class InputIt1, class InputIt2>
bool equal(InputIt1 first1, InputIt1 last1, InputIt2 first2)
{
while (first1 != last1)
if (*first1 != *first2)
return false;
else
++first1, ++first2;
return true;
}
template <class InputIt1,
class InputIt2,
class BinaryPredicate>
bool equal(InputIt1 first1,
InputIt1 last1, InputIt2 first2, BinaryPredicate p)
{
while (first1 != last1)
if (!p(*first1, *first2))
return false;
else
++first1, ++first2;
return true;
}
template <class InputIterator1, class InputIterator2, class Compare>
bool lexicographical_compare(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, Compare comp)
{
while (first1 != last1 && first2 != last2)
if (comp(*first1, *first2))
return true;
else if (comp(*first2, *first1))
return false;
else
++first1, ++first2;
return first1 == last1 && first2 != last2;
}
template <typename T, typename B>
class pair
{
public:
T first;
B second;
pair() : first(T()), second(B())
{
}
template <class U, class V>
pair(const pair<U, V> &pr) : first(pr.first), second(pr.second)
{
}
pair(const T &a, const B &b): first(a), second(b)
{
}
pair &operator=(const pair &pr)
{
first = pr.first;
second = pr.second;
return *this;
}
};
// PAIR NON MEMBER FUNCTIONS //
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 || (!(rhs.first < lhs.first) && lhs.second < rhs.second);
}
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);
}
template <class T1, class T2>
pair<T1, T2> make_pair(T1 x, T2 y)
{
return (pair<T1, T2>(x, y));
}
}