Why D const is annoying

Timon Gehr timon.gehr at gmx.ch
Sat Dec 10 02:51:03 PST 2011


On 12/10/2011 11:34 AM, Mehrdad wrote:
> ... and another...
>
> struct Matrix(T, size_t N = 1)
> { public auto mul(Matrix!(T, N) other) const { return this; } }
>
> void main()
> {
> Matrix!(int, 2) m;
> m.mul(m);
> }
>
> annoy.d(7): Error: function annoy.Matrix!(int,2).Matrix.mul
> (Matrix!(int,N) other) const is not callable using argument types
> (Matrix!(int,2))
> annoy.d(7): Error: cannot implicitly convert expression (m) of type
> Matrix!(int,2) to Matrix!(int,N)

Again, unrelated to const. This works:

struct Matrix(T, size_t N = 1)
{ public auto mul(Matrix other) const { return this; } }

void main()
{
     Matrix!(int, 2) m;
     m.mul(m);
}

But it seems to be a bug indeed, because this compiles:

struct Matrix(T, size_t N = 1)
{ public auto mul(Matrix!(T, 2) other) const { return this; } }

void main()
{
     Matrix!(int, 2) m;
     m.mul(m);
}


More information about the Digitalmars-d mailing list