|
Boost : |
From: Martin Bonner (Martin.Bonner_at_[hidden])
Date: 2008-02-05 05:58:47
----Original Message----
From: boost-bounces_at_[hidden]
[mailto:boost-bounces_at_[hidden]] On Behalf Of John Maddock Sent:
05 February 2008 10:26 To: boost_at_[hidden]
Subject: Re: [boost] [Boost] Compile-time power of a run-time base
> 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),
boost.units:
pow<3>( length )
is going to have units of volume.
>>> * 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
> 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?
... and I /believe/ that boost.units only needs half powers. So (modulu
units)
template<class T1, class T2, int N>
T2 pow<N,2>(T1 val) { return sqrt(pow<N>(val)); }
should do it.
... in fact, I suspect that boost.math pow should /only/ offer the
integral powers, and boost.units should wrap it to add the rational
support.
-- Martin Bonner Senior Software Engineer/Team Leader PI SHURLOK LTD Telephone: +44 1223 441434 / 203894 (direct) Fax: +44 1223 203999 Email: martin.bonner_at_[hidden] www.pi-shurlok.com disclaimer
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk