Andrei Alexandrescu wrote:
* Encode operators by compile-time strings. For example, instead of the plethora of opAdd, opMul, ..., we'd have this:

T opBinary(string op)(T rhs) { ... }

The string is "+", "*", etc. We need to design what happens with read-modify-write operators like "+=" (should they be dispatch to a different function? etc.) and also what happens with index-and-modify operators like "[]=", "[]+=" etc. Should we go with proxies? Absorb them in opBinary? Define another dedicated method? etc.

Andrei

What about pure, what about const?

Will we need to

pure T opBinary(string op)(T rhs) if (op == "+" || op == "-") {
  static if (op == "+") { /* ... */ }
  else static if (op == "-") { /* ... */ }
}
T opBinary(string op)(T rhs) if (op == "+=" || ...) {
  // more static if's
}

thereby duplicating every case?

Reply via email to