Boost logo

Boost Users :

From: Gottlob Frege (gottlobfrege_at_[hidden])
Date: 2007-01-22 17:59:01


On 1/22/07, Sami <randomaccessiterator_at_[hidden]> 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



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net