Cross product template

Diggory diggsey at googlemail.com
Tue May 14 18:31:40 PDT 2013


I have a vector struct, Vector(T, uint N) templated on the type T 
and number of components, N. I'm trying to write a function 
"cross" which will calculate the cross product of a number of 
vectors.

For a given number of components, N, the cross function should 
take N-1 arguments, each one a Vector!(?, N) and will return a 
vector perpendicular to the vectors passed in. The ? means the 
type is free to be anything.

The problem is that however I try to write it, the template 
argument deduction isn't powerful enough to work out which 
instantiation to use.

I thought something like this would work to deduce the parameters 
and then I could use constraints to enforce the other rules, but 
no:
auto cross(T, N, U...)(Vector!(T, N) a, U b) { return 0; }


More information about the Digitalmars-d-learn mailing list