Files

49 lines
1.1 KiB
Plaintext
Raw Permalink Normal View History

2023-06-19 10:40:14 -04:00
#ifndef MSL_CPP_ALGORITHM_H
#define MSL_CPP_ALGORITHM_H
#include <iterator>
2021-07-28 13:01:11 -04:00
2023-12-14 12:41:41 -05:00
namespace std {
2022-01-31 19:06:41 -05:00
2023-12-14 12:41:41 -05:00
template <typename T> inline const T& max(const T& a, const T& b) {
return (a < b) ? b : a;
2021-07-28 13:01:11 -04:00
}
2023-12-14 12:41:41 -05:00
template <typename T> inline const T& min(const T& a, const T& b) {
return (b < a) ? b : a;
}
template <typename TPtr, typename T>
inline TPtr find(TPtr first, TPtr last, const T& value) {
while (first != last && *first != value) {
++first;
}
return first;
}
template <typename TPtr> inline long distance(TPtr first, TPtr last) {
random_access_iterator_tag tag;
return __distance(first, last, tag);
}
template <typename TPtr>
2024-09-07 17:38:05 -04:00
inline long __distance(TPtr first, TPtr last,
random_access_iterator_tag /* tag */) {
2023-12-14 12:41:41 -05:00
long dist = reinterpret_cast<long>(last) - reinterpret_cast<long>(first);
return dist / static_cast<long>(sizeof(TPtr));
}
2024-09-07 17:38:05 -04:00
template <typename T> inline T& move(T& x) {
return x;
}
2023-12-14 12:41:41 -05:00
template <typename T> inline void swap(T& a, T& b) {
T tmp = move(a);
a = move(b);
b = move(tmp);
}
} // namespace std
#endif