
Boost : 
From: Geoffrey Irving (irving_at_[hidden])
Date: 20060620 15:55:56
On Mon, Jun 19, 2006 at 08:30:00PM 0700, Frederick Akalin wrote:
>
> > Having rank also solves the following problem I was wondering about: how
> > do you define vector scalar multiplication in a sufficiently restrictive
> > way. Without a notion of rank, matrix * vector could be ambiguous with
> > scalar * vector since (matrix * x, matrix * y, matrix * z) would be a
> > valid
> > vector<matrix<T> >.
> >
> >
> Perhaps I'm horribly misunderstanding something, but wouldn't the fact
> that "matrix<T> * vector<T>" has to return "vector<T>" be enough to
> disambiguate it? Your example is implying that matrix<T> * vector<T>
> can somehow return vector<matrix<T> >.
Oops, left out the context.
If you want general support for units, but also want the vector classes
completely decoupled from units, you'll need to be able to multiply things
like matrix<float> * vector<length> or matrix<stress / area> * vector<area>.
You also want to be able to multiple a scalar with arbitrary units times
a vector to get another scalar. The scalar multiplication function will
look something like
template<class S,class T> vector<typeof(S*T>)>
operator*(const S& s,const vector<T>& v)
{
return vector<typeof(S*T)>(s*v.x,s*v.y,s*v.z);
}
but this function works perfectly well if you plug in S = matrix, so it
has to be restricted in some way.
Geoffrey
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk