On Saturday, 4 April 2020 at 10:22:29 UTC, Robert M. Münch wrote:
D doesn't have implicit operators for structs?

struct S {float a, float b};
S a = {1, 5};
S b = {2, 5);

a += b;
Error: a is not a scalar, it is a S

So I really have to write an overloaded operator for such cases?

Probably I didn't understand what you mean. Sorry if this is not the case, but this one is easy.
...
struct S {
    float a;
    float b;

    S opOpAssign(string op)(ref S rhs) if (op == "+"){
        this.a += rhs.a;
        this.b += rhs.b;
        return this;
    }
}


void main()
{
    S a = {1, 5};
    S b = {2, 5};

    a += b;

    writeln(a);
}
...

Reply via email to