template<uint TValue>
struct bit_to_bytes
{
static const uint value = TValue >> 3;
};
template<uint TValue>
struct byte_to_bits
{
static const uint value = TValue << 3;
};
template<int TValue>
struct power2
{
static const uint value = 1 << TValue;
};
namespace detail
{
template<uint TValue, bool = TValue != 1>
struct log2_helper
{
static const int value = 1 + log2<(TValue >> 1)>::value;
};
template<uint TValue>
struct log2_helper<TValue, false>
{
static const int value = 0;
};
}
template<uint TValue>
struct log2
{
static const int value = detail::log2_helper<TValue>::value;
};
template<uint TValue>
struct is_power2
{
static const bool value = TValue == power2<log2<TValue>::value>::value;
};
namespace detail
{
template<uint TValue, bool = is_power2<TValue>::value>
struct floor2_helper
{
static const uint value = power2<log2<TValue>::value>::value;
};
template<uint TValue>
struct floor2_helper<TValue, false>
{
static const uint value = power2<1 + log2<TValue>::value>::value;
};
}
template<uint TValue>
struct floor2
{
static const uint value = detail::floor2_helper<TValue>::value;
};
template<uint TValue, int TAlign>
struct alignment
{
static const uint value = (TValue + TAlign - 1) / TAlign * TAlign;
};