ladybird/AK/StdLib.h

68 lines
933 B
C
Raw Normal View History

#pragma once
#ifdef SERENITY_KERNEL
#include <Kernel/StdLib.h>
#else
#include <cstring>
#include <utility>
#endif
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);
}
template<typename T>
struct identity {
typedef T type;
};
template<class T>
constexpr T&& forward(typename identity<T>::type& param)
{
return static_cast<T&&>(param);
}
template<typename T, typename U>
T exchange(T& a, U&& b)
{
T tmp = move(a);
a = move(b);
return tmp;
}
}
using AK::min;
using AK::max;
using AK::move;
using AK::forward;
using AK::exchange;
using AK::ceilDiv;