Error: array operation d1[] + d2[] without assignment not implemented

deed via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Sep 13 07:18:54 PDT 2014


struct Vector (T)
{
   T[]arr;
   void opSliceAssign (T[] a) { arr[] = a[]; }
}
unittest
{
   auto v = Vector!double([1, 2]);
   double[] d1 = [11, 12];
   double[] d2 = [21, 22];
   double[] d3 = new double[](2);
   d3[] = d1[] + d2[];
   assert (d3 == [11.+21., 12.+22.]);
   assert (is(typeof(d1[] + d2[]) == double[]));
   v[] = d1[]          // Fine
   v[] = d1[] + d2[];  // Error: array operation d1[] + d2[] 
without assignment not implemented
}

How can opSliceAssign be defined to make this work?


More information about the Digitalmars-d-learn mailing list