-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.hpp
More file actions
286 lines (252 loc) · 5.29 KB
/
utils.hpp
File metadata and controls
286 lines (252 loc) · 5.29 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
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: davidzh <davidzh@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/07/19 02:33:41 by tyamcha #+# #+# */
/* Updated: 2022/09/11 19:43:22 by davidzh ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef UTILS_HPP
# define UTILS_HPP
# include <memory>
# include <iostream>
# include <cstddef>
# include <limits>
namespace ft
{
template <typename T>
void
swap(T& a, T& b)
{
T c;
c = a;
a = b;
b = c;
}
template <typename T>
inline const T&
max(const T& a, const T& b)
{
if (a < b)
return (b);
return (a);
}
template <typename T>
inline bool
itcmp (const T& lhs, const T& rhs)
{
if (lhs.size() != rhs.size())
return (false);
typedef typename T::const_iterator const_iterator;
const_iterator it1;
const_iterator it2;
const_iterator end1;
const_iterator end2;
it1 = lhs.begin();
it2 = rhs.begin();
end1 = lhs.end();
end2 = rhs.end();
if (it1 == it2 && end1 == end2)
return (true);
while (it1 != end1 && it2 != end2 && *it1 == *it2)
{
it1++;
it2++;
}
return (*it1 == *it2);
}
template <typename IT1, typename IT2>
inline bool
itcmp (IT1 first1, IT1 last1, IT2 first2)
{
while (first1 != last1 && *first1 == *first2)
{
first1++;
first2++;
}
return (*first1 == *first2);
}
template <typename T>
inline bool
itinf (const T& lhs, const T& rhs)
{
typedef typename T::const_iterator const_iterator;
const_iterator it1;
const_iterator it2;
it1 = lhs.begin();
it2 = rhs.begin();
while (it1 != lhs.end())
{
if (it2 == rhs.end() || *it2 < *it1)
return (false);
else if (*it1 < *it2)
return (true);
++it1;
++it2;
}
return (it2 != rhs.end());
}
template <class InputIterator1, class InputIterator2>
bool itinf (InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2)
{
while (first1 != last1)
{
if (first2 == last2 || (*first2) < (*first1))
return (false);
else if ((*first1) < (*first2))
return (true);
++first1;
++first2;
}
return (first2 != last2);
}
template<typename Arg1, typename Arg2, typename Result>
struct binary_function
{
typedef Arg1 first_argument_type;
typedef Arg2 second_argument_type;
typedef Result result_type;
};
template <typename Arg, typename Result>
struct unary_function
{
typedef Arg argument_type;
typedef Result result_type;
};
template<typename T>
struct _Identity
: public unary_function<T, T>
{
T&
operator() (T& x) const
{
return (x);
}
const T&
operator() (const T& x) const
{
return (x);
}
};
template <typename P>
struct _Select1st
: public unary_function<P, typename P::first_type>
{
typename P::first_type&
operator()(P& x) const
{
return (x.first);
}
const typename P::first_type&
operator()(const P& x) const
{
return (x.first);
}
};
template<typename T>
struct less
: public binary_function<T, T, bool>
{
bool
operator() (const T& x, const T& y) const
{
return (x < y);
}
};
struct true_type {};
struct false_type {};
template<typename _Tp>
struct is_integer
{
enum { value = 0 };
typedef false_type type;
};
template<>
struct is_integer<bool>
{
enum { value = 1 };
typedef true_type type;
};
template<>
struct is_integer<char>
{
enum { value = 1 };
typedef true_type type;
};
template<>
struct is_integer<signed char>
{
enum { value = 1 };
typedef true_type type;
};
template<>
struct is_integer<unsigned char>
{
enum { value = 1 };
typedef true_type type;
};
template<>
struct is_integer<short>
{
enum { value = 1 };
typedef true_type type;
};
template<>
struct is_integer<unsigned short>
{
enum { value = 1 };
typedef true_type type;
};
template<>
struct is_integer<int>
{
enum { value = 1 };
typedef true_type type;
};
template<>
struct is_integer<unsigned int>
{
enum { value = 1 };
typedef true_type type;
};
template<>
struct is_integer<long>
{
enum { value = 1 };
typedef true_type type;
};
template<>
struct is_integer<unsigned long>
{
enum { value = 1 };
typedef true_type type;
};
template<>
struct is_integer<long long>
{
enum { value = 1 };
typedef true_type type;
};
template<>
struct is_integer<unsigned long long>
{
enum { value = 1 };
typedef true_type type;
};
}
# include "iterator.hpp"
# include "pair.hpp"
# include "binary_tree.hpp"
# include "list.hpp"
# include "vector.hpp"
# include "map.hpp"
# include "stack.hpp"
# include "queue.hpp"
# include "set.hpp"
# include "multiset.hpp"
# include "multimap.hpp"
#endif