there we go...
Code:
template<unsigned int number,unsigned int exponent> class Pow:
Pow<number,exponent-1>
{
public:
static const unsigned int value = Pow<number,exponent-1>::value*number;
};
template<unsigned int number> class Pow<number,1>
{
public:
static const unsigned int value = number;
};
template<unsigned int base,unsigned int number, bool numberGreaterThanBase=true>
class Log:
private Log<base, number/base, (number > base) >
{
static_assert(number>=base,"number must be greater than base");
public:
static const unsigned int value = 1+Log<base,number/base,(number>base)>::value;
static const bool isPerfectPower = Pow<value,base>::value == number;
};
template<unsigned int base,bool numberGreaterThanBase>
class Log<base,1,numberGreaterThanBase>
{
public:
static const unsigned int value=0;
};
template<unsigned int base>
class Log<base,0,false>
{
public:
static const unsigned int value=0;
};
template<unsigned int of,bool isPowerOfTwo>
class NextMultiple
{
public:
inline static unsigned int evaluate(unsigned int from)
{
return from ? ((from - 1) / of + 1) * of : of;
}
};
template<unsigned int of>
class NextMultiple<of,true>
{
public:
inline static unsigned int evaluate(unsigned int from)
{
return (from + of-1) & ~(of-1);
}
};
template<unsigned int of>inline static unsigned int nextMultiple(unsigned int from)
{
return NextMultiple<of,Log<2,of>::isPerfectPower>::evaluate(from);
}
thanks again all - good catch soma; i probably would have forgotten about that until well after investigating random segfaults.