Boost logo

Boost :

From: Schrader, Glenn (gschrad_at_[hidden])
Date: 2008-05-22 08:34:54


I don't remember the following being suggested:

--ges

template<int N>
struct positive_power_increment;

template<>
struct positive_power_increment<1>
{
    template<typename T>
    static T result(T pow2, T base) {
        return pow2 * base;
    }
};

template <>
struct positive_power_increment<0>
{
    template<typename T>
    static T result(T pow2, T base) {
        return pow2;
    }
};

template<int N>
struct positive_power
{
    template <typename T>
    static T result(T base) {
        T val = positive_power<N/2>::result(base);
        return positive_power_increment<N%2>::result(val*val,base);
    }
};

template<>
struct positive_power<1>
{
    template <typename T>
    static T result(T base) {
        return base;
    }
};


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk