22 May 11:10
Re: [math] pow redux and observations
Bruno Lalande <bruno.lalande <at> gmail.com>
2008-05-22 09:10:10 GMT
2008-05-22 09:10:10 GMT
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
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
RSS Feed