Andrei Alexandrescu wrote:
opBinary does solve opIndex* morass because it only adds one function per category, not one function per operator. For example:

struct T {
    // op can be "=", "+=", "-=" etc.
    E opAssign(string op)(E rhs) { ... }
    // op can be "=", "+=", "-=" etc.
    E opIndexAssign(string op)(size_t i, E rhs) { ... }
}

I see, that makes sense now. It shouldn't be "+=", though (rather "+"), because it makes chaining harder.

Reply via email to