On 1/22/07, Sami <randomaccessiterator@gmail.com> wrote:
Hi All,

This is a newbie mpl question, and here goes:

How can evaluate integer powers using mpl? Such as,

template < unsigned Pow, class Real > Real pow( Real r )
{
   return <compile time r*r*r* ... r > ;
// the expression is compile time,
// not the result of course.

    if (Pow == 0) return 1; // to do argue about the value of '0 to the 0'.
    if (Pow == 1) return r;
    return pow<Pow - 1>(r) * r; 

}


Now, why do you want it - I doubt that it will buy you anything in terms of performance.


Tony