|
Boost : |
From: John Maddock (john_at_[hidden])
Date: 2008-02-05 05:26:28
Bruno Lalande wrote:
>> * The result type is not necessarily going to be the same as the
>> arguments so it would need to use Boost.Typeof or some such.
>
>
> Yep, I had already thought about this improvement.
The only use case I can think of is where the argument is an integer rather
than a real number (and the result is therefore a double), if that's the
case then
typename boost::math::tools::promote_args<T>::type
would provide what's needed.
>> * Rational exponents need to work, so I would need a way to
>> specialize the function to work with
>> boost::units::static_rational. I would expect the customization
>> mechanism to look something like this:
>>
>> struct default_value_tag;
>>
>> template<class T>
>> struct pow_value_tag {
>> typedef default_value_tag tag;
>> };
>>
>> template<class Exp>
>> struct pow_exponent_tag {
>> typedef typename Exp::tag type;
>> };
>>
>> template<class ValueTag, class ExponentTag>
>> struct pow_impl;
>>
>> template<class Value, class Exponent>
>> struct pow {
>> typedef typename pow_impl<
>> typename pow_value_tag<Value>::type,
>> typename pow_exponent_tag<Exponent>::type
>> >::template apply<Value, Exponent> impl;
>> typedef typename impl::type type;
>> static type call(const Value& v) {
>> return(impl::call(v));
>> }
>> };
>>
>
> OK I will consider this need and find a way to satisfy it.
>
> I'm going to write a first version of tests and docs with the
> implementation we have for now, and then I'll add those additional
> functionalities.
I'm a bit concerned about this interface: my guess is that 90% or more of
users would just want integer exponents, and these should be very easy to
use, preferably simply:
pow<2>(val)
Hmmm, I wonder if we can define an overload such that:
pow<2,3>(val)
is also valid?
Regards, John.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk