Boost logo

Boost Users :

Subject: Re: [Boost-users] [math][tools][units] generic libraries not genericenough
From: Dave Abrahams (dave_at_[hidden])
Date: 2011-08-26 13:38:31


on Fri Aug 26 2011, Michael Fawcett <michael.fawcett-AT-gmail.com> wrote:

> I don't think it has to be a chicken and egg problem. If the math
> library says that it is generic it should support return types that
> are different from the input types IMHO.
>
> In the past I have implemented math libraries like so:
>
> template
> <
> typename X0, typename Y0, typename Z0,
> typename X1, typename Y1, typename Z1
>>
> BOOST_TYPEOF_TPL(X0() * X1() + Y0() * Y1() + Z0() * Z1())
> dot_product(const vector3<X0, Y0, Z0> &lhs, const vector3<X1, Y1, Z1>
> &rhs)
> {
> return lhs.x * rhs.x + lhs.y * rhs.y + lhs.z * rhs.z;
> }
>
> which admittedly is not *entirely* generic since it relies on the
> vector3 type and probably should have taken a generic tuple, but you
> can at least see how the result type gets computed.

What are the requirements you place on X0,X1,Y0,Y1,Z0,and Z1, and how do
you describe the result? Unless you can nail the semantics down, you
haven't written a generic algorithm.

-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net