Boost logo

Boost :

From: Bruno Lalande (bruno.lalande_at_[hidden])
Date: 2008-05-22 05:10:10


Hi,

I thought about something last night... since with the last
proposition, odd and even specializations are almost similar, it's
possible to simplify the code and remove the second template parameter
by doing this:

template <int N>
struct positive_power
{
    template <typename T>
    static typename tools::promote_args<T>::type result(T base)
    {
       return
       positive_power<N%2>::result(base)
           *positive_power<2>::result(
               positive_power<N/2>::result(base));
    }
};

At the cost of one additional template instantiation (power<0> will
always be instantiated) we get rid of the second parameter and have no
runtime evaluation, as advocated in the other thread.

Bruno


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