-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.hpp
93 lines (81 loc) · 2.54 KB
/
utils.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
#ifndef UTILS_HPP
#define UTILS_HPP
namespace ft {
template <typename T>
struct remove_const {
typedef T type;
};
template <typename T>
struct remove_const<const T> {
typedef T type;
};
template <bool cond, typename result=void>
struct enable_if {
};
template <typename result>
struct enable_if<true, result> {
typedef result type;// = result;
};
template <typename T, T val> struct is_integral_base {
static const T value = val;
};
typedef is_integral_base<bool, true> true_type;
typedef is_integral_base<bool, false> false_type;
template <typename T> struct is_integral : public false_type {};
template <> struct is_integral<bool> : true_type {};
template <> struct is_integral<char> : true_type {};
template <> struct is_integral<wchar_t> : true_type {};
template <> struct is_integral<signed char> : true_type {};
template <> struct is_integral<short int> : true_type {};
template <> struct is_integral<int> : true_type {};
template <> struct is_integral<long int> : true_type {};
template <> struct is_integral<long long int > : true_type {};
template <> struct is_integral<unsigned char> : true_type {};
template <> struct is_integral<unsigned short int> : true_type {};
template <> struct is_integral<unsigned int> : true_type {};
template <> struct is_integral<unsigned long int> : true_type {};
template <> struct is_integral<unsigned long long int> : true_type {};
template <class InputIterator1, class InputIterator2>
bool equal(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2) {
while (first1 != last1) {
if (!(*first1 == *first2))
return false;
++first1;
++first2;
}
return true;
};
template <class InputIterator1, class InputIterator2>
bool lexicographical_compare(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 <class InputIterator1, class InputIterator2, class Compare>
bool lexicographical_compare(InputIterator1 first1,
InputIterator1 last1,
InputIterator2 first2,
InputIterator2 last2,
Compare comp) {
while (first1 != last1) {
if (first2 == last2 || comp(*first2, *first1))
return false;
else if (comp(*first1, *first2))
return true;
++first1;
++first2;
}
return (first2 != last2);
};
};
#endif