Hello,

I am trying to understand the template mechanism in D, but I don't get it 
working.

I want to compute the dot product as follows:
        int[] a = [1, 2, 3];
        int[] b = [5, 6, 7];

        double dd = ???.dot_product( a, b );

with classes like this:
class DotProduct(DIM, T)
{
        static T result(T a, T b)
        {
                return a * b + DotProduct!(DIM-1, T).result(a+1, b+1);
        }
}

class DotProduct(1, T)
{
        static T result(T a, T b)
        {
                return a * b;
        }
}

and a function :
T dot_product(DIM a, T b)
{
  return ???.result( a, b );
}

Can anyone help me? In C++ its not the problem but with D I can't
get it working.

Thanks,
Andreas

Reply via email to