
22 May
2008
22 May
'08
9:10 a.m.
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