forked from managarm/cxxshim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalgorithm
75 lines (63 loc) · 1.32 KB
/
algorithm
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
#ifndef _CXXSHIM_ALGORITHM
#define _CXXSHIM_ALGORITHM
#include <initializer_list>
namespace std {
template<typename T>
const T &min(const T &a, const T &b) {
return (b < a) ? b : a;
}
template<typename T>
const T &max(const T &a, const T &b) {
return (a < b) ? b : a;
}
template <typename T>
constexpr T min(std::initializer_list<T> list) {
auto it = list.begin();
T x = *it;
++it;
while(it != list.end()) {
if (*it < x)
x = *it;
++it;
}
return x;
}
template <typename T>
constexpr T max(std::initializer_list<T> list) {
auto it = list.begin();
T x = *it;
++it;
while(it != list.end()) {
if (*it > x)
x = *it;
++it;
}
return x;
}
template<typename It, typename T>
It find(It begin, It end, const T &value) {
for(auto it = begin; it != end; ++it)
if(*it == value)
return it;
return end;
}
template<typename It, typename Pred>
It find_if(It begin, It end, Pred p) {
for(auto it = begin; it != end; ++it)
if(p(*it))
return it;
return end;
}
template<typename InIt, typename OutIt>
OutIt copy(InIt begin, InIt end, OutIt d_first) {
while (begin != end)
*d_first++ = *begin++;
return d_first;
}
template<class OutputIt, class Size, class T>
void fill_n(OutputIt first, Size count, const T &value) {
for (Size i = 0; i < count; i++)
*first++ = value;
}
} // namespace std
#endif // _CXXSHIM_ALGORITHM