Cross product template
Simen Kjaeraas
simen.kjaras at gmail.com
Tue May 14 23:26:11 PDT 2013
On Wed, 15 May 2013 03:31:40 +0200, Diggory <diggsey at googlemail.com> wrote:
> 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; }
auto cross(T, uint N, U...)(Vector!(T,N) a, U b) { return 0; }
Oughta work.
--
Simen
More information about the Digitalmars-d-learn
mailing list