Some strange parameter deduction problems in opOpAssign and opBinary
Ivan Agafonov
armadil at yandex.ru
Sat Sep 1 21:11:13 PDT 2012
There are 3 separated versions of opOpAssign
first version must be the same as the second for Vec!(sometype, 4)
why it doesn't work?
Simplified code:
struct Vec(T, uint size)
{
this(T rhs) { array[] = rhs; }
// It doesn't work but compiles
ref Vec!(T, size) opOpAssign(string op) (Vec!(T, size) rhs)
{
mixin("array[] "~op~"= rhs.array[];");
return this;
}
// but it work's
ref Vec!(T, 4) opOpAssign(string op) (Vec!(T, 4) rhs)
{
mixin("array[] "~op~"= rhs.array[];");
return this;
}
// and this work;s
ref Vec!(T, size) opAddAssign(Vec!(T, size) rhs)
{
array[] += rhs.array[];
return this;
}
T[size] array = 0;
}
int main()
{
auto z = Vec!(float, 4)(5.0f);
z += z;
writeln(z);
return 0;
}
More information about the Digitalmars-d-learn
mailing list