Why D const is annoying

Mehrdad wfunction at hotmail.com
Sat Dec 10 11:44:18 PST 2011


On 12/10/2011 11:43 AM, Mehrdad wrote:
> 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; }

BTW this _DOES_ look like another issue related to const.

Oh and the error is
annoy.d(12): Error: cannot uniquely infer foreach argument types
Assertion failure: '0' on line 144 in file 'statement.c'


More information about the Digitalmars-d mailing list