
Boost : 
From: Leland Brown (lelandbrown_at_[hidden])
Date: 20060609 00:07:17
Michael Fawcett <michael.fawcett <at> gmail.com> writes:
>
> Contrived example using theoretical code:
>
> // Multiply accumulate (Is there a simpler way?)
> template
> <
> typename X, typename Y, typename Z,
> typename VX, typename VY, typename VZ
> >
> struct macc
> {
> // X * VX + Y * VY + Z * VZ
> typedef typename boost::result_of_multiplies<X, VX>::type x_times_x;
> typedef typename boost::result_of_multiplies<Y, VY>::type y_times_y;
> typedef typename boost::result_of_multiplies<Z, VZ>::type z_times_z;
> typedef typename boost::result_of_plus<y_times_y, z_times_z>::type
> y_times_y_plus_z_times_z;
> typedef typename boost::result_of_plus<x_times_x,
> y_times_y_plus_z_times_z>::type x_plus_y_plus_z;
> typedef x_plus_y_plus_z type;
> };
>
> template
> <
> typename X, typename Y, typename Z,
> typename VX, typename VY, typename VZ
> >
> typename macc<X, Y, Z, VX, VY, VZ>::type
> dot_product(const vec3<X, Y, Z> &lhs, const vec3<VX, VY, VZ> &rhs)
> {
> return lhs.x * rhs.x + lhs.y * rhs.y + lhs.z * rhs.z;
> }
Yes, surely a matrix library written like this could do the trick for PQS. But
it has its limitations too  see my other comment below.
> This would require the math library be more heavily templated than it
> currently is. Note that a matrix would need to hold mutliple types
> (up to NxN). For instance, what would be the syntax for a 3D
> transform? Perhaps something like:
>
> matrix4x4
> <
> float, float, float, length,
> float, float, float, length,
> float, float, float, length,
> length, length, length, float
> > m;
But consider the following situation (which, though it may sound contrived, is
pretty similar to what came up in my real application), Suppose I have a
compiletime constant like
const int NUM_OF_ITEMS = 5;
And I need a vector containing 3 dimensionless quantities, a time, and
NUM_OF_ITEMS length values. And then I need a scaling matrix for that! Yes,
the value "5" is known a priori, and I could write out the whole 10x10
transform. But I've defined NUM_OF_ITEMS as a symbolic constant because it's
subject to change. Next month I find out we have 7 items instead of 5. I'd
like it to be a singlepoint code change:
const int NUM_OF_ITEMS = 7;
Can I get the compiler to generate the 12x12 matrix definition for me? I bet
it's theoretically possible with template metaprogramming, but I doubt it would
be worth anybody's time to implement such a monster.
This is the point where I threw up my hands and accepted that I was going to
need the t3_quantity.
 Leland
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk