Why D const is annoying

Mehrdad wfunction at hotmail.com
Sat Dec 10 11:43:50 PST 2011


Oh, nice, here's an ICE for y'all :)


struct Matrix(T)
{
     @property T[] data() { return null; }

     int opApply(scope int delegate(ref size_t[], ref T) dg) { return 0; }
     int opApply(scope int delegate(ref const(size_t[]), ref const(T)) 
dg) const { return 0; }

     Matrix!(typeof(mixin("data[0] " ~ op ~ " data[0]"))) 
opBinary(string op)(Matrix other)
     {
         auto result = typeof(return)();
         foreach (i, ref val; this)
         { mixin("result[i] = val " ~ op ~ " other[i];"); }
         return result;
     }
}

void main() { auto m = Matrix!size_t(); m = m * m; }


More information about the Digitalmars-d mailing list