2018-10-10 09:53:07 +00:00
|
|
|
#pragma once
|
|
|
|
|
2018-10-16 11:59:28 +00:00
|
|
|
#ifdef SERENITY_KERNEL
|
|
|
|
#include <Kernel/StdLib.h>
|
|
|
|
#else
|
|
|
|
#include <cstring>
|
|
|
|
#include <utility>
|
|
|
|
#endif
|
|
|
|
|
2018-10-10 09:53:07 +00:00
|
|
|
namespace AK {
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
inline T min(const T& a, const T& b)
|
|
|
|
{
|
|
|
|
return a < b ? a : b;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
inline T max(const T& a, const T& b)
|
|
|
|
{
|
|
|
|
return a < b ? b : a;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
static inline T ceilDiv(T a, T b)
|
|
|
|
{
|
|
|
|
T result = a / b;
|
|
|
|
if ((a % b) != 0)
|
|
|
|
++result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-10-16 10:10:01 +00:00
|
|
|
template <typename T>
|
|
|
|
T&& move(T& arg)
|
|
|
|
{
|
|
|
|
return static_cast<T&&>(arg);
|
|
|
|
}
|
2018-10-10 09:53:07 +00:00
|
|
|
|
2018-10-16 10:20:51 +00:00
|
|
|
template<typename T>
|
|
|
|
struct identity {
|
|
|
|
typedef T type;
|
|
|
|
};
|
2018-10-16 11:59:28 +00:00
|
|
|
template<class T>
|
|
|
|
constexpr T&& forward(typename identity<T>::type& param)
|
2018-10-16 10:20:51 +00:00
|
|
|
{
|
2018-10-16 11:59:28 +00:00
|
|
|
return static_cast<T&&>(param);
|
2018-10-16 10:20:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T, typename U>
|
|
|
|
T exchange(T& a, U&& b)
|
|
|
|
{
|
|
|
|
T tmp = move(a);
|
|
|
|
a = move(b);
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
2018-10-16 12:33:16 +00:00
|
|
|
template<typename T, typename U>
|
|
|
|
void swap(T& a, U& b)
|
|
|
|
{
|
|
|
|
U tmp = move((U&)a);
|
|
|
|
a = (T&&)move(b);
|
|
|
|
b = move(tmp);
|
|
|
|
}
|
2018-10-16 10:20:51 +00:00
|
|
|
|
2018-10-10 09:53:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
using AK::min;
|
|
|
|
using AK::max;
|
2018-10-16 10:20:51 +00:00
|
|
|
using AK::move;
|
|
|
|
using AK::forward;
|
|
|
|
using AK::exchange;
|
2018-10-16 12:33:16 +00:00
|
|
|
using AK::swap;
|
2018-10-10 09:53:07 +00:00
|
|
|
using AK::ceilDiv;
|
|
|
|
|